KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > publication > URLInformation


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: URLInformation.java 42946 2004-04-30 09:34:23Z andreas $ */
19
20 package org.apache.lenya.cms.publication;
21
22 /**
23  * This class resolves all Lenya-specific information from a webapp URL.
24  */

25 public class URLInformation {
26     
27     private String JavaDoc publicationId = null;
28     private String JavaDoc area = null;
29     private String JavaDoc completeArea = null;
30     private String JavaDoc documentUrl = null;
31     
32     /**
33      * Returns the area (without the "info-" prefix).
34      * @return A string.
35      */

36     public String JavaDoc getArea() {
37         return area;
38     }
39
40     /**
41      * Returns the complete area (including the "info-" prefix).
42      * @return A string.
43      */

44     public String JavaDoc getCompleteArea() {
45         return completeArea;
46     }
47
48     /**
49      * Returns the document URL.
50      * @return A string.
51      */

52     public String JavaDoc getDocumentUrl() {
53         return documentUrl;
54     }
55
56     /**
57      * Returns the publication ID.
58      * @return A string.
59      */

60     public String JavaDoc getPublicationId() {
61         return publicationId;
62     }
63
64     /**
65      * Ctor.
66      * @param webappUrl A webapp URL (without context prefix).
67      */

68     public URLInformation(String JavaDoc webappUrl) {
69         assert webappUrl.startsWith("/");
70         
71         String JavaDoc url = webappUrl.substring(1);
72         
73         String JavaDoc[] fragments = url.split("/");
74         this.publicationId = fragments[0];
75         
76         if (fragments.length > 1) {
77             this.completeArea = fragments[1];
78             
79             if (url.length() > (this.publicationId + "/" + completeArea).length()) {
80                 this.documentUrl = url.substring((this.publicationId + "/" + completeArea).length());
81             }
82             else {
83                 this.documentUrl = "";
84             }
85             
86             if (completeArea.startsWith(Publication.INFO_AREA_PREFIX)) {
87                 this.area = completeArea.substring(Publication.INFO_AREA_PREFIX.length());
88             }
89             else if (completeArea.startsWith(Publication.SEARCH_AREA_PREFIX)) {
90                 this.area = completeArea.substring(Publication.SEARCH_AREA_PREFIX.length());
91             }
92             else {
93                 this.area = completeArea;
94             }
95         }
96     }
97     
98     
99 }
100
Popular Tags