1 17 18 19 20 package org.apache.lenya.cms.publication; 21 22 import java.util.Map ; 23 24 import org.apache.cocoon.environment.ObjectModelHelper; 25 import org.apache.cocoon.environment.Request; 26 import org.apache.lenya.cms.rc.RCEnvironment; 27 import org.apache.lenya.util.ServletHelper; 28 29 33 public class PageEnvelope { 34 public static final String PUBLICATION_ID = "publication-id"; 35 public static final String PUBLICATION = "publication"; 36 public static final String PUBLICATION_LANGUAGES_CSV = "publication-languages-csv"; 37 public static final String CONTEXT = "context-prefix"; 38 public static final String AREA = "area"; 39 public static final String DEFAULT_LANGUAGE = "default-language"; 40 public static final String DOCUMENT = "document"; 41 public static final String DOCUMENT_ID = "document-id"; 42 public static final String DOCUMENT_NAME = "document-name"; 43 public static final String DOCUMENT_TYPE = "document-type"; 44 public static final String DOCUMENT_NODE_ID = "document-node-id"; 45 public static final String DOCUMENT_LABEL = "document-label"; 46 public static final String DOCUMENT_URL = "document-url"; 47 public static final String DOCUMENT_URL_WITHOUT_LANGUAGE = "document-url-without-language"; 48 public static final String DOCUMENT_FILE = "document-file"; 49 public static final String DOCUMENT_PATH = "document-path"; 50 public static final String DOCUMENT_EXTENSION = "document-extension"; 51 public static final String DOCUMENT_LANGUAGE = "document-language"; 52 public static final String DOCUMENT_LANGUAGES = "document-languages"; 53 public static final String DOCUMENT_LANGUAGES_CSV = "document-languages-csv"; 54 55 56 public static final String DOCUMENT_DC_TITLE = "document-dc-title"; 57 58 59 public static final String DOCUMENT_DC_CREATOR = "document-dc-creator"; 60 61 62 public static final String DOCUMENT_DC_SUBJECT = "document-dc-subject"; 63 64 65 public static final String DOCUMENT_DC_PUBLISHER = "document-dc-publisher"; 66 67 68 public static final String DOCUMENT_DC_DATE_CREATED = "document-dc-date-created"; 69 70 71 public static final String DOCUMENT_DC_DESCRIPTION = "document-dc-description"; 72 73 74 public static final String DOCUMENT_DC_RIGHTS = "document-dc-rights"; 75 76 public static final String DOCUMENT_LASTMODIFIED = "document-lastmodified"; 77 78 public static final String BREADCRUMB_PREFIX = "breadcrumb-prefix"; 79 80 public static final String SSL_PREFIX = "ssl-prefix"; 81 82 public static final String NAMESPACE = "http://apache.org/cocoon/lenya/page-envelope/1.0"; 83 public static final String DEFAULT_PREFIX = "lenya"; 84 85 private String context; 86 87 90 protected PageEnvelope() { 91 } 92 93 105 public PageEnvelope(Publication publication, Request request) throws PageEnvelopeException { 106 init(publication, request); 107 } 108 109 119 public PageEnvelope(Map objectModel) throws PageEnvelopeException { 120 try { 121 init( 122 PublicationFactory.getPublication(objectModel), 123 ObjectModelHelper.getRequest(objectModel)); 124 } catch (PublicationException e) { 125 throw new PageEnvelopeException(e); 126 } 127 } 128 129 139 public PageEnvelope(Publication publication, Request request, boolean createdByFactory) 140 throws PageEnvelopeException { 141 this(publication, request); 142 } 143 144 155 protected PageEnvelope(Map objectModel, boolean createdByFactory) 156 throws PageEnvelopeException { 157 this(objectModel); 158 } 159 160 173 protected void init(Publication publication, Request request) 174 throws PageEnvelopeException { 182 assert publication != null; 183 assert request != null; 184 String webappURI; 185 try { 186 187 context = request.getContextPath(); 188 if (context == null) { 189 context = ""; 190 } 191 192 webappURI = ServletHelper.getWebappURI(request); 193 Document document = 194 publication.getDocumentBuilder().buildDocument(publication, webappURI); 195 setDocument(document); 196 197 } catch (Exception e) { 198 throw new PageEnvelopeException(e); 199 } 200 201 206 } 207 208 215 protected String createExceptionMessage(Request request) { 216 return "Resolving page envelope failed:" 217 + "\n URI: " 218 + request.getRequestURI() 219 + "\n Context: " 220 + getContext() 221 + "\n Publication ID: " 222 + getPublication().getId() 223 + "\n Area: " 224 + document.getArea() 225 + "\n Document ID: " 226 + document.getId(); 227 } 228 229 234 public Publication getPublication() { 235 return getDocument().getPublication(); 236 } 237 238 244 public RCEnvironment getRCEnvironment() { 245 return RCEnvironment.getInstance(getPublication().getServletContext().getAbsolutePath()); 246 } 247 248 253 public String getContext() { 254 return context; 255 } 256 257 262 public String getDocumentPath() { 263 264 return getPublication().getPathMapper().getPath( 265 getDocument().getId(), 266 getDocument().getLanguage()); 267 } 268 269 272 public static final String [] PARAMETER_NAMES = 273 { 274 PageEnvelope.AREA, 275 PageEnvelope.CONTEXT, 276 PageEnvelope.PUBLICATION_ID, 277 PageEnvelope.PUBLICATION, 278 PageEnvelope.PUBLICATION_LANGUAGES_CSV, 279 PageEnvelope.DOCUMENT, 280 PageEnvelope.DOCUMENT_ID, 281 PageEnvelope.DOCUMENT_NAME, 282 PageEnvelope.DOCUMENT_NODE_ID, 283 PageEnvelope.DOCUMENT_LABEL, 284 PageEnvelope.DOCUMENT_URL, 285 PageEnvelope.DOCUMENT_URL_WITHOUT_LANGUAGE, 286 PageEnvelope.DOCUMENT_PATH, 287 PageEnvelope.DOCUMENT_EXTENSION, 288 PageEnvelope.DEFAULT_LANGUAGE, 289 PageEnvelope.DOCUMENT_LANGUAGE, 290 PageEnvelope.DOCUMENT_LANGUAGES, 291 PageEnvelope.DOCUMENT_LANGUAGES_CSV, 292 PageEnvelope.DOCUMENT_DC_TITLE, 293 PageEnvelope.DOCUMENT_DC_CREATOR, 294 PageEnvelope.DOCUMENT_DC_PUBLISHER, 295 PageEnvelope.DOCUMENT_DC_SUBJECT, 296 PageEnvelope.DOCUMENT_DC_DATE_CREATED, 297 PageEnvelope.DOCUMENT_DC_DESCRIPTION, 298 PageEnvelope.DOCUMENT_DC_RIGHTS, 299 PageEnvelope.DOCUMENT_LASTMODIFIED, 300 PageEnvelope.BREADCRUMB_PREFIX, 301 PageEnvelope.SSL_PREFIX }; 302 303 307 protected void setContext(String string) { 308 context = string; 309 } 310 311 private Document document; 312 313 318 public Document getDocument() { 319 return document; 320 } 321 322 328 public void setDocument(Document document) { 329 this.document = document; 330 } 331 332 } 333 | Popular Tags |