Organized imports
[phpeclipse.git] / net.sourceforge.phpeclipse.xml.ui / src / net / sourceforge / phpeclipse / xml / ui / text / XMLTextTools.java
1 /*
2  * Copyright (c) 2002-2004 Widespace, OU and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     Igor Malinin - initial contribution
10  *
11  * $Id: XMLTextTools.java,v 1.2 2005-05-06 00:55:41 stefanbjarni Exp $
12  */
13
14 package net.sourceforge.phpeclipse.xml.ui.text;
15
16 import java.util.Map;
17
18 import net.sourceforge.phpeclipse.ui.text.AbstractTextTools;
19 import net.sourceforge.phpeclipse.xml.ui.internal.text.DeclScanner;
20 import net.sourceforge.phpeclipse.xml.ui.internal.text.SingleTokenScanner;
21 import net.sourceforge.phpeclipse.xml.ui.internal.text.TextScanner;
22 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLCDATAScanner;
23 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
24 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLTagScanner;
25
26 import org.eclipse.jface.preference.IPreferenceStore;
27 import org.eclipse.jface.text.IDocumentPartitioner;
28 import org.eclipse.jface.text.rules.DefaultPartitioner;
29 import org.eclipse.jface.text.rules.IPartitionTokenScanner;
30 import org.eclipse.jface.text.rules.ITokenScanner;
31 import org.eclipse.jface.text.rules.RuleBasedScanner;
32
33
34 /**
35  * 
36  * 
37  * @author Igor Malinin
38  */
39 public class XMLTextTools extends AbstractTextTools {
40         /** Text Attributes for XML editors */
41         public static final String[] TOKENS = {
42                 IXMLSyntaxConstants.XML_DEFAULT,
43                 IXMLSyntaxConstants.XML_TAG,
44                 IXMLSyntaxConstants.XML_ATT_NAME,
45                 IXMLSyntaxConstants.XML_ATT_VALUE,
46                 IXMLSyntaxConstants.XML_ENTITY,
47                 IXMLSyntaxConstants.XML_PI,
48                 IXMLSyntaxConstants.XML_CDATA,
49                 IXMLSyntaxConstants.XML_COMMENT,
50                 IXMLSyntaxConstants.XML_SMARTY,
51                 IXMLSyntaxConstants.XML_DECL,
52         };
53
54         /** Content types for XML editors */
55         public static final String[] TYPES = {
56                 XMLPartitionScanner.XML_PI,
57                 XMLPartitionScanner.XML_COMMENT,
58                 XMLPartitionScanner.XML_DECL,
59                 XMLPartitionScanner.XML_TAG,
60                 XMLPartitionScanner.XML_ATTRIBUTE,
61                 XMLPartitionScanner.XML_CDATA,
62                 XMLPartitionScanner.DTD_INTERNAL,
63                 XMLPartitionScanner.DTD_INTERNAL_PI,
64                 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
65                 XMLPartitionScanner.DTD_INTERNAL_DECL,
66         };
67
68         /** The XML partitions scanner */
69         private XMLPartitionScanner xmlPartitionScanner;
70
71         /** The XML text scanner */
72         private TextScanner xmlTextScanner;
73
74         /** The DTD text scanner */
75         private TextScanner dtdTextScanner;
76
77         /** The XML tags scanner */
78         private XMLTagScanner xmlTagScanner;
79
80         /** The XML attributes scanner */
81         private TextScanner xmlAttributeScanner;
82
83         /** The XML CDATA sections scanner */
84         private XMLCDATAScanner xmlCDATAScanner;
85
86         /** The XML processing instructions scanner */
87         private SingleTokenScanner xmlPIScanner;
88
89         /** The XML comments scanner */ 
90         private SingleTokenScanner xmlCommentScanner;
91
92         /** The XML declarations scanner */
93         private DeclScanner xmlDeclScanner;
94         public XMLTextTools( IPreferenceStore store ) {
95                 this( store, TOKENS );
96         }
97         /**
98          * Creates a new XML text tools collection.
99          */
100         public XMLTextTools( IPreferenceStore store, String[] strTokens ) {
101                 super( store, strTokens );
102
103                 xmlPartitionScanner = new XMLPartitionScanner( false );
104
105                 Map tokens = getTokens();
106
107                 xmlTextScanner = new TextScanner(
108                         tokens, '&', IXMLSyntaxConstants.XML_DEFAULT );
109
110                 dtdTextScanner = new TextScanner(
111                         tokens, '%', IXMLSyntaxConstants.XML_DEFAULT );
112
113                 xmlPIScanner = new SingleTokenScanner(
114                                 tokens, IXMLSyntaxConstants.XML_PI );
115
116                 xmlCommentScanner = new SingleTokenScanner(
117                                 tokens, IXMLSyntaxConstants.XML_COMMENT );
118
119                 xmlDeclScanner = new DeclScanner( tokens );
120
121                 xmlTagScanner = new XMLTagScanner( tokens );
122
123                 xmlAttributeScanner = new TextScanner(
124                         tokens, '&', IXMLSyntaxConstants.XML_ATT_VALUE );
125
126                 xmlCDATAScanner = new XMLCDATAScanner( tokens );
127         }
128
129         /**
130          * 
131          */
132         public IDocumentPartitioner createXMLPartitioner() {
133                 return new DefaultPartitioner( xmlPartitionScanner, TYPES );
134         }
135
136         /**
137          * 
138          */
139         public IPartitionTokenScanner getXMLPartitionScanner() {
140                 return xmlPartitionScanner;
141         }
142
143         /**
144          * Returns a scanner which is configured to scan XML text.
145          * 
146          * @return  an XML text scanner
147          */
148         public RuleBasedScanner getXMLTextScanner() {
149                 return xmlTextScanner;
150         }
151
152         /**
153          * Returns a scanner which is configured to scan DTD text.
154          * 
155          * @return  an DTD text scanner
156          */
157         public RuleBasedScanner getDTDTextScanner() {
158                 return dtdTextScanner;
159         }
160
161         /**
162          * Returns a scanner which is configured to scan XML tags.
163          * 
164          * @return  an XML tag scanner
165          */
166         public RuleBasedScanner getXMLTagScanner() {
167                 return xmlTagScanner;
168         }
169
170         /**
171          * Returns a scanner which is configured to scan XML tag attributes.
172          * 
173          * @return  an XML tag attribute scanner
174          */
175         public RuleBasedScanner getXMLAttributeScanner() {
176                 return xmlAttributeScanner;
177         }
178
179         /**
180          * Returns a scanner which is configured to scan XML CDATA sections.
181          * 
182          * @return  an XML CDATA section scanner
183          */
184         public ITokenScanner getXMLCDATAScanner() {
185                 return xmlCDATAScanner;
186         }
187
188         /**
189          * Returns a scanner which is configured to scan XML
190          * processing instructions.
191          * 
192          * @return  an XML processing instruction scanner
193          */
194         public RuleBasedScanner getXMLPIScanner() {
195                 return xmlPIScanner;
196         }
197
198         /**
199          * Returns a scanner which is configured to scan XML comments.
200          * 
201          * @return  an XML comment scanner
202          */
203         public RuleBasedScanner getXMLCommentScanner() {
204                 return xmlCommentScanner;
205         }
206
207         /**
208          * Returns a scanner which is configured to scan XML declarations.
209          * 
210          * @return  an XML declaration scanner
211          */
212         public RuleBasedScanner getXMLDeclScanner() {
213                 return xmlDeclScanner;
214         }
215 }