001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixxml.targets;
021:
022: import java.io.IOException;
023:
024: import javax.xml.transform.Templates;
025: import javax.xml.transform.TransformerException;
026:
027: import org.w3c.dom.Document;
028:
029: import de.schlund.pfixxml.resources.FileResource;
030: import de.schlund.pfixxml.resources.ResourceUtil;
031: import de.schlund.pfixxml.util.Xml;
032: import de.schlund.pfixxml.util.Xslt;
033:
034: /**
035: * XSLLeafTarget.java
036: *
037: *
038: * Created: Mon Jul 23 21:53:06 2001
039: *
040: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
041: *
042: *
043: */
044:
045: public class XSLLeafTarget extends LeafTarget {
046:
047: public XSLLeafTarget(TargetType type, TargetGenerator gen,
048: String key, Themes themes) throws Exception {
049: this .type = type;
050: this .generator = gen;
051: this .targetkey = key;
052: this .themes = themes;
053: FileResource targetpath = ResourceUtil
054: .getFileResourceFromDocroot(key);
055: this .sharedleaf = SharedLeafFactory.getInstance()
056: .getSharedLeaf(generator.getXsltVersion(), targetpath);
057: this .auxdepmanager = new AuxDependencyManager(this );
058: this .auxdepmanager.tryInitAuxdepend();
059: }
060:
061: /**
062: * @see de.schlund.pfixxml.targets.TargetImpl#getValueFromDiscCache()
063: */
064: protected Object getValueFromDiscCache()
065: throws TransformerException {
066: FileResource thefile = ResourceUtil
067: .getFileResourceFromDocroot(getTargetKey());
068: if (thefile.exists() && thefile.isFile()) {
069: // reset the target dependency list as they will be set up again
070: this .getAuxDependencyManager().reset();
071:
072: Templates tmpl = Xslt.loadTemplates(generator
073: .getXsltVersion(), thefile, this );
074:
075: // save aux dependencies
076: try {
077:
078: this .getAuxDependencyManager().saveAuxdepend();
079: } catch (IOException e) {
080: throw new TransformerException(
081: "Error while writing auxdependency information");
082: }
083:
084: return tmpl;
085: } else {
086: return null;
087: }
088: }
089:
090: public Document getDOM() throws TargetGenerationException {
091: FileResource thefile = ResourceUtil
092: .getFileResourceFromDocroot(getTargetKey());
093: if (thefile.exists() && thefile.isFile()) {
094: try {
095: return Xml.parse(generator.getXsltVersion(), thefile);
096: } catch (TransformerException e) {
097: throw new TargetGenerationException(
098: "Error while reading DOM from disccache for target "
099: + getTargetKey(), e);
100: }
101: } else {
102: return null;
103: }
104: }
105:
106: }// XSLLeafTarget
|