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.2 2006-10-21 23:13:43 pombredanne 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,
33 // Instance Variables ------------------------------------------------------
35 private IXMLElement root;
37 private String systemId;
39 private Object dirtyLock = new Object();
41 private boolean dirty = true;
43 // Constructors ------------------------------------------------------------
45 public XMLDocument(IDocument document, String systemId) {
46 super(document, 0, document.getLength());
47 this.systemId = systemId;
50 // IXMLDocument Implementation ---------------------------------------------
53 * @see IXMLDocument#getRoot()
55 public IXMLElement getRoot() {
60 * @see net.sourceforge.phpeclipse.xml.core.model.IXMLDocument#getSystemId()
62 public String getSystemId() {
67 * @see IStyleSheet#reconcile(IProblemCollector)
69 public void reconcile(IProblemCollector problemCollector, IFile file) {
70 synchronized (dirtyLock) {
78 boolean doParse = false;
81 String filename = file.getLocation().toString();
82 int len = filename.length();
84 if ((filename.charAt(len - 1) != 'l' && filename
85 .charAt(len - 1) != 'L')
86 || (filename.charAt(len - 2) != 'p' && filename
87 .charAt(len - 2) != 'P')
88 || (filename.charAt(len - 3) != 't' && filename
89 .charAt(len - 3) != 'T')
90 || (filename.charAt(len - 4) != '.')) {
91 if ((filename.charAt(len - 1) != 'm' && filename
92 .charAt(len - 1) != 'M')
93 || (filename.charAt(len - 2) != 't' && filename
94 .charAt(len - 2) != 'T')
95 || (filename.charAt(len - 3) != 'h' && filename
96 .charAt(len - 3) != 'H')
97 || (filename.charAt(len - 4) != '.')) {
99 if ((filename.charAt(len - 1) != 'l' && filename
100 .charAt(len - 1) != 'L')
101 || (filename.charAt(len - 2) != 'm' && filename
102 .charAt(len - 2) != 'M')
103 || (filename.charAt(len - 3) != 't' && filename
104 .charAt(len - 3) != 'T')
105 || (filename.charAt(len - 4) != 'h' && filename
106 .charAt(len - 4) != 'H')
107 || (filename.charAt(len - 5) != '.')) {
118 IXMLParser parser = new XMLParser();
119 parser.setProblemCollector(problemCollector);
120 parser.setSource(getDocument());
121 parser.setSystemId(systemId);
122 IXMLDocument model = parser.parse();
124 root = model.getRoot();
130 // IDocumentListener Implementation ----------------------------------------
133 * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent)
135 public void documentAboutToBeChanged(DocumentEvent event) {
140 * @see IDocumentListener#documentChanged(DocumentEvent)
142 public void documentChanged(DocumentEvent event) {
143 synchronized (dirtyLock) {
148 // Public Methods ----------------------------------------------------------
151 * Sets the root element.
154 * the root element to set
156 public void setRoot(IXMLElement root) {