01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixxml;
21:
22: import java.io.IOException;
23:
24: import javax.xml.transform.TransformerException;
25:
26: import org.w3c.dom.Document;
27: import org.xml.sax.SAXException;
28:
29: import de.schlund.pfixxml.resources.FileResource;
30: import de.schlund.pfixxml.util.Xml;
31: import de.schlund.pfixxml.util.XsltVersion;
32:
33: /**
34: * IncludeDocument.java
35: *
36: *
37: * Created: 20021031
38: *
39: * @author <a href="mailto:haecker@schlund.de">Joerg Haecker</a>
40: *
41: *
42: * This class encapsulates an include-module of the PUSTEFIX-system.
43: * A IncludeDocument stores a Document created from a file. Currently
44: * there are two types of Documents: mutable and immutable. The user
45: * of this class must know which type he wants.
46: * Various administrative data like modification time
47: * of the file from which it is created from and more are stored.
48: */
49: public class IncludeDocument {
50:
51: //~ Instance/static variables ..................................................................
52:
53: private Document doc;
54: private long modTime = 0;
55:
56: // private static final Logger LOG = Logger.getLogger(IncludeDocument.class);
57:
58: //~ Methods ....................................................................................
59:
60: /**
61: * Create the internal document.
62: * @param path the path in the filesystem to create the document from.
63: * @param mutable determine if the document is mutable or not. Any attempts
64: * to modify an immutable document will cause an exception.
65: */
66: public void createDocument(XsltVersion xsltVersion,
67: FileResource path, boolean mutable) throws SAXException,
68: IOException, TransformerException {
69: modTime = path.lastModified();
70:
71: if (mutable) {
72: doc = Xml.parseMutable(path);
73: } else {
74: //TODO: avoid exception by providing an appropriate method signature
75: if (xsltVersion == null)
76: throw new IllegalArgumentException(
77: "XsltVersion is required!");
78: doc = Xml.parse(xsltVersion, path);
79: }
80: }
81:
82: public Document getDocument() {
83: return doc;
84: }
85:
86: public long getModTime() {
87: return modTime;
88: }
89:
90: public void resetModTime() {
91: modTime -= 1L;
92: }
93: }
|