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;
021:
022: import org.apache.log4j.Logger;
023:
024: import de.schlund.pfixxml.resources.DocrootResource;
025: import de.schlund.pfixxml.resources.FileResource;
026: import de.schlund.pfixxml.resources.ResourceUtil;
027: import de.schlund.pfixxml.targets.DependencyType;
028: import de.schlund.pfixxml.targets.TargetGenerator;
029: import de.schlund.pfixxml.targets.TargetGeneratorFactory;
030: import de.schlund.pfixxml.targets.VirtualTarget;
031: import de.schlund.pfixxml.util.XsltContext;
032:
033: public class DependencyTracker {
034: private final static Logger LOG = Logger
035: .getLogger(DependencyTracker.class);
036:
037: /** xslt extension */
038: public static String logImage(XsltContext context, String path,
039: String parent_part_in, String parent_theme_in,
040: String targetGen, String targetKey, String type)
041: throws Exception {
042:
043: if (targetKey.equals("__NONE__")) {
044: return "0";
045: }
046:
047: FileResource tgen_path = ResourceUtil
048: .getFileResource(targetGen);
049: TargetGenerator gen = TargetGeneratorFactory.getInstance()
050: .createGenerator(tgen_path);
051: VirtualTarget target = (VirtualTarget) gen.getTarget(targetKey);
052:
053: String parent_path = "";
054: String parent_part = "";
055: String parent_theme = "";
056:
057: if (IncludeDocumentExtension.isIncludeDocument(context)) {
058: parent_path = IncludeDocumentExtension
059: .makeSystemIdRelative(context);
060: parent_part = parent_part_in;
061: parent_theme = parent_theme_in;
062: }
063:
064: if (target == null) {
065: LOG
066: .error("Error adding Dependency: target not found (targetGen="
067: + targetGen
068: + ", targetKey="
069: + targetKey
070: + ")");
071: return "1";
072: }
073: if (path.length() == 0) {
074: LOG.error("Error adding Dependency: empty path");
075: return "1";
076: }
077: DocrootResource relativePath = ResourceUtil
078: .getFileResourceFromDocroot(path);
079: DocrootResource relativeParent = parent_path.equals("") ? null
080: : ResourceUtil.getFileResourceFromDocroot(parent_path);
081: try {
082: logTyped(type, relativePath, "", "", relativeParent,
083: parent_part, parent_theme, target);
084: return "0";
085: } catch (Exception e) {
086: LOG.error("Error adding Dependency: ", e);
087: return "1";
088: }
089: }
090:
091: public static void logTyped(String type, DocrootResource path,
092: String part, String theme, DocrootResource parent_path,
093: String parent_part, String parent_theme,
094: VirtualTarget target) {
095: if (LOG.isDebugEnabled()) {
096: String project = target.getTargetGenerator().getName();
097: LOG.debug("Adding dependency to AuxdependencyManager :+\n"
098: + "Type = "
099: + type
100: + "\n"
101: + "Path = "
102: + path.getRelativePath()
103: + "\n"
104: + "Part = "
105: + part
106: + "\n"
107: + "Theme = "
108: + theme
109: + "\n"
110: + "ParentPath = "
111: + ((parent_path == null) ? "null" : parent_path
112: .getRelativePath())
113: + "\n"
114: + "ParentPart = "
115: + parent_part
116: + "\n"
117: + "ParentProd = "
118: + parent_theme
119: + "\n"
120: + "Project = " + project + "\n");
121: }
122: DependencyType thetype = DependencyType.getByTag(type);
123: if (thetype == DependencyType.TEXT) {
124: target.getAuxDependencyManager()
125: .addDependencyInclude(path, part, theme,
126: parent_path, parent_part, parent_theme);
127: } else if (thetype == DependencyType.IMAGE) {
128: target.getAuxDependencyManager().addDependencyImage(path,
129: parent_path, parent_part, parent_theme);
130: } else {
131: throw new RuntimeException("Unknown dependency type '"
132: + type + "'!");
133: }
134: }
135: }
|