2 * Copyright (c) 2004 Christopher Lenz 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 * Christopher Lenz - initial API
11 * $Id: XMLDocument.java,v 1.1 2004-09-02 18:26:55 jsurfer Exp $
14 package net.sourceforge.phpeclipse.xml.core.internal.model;
16 import net.sourceforge.phpeclipse.core.model.SourceReference;
17 import net.sourceforge.phpeclipse.xml.core.internal.parser.XMLParser;
18 import net.sourceforge.phpeclipse.xml.core.model.IXMLDocument;
19 import net.sourceforge.phpeclipse.xml.core.model.IXMLElement;
20 import net.sourceforge.phpeclipse.xml.core.parser.IProblemCollector;
21 import net.sourceforge.phpeclipse.xml.core.parser.IXMLParser;
23 import org.eclipse.core.resources.IFile;
24 import org.eclipse.jface.text.DocumentEvent;
25 import org.eclipse.jface.text.IDocument;
26 import org.eclipse.jface.text.IDocumentListener;
31 public class XMLDocument extends SourceReference implements IXMLDocument, IDocumentListener {
32 // Instance Variables ------------------------------------------------------
34 private IXMLElement root;
36 private String systemId;
38 private Object dirtyLock = new Object();
40 private boolean dirty = true;
42 // Constructors ------------------------------------------------------------
44 public XMLDocument(IDocument document, String systemId) {
45 super(document, 0, document.getLength());
46 this.systemId = systemId;
49 // IXMLDocument Implementation ---------------------------------------------
52 * @see IXMLDocument#getRoot()
54 public IXMLElement getRoot() {
59 * @see net.sourceforge.phpeclipse.xml.core.model.IXMLDocument#getSystemId()
61 public String getSystemId() {
66 * @see IStyleSheet#reconcile(IProblemCollector)
68 public void reconcile(IProblemCollector problemCollector, IFile file) {
69 synchronized (dirtyLock) {
77 boolean doParse = false;
80 String filename = file.getLocation().toString();
81 int len = filename.length();
83 if ((filename.charAt(len - 1) != 'l' && filename.charAt(len - 1) != 'L')
84 || (filename.charAt(len - 2) != 'p' && filename.charAt(len - 2) != 'P')
85 || (filename.charAt(len - 3) != 't' && filename.charAt(len - 3) != 'T')
86 || (filename.charAt(len - 4) != '.')) {
87 if ((filename.charAt(len - 1) != 'm' && filename.charAt(len - 1) != 'M')
88 || (filename.charAt(len - 2) != 't' && filename.charAt(len - 2) != 'T')
89 || (filename.charAt(len - 3) != 'h' && filename.charAt(len - 3) != 'H')
90 || (filename.charAt(len - 4) != '.')) {
92 if ((filename.charAt(len - 1) != 'l' && filename.charAt(len - 1) != 'L')
93 || (filename.charAt(len - 2) != 'm' && filename.charAt(len - 2) != 'M')
94 || (filename.charAt(len - 3) != 't' && filename.charAt(len - 3) != 'T')
95 || (filename.charAt(len - 4) != 'h' && filename.charAt(len - 4) != 'H')
96 || (filename.charAt(len - 5) != '.')) {
107 IXMLParser parser = new XMLParser();
108 parser.setProblemCollector(problemCollector);
109 parser.setSource(getDocument());
110 parser.setSystemId(systemId);
111 IXMLDocument model = parser.parse();
113 root = model.getRoot();
119 // IDocumentListener Implementation ----------------------------------------
122 * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent)
124 public void documentAboutToBeChanged(DocumentEvent event) {
129 * @see IDocumentListener#documentChanged(DocumentEvent)
131 public void documentChanged(DocumentEvent event) {
132 synchronized (dirtyLock) {
137 // Public Methods ----------------------------------------------------------
140 * Sets the root element.
143 * the root element to set
145 public void setRoot(IXMLElement root) {