KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jpublish > util > uri > TemplateURI


1 /*--
2  Copyright (C) 2001-2003 Aetrion LLC.
3  All rights reserved.
4
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions
7  are met:
8
9  1. Redistributions of source code must retain the above copyright
10     notice, this list of conditions, and the following disclaimer.
11
12  2. Redistributions in binary form must reproduce the above copyright
13     notice, this list of conditions, and the disclaimer that follows
14     these conditions in the documentation and/or other materials
15     provided with the distribution.
16  3. The name "JPublish" must not be used to endorse or promote products
17     derived from this software without prior written permission. For
18     written permission, please contact info@aetrion.com.
19
20  4. Products derived from this software may not be called "JPublish", nor
21     may "JPublish" appear in their name, without prior written permission
22     from Aetrion LLC (info@aetrion.com).
23
24  In addition, the authors of this software request (but do not require)
25  that you include in the end-user documentation provided with the
26  redistribution and/or in the software itself an acknowledgement equivalent
27  to the following:
28      "This product includes software developed by
29       Aetrion LLC (http://www.aetrion.com/)."
30  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
31  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33  DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
34  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
39  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40  POSSIBILITY OF SUCH DAMAGE.
41  For more information on JPublish, please see <http://www.jpublish.org/>.
42
43  */

44 package org.jpublish.util.uri;
45
46 import org.apache.commons.logging.Log;
47 import org.apache.commons.logging.LogFactory;
48
49 /**
50  * Description of the Class
51  *
52  * @author Anthony Eden
53  */

54 public class TemplateURI extends InternalURI {
55
56     private Log log = LogFactory.getLog(TemplateURI.class);
57
58     /**
59      * Description of the Field
60      */

61     protected String JavaDoc templateManagerName;
62
63     /**
64      * Get the template manager name.
65      *
66      * @return The template manager name
67      */

68
69     public String JavaDoc getTemplateManagerName() {
70         return templateManagerName;
71     }
72
73     /**
74      * Set the template manager name.
75      *
76      * @param templateManagerName The new template manager name
77      */

78
79     public void setTemplateManagerName(String JavaDoc templateManagerName) {
80         this.templateManagerName = templateManagerName;
81     }
82
83     /**
84      * Construct a String version of the URI.
85      *
86      * @return The URI as a String
87      */

88
89     public String JavaDoc toURI() {
90         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
91         buffer.append(protocol);
92         if (templateManagerName != null) {
93             buffer.append(":");
94             buffer.append(templateManagerName);
95         }
96         buffer.append("://");
97         buffer.append(path);
98         return buffer.toString();
99     }
100
101     /**
102      * Set the URI to the specified String. Invoking this method will parse the specified String.
103      *
104      * @param uriString The URI string
105      */

106
107     public void setURI(String JavaDoc uriString) {
108         if (log.isDebugEnabled()) {
109             log.debug("setURI(" + uriString + ")");
110         }
111
112         int protocolTerminatorIndex = uriString.indexOf(PROTOCOL_SEPARATOR);
113         if (uriString.indexOf("/", protocolTerminatorIndex) ==
114                 (protocolTerminatorIndex + 1)) {
115             protocol = uriString.substring(0, protocolTerminatorIndex);
116             path = uriString.substring(protocolTerminatorIndex +
117                     URI_SEPARATOR.length());
118         } else {
119             int nameTerminatorIndex = uriString.indexOf(PROTOCOL_SEPARATOR,
120                     protocolTerminatorIndex + 1);
121             protocol = uriString.substring(0, protocolTerminatorIndex);
122             templateManagerName = uriString.substring(protocolTerminatorIndex + 1,
123                     nameTerminatorIndex);
124             path = uriString.substring(nameTerminatorIndex +
125                     URI_SEPARATOR.length());
126         }
127     }
128
129 }
130
131
Popular Tags