1 16 package nl.hippo.cms.workflows.multiplesitesdocument; 17 18 import java.util.Iterator ; 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 ; 25 import org.xml.sax.helpers.AttributesImpl ; 26 import org.xml.sax.helpers.DefaultHandler ; 27 28 public class RequestPublicationInputSchemaGenerator extends ResourceGeneratorComponent 29 { 30 31 public RequestPublicationInputSchemaGenerator() 32 { 33 super(); 34 } 35 36 public void generateImpl(String uri, Project project, DefaultHandler handler) throws SAXException 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 (e); 57 } 58 } 59 60 private void sendSchema(DefaultHandler handler, SitesDirectory sitesDir) throws SAXException 61 { 62 handler.startElement(null, "schema", "schema", new AttributesImpl ()); 63 64 boolean outputCheckboxes = sitesDir.getNumberOfSites() > 1; 65 Iterator siteIdsIter = sitesDir.siteIdsIterator(); 66 while (siteIdsIter.hasNext()) 67 { 68 String siteId = (String ) 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 handler, SiteInformation siteInfo, 77 boolean outputCheckboxes) throws SAXException 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 handler, SiteInformation siteInfo) 91 throws SAXException 92 { 93 AttributesImpl pubDateModeFieldAttr = new AttributesImpl (); 95 pubDateModeFieldAttr.addAttribute(null, "name", "name", "CDATA", siteInfo.getId() 96 + "-selection"); 97 handler.startElement(null, "field", "field", pubDateModeFieldAttr); 98 99 handler.startElement(null, "label", "label", new AttributesImpl ()); 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 ()); 107 handler.endElement(null, "boolean", "boolean"); 108 109 handler.endElement(null, "field", "field"); 110 } 111 112 private void sendPublicationDateModeField(DefaultHandler handler, SiteInformation siteInfo) 113 throws SAXException 114 { 115 AttributesImpl pubDateModeFieldAttr = new AttributesImpl (); 117 pubDateModeFieldAttr.addAttribute(null, "name", "name", "CDATA", siteInfo.getId() 118 + "-publicationDateMode"); 119 handler.startElement(null, "field", "field", pubDateModeFieldAttr); 120 121 handler.startElement(null, "label", "label", new AttributesImpl ()); 123 char[] pubDateModeLabelText = "cms.workflows.multiplesitesdocument.publicationDateMode" 124 .toCharArray(); 125 handler.characters(pubDateModeLabelText, 0, pubDateModeLabelText.length); 126 handler.endElement(null, "label", "label"); 127 128 handler.startElement(null, "enumeration", "enumeration", new AttributesImpl ()); 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 handler, SiteInformation siteInfo) 140 throws SAXException 141 { 142 AttributesImpl pubDateFieldAttr = new AttributesImpl (); 144 pubDateFieldAttr.addAttribute(null, "name", "name", "CDATA", siteInfo.getId() 145 + "-publicationDate"); 146 handler.startElement(null, "field", "field", pubDateFieldAttr); 147 148 handler.startElement(null, "label", "label", new AttributesImpl ()); 150 char[] pubDateLabelText = "cms.workflows.multiplesitesdocument.publicationDate" 151 .toCharArray(); 152 handler.characters(pubDateLabelText, 0, pubDateLabelText.length); 153 handler.endElement(null, "label", "label"); 154 155 handler.startElement(null, "date", "date", new AttributesImpl ()); 157 handler.endElement(null, "date", "date"); 158 159 handler.endElement(null, "field", "field"); 160 } 161 162 private void sendUnpublicationDateModeField(DefaultHandler handler, SiteInformation siteInfo) 163 throws SAXException 164 { 165 AttributesImpl unpubDateModeFieldAttr = new AttributesImpl (); 167 unpubDateModeFieldAttr.addAttribute(null, "name", "name", "CDATA", siteInfo.getId() 168 + "-unpublicationDateMode"); 169 handler.startElement(null, "field", "field", unpubDateModeFieldAttr); 170 171 handler.startElement(null, "label", "label", new AttributesImpl ()); 173 char[] unpubDateModeLabelText = "cms.workflows.multiplesitesdocument.unpublicationDateMode" 174 .toCharArray(); 175 handler.characters(unpubDateModeLabelText, 0, unpubDateModeLabelText.length); 176 handler.endElement(null, "label", "label"); 177 178 handler.startElement(null, "enumeration", "enumeration", new AttributesImpl ()); 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 handler, SiteInformation siteInfo) 190 throws SAXException 191 { 192 AttributesImpl unpubDateFieldAttr = new AttributesImpl (); 194 unpubDateFieldAttr.addAttribute(null, "name", "name", "CDATA", siteInfo.getId() 195 + "-unpublicationDate"); 196 handler.startElement(null, "field", "field", unpubDateFieldAttr); 197 198 handler.startElement(null, "label", "label", new AttributesImpl ()); 200 char[] unpubDateLabelText = "cms.workflows.multiplesitesdocument.unpublicationDate" 201 .toCharArray(); 202 handler.characters(unpubDateLabelText, 0, unpubDateLabelText.length); 203 handler.endElement(null, "label", "label"); 204 205 handler.startElement(null, "date", "date", new AttributesImpl ()); 207 handler.endElement(null, "date", "date"); 208 209 handler.endElement(null, "field", "field"); 210 } 211 212 private void sendEnumerationValue(DefaultHandler handler, String value, String labelKey) 213 throws SAXException 214 { 215 AttributesImpl enumValueAttr = new AttributesImpl (); 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 ()); 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 |