1 16 package nl.hippo.cms.workflows.multiplesitesdocument; 17 18 import java.io.IOException ; 19 import java.text.MessageFormat ; 20 import java.util.Iterator ; 21 import nl.hippo.cms.sitesdirectory.SiteInformation; 22 import nl.hippo.cms.sitesdirectory.SitesDirectory; 23 import nl.hippo.cms.workflows.shared.ResourceGeneratorComponent; 24 import nl.hippo.componentcontainers.AvalonSpringBridge; 25 import nl.hippo.servermanager.Project; 26 import org.apache.avalon.framework.service.ServiceException; 27 import org.apache.commons.httpclient.HttpState; 28 import org.xml.sax.SAXException ; 29 import org.xml.sax.helpers.AttributesImpl ; 30 import org.xml.sax.helpers.DefaultHandler ; 31 32 public class RequestPublicationInputFormGenerator extends ResourceGeneratorComponent 33 { 34 35 public RequestPublicationInputFormGenerator() 36 { 37 super(); 38 } 39 40 public void generateImpl(String uri, Project project, DefaultHandler handler) 41 throws SAXException 42 { 43 try 44 { 45 SitesDirectory sitesDir = (SitesDirectory) m_manager.lookup(SitesDirectory.ROLE); 46 try 47 { 48 handler.startDocument(); 49 50 sendForm(uri, project, handler, sitesDir); 51 52 handler.endDocument(); 53 } 54 finally 55 { 56 m_manager.release(sitesDir); 57 } 58 } 59 catch (ServiceException e) 60 { 61 throw new SAXException (e); 62 } 63 } 64 65 private void sendForm(String uri, Project project, DefaultHandler handler, 66 SitesDirectory sitesDir) throws SAXException 67 { 68 handler.startElement(null, "form", "form", new AttributesImpl ()); 69 70 boolean outputCheckboxes = sitesDir.getNumberOfSites() > 1; 71 Iterator siteIdsIter = sitesDir.siteIdsIterator(); 72 while (siteIdsIter.hasNext()) 73 { 74 String siteId = (String ) siteIdsIter.next(); 75 SiteInformation siteInfo = sitesDir.getSite(siteId); 76 sendSiteWidgets(uri, project, handler, siteInfo, outputCheckboxes); 77 } 78 79 handler.endElement(null, "form", "form"); 80 } 81 82 private void sendSiteWidgets(String uri, Project project, DefaultHandler handler, 83 SiteInformation siteInfo, boolean outputCheckboxes) throws SAXException 84 { 85 try 86 { 87 AvalonSpringBridge avalonSpringBridge = (AvalonSpringBridge) m_manager 88 .lookup(AvalonSpringBridge.ROLE); 89 try 90 { 91 HttpState httpState = (HttpState) avalonSpringBridge.getBean("httpState"); 92 boolean isPublished = MultipleSitesDocumentUtil.isPublishedOnSite(uri, siteInfo 93 .getId(), project, httpState); 94 95 if (outputCheckboxes) 96 { 97 AttributesImpl selectionAttr = new AttributesImpl (); 98 selectionAttr.addAttribute(null, "ref", "ref", "CDATA", siteInfo.getId() 99 + "-selection"); 100 selectionAttr.addAttribute(null, "parameter-box-id", "parameter-box-id", "CDATA", siteInfo.getId() 101 + "-parameters"); 102 handler.startElement(null, "checkbox", "checkbox", selectionAttr); 103 handler.startElement(null, "output", "output", new AttributesImpl ()); 104 String siteName = siteInfo.getName("en"); 106 handler.characters(siteName.toCharArray(), 0, siteName.length()); 107 handler.endElement(null, "output", "output"); 108 sendPublicationInfoAndParameters(uri, project, handler, siteInfo, isPublished); 109 handler.endElement(null, "checkbox", "checkbox"); 110 } 111 else 112 { 113 sendPublicationInfoAndParameters(uri, project, handler, siteInfo, isPublished); 114 } 115 } 116 finally 117 { 118 m_manager.release(avalonSpringBridge); 119 } 120 } 121 catch (IOException e) 122 { 123 throw new SAXException (e); 124 } 125 catch (ServiceException e) 126 { 127 throw new SAXException (e); 128 } 129 } 130 131 private void sendPublicationInfoAndParameters(String uri, Project project, DefaultHandler handler, SiteInformation siteInfo, 132 boolean isPublished) throws SAXException , ServiceException, IOException 133 { 134 handler.startElement(null, "output", "output", new AttributesImpl ()); 135 if (isPublished) 136 { 137 VersionInformation versionInfo = MultipleSitesDocumentUtil 138 .getPublishedVersionInformation(uri, project, siteInfo.getId(), m_manager); 139 MessageFormat mf = new MessageFormat ("Version {0}. {1}"); 141 StringBuffer versionInfoTextBuffer = mf.format(new Object [] 142 { 143 new Integer (versionInfo.getVersionNumber()), versionInfo.getComment(), 144 }, new StringBuffer (), null); 145 String versionInfoText = versionInfoTextBuffer.toString(); 146 handler.characters(versionInfoText.toCharArray(), 0, versionInfoText.length()); 147 } 148 else 149 { 150 String notPublishedText = "Not published."; 152 handler.characters(notPublishedText.toCharArray(), 0, notPublishedText.length()); 153 } 154 handler.endElement(null, "output", "output"); 155 156 AttributesImpl groupAttributes = new AttributesImpl (); 157 groupAttributes.addAttribute(null, "id", "id", "CDATA", siteInfo.getId() + "-parameters"); 158 groupAttributes.addAttribute(null, "visible", "visible", "CDATA", isPublished 159 ? "true" 160 : "false"); 161 handler.startElement(null, "group", "group", groupAttributes); 162 163 AttributesImpl pubDateModeLabelAttr = new AttributesImpl (); 165 pubDateModeLabelAttr.addAttribute(null, "ref", "ref", "CDATA", siteInfo.getId() 166 + "-publicationDateMode"); 167 handler.startElement(null, "label", "label", pubDateModeLabelAttr); 168 handler.endElement(null, "label", "label"); 169 170 AttributesImpl pubDateModeAttr = new AttributesImpl (); 172 pubDateModeAttr.addAttribute(null, "ref", "ref", "CDATA", siteInfo.getId() 173 + "-publicationDateMode"); 174 pubDateModeAttr.addAttribute(null, "appearance", "appearance", "CDATA", "full"); 175 handler.startElement(null, "select1", "select1", pubDateModeAttr); 176 handler.endElement(null, "select1", "select1"); 177 178 AttributesImpl pubDateAttr = new AttributesImpl (); 180 pubDateAttr 181 .addAttribute(null, "ref", "ref", "CDATA", siteInfo.getId() + "-publicationDate"); 182 handler.startElement(null, "input", "input", pubDateAttr); 183 handler.endElement(null, "input", "input"); 184 185 AttributesImpl unpubDateModeLabelAttr = new AttributesImpl (); 187 unpubDateModeLabelAttr.addAttribute(null, "ref", "ref", "CDATA", siteInfo.getId() 188 + "-unpublicationDateMode"); 189 handler.startElement(null, "label", "label", unpubDateModeLabelAttr); 190 handler.endElement(null, "label", "label"); 191 192 AttributesImpl unpubDateModeAttr = new AttributesImpl (); 194 unpubDateModeAttr.addAttribute(null, "ref", "ref", "CDATA", siteInfo.getId() 195 + "-unpublicationDateMode"); 196 unpubDateModeAttr.addAttribute(null, "appearance", "appearance", "CDATA", "full"); 197 handler.startElement(null, "select1", "select1", unpubDateModeAttr); 198 handler.endElement(null, "select1", "select1"); 199 200 AttributesImpl unpubDateAttr = new AttributesImpl (); 202 unpubDateAttr.addAttribute(null, "ref", "ref", "CDATA", siteInfo.getId() 203 + "-unpublicationDate"); 204 handler.startElement(null, "input", "input", unpubDateAttr); 205 handler.endElement(null, "input", "input"); 206 207 handler.endElement(null, "group", "group"); 208 } 209 210 } 211 | Popular Tags |