KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nl > hippo > cms > workflows > multiplesitesdocument > RequestPublicationInputSchemaGenerator


1 /*
2  * Copyright 2004 Hippo Webworks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package nl.hippo.cms.workflows.multiplesitesdocument;
17
18 import java.util.Iterator JavaDoc;
19 import nl.hippo.cms.sitesdirectory.SiteInformation;
20 import nl.hippo.cms.sitesdirectory.SitesDirectory;
21 import nl.hippo.cms.workflows.shared.ResourceGeneratorComponent;
22 import nl.hippo.servermanager.Project;
23 import org.apache.avalon.framework.service.ServiceException;
24 import org.xml.sax.SAXException JavaDoc;
25 import org.xml.sax.helpers.AttributesImpl JavaDoc;
26 import org.xml.sax.helpers.DefaultHandler JavaDoc;
27
28 public class RequestPublicationInputSchemaGenerator extends ResourceGeneratorComponent
29 {
30
31     public RequestPublicationInputSchemaGenerator()
32     {
33         super();
34     }
35
36     public void generateImpl(String JavaDoc uri, Project project, DefaultHandler JavaDoc handler) throws SAXException JavaDoc
37     {
38         try
39         {
40             SitesDirectory sitesDir = (SitesDirectory) m_manager.lookup(SitesDirectory.ROLE);
41             try
42             {
43                 handler.startDocument();
44
45                 sendSchema(handler, sitesDir);
46
47                 handler.endDocument();
48             }
49             finally
50             {
51                 m_manager.release(sitesDir);
52             }
53         }
54         catch (ServiceException e)
55         {
56             throw new SAXException JavaDoc(e);
57         }
58     }
59
60     private void sendSchema(DefaultHandler JavaDoc handler, SitesDirectory sitesDir) throws SAXException JavaDoc
61     {
62         handler.startElement(null, "schema", "schema", new AttributesImpl JavaDoc());
63
64         boolean outputCheckboxes = sitesDir.getNumberOfSites() > 1;
65         Iterator JavaDoc siteIdsIter = sitesDir.siteIdsIterator();
66         while (siteIdsIter.hasNext())
67         {
68             String JavaDoc siteId = (String JavaDoc) siteIdsIter.next();
69             SiteInformation siteInfo = sitesDir.getSite(siteId);
70             sendSiteFields(handler, siteInfo, outputCheckboxes);
71         }
72
73         handler.endElement(null, "schema", "schema");
74     }
75
76     private void sendSiteFields(DefaultHandler JavaDoc handler, SiteInformation siteInfo,
77             boolean outputCheckboxes) throws SAXException JavaDoc
78     {
79         if (outputCheckboxes)
80         {
81             sendSelectionField(handler, siteInfo);
82         }
83
84         sendPublicationDateModeField(handler, siteInfo);
85         sendPublicationDateField(handler, siteInfo);
86         sendUnpublicationDateModeField(handler, siteInfo);
87         sendUnpublicationDateField(handler, siteInfo);
88     }
89
90     private void sendSelectionField(DefaultHandler JavaDoc handler, SiteInformation siteInfo)
91             throws SAXException JavaDoc
92     {
93         // Publication selection field
94
AttributesImpl JavaDoc pubDateModeFieldAttr = new AttributesImpl JavaDoc();
95         pubDateModeFieldAttr.addAttribute(null, "name", "name", "CDATA", siteInfo.getId()
96                 + "-selection");
97         handler.startElement(null, "field", "field", pubDateModeFieldAttr);
98
99         // Publication selection label
100
handler.startElement(null, "label", "label", new AttributesImpl JavaDoc());
101         char[] pubDateModeLabelText = "cms.workflows.multiplesitesdocument.publicationSelection"
102                 .toCharArray();
103         handler.characters(pubDateModeLabelText, 0, pubDateModeLabelText.length);
104         handler.endElement(null, "label", "label");
105         
106         handler.startElement(null, "boolean", "boolean", new AttributesImpl JavaDoc());
107         handler.endElement(null, "boolean", "boolean");
108
109         handler.endElement(null, "field", "field");
110     }
111
112     private void sendPublicationDateModeField(DefaultHandler JavaDoc handler, SiteInformation siteInfo)
113             throws SAXException JavaDoc
114     {
115         // Publication-date mode field
116
AttributesImpl JavaDoc pubDateModeFieldAttr = new AttributesImpl JavaDoc();
117         pubDateModeFieldAttr.addAttribute(null, "name", "name", "CDATA", siteInfo.getId()
118                 + "-publicationDateMode");
119         handler.startElement(null, "field", "field", pubDateModeFieldAttr);
120
121         // Publication-date mode label
122
handler.startElement(null, "label", "label", new AttributesImpl JavaDoc());
123         char[] pubDateModeLabelText = "cms.workflows.multiplesitesdocument.publicationDateMode"
124                 .toCharArray();
125         handler.characters(pubDateModeLabelText, 0, pubDateModeLabelText.length);
126         handler.endElement(null, "label", "label");
127
128         // Publication-date mode enumeration
129
handler.startElement(null, "enumeration", "enumeration", new AttributesImpl JavaDoc());
130         sendEnumerationValue(handler, "now",
131                 "cms.workflows.multiplesitesdocument.publicationDateModeNow");
132         sendEnumerationValue(handler, "other",
133                 "cms.workflows.multiplesitesdocument.publicationDateModeOther");
134         handler.endElement(null, "enumeration", "enumeration");
135
136         handler.endElement(null, "field", "field");
137     }
138
139     private void sendPublicationDateField(DefaultHandler JavaDoc handler, SiteInformation siteInfo)
140             throws SAXException JavaDoc
141     {
142         // Publication-date field
143
AttributesImpl JavaDoc pubDateFieldAttr = new AttributesImpl JavaDoc();
144         pubDateFieldAttr.addAttribute(null, "name", "name", "CDATA", siteInfo.getId()
145                 + "-publicationDate");
146         handler.startElement(null, "field", "field", pubDateFieldAttr);
147
148         // Publication-date label
149
handler.startElement(null, "label", "label", new AttributesImpl JavaDoc());
150         char[] pubDateLabelText = "cms.workflows.multiplesitesdocument.publicationDate"
151                 .toCharArray();
152         handler.characters(pubDateLabelText, 0, pubDateLabelText.length);
153         handler.endElement(null, "label", "label");
154
155         // Publication-date date
156
handler.startElement(null, "date", "date", new AttributesImpl JavaDoc());
157         handler.endElement(null, "date", "date");
158
159         handler.endElement(null, "field", "field");
160     }
161
162     private void sendUnpublicationDateModeField(DefaultHandler JavaDoc handler, SiteInformation siteInfo)
163             throws SAXException JavaDoc
164     {
165         // Unpublication-date mode field
166
AttributesImpl JavaDoc unpubDateModeFieldAttr = new AttributesImpl JavaDoc();
167         unpubDateModeFieldAttr.addAttribute(null, "name", "name", "CDATA", siteInfo.getId()
168                 + "-unpublicationDateMode");
169         handler.startElement(null, "field", "field", unpubDateModeFieldAttr);
170
171         // Unpublication-date mode label
172
handler.startElement(null, "label", "label", new AttributesImpl JavaDoc());
173         char[] unpubDateModeLabelText = "cms.workflows.multiplesitesdocument.unpublicationDateMode"
174                 .toCharArray();
175         handler.characters(unpubDateModeLabelText, 0, unpubDateModeLabelText.length);
176         handler.endElement(null, "label", "label");
177
178         // Unpublication-date mode enumeration
179
handler.startElement(null, "enumeration", "enumeration", new AttributesImpl JavaDoc());
180         sendEnumerationValue(handler, "never",
181                 "cms.workflows.multiplesitesdocument.unpublicationDateModeNever");
182         sendEnumerationValue(handler, "other",
183                 "cms.workflows.multiplesitesdocument.unpublicationDateModeOther");
184         handler.endElement(null, "enumeration", "enumeration");
185
186         handler.endElement(null, "field", "field");
187     }
188
189     private void sendUnpublicationDateField(DefaultHandler JavaDoc handler, SiteInformation siteInfo)
190             throws SAXException JavaDoc
191     {
192         // Unpublication-date field
193
AttributesImpl JavaDoc unpubDateFieldAttr = new AttributesImpl JavaDoc();
194         unpubDateFieldAttr.addAttribute(null, "name", "name", "CDATA", siteInfo.getId()
195                 + "-unpublicationDate");
196         handler.startElement(null, "field", "field", unpubDateFieldAttr);
197
198         // Unpublication-date label
199
handler.startElement(null, "label", "label", new AttributesImpl JavaDoc());
200         char[] unpubDateLabelText = "cms.workflows.multiplesitesdocument.unpublicationDate"
201                 .toCharArray();
202         handler.characters(unpubDateLabelText, 0, unpubDateLabelText.length);
203         handler.endElement(null, "label", "label");
204
205         // Unpublication-date date
206
handler.startElement(null, "date", "date", new AttributesImpl JavaDoc());
207         handler.endElement(null, "date", "date");
208
209         handler.endElement(null, "field", "field");
210     }
211
212     private void sendEnumerationValue(DefaultHandler JavaDoc handler, String JavaDoc value, String JavaDoc labelKey)
213             throws SAXException JavaDoc
214     {
215         AttributesImpl JavaDoc enumValueAttr = new AttributesImpl JavaDoc();
216         enumValueAttr.addAttribute(null, "value", "value", "CDATA", value);
217         handler.startElement(null, "enumeration-value", "enumeration-value", enumValueAttr);
218
219         handler.startElement(null, "label", "label", new AttributesImpl JavaDoc());
220         char[] labelKeyAsCharArray = labelKey.toCharArray();
221         handler.characters(labelKeyAsCharArray, 0, labelKeyAsCharArray.length);
222         handler.endElement(null, "label", "label");
223
224         handler.endElement(null, "enumeration-value", "enumeration-value");
225     }
226 }
227
Popular Tags