01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.text;
11:
12: import org.eclipse.jface.text.rules.IRule;
13: import org.eclipse.jface.text.rules.SingleLineRule;
14: import org.eclipse.jface.text.rules.Token;
15: import org.eclipse.jface.text.rules.WhitespaceRule;
16: import org.eclipse.jface.util.PropertyChangeEvent;
17:
18: public class XMLScanner extends BasePDEScanner {
19: private Token fProcInstr;
20:
21: private Token fExternalizedString;
22:
23: public XMLScanner(IColorManager manager) {
24: super (manager);
25: }
26:
27: protected void initialize() {
28: fProcInstr = new Token(
29: createTextAttribute(IPDEColorConstants.P_PROC_INSTR));
30: fExternalizedString = new Token(
31: createTextAttribute(IPDEColorConstants.P_EXTERNALIZED_STRING));
32:
33: IRule[] rules = new IRule[3];
34: //Add rule for processing instructions
35: rules[0] = new SingleLineRule("<?", "?>", fProcInstr); //$NON-NLS-1$ //$NON-NLS-2$
36: rules[1] = new ExternalizedStringRule(fExternalizedString);
37: // Add generic whitespace rule.
38: rules[2] = new WhitespaceRule(new XMLWhitespaceDetector());
39: setRules(rules);
40: setDefaultReturnToken(new Token(
41: createTextAttribute(IPDEColorConstants.P_DEFAULT)));
42: }
43:
44: protected Token getTokenAffected(PropertyChangeEvent event) {
45: if (event.getProperty().startsWith(
46: IPDEColorConstants.P_PROC_INSTR)) {
47: return fProcInstr;
48: } else if (event.getProperty().startsWith(
49: IPDEColorConstants.P_EXTERNALIZED_STRING)) {
50: return fExternalizedString;
51: }
52: return (Token) fDefaultReturnToken;
53: }
54:
55: public boolean affectsTextPresentation(String property) {
56: return property.startsWith(IPDEColorConstants.P_DEFAULT)
57: || property.startsWith(IPDEColorConstants.P_PROC_INSTR)
58: || property
59: .startsWith(IPDEColorConstants.P_EXTERNALIZED_STRING);
60: }
61:
62: }
|