Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 2f689c4af46aeda9f4c246dc4b47a9b3ae4cd57e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*******************************************************************************
 * Copyright (c) 2004, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.css.core.internal.formatter;

import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;


/**
 * 
 */
public class CSSSourceFormatterFactory {
	/**
	 * 
	 */
	private CSSSourceFormatterFactory() {
		super();
	}

	/**
	 * 
	 */
	public CSSSourceGenerator getSourceFormatter(INodeNotifier target) {
		ICSSNode node = (ICSSNode) target;
		short type = node.getNodeType();
		switch (type) {
			case ICSSNode.CHARSETRULE_NODE :
				return CharsetRuleFormatter.getInstance();
			case ICSSNode.FONTFACERULE_NODE :
				return FontFaceRuleFormatter.getInstance();
			case ICSSNode.IMPORTRULE_NODE :
				return ImportRuleFormatter.getInstance();
			case ICSSNode.MEDIALIST_NODE :
				return MediaListFormatter.getInstance();
			case ICSSNode.MEDIARULE_NODE :
				return MediaRuleFormatter.getInstance();
			case ICSSNode.PRIMITIVEVALUE_NODE :
				ICSSPrimitiveValue value = (ICSSPrimitiveValue) node;
				if (value.getPrimitiveType() == org.w3c.dom.css.CSSPrimitiveValue.CSS_COUNTER)
					return CounterFormatter.getInstance();
				else if (value.getPrimitiveType() == org.w3c.dom.css.CSSPrimitiveValue.CSS_RECT)
					return RectFormatter.getInstance();
				else if (value.getPrimitiveType() == org.w3c.dom.css.CSSPrimitiveValue.CSS_RGBCOLOR)
					return RGBFormatter.getInstance();
				else
					return PrimitiveValueFormatter.getInstance();
			case ICSSNode.PAGERULE_NODE :
				return PageRuleFormatter.getInstance();
			case ICSSNode.STYLEDECLARATION_NODE :
				return StyleDeclarationFormatter.getInstance();
			case ICSSNode.STYLEDECLITEM_NODE :
				return StyleDeclItemFormatter.getInstance();
			case ICSSNode.STYLERULE_NODE :
				return StyleRuleFormatter.getInstance();
			case ICSSNode.STYLESHEET_NODE :
				return StyleSheetFormatter.getInstance();
			case ICSSNode.ATTR_NODE :
				return AttrFormatter.getInstance();
			default :
				return UnknownRuleFormatter.getInstance();
		}
	}

	public synchronized static CSSSourceFormatterFactory getInstance() {
		if (fInstance == null) {
			fInstance = new CSSSourceFormatterFactory();
		}
		return fInstance;
	}

	private static CSSSourceFormatterFactory fInstance;
}

Back to the top