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.3 2005-05-15 23:23:02 axelcl 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.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 private PHPXMLPartitionScanner phpXMLPartitionScanner;
72 /** The XML text scanner */
73 private TextScanner xmlTextScanner;
75 /** The DTD text scanner */
76 private TextScanner dtdTextScanner;
78 /** The XML tags scanner */
79 private XMLTagScanner xmlTagScanner;
81 /** The XML attributes scanner */
82 private TextScanner xmlAttributeScanner;
84 /** The XML CDATA sections scanner */
85 private XMLCDATAScanner xmlCDATAScanner;
87 /** The XML processing instructions scanner */
88 private SingleTokenScanner xmlPIScanner;
90 /** The XML comments scanner */
91 private SingleTokenScanner xmlCommentScanner;
93 /** The XML declarations scanner */
94 private DeclScanner xmlDeclScanner;
95 public XMLTextTools( IPreferenceStore store ) {
96 this( store, TOKENS );
99 * Creates a new XML text tools collection.
101 public XMLTextTools( IPreferenceStore store, String[] strTokens ) {
102 super( store, strTokens );
104 xmlPartitionScanner = new XMLPartitionScanner( false );
105 phpXMLPartitionScanner = new PHPXMLPartitionScanner( false );
106 Map tokens = getTokens();
108 xmlTextScanner = new TextScanner(
109 tokens, '&', IXMLSyntaxConstants.XML_DEFAULT );
111 dtdTextScanner = new TextScanner(
112 tokens, '%', IXMLSyntaxConstants.XML_DEFAULT );
114 xmlPIScanner = new SingleTokenScanner(
115 tokens, IXMLSyntaxConstants.XML_PI );
117 xmlCommentScanner = new SingleTokenScanner(
118 tokens, IXMLSyntaxConstants.XML_COMMENT );
120 xmlDeclScanner = new DeclScanner( tokens );
122 xmlTagScanner = new XMLTagScanner( tokens );
124 xmlAttributeScanner = new TextScanner(
125 tokens, '&', IXMLSyntaxConstants.XML_ATT_VALUE );
127 xmlCDATAScanner = new XMLCDATAScanner( tokens );
133 public IDocumentPartitioner createXMLPartitioner() {
134 return new DefaultPartitioner( xmlPartitionScanner, TYPES );
137 public IDocumentPartitioner createPHPXMLPartitioner() {
138 return new DefaultPartitioner( phpXMLPartitionScanner, TYPES );
144 // public IPartitionTokenScanner getXMLPartitionScanner() {
145 // return xmlPartitionScanner;
149 * Returns a scanner which is configured to scan XML text.
151 * @return an XML text scanner
153 public RuleBasedScanner getXMLTextScanner() {
154 return xmlTextScanner;
158 * Returns a scanner which is configured to scan DTD text.
160 * @return an DTD text scanner
162 public RuleBasedScanner getDTDTextScanner() {
163 return dtdTextScanner;
167 * Returns a scanner which is configured to scan XML tags.
169 * @return an XML tag scanner
171 public RuleBasedScanner getXMLTagScanner() {
172 return xmlTagScanner;
176 * Returns a scanner which is configured to scan XML tag attributes.
178 * @return an XML tag attribute scanner
180 public RuleBasedScanner getXMLAttributeScanner() {
181 return xmlAttributeScanner;
185 * Returns a scanner which is configured to scan XML CDATA sections.
187 * @return an XML CDATA section scanner
189 public ITokenScanner getXMLCDATAScanner() {
190 return xmlCDATAScanner;
194 * Returns a scanner which is configured to scan XML
195 * processing instructions.
197 * @return an XML processing instruction scanner
199 public RuleBasedScanner getXMLPIScanner() {
204 * Returns a scanner which is configured to scan XML comments.
206 * @return an XML comment scanner
208 public RuleBasedScanner getXMLCommentScanner() {
209 return xmlCommentScanner;
213 * Returns a scanner which is configured to scan XML declarations.
215 * @return an XML declaration scanner
217 public RuleBasedScanner getXMLDeclScanner() {
218 return xmlDeclScanner;