Fixed Bug<a href="http://sourceforge.net/tracker/?func=detail&atid=484801&aid=1145683...
[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.3 2005-05-15 23:23:02 axelcl 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.PHPXMLPartitionScanner;
21 import net.sourceforge.phpeclipse.xml.ui.internal.text.SingleTokenScanner;
22 import net.sourceforge.phpeclipse.xml.ui.internal.text.TextScanner;
23 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLCDATAScanner;
24 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
25 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLTagScanner;
26
27 import org.eclipse.jface.preference.IPreferenceStore;
28 import org.eclipse.jface.text.IDocumentPartitioner;
29 import org.eclipse.jface.text.rules.DefaultPartitioner;
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         private PHPXMLPartitionScanner phpXMLPartitionScanner;
72         /** The XML text scanner */
73         private TextScanner xmlTextScanner;
74
75         /** The DTD text scanner */
76         private TextScanner dtdTextScanner;
77
78         /** The XML tags scanner */
79         private XMLTagScanner xmlTagScanner;
80
81         /** The XML attributes scanner */
82         private TextScanner xmlAttributeScanner;
83
84         /** The XML CDATA sections scanner */
85         private XMLCDATAScanner xmlCDATAScanner;
86
87         /** The XML processing instructions scanner */
88         private SingleTokenScanner xmlPIScanner;
89
90         /** The XML comments scanner */ 
91         private SingleTokenScanner xmlCommentScanner;
92
93         /** The XML declarations scanner */
94         private DeclScanner xmlDeclScanner;
95         public XMLTextTools( IPreferenceStore store ) {
96                 this( store, TOKENS );
97         }
98         /**
99          * Creates a new XML text tools collection.
100          */
101         public XMLTextTools( IPreferenceStore store, String[] strTokens ) {
102                 super( store, strTokens );
103
104                 xmlPartitionScanner = new XMLPartitionScanner( false );
105                 phpXMLPartitionScanner = new PHPXMLPartitionScanner( false );
106                 Map tokens = getTokens();
107
108                 xmlTextScanner = new TextScanner(
109                         tokens, '&', IXMLSyntaxConstants.XML_DEFAULT );
110
111                 dtdTextScanner = new TextScanner(
112                         tokens, '%', IXMLSyntaxConstants.XML_DEFAULT );
113
114                 xmlPIScanner = new SingleTokenScanner(
115                                 tokens, IXMLSyntaxConstants.XML_PI );
116
117                 xmlCommentScanner = new SingleTokenScanner(
118                                 tokens, IXMLSyntaxConstants.XML_COMMENT );
119
120                 xmlDeclScanner = new DeclScanner( tokens );
121
122                 xmlTagScanner = new XMLTagScanner( tokens );
123
124                 xmlAttributeScanner = new TextScanner(
125                         tokens, '&', IXMLSyntaxConstants.XML_ATT_VALUE );
126
127                 xmlCDATAScanner = new XMLCDATAScanner( tokens );
128         }
129
130         /**
131          * 
132          */
133         public IDocumentPartitioner createXMLPartitioner() {
134                 return new DefaultPartitioner( xmlPartitionScanner, TYPES );
135         }
136
137         public IDocumentPartitioner createPHPXMLPartitioner() {
138                 return new DefaultPartitioner( phpXMLPartitionScanner, TYPES );
139         }
140         
141         /**
142          * 
143          */
144 //      public IPartitionTokenScanner getXMLPartitionScanner() {
145 //              return xmlPartitionScanner;
146 //      }
147
148         /**
149          * Returns a scanner which is configured to scan XML text.
150          * 
151          * @return  an XML text scanner
152          */
153         public RuleBasedScanner getXMLTextScanner() {
154                 return xmlTextScanner;
155         }
156
157         /**
158          * Returns a scanner which is configured to scan DTD text.
159          * 
160          * @return  an DTD text scanner
161          */
162         public RuleBasedScanner getDTDTextScanner() {
163                 return dtdTextScanner;
164         }
165
166         /**
167          * Returns a scanner which is configured to scan XML tags.
168          * 
169          * @return  an XML tag scanner
170          */
171         public RuleBasedScanner getXMLTagScanner() {
172                 return xmlTagScanner;
173         }
174
175         /**
176          * Returns a scanner which is configured to scan XML tag attributes.
177          * 
178          * @return  an XML tag attribute scanner
179          */
180         public RuleBasedScanner getXMLAttributeScanner() {
181                 return xmlAttributeScanner;
182         }
183
184         /**
185          * Returns a scanner which is configured to scan XML CDATA sections.
186          * 
187          * @return  an XML CDATA section scanner
188          */
189         public ITokenScanner getXMLCDATAScanner() {
190                 return xmlCDATAScanner;
191         }
192
193         /**
194          * Returns a scanner which is configured to scan XML
195          * processing instructions.
196          * 
197          * @return  an XML processing instruction scanner
198          */
199         public RuleBasedScanner getXMLPIScanner() {
200                 return xmlPIScanner;
201         }
202
203         /**
204          * Returns a scanner which is configured to scan XML comments.
205          * 
206          * @return  an XML comment scanner
207          */
208         public RuleBasedScanner getXMLCommentScanner() {
209                 return xmlCommentScanner;
210         }
211
212         /**
213          * Returns a scanner which is configured to scan XML declarations.
214          * 
215          * @return  an XML declaration scanner
216          */
217         public RuleBasedScanner getXMLDeclScanner() {
218                 return xmlDeclScanner;
219         }
220 }