You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by eg...@apache.org on 2003/07/15 16:55:49 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/publication PageEnvelope.java

egli        2003/07/15 07:55:49

  Modified:    src/java/org/apache/lenya/cms/publication PageEnvelope.java
  Log:
  The publication now (optionally for backwards compatibility)
  looks for a config file named publication.xconf and fetches
  the languages, the default language and the DocumentToPathMapper
  from it.
  
  Since the Constructor of Publication can throw an PublicationException
  now a lot of files have to be adapted.
  
  In order to handle that the constructor functionality needed to be
  factored out into the init method.
  
  This is possibly not needed anymore if the deprecated constructor
  is removed.
  
  Revision  Changes    Path
  1.28      +80 -39    cocoon-lenya/src/java/org/apache/lenya/cms/publication/PageEnvelope.java
  
  Index: PageEnvelope.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/publication/PageEnvelope.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- PageEnvelope.java	8 Jul 2003 14:22:09 -0000	1.27
  +++ PageEnvelope.java	15 Jul 2003 14:55:49 -0000	1.28
  @@ -66,7 +66,6 @@
   
   import java.util.Map;
   
  -
   /**
    * A page envelope carries a set of information that are needed
    * during the presentation of a document.
  @@ -88,8 +87,7 @@
       /**
        * Constructor.
        */
  -    protected PageEnvelope() {
  -    }
  +    protected PageEnvelope() {}
   
       /**
        * Creates a new instance of PageEnvelope from a sitemap inside a publication.
  @@ -100,6 +98,49 @@
        */
       public PageEnvelope(Publication publication, Request request)
           throws PageEnvelopeException {
  +        init(publication, request);
  +    }
  +
  +    /**
  +     * Creates a page envelope from an object model.
  +     * @param objectModel The object model.
  +     * @throws PageEnvelopeException when something went wrong.
  +     * @deprecated Performance problems. Use {@link PageEnvelopeFactory#getPageEnvelope(Map)} instead.
  +     */
  +    public PageEnvelope(Map objectModel) throws PageEnvelopeException {
  +        try {
  +            init(
  +                PublicationFactory.getPublication(objectModel),
  +                ObjectModelHelper.getRequest(objectModel));
  +        } catch (PublicationException e) {
  +            throw new PageEnvelopeException(e);
  +        }
  +    }
  +
  +    /**
  +     * Creates a page envelope from an object model.
  +     * @param objectModel The object model.
  +     * @param createdByFactory A dummy parameter to allow creating an additional
  +     * protected constructor that is not deprecated.
  +     * @throws PageEnvelopeException when something went wrong.
  +     */
  +    protected PageEnvelope(Map objectModel, boolean createdByFactory)
  +        throws PageEnvelopeException {
  +        this(objectModel);
  +    }
  +
  +	/**
  +	 * Setup an instance of Publication.
  +	 * 
  +	 * Shared by multiple constructors.
  +	 * 
  +	 * @param publication The publication the page belongs to.
  +	 * @param request The request that calls the page.
  +	 * 
  +	 * @throws PageEnvelopeException if an error occurs.
  +	 */
  +    protected void init(Publication publication, Request request)
  +        throws PageEnvelopeException {
           assert publication != null;
           assert request != null;
   
  @@ -112,7 +153,9 @@
               }
   
               String webappURI = requestURI.substring(context.length());
  -            Document document = DefaultDocumentBuilder.getInstance().buildDocument(publication,
  +            Document document =
  +                DefaultDocumentBuilder.getInstance().buildDocument(
  +                    publication,
                       webappURI);
               setDocument(document);
   
  @@ -121,8 +164,15 @@
           }
   
           // plausibility check
  -        if (!request.getRequestURI().startsWith(getContext() + "/" + getPublication().getId() +
  -                    "/" + getArea() + getDocumentId())) {
  +        if (!request
  +            .getRequestURI()
  +            .startsWith(
  +                getContext()
  +                    + "/"
  +                    + getPublication().getId()
  +                    + "/"
  +                    + getArea()
  +                    + getDocumentId())) {
               throw new PageEnvelopeException(createExceptionMessage(request));
           }
       }
  @@ -133,32 +183,17 @@
        * @return A string.
        */
       protected String createExceptionMessage(Request request) {
  -        return "Resolving page envelope failed:" + "\n  URI: " + request.getRequestURI() +
  -        "\n  Context: " + getContext() + "\n  Publication ID: " + getPublication().getId() +
  -        "\n  Area: " + getArea() + "\n  Document ID: " + getDocumentId();
  -    }
  -
  -    /**
  -     * Creates a page envelope from an object model.
  -     * @param objectModel The object model.
  -     * @throws PageEnvelopeException when something went wrong.
  -     * @deprecated Performance problems. Use {@link PageEnvelopeFactory#getPageEnvelope(Map)} instead.
  -     */
  -    public PageEnvelope(Map objectModel) throws PageEnvelopeException {
  -        this(PublicationFactory.getPublication(objectModel),
  -            ObjectModelHelper.getRequest(objectModel));
  -    }
  -
  -    /**
  -     * Creates a page envelope from an object model.
  -     * @param objectModel The object model.
  -     * @param createdByFactory A dummy parameter to allow creating an additional
  -     * protected constructor that is not deprecated.
  -     * @throws PageEnvelopeException when something went wrong.
  -     */
  -    protected PageEnvelope(Map objectModel, boolean createdByFactory)
  -        throws PageEnvelopeException {
  -        this(objectModel);
  +        return "Resolving page envelope failed:"
  +            + "\n  URI: "
  +            + request.getRequestURI()
  +            + "\n  Context: "
  +            + getContext()
  +            + "\n  Publication ID: "
  +            + getPublication().getId()
  +            + "\n  Area: "
  +            + getArea()
  +            + "\n  Document ID: "
  +            + getDocumentId();
       }
   
       /**
  @@ -175,7 +210,8 @@
        * @deprecated We should detach the RC environment from the page envelope.
        */
       public RCEnvironment getRCEnvironment() {
  -        return RCEnvironment.getInstance(getPublication().getServletContext().getAbsolutePath());
  +        return RCEnvironment.getInstance(
  +            getPublication().getServletContext().getAbsolutePath());
       }
   
       /**
  @@ -221,11 +257,16 @@
       /**
        * The names of the page envelope parameters.
        */
  -    public static final String[] PARAMETER_NAMES = {
  -        PageEnvelope.AREA, PageEnvelope.CONTEXT, PageEnvelope.PUBLICATION_ID,
  -        PageEnvelope.PUBLICATION, PageEnvelope.DOCUMENT_ID, PageEnvelope.DOCUMENT_URL,
  -        PageEnvelope.DOCUMENT_PATH, PageEnvelope.DOCUMENT_LANGUAGE
  -    };
  +    public static final String[] PARAMETER_NAMES =
  +        {
  +            PageEnvelope.AREA,
  +            PageEnvelope.CONTEXT,
  +            PageEnvelope.PUBLICATION_ID,
  +            PageEnvelope.PUBLICATION,
  +            PageEnvelope.DOCUMENT_ID,
  +            PageEnvelope.DOCUMENT_URL,
  +            PageEnvelope.DOCUMENT_PATH,
  +            PageEnvelope.DOCUMENT_LANGUAGE };
   
       /**
        * @param string The context.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org