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