1 /*
2 * $Id: HomepageURIResolver.java 2993 2011-11-24 19:51:48Z andrewinkler $
3 * ============================================================================
4 * Project gluehloch-homepage-core
5 * Copyright (c) 2004-2014 by Andre Winkler. All rights reserved.
6 * ============================================================================
7 * GNU LESSER GENERAL PUBLIC LICENSE
8 * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26 package de.awtools.homegen.xml;
27
28 import javax.xml.transform.Source;
29 import javax.xml.transform.TransformerException;
30 import javax.xml.transform.URIResolver;
31 import javax.xml.transform.stream.StreamSource;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 import de.awtools.basic.file.AWToolsFileUtils;
37 import de.awtools.homegen.config.GHConfiguration;
38
39 /**
40 * Ein <code>URIResolver</code> für das Homepage Projekt.
41 *
42 * @version $LastChangedRevision: 2993 $ $LastChangedDate: 2011-11-24 20:51:48
43 * +0100 (Thu, 24 Nov 2011) $
44 * @author by Andre Winkler, $LastChangedBy: andrewinkler $
45 */
46 public final class HomepageURIResolver implements URIResolver {
47
48 /** Der private Logger der Klasse. */
49 private static Log log = LogFactory.getLog(HomepageURIResolver.class);
50
51 private static final String YAML = "yaml";
52 private static final String BOOTSTRAP = "bootstrap";
53 private final String path;
54
55 /**
56 * Konstruktor.
57 *
58 * @param cssFramework
59 * Konfiguration
60 */
61 public HomepageURIResolver(GHConfiguration.CssFramework cssFramework) {
62 switch (cssFramework) {
63 case YAML:
64 path = YAML;
65 break;
66 case BOOTSTRAP:
67 path = BOOTSTRAP;
68 break;
69 default:
70 throw new IllegalArgumentException("Unknown CSS framework: "
71 + cssFramework);
72 }
73 }
74
75 /**
76 * Löst eine URI auf.
77 *
78 * @param href
79 * Die konkrete Resource.
80 * @param base
81 * Das Verzeichnis in dem diese JVM gestartet wurde plus die
82 * Klasse, die diese Methode aufruft.
83 * @return Liefert ein <code>Source</code> Objekt.
84 * @throws TransformerException
85 * Die URI konnte nicht aufgelöst werden.
86 */
87 @Override
88 public final Source resolve(final String href, final String base)
89 throws TransformerException {
90
91 if (log.isDebugEnabled()) {
92 StringBuffer buf = new StringBuffer("href: '").append(href)
93 .append("' - base: '").append(base).append("'.");
94 log.debug(buf);
95 }
96
97 return (new StreamSource(
98 AWToolsFileUtils.classpathLoader("plugin-resources/xsl/" + path
99 + "/" + href)));
100 }
101
102 }