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: DTDTextTools.java,v 1.3 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.SingleTokenScanner;
21 import net.sourceforge.phpeclipse.xml.ui.internal.text.TextScanner;
22 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLPartitionScanner;
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;
33 * @author Igor Malinin
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, };
42 private static final String[] TYPES = { XMLPartitionScanner.XML_PI,
43 XMLPartitionScanner.XML_COMMENT, XMLPartitionScanner.XML_DECL,
44 XMLPartitionScanner.DTD_CONDITIONAL, };
46 /** The DTD partitions scanner */
47 private XMLPartitionScanner dtdPartitionScanner;
49 /** The DTD text scanner */
50 private TextScanner dtdTextScanner;
52 /** The DTD conditional sections scanner */
53 private SingleTokenScanner dtdConditionalScanner;
55 /** The XML processing instructions scanner */
56 private SingleTokenScanner xmlPIScanner;
58 /** The XML comments scanner */
59 private SingleTokenScanner xmlCommentScanner;
61 /** The XML declarations scanner */
62 private DeclScanner xmlDeclScanner;
65 * Creates a new DTD text tools collection.
67 public DTDTextTools(IPreferenceStore store) {
70 dtdPartitionScanner = new XMLPartitionScanner(true);
72 Map tokens = getTokens();
74 dtdTextScanner = new TextScanner(tokens, '%',
75 IXMLSyntaxConstants.XML_DEFAULT);
77 dtdConditionalScanner = new SingleTokenScanner(tokens,
78 IXMLSyntaxConstants.DTD_CONDITIONAL); // cond
80 xmlPIScanner = new SingleTokenScanner(tokens,
81 IXMLSyntaxConstants.XML_PI);
83 xmlCommentScanner = new SingleTokenScanner(tokens,
84 IXMLSyntaxConstants.XML_COMMENT);
86 xmlDeclScanner = new DeclScanner(tokens);
92 public IDocumentPartitioner createDTDPartitioner() {
93 return new DefaultPartitioner(dtdPartitionScanner, TYPES);
99 public IPartitionTokenScanner getDTDPartitionScanner() {
100 return dtdPartitionScanner;
104 * Returns a scanner which is configured to scan DTD text.
106 * @return an DTD text scanner
108 public RuleBasedScanner getDTDTextScanner() {
109 return dtdTextScanner;
113 * Returns a scanner which is configured to scan DTD conditional sections.
115 * @return an DTD conditional section scanner
117 public RuleBasedScanner getDTDConditionalScanner() {
118 return dtdConditionalScanner;
122 * Returns a scanner which is configured to scan XML processing
125 * @return an XML processing instruction scanner
127 public RuleBasedScanner getXMLPIScanner() {
132 * Returns a scanner which is configured to scan XML comments.
134 * @return an XML comment scanner
136 public RuleBasedScanner getXMLCommentScanner() {
137 return xmlCommentScanner;
141 * Returns a scanner which is configured to scan XML declarations.
143 * @return an XML declaration scanner
145 public RuleBasedScanner getXMLDeclScanner() {
146 return xmlDeclScanner;