(no commit message)
[phpeclipse.git] / net.sourceforge.phpeclipse.xml.ui / src / net / sourceforge / phpeclipse / xml / ui / text / DTDTextTools.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: DTDTextTools.java,v 1.3 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.SingleTokenScanner;
21 import net.sourceforge.phpeclipse.xml.ui.internal.text.TextScanner;
22 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
23
24 import org.eclipse.jface.preference.IPreferenceStore;
25 import org.eclipse.jface.text.IDocumentPartitioner;
26 //import org.eclipse.jface.text.rules.DefaultPartitioner;
27 import org.eclipse.jface.text.rules.FastPartitioner;
28 import org.eclipse.jface.text.rules.IPartitionTokenScanner;
29 import org.eclipse.jface.text.rules.RuleBasedScanner;
30
31 /**
32  * 
33  * 
34  * @author Igor Malinin
35  */
36 public class DTDTextTools extends AbstractTextTools {
37         private static final String[] TOKENS = { IXMLSyntaxConstants.XML_DEFAULT,
38                         IXMLSyntaxConstants.XML_ATT_NAME,
39                         IXMLSyntaxConstants.XML_ATT_VALUE, IXMLSyntaxConstants.XML_ENTITY,
40                         IXMLSyntaxConstants.XML_PI, IXMLSyntaxConstants.XML_COMMENT,
41                         IXMLSyntaxConstants.XML_DECL, IXMLSyntaxConstants.DTD_CONDITIONAL, };
42
43         private static final String[] TYPES = { XMLPartitionScanner.XML_PI,
44                         XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
45                         XMLPartitionScanner.DTD_CONDITIONAL, };
46
47         /** The DTD partitions scanner */
48         private XMLPartitionScanner dtdPartitionScanner;
49
50         /** The DTD text scanner */
51         private TextScanner dtdTextScanner;
52
53         /** The DTD conditional sections scanner */
54         private SingleTokenScanner dtdConditionalScanner;
55
56         /** The XML processing instructions scanner */
57         private SingleTokenScanner xmlPIScanner;
58
59         /** The XML comments scanner */
60         private SingleTokenScanner xmlCommentScanner;
61
62         /** The XML declarations scanner */
63         private DeclScanner xmlDeclScanner;
64
65         /**
66          * Creates a new DTD text tools collection.
67          */
68         public DTDTextTools(IPreferenceStore store) {
69                 super(store, TOKENS);
70
71                 dtdPartitionScanner = new XMLPartitionScanner(true);
72
73                 Map tokens = getTokens();
74
75                 dtdTextScanner = new TextScanner(tokens, '%',
76                                 IXMLSyntaxConstants.XML_DEFAULT);
77
78                 dtdConditionalScanner = new SingleTokenScanner(tokens,
79                                 IXMLSyntaxConstants.DTD_CONDITIONAL); // cond
80
81                 xmlPIScanner = new SingleTokenScanner(tokens,
82                                 IXMLSyntaxConstants.XML_PI);
83
84                 xmlCommentScanner = new SingleTokenScanner(tokens,
85                                 IXMLSyntaxConstants.XML_COMMENT);
86
87                 xmlDeclScanner = new DeclScanner(tokens);
88         }
89
90         /**
91          * 
92          */
93         public IDocumentPartitioner createDTDPartitioner() {
94                 return new /*DefaultPartitioner*/FastPartitioner(dtdPartitionScanner, TYPES);
95         }
96
97         /**
98          * 
99          */
100         public IPartitionTokenScanner getDTDPartitionScanner() {
101                 return dtdPartitionScanner;
102         }
103
104         /**
105          * Returns a scanner which is configured to scan DTD text.
106          * 
107          * @return an DTD text scanner
108          */
109         public RuleBasedScanner getDTDTextScanner() {
110                 return dtdTextScanner;
111         }
112
113         /**
114          * Returns a scanner which is configured to scan DTD conditional sections.
115          * 
116          * @return an DTD conditional section scanner
117          */
118         public RuleBasedScanner getDTDConditionalScanner() {
119                 return dtdConditionalScanner;
120         }
121
122         /**
123          * Returns a scanner which is configured to scan XML processing
124          * instructions.
125          * 
126          * @return an XML processing instruction scanner
127          */
128         public RuleBasedScanner getXMLPIScanner() {
129                 return xmlPIScanner;
130         }
131
132         /**
133          * Returns a scanner which is configured to scan XML comments.
134          * 
135          * @return an XML comment scanner
136          */
137         public RuleBasedScanner getXMLCommentScanner() {
138                 return xmlCommentScanner;
139         }
140
141         /**
142          * Returns a scanner which is configured to scan XML declarations.
143          * 
144          * @return an XML declaration scanner
145          */
146         public RuleBasedScanner getXMLDeclScanner() {
147                 return xmlDeclScanner;
148         }
149 }