View Javadoc

1   /*
2    * $Id: GHConfiguration.java 2993 2011-11-24 19:51:48Z andrewinkler $
3    * ============================================================================
4    * Project gluehloch-homepage-core
5    * Copyright (c) 2004-2010 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.config;
27  
28  import java.io.File;
29  import java.io.InputStream;
30  
31  import org.apache.commons.lang.StringUtils;
32  
33  /**
34   * Konfigurationskram der Standalone Variante. Es ergibt sich folgende
35   * Verzeichnisstruktur:<br>
36   * <pre>
37   *   --+ ${projectDirectory} I.d.R. ein nicht-relativer Pfad.
38   *     +-- ./homepage-css.properties Benutzerdefinierte CSS Definitionen.
39   *     +-- ./build.properties        Die FTP Eigenschaften.
40   *     !
41   *     +-- ${www} Das Verzeichnis mit den XML Snippets. Der Name 'www' ist
42   *     !          vorgegeben.
43   *     !
44   *     +--+ ${target} Das Arbeitsverzeichnis. Alle Ausgaben landen hier in
45   *        !           dieses Verzeichnis. Der Name 'target' ist vorgegeben.
46   *        !
47   *        +--+ ${resource} Die 'Plugin-Resourcen'. Die Standalone Variante
48   *        !  !             entpackt die Resourcen aus gluehloch-homepage-resource 
49   *        !  !             in dieses Verzeichnis. Der Name 'resource' ist
50   *        !  !             vorgegeben.
51   *        !  +-- web       Die Plugin-Resourcen die 1:1 in das target/www
52   *        !                Verzeichnis kopiert werden können (css, ja, images).
53   *        !
54   *        +-- ${wwwPrep}   Erster Transformationsschritt. Der Name 'www-prep'
55   *        !                ist vorgegeben.
56   *        !
57   *        +-- ${www}       Zweiter Transformationsschritt. Endprodukt. Der Name
58   *                         'www' ist vorgegeben.
59   * </pre>
60   * 
61   * @version $LastChangedRevision: 2993 $ $LastChangedDate: 2011-11-24 20:51:48 +0100 (Thu, 24 Nov 2011) $
62   * @author by Andre Winkler, $LastChangedBy: andrewinkler $
63   *
64   * @since 1.4
65   */
66  public final class GHConfiguration {
67  
68      /** Das Default Sourcen-Verzeichnis. */
69      private static final String DEFAULT_SOURCE_WWW = "www";
70  
71      /** Das Default Target-Verzeichnis. */
72      private static final String DEFAULT_TARGET = "target";
73  
74      /** Das Default target/resource/yaml Verzeichnis. */
75      private static final String DEFAULT_TARGET_RESOURCE_YAML = "resource/yaml";
76  
77      /** Das Default target/resource/bootstrap Verzeichnis */
78      private static final String DEFAULT_TARGET_RESOURCE_BOOTSTRAP = "resource/bootstrap";
79  
80      /** Das Default target/www-prep Verzeichnis. */
81      private static final String DEFAULT_TARGET_WWWPREP = "www-prep";
82  
83      /** Das Default target/www Verzeichnis. */
84      private static final String DEFAULT_TARGET_WWW = "www";
85  
86      /** Das web-Verzeichnis unter target/resource. */
87      private static final String DEFAULT_RESOURCE_WEB_YAML = "web/yaml";
88  
89      /** Das web-Verzeichnis unter target/resource. */
90      private static final String DEFAULT_RESOURCE_WEB_BOOTSTRAP = "web/bootstrap";
91  
92      /** Select the YAML framework. */
93      private static final String CSS_YAML = "yaml";
94  
95      /** Select the Bootstrap framework. */
96      private static final String CSS_BOOTSTRAP = "bootstrap";
97  
98      public enum CssFramework {
99          YAML, BOOTSTRAP
100     }
101 
102     // -- projectDirectory ----------------------------------------------------
103 
104     /**
105      * Das Projektverzeichnis.
106      */
107     private File projectDirectory;
108 
109     /**
110      * Liefert das Projektverzeichnis.
111      * 
112      * @return Das Projektverzeichnis.
113      */
114     public File getProjectDirectory() {
115         return projectDirectory;
116     }
117 
118     /**
119      * Setzt das Projektverzeichnis.
120      * 
121      * @param value Das Projektverzeichnis.
122      */
123     public void setWorkspaceDirectory(final File value) {
124         projectDirectory = value;
125     }
126 
127     // -- uploadEnabled -------------------------------------------------------
128 
129     /** Nach der Transformation den Upload zum Server starten? */
130     private boolean uploadEnabled = false;
131 
132     /**
133      * Nach der Transformation den Upload zum Server starten?
134      *
135      * @return Liefert <code>true</code>, wenn nach der Transformation der
136      *     Upload gestartet werden soll.
137      */
138     public boolean isUploadEnabled() {
139         return uploadEnabled;
140     }
141 
142     /**
143      * Nach der Transformation den Upload zum Server starten?
144      *
145      * @param _uploadEnabled Upload starten?
146      */
147     public void setUploadEnabled(final boolean _uploadEnabled) {
148         uploadEnabled = _uploadEnabled;
149     }
150 
151     // -- cleanBuild ----------------------------------------------------------
152 
153     /** Clean Build, d.h. löschen des Target Verzeichnisses? */
154     private boolean cleanBuild = false;
155 
156     /**
157      * Ausführen eines Clean-Build?
158      *
159      * @return Clean Target Directory?
160      */
161     public boolean isCleanBuild() {
162         return cleanBuild;
163     }
164 
165     /**
166      * Setzt das Clean-Build Flag.
167      *
168      * @param _cleanBuild Das neue Clean-Build Flag.
169      */
170     public void setCleanBuild(final boolean _cleanBuild) {
171         cleanBuild = _cleanBuild;
172     }
173 
174     // -- forceBuild ----------------------------------------------------------
175 
176     /** Forciert das Bauen der Homepage. */
177     private boolean forceBuild = false;
178 
179     /**
180      * Soll das Bauen der Homepage forciert werden?
181      *
182      * @return Bauen forcieren?
183      */
184     public boolean isForceBuild() {
185         return forceBuild;
186     }
187 
188     /**
189      * Setzt das Force-Build Flag.
190      *
191      * @param _forceBuild Build Prozess forcieren.
192      */
193     public void setForceBuild(final boolean _forceBuild) {
194         forceBuild = _forceBuild;
195     }
196 
197     // -- statusChannel -------------------------------------------------------
198 
199     /** Der Kanal zur Anzeige des aktuellen Bearbeitungsstatus. */
200     private StatusChannel statusChannel;
201 
202     /**
203      * Liefert den Kanal für Statusmeldungen.
204      *
205      * @return Kanal für Statusmeldungen.
206      */
207     public StatusChannel getStatusChannel() {
208         return statusChannel;
209     }
210 
211     /**
212      * Setzt einen neuen Status-Kanal.
213      *
214      * @param _statusChannel Der Kanal für Statusmeldungen.
215      */
216     public void setStatusChannel(final StatusChannel _statusChannel) {
217         statusChannel = _statusChannel;
218     }
219 
220     // -- style ---------------------------------------------------------------
221 
222     /** Die Stylesheet Datei. */
223     private InputStream style;
224 
225     /**
226      * Liefert das Stylesheet.
227      * 
228      * @return Das Stylesheet.
229      */
230     public final InputStream getStyle() {
231         return style;
232     }
233 
234     /**
235      * Setzt das Stylesheet.
236      * 
237      * @param value Das Stylesheet.
238      */
239     public final void setStyle(final InputStream value) {
240         style = value;
241     }
242 
243     // -- cssFramework --------------------------------------------------------
244 
245     /** The selected CSS framework. */
246     private CssFramework cssFramework;
247 
248     /**
249      * Set the css framework.
250      *
251      * @param optionValue
252      */
253     public void setCssFramework(String optionValue) {
254         if (StringUtils.equalsIgnoreCase(CSS_YAML, optionValue)) {
255             cssFramework = CssFramework.YAML;
256         } else if (StringUtils.equalsIgnoreCase(CSS_BOOTSTRAP, optionValue)) {
257             cssFramework = CssFramework.BOOTSTRAP;
258         } else {
259             throw new IllegalArgumentException("Unknown CSS option: "
260                     + optionValue);
261         }
262     }
263 
264     /**
265      * Returns the css framework.
266      *
267      * @return yaml or bootstrap
268      */
269     public CssFramework getCssFramework() {
270         return cssFramework;
271     }
272 
273     // ------------------------------------------------------------------------
274     // Definiert verschiedene Verzeichnisse für den Transformationsprozess.
275     // ------------------------------------------------------------------------
276 
277     /**
278      * @return Das Sourcenverzeichnis. Absoluter Pfad. 
279      */
280     public File getWww() {
281         return (new File(projectDirectory, DEFAULT_SOURCE_WWW));
282     }
283 
284     /**
285      * @return Die Datei ./homepage-css.properties. Absoluter Pfad.
286      */
287     public File getUserDirHomepagecssProperties() {
288         return (new File(projectDirectory, "homepage-css.properties"));
289     }
290 
291     /**
292      * @return Die Datei ./build.properties. Absoluter Pfad.
293      */
294     public File getUserBuildProperties() {
295         return (new File(projectDirectory, "build.properties"));
296     }
297 
298     /**
299      * @return Die Datei www/navigation.xml. Absoluter Pfad.
300      */
301     public String getNavigation() {
302         return "navigation.xml";
303     }
304 
305     /**
306      * @return Das target Verzeichnis. Absoluter Pfad. 
307      */
308     public File getTarget() {
309         return (new File(projectDirectory, DEFAULT_TARGET));
310     }
311 
312     /**
313      * @return Das target/resource Verzeichnis. Absoluter Pfad. 
314      */
315     public File getTargetResource() {
316         String resourcePath;
317         switch (getCssFramework()) {
318         case YAML:
319             resourcePath = DEFAULT_TARGET_RESOURCE_YAML;
320             break;
321         case BOOTSTRAP:
322             resourcePath = DEFAULT_TARGET_RESOURCE_BOOTSTRAP;
323             break;
324         default:
325             throw new IllegalStateException("Unknown css framework: "
326                     + getCssFramework());
327         }
328 
329         return (new File(getTarget(), resourcePath));
330     }
331 
332     /**
333      * @return Das target/resource/web Verzeichnis. Absoluter Pfad.
334      */
335     public File getTargetResourceWeb() {
336         String resourcePath;
337         switch (getCssFramework()) {
338         case YAML:
339             resourcePath = DEFAULT_RESOURCE_WEB_YAML;
340             break;
341         case BOOTSTRAP:
342             resourcePath = DEFAULT_RESOURCE_WEB_BOOTSTRAP;
343             break;
344         default:
345             throw new IllegalStateException("Unknown css framework: "
346                     + getCssFramework());
347         }
348 
349         return (new File(getTargetResource(), resourcePath));
350     }
351 
352     /**
353      * @return Die Datei target/resource/default.properties. Absoluter Pfad.
354      */
355     public File getPluginDefaultProperties() {
356         return (new File(getTargetResource(), "default.properties"));
357     }
358 
359     /**
360      * @return Das target/www-prep Verzeichnis. Absoluter Pfad. 
361      */
362     public File getTargetWwwPrep() {
363         return (new File(getTarget(), DEFAULT_TARGET_WWWPREP));
364     }
365 
366     /**
367      * @return Das target/www Verzeichnis. Absoluter Pfad. 
368      */
369     public File getTargetWww() {
370         return (new File(getTarget(), DEFAULT_TARGET_WWW));
371     }
372 
373     /**
374      * Liefert die Zeichensatzkodierung.
375      *
376      * @return Die Zeichensatzkodierung.
377      */
378     public String getEncoding() {
379         return "UTF-8";
380     }
381 
382     /**
383      * Liefert den Klassenpfad zu den Velocity Templates.
384      *
385      * @return Klassenpfad zu den Velocity Templates.
386      */
387     public String getVelocityTemplatePath() {
388         String css;
389         switch (getCssFramework()) {
390         case YAML:
391             css = "yaml";
392             break;
393         case BOOTSTRAP:
394             css = "bootstrap";
395             break;
396         default:
397             throw new IllegalStateException("Unknown css framework: "
398                     + getCssFramework());
399         }
400         return "plugin-resources/templates/" + css;
401     }
402 
403 }