lenya/src/java/org/apache/lenya/cms/publication PageEnvelope.java,1.10,1.11

Christian Egli <[email protected]>
Newsgroups gmane.comp.cms.wyona.cvs
Message-ID <[email protected]>
Update of /repository/lenya/src/java/org/apache/lenya/cms/publication
In directory erbium:/tmp/cvs-serv334/src/java/org/apache/lenya/cms/publication

Modified Files:
	PageEnvelope.java 
Log Message:
Added some more heuristics to the computation of the document-id: if
the requestURI ends in "index" chop it of.


Index: PageEnvelope.java
===================================================================
RCS file: /repository/lenya/src/java/org/apache/lenya/cms/publication/PageEnvelope.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** PageEnvelope.java	8 May 2003 07:35:30 -0000	1.10
--- PageEnvelope.java	8 May 2003 13:40:57 -0000	1.11
***************
*** 23,26 ****
--- 23,27 ----
  import org.apache.lenya.cms.rc.RCEnvironment;
  /**
+  * Describe class <code>PageEnvelope</code> here.
   *
   * @author  nobby
***************
*** 43,47 ****
      private String documentId;
  
!     /** Creates a new instance of PageEnvelope */
      public PageEnvelope(SourceResolver resolver, Request request)
              throws PageEnvelopeException, ProcessingException, SAXException, IOException {
--- 44,56 ----
      private String documentId;
  
!     /**
!      * Creates a new instance of PageEnvelope
!      * @param resolver a <code>SourceResolver</code> value
!      * @param request a <code>Request</code> value
!      * @exception PageEnvelopeException if an error occurs
!      * @exception ProcessingException if an error occurs
!      * @exception SAXException if an error occurs
!      * @exception IOException if an error occurs
!      */
      public PageEnvelope(SourceResolver resolver, Request request)
              throws PageEnvelopeException, ProcessingException, SAXException, IOException {
***************
*** 74,82 ****
          area = directories[AREA_POS];
  
  	// the computation of the document id is based on the
  	// assumption that and URI matches of the following pattern:
  	// http:/<context-prefix>/<publication-id>/<area>/<document-id>.*
  	// where document-id can be foo/bar/baz
! 	documentId = "";
  	List documentIds = Arrays.asList(directories).subList(DOCUMENT_ID_POS, directories.length);
  	// remove the suffix from the last element
--- 83,114 ----
          area = directories[AREA_POS];
  
+ 	documentId = computeDocumentId(requestURI);
+         publication = new Publication(publicationId, path);
+         rcEnvironment = new RCEnvironment(path);
+         context = request.getContextPath();
+     }
+ 
+     /**
+      * <code>computeDocumentId</code> contains some heuristicts derive
+      * a document-id from a given requestURI. The basic assumption is
+      * that an URL consists of
+      * http:/<context-prefix>/<publication-id>/<area>/<document-id>.*. So
+      * to figure out the document-id we simply need to trim the parts
+      * before and including "area" and after and including '.'
+      *
+      * Also if the requestURI contains a "foo/index" we assume that
+      * the document-id is foo, i.e. we also trin "index"
+      *
+      * @param requestURI a <code>String</code> value
+      * @return a <code>String</code> value
+      */
+     protected String computeDocumentId(String requestURI) {
  	// the computation of the document id is based on the
  	// assumption that and URI matches of the following pattern:
  	// http:/<context-prefix>/<publication-id>/<area>/<document-id>.*
  	// where document-id can be foo/bar/baz
! 
!         String directories[] = requestURI.split("/");
! 	String documentId = "";
  	List documentIds = Arrays.asList(directories).subList(DOCUMENT_ID_POS, directories.length);
  	// remove the suffix from the last element
***************
*** 90,106 ****
  	    log.debug("w/oSuffix: " + lastPartOfDocumentId.substring(0, startOfSuffix));
  	}
  	log.debug("documentIds: " + documentIds);
  	for (Iterator i = documentIds.iterator(); i.hasNext();) {
  	    documentId += "/" + i.next();
  	}
! 
!         publication = new Publication(publicationId, path);
!         rcEnvironment = new RCEnvironment(path);
!         context = request.getContextPath();
      }
      
-     
      /**
       * Returns the publication of this PageEnvelope.
       */
      public Publication getPublication() {
--- 122,144 ----
  	    log.debug("w/oSuffix: " + lastPartOfDocumentId.substring(0, startOfSuffix));
  	}
+ 
+ 	// Another part of the heuristics is that if the last part of
+ 	// the document-id is "index" it is to be removed.
+ 	lastPartOfDocumentId = (String)documentIds.get(documentIds.size()-1);
+ 	int startOfIndex = lastPartOfDocumentId.indexOf("index");
+ 	if (startOfIndex >= 0) {
+ 	    documentIds.set(documentIds.size()-1, lastPartOfDocumentId.substring(0, startOfIndex));
+ 	}
+ 
  	log.debug("documentIds: " + documentIds);
  	for (Iterator i = documentIds.iterator(); i.hasNext();) {
  	    documentId += "/" + i.next();
  	}
! 	return documentId;
      }
      
      /**
       * Returns the publication of this PageEnvelope.
+      * @return a <code>Publication</code> value
       */
      public Publication getPublication() {
***************
*** 110,113 ****
--- 148,152 ----
      /**
       * Returns the rcEnvironment.
+      * @return a <code>RCEnvironment</code> value
       */
      public RCEnvironment getRCEnvironment() {
***************
*** 117,120 ****
--- 156,160 ----
      /**
       * Returns the context.
+      * @return a <code>String</code> value
       */
      public String getContext() {
***************
*** 124,127 ****
--- 164,168 ----
      /**
       * Returns the area (authoring/live).
+      * @return a <code>String</code> value
       */
      public String getArea() {
***************
*** 131,134 ****
--- 172,176 ----
      /**
       * Returns the document-id.
+      * @return a <code>String</code> value
       */
      public String getDocumentId() {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.