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.2 2005-05-06 00:55:41 stefanbjarni 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.SingleTokenScanner;
21 import net.sourceforge.phpeclipse.xml.ui.internal.text.TextScanner;
22 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLCDATAScanner;
23 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
24 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLTagScanner;
26 import org.eclipse.jface.preference.IPreferenceStore;
27 import org.eclipse.jface.text.IDocumentPartitioner;
28 import org.eclipse.jface.text.rules.DefaultPartitioner;
29 import org.eclipse.jface.text.rules.IPartitionTokenScanner;
30 import org.eclipse.jface.text.rules.ITokenScanner;
31 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 = {
42 IXMLSyntaxConstants.XML_DEFAULT,
43 IXMLSyntaxConstants.XML_TAG,
44 IXMLSyntaxConstants.XML_ATT_NAME,
45 IXMLSyntaxConstants.XML_ATT_VALUE,
46 IXMLSyntaxConstants.XML_ENTITY,
47 IXMLSyntaxConstants.XML_PI,
48 IXMLSyntaxConstants.XML_CDATA,
49 IXMLSyntaxConstants.XML_COMMENT,
50 IXMLSyntaxConstants.XML_SMARTY,
51 IXMLSyntaxConstants.XML_DECL,
54 /** Content types for XML editors */
55 public static final String[] TYPES = {
56 XMLPartitionScanner.XML_PI,
57 XMLPartitionScanner.XML_COMMENT,
58 XMLPartitionScanner.XML_DECL,
59 XMLPartitionScanner.XML_TAG,
60 XMLPartitionScanner.XML_ATTRIBUTE,
61 XMLPartitionScanner.XML_CDATA,
62 XMLPartitionScanner.DTD_INTERNAL,
63 XMLPartitionScanner.DTD_INTERNAL_PI,
64 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
65 XMLPartitionScanner.DTD_INTERNAL_DECL,
68 /** The XML partitions scanner */
69 private XMLPartitionScanner xmlPartitionScanner;
71 /** The XML text scanner */
72 private TextScanner xmlTextScanner;
74 /** The DTD text scanner */
75 private TextScanner dtdTextScanner;
77 /** The XML tags scanner */
78 private XMLTagScanner xmlTagScanner;
80 /** The XML attributes scanner */
81 private TextScanner xmlAttributeScanner;
83 /** The XML CDATA sections scanner */
84 private XMLCDATAScanner xmlCDATAScanner;
86 /** The XML processing instructions scanner */
87 private SingleTokenScanner xmlPIScanner;
89 /** The XML comments scanner */
90 private SingleTokenScanner xmlCommentScanner;
92 /** The XML declarations scanner */
93 private DeclScanner xmlDeclScanner;
94 public XMLTextTools( IPreferenceStore store ) {
95 this( store, TOKENS );
98 * Creates a new XML text tools collection.
100 public XMLTextTools( IPreferenceStore store, String[] strTokens ) {
101 super( store, strTokens );
103 xmlPartitionScanner = new XMLPartitionScanner( false );
105 Map tokens = getTokens();
107 xmlTextScanner = new TextScanner(
108 tokens, '&', IXMLSyntaxConstants.XML_DEFAULT );
110 dtdTextScanner = new TextScanner(
111 tokens, '%', IXMLSyntaxConstants.XML_DEFAULT );
113 xmlPIScanner = new SingleTokenScanner(
114 tokens, IXMLSyntaxConstants.XML_PI );
116 xmlCommentScanner = new SingleTokenScanner(
117 tokens, IXMLSyntaxConstants.XML_COMMENT );
119 xmlDeclScanner = new DeclScanner( tokens );
121 xmlTagScanner = new XMLTagScanner( tokens );
123 xmlAttributeScanner = new TextScanner(
124 tokens, '&', IXMLSyntaxConstants.XML_ATT_VALUE );
126 xmlCDATAScanner = new XMLCDATAScanner( tokens );
132 public IDocumentPartitioner createXMLPartitioner() {
133 return new DefaultPartitioner( xmlPartitionScanner, TYPES );
139 public IPartitionTokenScanner getXMLPartitionScanner() {
140 return xmlPartitionScanner;
144 * Returns a scanner which is configured to scan XML text.
146 * @return an XML text scanner
148 public RuleBasedScanner getXMLTextScanner() {
149 return xmlTextScanner;
153 * Returns a scanner which is configured to scan DTD text.
155 * @return an DTD text scanner
157 public RuleBasedScanner getDTDTextScanner() {
158 return dtdTextScanner;
162 * Returns a scanner which is configured to scan XML tags.
164 * @return an XML tag scanner
166 public RuleBasedScanner getXMLTagScanner() {
167 return xmlTagScanner;
171 * Returns a scanner which is configured to scan XML tag attributes.
173 * @return an XML tag attribute scanner
175 public RuleBasedScanner getXMLAttributeScanner() {
176 return xmlAttributeScanner;
180 * Returns a scanner which is configured to scan XML CDATA sections.
182 * @return an XML CDATA section scanner
184 public ITokenScanner getXMLCDATAScanner() {
185 return xmlCDATAScanner;
189 * Returns a scanner which is configured to scan XML
190 * processing instructions.
192 * @return an XML processing instruction scanner
194 public RuleBasedScanner getXMLPIScanner() {
199 * Returns a scanner which is configured to scan XML comments.
201 * @return an XML comment scanner
203 public RuleBasedScanner getXMLCommentScanner() {
204 return xmlCommentScanner;
208 * Returns a scanner which is configured to scan XML declarations.
210 * @return an XML declaration scanner
212 public RuleBasedScanner getXMLDeclScanner() {
213 return xmlDeclScanner;