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: XMLCDATAScanner.java,v 1.3 2007-04-05 07:50:15 toshihiro Exp $
14 package net.sourceforge.phpeclipse.xml.ui.internal.text;
18 import net.sourceforge.phpeclipse.xml.ui.text.IXMLSyntaxConstants;
20 import org.eclipse.jface.text.BadLocationException;
21 import org.eclipse.jface.text.IDocument;
22 import org.eclipse.jface.text.rules.IToken;
23 import org.eclipse.jface.text.rules.ITokenScanner;
24 import org.eclipse.jface.text.rules.Token;
27 * @author Igor Malinin
29 public class XMLCDATAScanner implements ITokenScanner {
33 private IDocument document;
45 public XMLCDATAScanner(Map tokens) {
50 * @see ITokenScanner#setRange(IDocument, int, int)
52 public void setRange(IDocument document, int offset, int length) {
53 this.document = document;
56 this.end = offset + length;
59 this.position = offset;
64 * @see ITokenScanner#nextToken()
66 public IToken nextToken() {
69 if (position == begin) {
71 // position += 3; // <![
73 // if (document.get(position, 6).equals("CDATA[")) {
76 // } catch (BadLocationException e) {
79 if (document.get(position, 3).equals("<![")) {
81 if (document.get(position, 6).equals("CDATA[")) {
84 } // else: xml cdata part is divided by php script block
85 } catch (BadLocationException e) {
88 return getToken(IXMLSyntaxConstants.XML_CDATA);
91 if (position == end) {
92 return getToken(null);
97 if (document.get(p, 3).equals("]]>")) {
100 return getToken(IXMLSyntaxConstants.XML_CDATA);
107 } catch (BadLocationException e) {
110 return getToken(IXMLSyntaxConstants.XML_DEFAULT);
113 private IToken getToken(String type) {
114 length = position - offset;
121 return Token.UNDEFINED;
124 IToken token = (IToken) tokens.get(type);
126 return Token.UNDEFINED;
133 * @see ITokenScanner#getTokenOffset()
135 public int getTokenOffset() {
140 * @see ITokenScanner#getTokenLength()
142 public int getTokenLength() {