KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > packaging > projects > creators > DisplayThemeCreator


1 /*
2  * This software is OSI Certified Open Source Software.
3  * OSI Certified is a certification mark of the Open Source Initiative.
4  * The license (Mozilla version 1.0) can be read at the MMBase site.
5  * See http://www.MMBase.org/license
6  */

7 package org.mmbase.applications.packaging.projects.creators;
8
9 import java.io.File JavaDoc;
10 import java.io.FileOutputStream JavaDoc;
11 import java.util.Date JavaDoc;
12 import java.util.jar.JarOutputStream JavaDoc;
13 import java.util.jar.Manifest JavaDoc;
14
15 import org.mmbase.applications.packaging.ProviderManager;
16 import org.mmbase.applications.packaging.projects.Target;
17 import org.mmbase.applications.packaging.projects.packageStep;
18 import org.mmbase.util.XMLEntityResolver;
19
20 /**
21  * DisplayThemePackage, Handler for theme packages
22  *
23  * @author Daniel Ockeloen (MMBased)
24  */

25 public class DisplayThemeCreator extends BasicCreator implements CreatorInterface {
26
27     /**
28      * Description of the Field
29      */

30     public final static String JavaDoc DTD_PACKAGING_DISPLAY_THEME_1_0 = "packaging_display_theme_1_0.dtd";
31     /**
32      * Description of the Field
33      */

34     public final static String JavaDoc PUBLIC_ID_PACKAGING_DISPLAY_THEME_1_0 = "-//MMBase//DTD packaging_display_theme config 1.0//EN";
35
36
37     /**
38      * Description of the Method
39      */

40     public static void registerPublicIDs() {
41         XMLEntityResolver.registerPublicID(PUBLIC_ID_PACKAGING_DISPLAY_THEME_1_0, "DTD_PACKAGING_DISPLAY_THEME_1_0", DisplayThemeCreator.class);
42     }
43
44
45     /**
46      *Constructor for the DisplayThemeCreator object
47      */

48     public DisplayThemeCreator() {
49         cl = DisplayThemeCreator.class;
50         prefix = "packaging_display_theme";
51     }
52
53
54     /**
55      * Description of the Method
56      *
57      * @param target Description of the Parameter
58      * @param newversion Description of the Parameter
59      * @return Description of the Return Value
60      */

61     public boolean createPackage(Target target, int newversion) {
62
63         clearPackageSteps();
64
65         // step1
66
packageStep step = getNextPackageStep();
67         step.setUserFeedBack("display/theme packager started");
68
69         String JavaDoc themename = getItemStringValue(target, "themename");
70
71         step = getNextPackageStep();
72         step.setUserFeedBack("used themename : " + themename);
73
74         String JavaDoc newfilename = getBuildPath() + getName(target).replace(' ', '_') + "@" + getMaintainer(target) + "_display_theme_" + newversion;
75         try {
76             JarOutputStream JavaDoc jarfile = new JarOutputStream JavaDoc(new FileOutputStream JavaDoc(newfilename + ".tmp"), new Manifest JavaDoc());
77
78             step = getNextPackageStep();
79             step.setUserFeedBack("creating package.xml file...");
80             createPackageMetaFile(jarfile, target, newversion);
81             step.setUserFeedBack("creating package.xml file...done");
82             step = getNextPackageStep();
83             step.setUserFeedBack("creating depends.xml file...");
84             createDependsMetaFile(jarfile, target);
85             step.setUserFeedBack("creating depends.xml file...done");
86
87             step = getNextPackageStep();
88             step.setUserFeedBack("theme name ... "+themename);
89
90         String JavaDoc packpath=target.getBaseDir()+"themes"+File.separator+themename+File.separator+File.separator+"theme.xml";
91             addFile(jarfile, packpath,themename+File.separator+"theme.xml", "themefile", "");
92
93         packpath=target.getBaseDir()+"themes"+File.separator+themename+File.separator+"images"+File.separator;
94             int filecount = addFiles(jarfile, packpath, "*", "/CVS/", "image themefiles", "images/"+themename);
95             if (filecount == 0) {
96                 step = getNextPackageStep();
97                 step.setUserFeedBack("did't add any theme image files, no files found");
98                 step.setType(packageStep.TYPE_WARNING);
99             }
100         packpath=target.getBaseDir()+"themes"+File.separator+themename+File.separator+"css"+File.separator;
101             filecount = addFiles(jarfile, packpath, "*", "/CVS/", "css themefiles", "css/"+themename);
102             if (filecount == 0) {
103                 step = getNextPackageStep();
104                 step.setUserFeedBack("did't add any theme css files, no files found");
105                 step.setType(packageStep.TYPE_WARNING);
106             }
107             jarfile.close();
108         } catch (Exception JavaDoc e) {
109             e.printStackTrace();
110         }
111
112
113         // update the build file to reflect the last build, should only be done if no errors
114
if (getErrorCount() == 0) {
115             File JavaDoc f1 = new File JavaDoc(newfilename + ".tmp");
116             File JavaDoc f2 = new File JavaDoc(newfilename + ".mmp");
117             if (f1.renameTo(f2)) {
118                 updatePackageTime(target, new Date JavaDoc(), newversion);
119                 target.save();
120             }
121         }
122
123     // do we need to send this to a publish provider ?
124
if (target.getPublishState()) {
125                 ProviderManager.resetSleepCounter();
126             step=getNextPackageStep();
127             step.setUserFeedBack("publishing to provider : "+target.getPublishProvider());
128             step=getNextPackageStep();
129             step.setUserFeedBack("sending file : "+target.getId()+" ...");
130         if (target.publish(newversion,step)) {
131                 step.setUserFeedBack("sending file : "+target.getId()+" ... done");
132         } else {
133                 step.setUserFeedBack("sending file : "+target.getId()+" ... failed");
134         }
135     }
136
137         step = getNextPackageStep();
138         step.setUserFeedBack("display/theme packager ended : " + getErrorCount() + " errors and " + getWarningCount() + " warnings");
139         return true;
140     }
141
142
143     /**
144      * Description of the Method
145      *
146      * @param target Description of the Parameter
147      * @return Description of the Return Value
148      */

149     public boolean decodeItems(Target target) {
150         super.decodeItems(target);
151         decodeStringItem(target, "themename");
152         return true;
153     }
154
155
156     /**
157      * Gets the xMLFile attribute of the DisplayThemeCreator object
158      *
159      * @param target Description of the Parameter
160      * @return The xMLFile value
161      */

162     public String JavaDoc getXMLFile(Target target) {
163         String JavaDoc body = getDefaultXMLHeader(target);
164         body += getDefaultXMLMetaInfo(target);
165         body += "\t<themename>" + getItemStringValue(target, "themename") + "</themename>\n";
166         body += getPackageDependsXML(target);
167         body += getRelatedPeopleXML("initiators", "initiator", target);
168         body += getRelatedPeopleXML("supporters", "supporter", target);
169         body += getRelatedPeopleXML("developers", "developer", target);
170         body += getRelatedPeopleXML("contacts", "contact", target);
171     if (target.getPublishProvider()!=null) {
172         if (target.getPublishState()) {
173             body+="\t<publishprovider name=\""+target.getPublishProvider()+"\" state=\"active\" sharepassword=\""+target.getPublishSharePassword()+"\" />\n";
174         } else {
175             body+="\t<publishprovider name=\""+target.getPublishProvider()+"\" state=\"inactive\" sharepassword=\""+target.getPublishSharePassword()+"\" />\n";
176         }
177     }
178         body += getDefaultXMLFooter(target);
179         return body;
180     }
181
182
183     /**
184      * Sets the defaults attribute of the DisplayThemeCreator object
185      *
186      * @param target The new defaults value
187      */

188     public void setDefaults(Target target) {
189         target.setItem("themename", target.getName());
190     }
191
192   public String JavaDoc getDefaultTargetName() {
193         return "theme";
194   }
195
196 }
197
198
Popular Tags