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.ITokenScanner;
31 import org.eclipse.jface.text.rules.RuleBasedScanner;
36 * @author Igor Malinin
38 public class XMLTextTools extends AbstractTextTools {
39 /** Text Attributes for XML editors */
40 public static final String[] TOKENS = { IXMLSyntaxConstants.XML_DEFAULT,
41 IXMLSyntaxConstants.XML_TAG, IXMLSyntaxConstants.XML_ATT_NAME,
42 IXMLSyntaxConstants.XML_ATT_VALUE, IXMLSyntaxConstants.XML_ENTITY,
43 IXMLSyntaxConstants.XML_PI, IXMLSyntaxConstants.XML_CDATA,
44 IXMLSyntaxConstants.XML_COMMENT, IXMLSyntaxConstants.XML_SMARTY,
45 IXMLSyntaxConstants.XML_DECL, };
47 /** Content types for XML editors */
48 public static final String[] TYPES = { XMLPartitionScanner.XML_PI,
49 XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
50 XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_ATTRIBUTE,
51 XMLPartitionScanner.XML_CDATA, XMLPartitionScanner.DTD_INTERNAL,
52 XMLPartitionScanner.DTD_INTERNAL_PI,
53 XMLPartitionScanner.DTD_INTERNAL_COMMENT,
54 XMLPartitionScanner.DTD_INTERNAL_DECL, };
56 /** The XML partitions scanner */
57 private XMLPartitionScanner xmlPartitionScanner;
59 private PHPXMLPartitionScanner phpXMLPartitionScanner;
61 /** The XML text scanner */
62 private TextScanner xmlTextScanner;
64 /** The DTD text scanner */
65 private TextScanner dtdTextScanner;
67 /** The XML tags scanner */
68 private XMLTagScanner xmlTagScanner;
70 /** The XML attributes scanner */
71 private TextScanner xmlAttributeScanner;
73 /** The XML CDATA sections scanner */
74 private XMLCDATAScanner xmlCDATAScanner;
76 /** The XML processing instructions scanner */
77 private SingleTokenScanner xmlPIScanner;
79 /** The XML comments scanner */
80 private SingleTokenScanner xmlCommentScanner;
82 /** The XML declarations scanner */
83 private DeclScanner xmlDeclScanner;
85 public XMLTextTools(IPreferenceStore store) {
90 * Creates a new XML text tools collection.
92 public XMLTextTools(IPreferenceStore store, String[] strTokens) {
93 super(store, strTokens);
95 xmlPartitionScanner = new XMLPartitionScanner(false);
96 phpXMLPartitionScanner = new PHPXMLPartitionScanner(false);
97 Map tokens = getTokens();
99 xmlTextScanner = new TextScanner(tokens, '&',
100 IXMLSyntaxConstants.XML_DEFAULT);
102 dtdTextScanner = new TextScanner(tokens, '%',
103 IXMLSyntaxConstants.XML_DEFAULT);
105 xmlPIScanner = new SingleTokenScanner(tokens,
106 IXMLSyntaxConstants.XML_PI);
108 xmlCommentScanner = new SingleTokenScanner(tokens,
109 IXMLSyntaxConstants.XML_COMMENT);
111 xmlDeclScanner = new DeclScanner(tokens);
113 xmlTagScanner = new XMLTagScanner(tokens);
115 xmlAttributeScanner = new TextScanner(tokens, '&',
116 IXMLSyntaxConstants.XML_ATT_VALUE);
118 xmlCDATAScanner = new XMLCDATAScanner(tokens);
124 public IDocumentPartitioner createXMLPartitioner() {
125 return new DefaultPartitioner(xmlPartitionScanner, TYPES);
128 public IDocumentPartitioner createPHPXMLPartitioner() {
129 return new DefaultPartitioner(phpXMLPartitionScanner, TYPES);
135 // public IPartitionTokenScanner getXMLPartitionScanner() {
136 // return xmlPartitionScanner;
139 * Returns a scanner which is configured to scan XML text.
141 * @return an XML text scanner
143 public RuleBasedScanner getXMLTextScanner() {
144 return xmlTextScanner;
148 * Returns a scanner which is configured to scan DTD text.
150 * @return an DTD text scanner
152 public RuleBasedScanner getDTDTextScanner() {
153 return dtdTextScanner;
157 * Returns a scanner which is configured to scan XML tags.
159 * @return an XML tag scanner
161 public RuleBasedScanner getXMLTagScanner() {
162 return xmlTagScanner;
166 * Returns a scanner which is configured to scan XML tag attributes.
168 * @return an XML tag attribute scanner
170 public RuleBasedScanner getXMLAttributeScanner() {
171 return xmlAttributeScanner;
175 * Returns a scanner which is configured to scan XML CDATA sections.
177 * @return an XML CDATA section scanner
179 public ITokenScanner getXMLCDATAScanner() {
180 return xmlCDATAScanner;
184 * Returns a scanner which is configured to scan XML processing
187 * @return an XML processing instruction scanner
189 public RuleBasedScanner getXMLPIScanner() {
194 * Returns a scanner which is configured to scan XML comments.
196 * @return an XML comment scanner
198 public RuleBasedScanner getXMLCommentScanner() {
199 return xmlCommentScanner;
203 * Returns a scanner which is configured to scan XML declarations.
205 * @return an XML declaration scanner
207 public RuleBasedScanner getXMLDeclScanner() {
208 return xmlDeclScanner;