KickJava   Java API By Example, From Geeks To Geeks.

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


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.FileOutputStream JavaDoc;
10 import java.util.Date JavaDoc;
11 import java.util.jar.JarOutputStream JavaDoc;
12 import java.util.jar.Manifest JavaDoc;
13
14 import org.mmbase.applications.packaging.ProviderManager;
15 import org.mmbase.applications.packaging.projects.Target;
16 import org.mmbase.applications.packaging.projects.packageStep;
17 import org.mmbase.util.XMLEntityResolver;
18
19 /**
20  * DisplayHtmlPackage, Handler for html packages
21  *
22  * @author Daniel Ockeloen (MMBased)
23  */

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

29     public final static String JavaDoc DTD_PACKAGING_FUNCTION_SET_1_0 = "packaging_function_set_1_0.dtd";
30     /**
31      * Description of the Field
32      */

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

39     public static void registerPublicIDs() {
40         XMLEntityResolver.registerPublicID(PUBLIC_ID_PACKAGING_FUNCTION_SET_1_0, "DTD_PACKAGING_FUNCTION_SET_1_0", FunctionSetCreator.class);
41     }
42
43
44     /**
45      *Constructor for the FunctionSetCreator object
46      */

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

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

137     public boolean decodeItems(Target target) {
138         super.decodeItems(target);
139         decodeStringItem(target, "functionsetfile");
140         decodeStringItem(target, "functionsetdir");
141         return true;
142     }
143
144
145     /**
146      * Gets the xMLFile attribute of the FunctionSetCreator object
147      *
148      * @param target Description of the Parameter
149      * @return The xMLFile value
150      */

151     public String JavaDoc getXMLFile(Target target) {
152         String JavaDoc body = getDefaultXMLHeader(target);
153         body += getDefaultXMLMetaInfo(target);
154         body += "\t<functionsetfile>" + getItemStringValue(target, "functionsetfile") + "</functionsetfile>\n";
155         body += "\t<functionsetdir>" + getItemStringValue(target, "functionsetdir") + "</functionsetdir>\n";
156         body += getPackageDependsXML(target);
157         body += getRelatedPeopleXML("initiators", "initiator", target);
158         body += getRelatedPeopleXML("supporters", "supporter", target);
159         body += getRelatedPeopleXML("developers", "developer", target);
160         body += getRelatedPeopleXML("contacts", "contact", target);
161     if (target.getPublishProvider()!=null) {
162         if (target.getPublishState()) {
163             body+="\t<publishprovider name=\""+target.getPublishProvider()+"\" state=\"active\" sharepassword=\""+target.getPublishSharePassword()+"\" />\n";
164         } else {
165             body+="\t<publishprovider name=\""+target.getPublishProvider()+"\" state=\"inactive\" sharepassword=\""+target.getPublishSharePassword()+"\" />\n";
166         }
167     }
168         body += getDefaultXMLFooter(target);
169         return body;
170     }
171
172
173     /**
174      * Sets the defaults attribute of the FunctionSetCreator object
175      *
176      * @param target The new defaults value
177      */

178     public void setDefaults(Target target) {
179         target.setItem("functionsetfile", "config/functions/functionsetfile.xml");
180         target.setItem("functionsetdir", "config/functions/sets/");
181     }
182
183   public String JavaDoc getDefaultTargetName() {
184         return "functionsets";
185   }
186
187 }
188
189
Popular Tags