5c6d32b240008275a5b75fb34c6cd4bccc91ec07
[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.4 2006-10-21 23:14:13 pombredanne 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  * @author Igor Malinin
37  */
38 public class XMLTextTools extends AbstractTextTools {
39         /** Text Attributes for XML editors */
40         public static final String[] TOKENS = { IXMLSyntaxConstants.XML_DEFAULT,
41                         IXMLSyntaxConstants.XML_TAG, IXMLSyntaxConstants.XML_ATT_NAME,
42                         IXMLSyntaxConstants.XML_ATT_VALUE, IXMLSyntaxConstants.XML_ENTITY,
43                         IXMLSyntaxConstants.XML_PI, IXMLSyntaxConstants.XML_CDATA,
44                         IXMLSyntaxConstants.XML_COMMENT, IXMLSyntaxConstants.XML_SMARTY,
45                         IXMLSyntaxConstants.XML_DECL, };
46
47         /** Content types for XML editors */
48         public static final String[] TYPES = { XMLPartitionScanner.XML_PI,
49                         XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
50                         XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE,
51                         XMLPartitionScanner.XML_CDATA, XMLPartitionScanner.DTD_INTERNAL,
52                         XMLPartitionScanner.DTD_INTERNAL_PI,
53                         XMLPartitionScanner.DTD_INTERNAL_COMMENT,
54                         XMLPartitionScanner.DTD_INTERNAL_DECL, };
55
56         /** The XML partitions scanner */
57         private XMLPartitionScanner xmlPartitionScanner;
58
59         private PHPXMLPartitionScanner phpXMLPartitionScanner;
60
61         /** The XML text scanner */
62         private TextScanner xmlTextScanner;
63
64         /** The DTD text scanner */
65         private TextScanner dtdTextScanner;
66
67         /** The XML tags scanner */
68         private XMLTagScanner xmlTagScanner;
69
70         /** The XML attributes scanner */
71         private TextScanner xmlAttributeScanner;
72
73         /** The XML CDATA sections scanner */
74         private XMLCDATAScanner xmlCDATAScanner;
75
76         /** The XML processing instructions scanner */
77         private SingleTokenScanner xmlPIScanner;
78
79         /** The XML comments scanner */
80         private SingleTokenScanner xmlCommentScanner;
81
82         /** The XML declarations scanner */
83         private DeclScanner xmlDeclScanner;
84
85         public XMLTextTools(IPreferenceStore store) {
86                 this(store, TOKENS);
87         }
88
89         /**
90          * Creates a new XML text tools collection.
91          */
92         public XMLTextTools(IPreferenceStore store, String[] strTokens) {
93                 super(store, strTokens);
94
95                 xmlPartitionScanner = new XMLPartitionScanner(false);
96                 phpXMLPartitionScanner = new PHPXMLPartitionScanner(false);
97                 Map tokens = getTokens();
98
99                 xmlTextScanner = new TextScanner(tokens, '&',
100                                 IXMLSyntaxConstants.XML_DEFAULT);
101
102                 dtdTextScanner = new TextScanner(tokens, '%',
103                                 IXMLSyntaxConstants.XML_DEFAULT);
104
105                 xmlPIScanner = new SingleTokenScanner(tokens,
106                                 IXMLSyntaxConstants.XML_PI);
107
108                 xmlCommentScanner = new SingleTokenScanner(tokens,
109                                 IXMLSyntaxConstants.XML_COMMENT);
110
111                 xmlDeclScanner = new DeclScanner(tokens);
112
113                 xmlTagScanner = new XMLTagScanner(tokens);
114
115                 xmlAttributeScanner = new TextScanner(tokens, '&',
116                                 IXMLSyntaxConstants.XML_ATT_VALUE);
117
118                 xmlCDATAScanner = new XMLCDATAScanner(tokens);
119         }
120
121         /**
122          * 
123          */
124         public IDocumentPartitioner createXMLPartitioner() {
125                 return new DefaultPartitioner(xmlPartitionScanner, TYPES);
126         }
127
128         public IDocumentPartitioner createPHPXMLPartitioner() {
129                 return new DefaultPartitioner(phpXMLPartitionScanner, TYPES);
130         }
131
132         /**
133          * 
134          */
135         // public IPartitionTokenScanner getXMLPartitionScanner() {
136         // return xmlPartitionScanner;
137         // }
138         /**
139          * Returns a scanner which is configured to scan XML text.
140          * 
141          * @return an XML text scanner
142          */
143         public RuleBasedScanner getXMLTextScanner() {
144                 return xmlTextScanner;
145         }
146
147         /**
148          * Returns a scanner which is configured to scan DTD text.
149          * 
150          * @return an DTD text scanner
151          */
152         public RuleBasedScanner getDTDTextScanner() {
153                 return dtdTextScanner;
154         }
155
156         /**
157          * Returns a scanner which is configured to scan XML tags.
158          * 
159          * @return an XML tag scanner
160          */
161         public RuleBasedScanner getXMLTagScanner() {
162                 return xmlTagScanner;
163         }
164
165         /**
166          * Returns a scanner which is configured to scan XML tag attributes.
167          * 
168          * @return an XML tag attribute scanner
169          */
170         public RuleBasedScanner getXMLAttributeScanner() {
171                 return xmlAttributeScanner;
172         }
173
174         /**
175          * Returns a scanner which is configured to scan XML CDATA sections.
176          * 
177          * @return an XML CDATA section scanner
178          */
179         public ITokenScanner getXMLCDATAScanner() {
180                 return xmlCDATAScanner;
181         }
182
183         /**
184          * Returns a scanner which is configured to scan XML processing
185          * instructions.
186          * 
187          * @return an XML processing instruction scanner
188          */
189         public RuleBasedScanner getXMLPIScanner() {
190                 return xmlPIScanner;
191         }
192
193         /**
194          * Returns a scanner which is configured to scan XML comments.
195          * 
196          * @return an XML comment scanner
197          */
198         public RuleBasedScanner getXMLCommentScanner() {
199                 return xmlCommentScanner;
200         }
201
202         /**
203          * Returns a scanner which is configured to scan XML declarations.
204          * 
205          * @return an XML declaration scanner
206          */
207         public RuleBasedScanner getXMLDeclScanner() {
208                 return xmlDeclScanner;
209         }
210 }