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
9 * Igor Malinin - initial contribution
11 * $Id: XMLTextTools.java,v 1.4 2006-10-21 23:14:13 pombredanne Exp $
14 package net.sourceforge.phpeclipse.xml.ui.text;
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;
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.FastPartitioner;
31 import org.eclipse.jface.text.rules.ITokenScanner;
32 import org.eclipse.jface.text.rules.RuleBasedScanner;
37 * @author Igor Malinin
39 public class XMLTextTools extends AbstractTextTools {
40 /** Text Attributes for XML editors */
41 public static final String[] TOKENS = { IXMLSyntaxConstants.XML_DEFAULT,
42 IXMLSyntaxConstants.XML_TAG, IXMLSyntaxConstants.XML_ATT_NAME,
43 IXMLSyntaxConstants.XML_ATT_VALUE, IXMLSyntaxConstants.XML_ENTITY,
44 IXMLSyntaxConstants.XML_PI, IXMLSyntaxConstants.XML_CDATA,
45 IXMLSyntaxConstants.XML_COMMENT, IXMLSyntaxConstants.XML_SMARTY,
46 IXMLSyntaxConstants.XML_DECL, };
48 /** Content types for XML editors */
49 public static final String[] TYPES = { XMLPartitionScanner.XML_PI,
50 XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
51 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE,
52 XMLPartitionScanner.XML_CDATA, XMLPartitionScanner.DTD_INTERNAL,
53 XMLPartitionScanner.DTD_INTERNAL_PI,
54 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
55 XMLPartitionScanner.DTD_INTERNAL_DECL, };
57 /** The XML partitions scanner */
58 private XMLPartitionScanner xmlPartitionScanner;
60 private PHPXMLPartitionScanner phpXMLPartitionScanner;
62 /** The XML text scanner */
63 private TextScanner xmlTextScanner;
65 /** The DTD text scanner */
66 private TextScanner dtdTextScanner;
68 /** The XML tags scanner */
69 private XMLTagScanner xmlTagScanner;
71 /** The XML attributes scanner */
72 private TextScanner xmlAttributeScanner;
74 /** The XML CDATA sections scanner */
75 private XMLCDATAScanner xmlCDATAScanner;
77 /** The XML processing instructions scanner */
78 private SingleTokenScanner xmlPIScanner;
80 /** The XML comments scanner */
81 private SingleTokenScanner xmlCommentScanner;
83 /** The XML declarations scanner */
84 private DeclScanner xmlDeclScanner;
86 public XMLTextTools(IPreferenceStore store) {
91 * Creates a new XML text tools collection.
93 public XMLTextTools(IPreferenceStore store, String[] strTokens) {
94 super(store, strTokens);
96 xmlPartitionScanner = new XMLPartitionScanner(false);
97 phpXMLPartitionScanner = new PHPXMLPartitionScanner(false);
98 Map tokens = getTokens();
100 xmlTextScanner = new TextScanner(tokens, '&',
101 IXMLSyntaxConstants.XML_DEFAULT);
103 dtdTextScanner = new TextScanner(tokens, '%',
104 IXMLSyntaxConstants.XML_DEFAULT);
106 xmlPIScanner = new SingleTokenScanner(tokens,
107 IXMLSyntaxConstants.XML_PI);
109 xmlCommentScanner = new SingleTokenScanner(tokens,
110 IXMLSyntaxConstants.XML_COMMENT);
112 xmlDeclScanner = new DeclScanner(tokens);
114 xmlTagScanner = new XMLTagScanner(tokens);
116 xmlAttributeScanner = new TextScanner(tokens, '&',
117 IXMLSyntaxConstants.XML_ATT_VALUE);
119 xmlCDATAScanner = new XMLCDATAScanner(tokens);
125 public IDocumentPartitioner createXMLPartitioner() {
126 return new /*DefaultPartitioner*/FastPartitioner(xmlPartitionScanner, TYPES);
129 public IDocumentPartitioner createPHPXMLPartitioner() {
130 return new /*DefaultPartitioner*/FastPartitioner(phpXMLPartitionScanner, TYPES);
136 // public IPartitionTokenScanner getXMLPartitionScanner() {
137 // return xmlPartitionScanner;
140 * Returns a scanner which is configured to scan XML text.
142 * @return an XML text scanner
144 public RuleBasedScanner getXMLTextScanner() {
145 return xmlTextScanner;
149 * Returns a scanner which is configured to scan DTD text.
151 * @return an DTD text scanner
153 public RuleBasedScanner getDTDTextScanner() {
154 return dtdTextScanner;
158 * Returns a scanner which is configured to scan XML tags.
160 * @return an XML tag scanner
162 public RuleBasedScanner getXMLTagScanner() {
163 return xmlTagScanner;
167 * Returns a scanner which is configured to scan XML tag attributes.
169 * @return an XML tag attribute scanner
171 public RuleBasedScanner getXMLAttributeScanner() {
172 return xmlAttributeScanner;
176 * Returns a scanner which is configured to scan XML CDATA sections.
178 * @return an XML CDATA section scanner
180 public ITokenScanner getXMLCDATAScanner() {
181 return xmlCDATAScanner;
185 * Returns a scanner which is configured to scan XML processing
188 * @return an XML processing instruction scanner
190 public RuleBasedScanner getXMLPIScanner() {
195 * Returns a scanner which is configured to scan XML comments.
197 * @return an XML comment scanner
199 public RuleBasedScanner getXMLCommentScanner() {
200 return xmlCommentScanner;
204 * Returns a scanner which is configured to scan XML declarations.
206 * @return an XML declaration scanner
208 public RuleBasedScanner getXMLDeclScanner() {
209 return xmlDeclScanner;