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