File Source: AppUrl.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * 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. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18 package org.apache.roller.weblogger.webservices.adminprotocol;
19
20 import java.net.MalformedURLException;
21 import java.net.URL;
22 import java.util.regex.Pattern;
23 import java.util.regex.Matcher;
24 /**
25 * This class generates Atom Publishing Protocol (APP) URls.
26 */
27 public class AppUrl {
28 private static final String ENDPOINT = "/app";
/*
P/P * Method: org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init
*
* Postconditions:
* init'ed(ENDPOINT_PATTERN)
* init'ed(ID_PATTERN)
*/
29 private static Pattern ID_PATTERN = Pattern.compile("^http://.*/(.*)/(?:entries|resources)$");
30 private static Pattern ENDPOINT_PATTERN = Pattern.compile("^(http://.*)/.*/(?:entries|resources)$");
31
32 private URL entryUrl;
33 private URL resourceUrl;
34 private String handle;
35
/*
P/P * Method: void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)
*
* Postconditions:
* this.entryUrl == &new URL(AppUrl#1)
* this.resourceUrl == &new URL(AppUrl#3)
* new URL(AppUrl#1) num objects == 1
* new URL(AppUrl#3) num objects == 1
*/
36 public AppUrl(String urlPrefix, String handle) throws MalformedURLException {
37 //TODO: is this the right thing to do? hardcode roller-services?
38 entryUrl = new URL(urlPrefix + "/roller-services" + ENDPOINT + "/" + handle + "/entries");
39 resourceUrl = new URL(urlPrefix + "/roller-services" + ENDPOINT + "/" + handle + "/resources");
40 }
41
/*
P/P * Method: void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)
*
* Preconditions:
* ENDPOINT_PATTERN != null
* ID_PATTERN != null
* url != null
*
* Postconditions:
* this.entryUrl == &new URL(AppUrl#1)
* init'ed(this.handle)
* this.resourceUrl == &new URL(AppUrl#3)
* new URL(AppUrl#1) num objects == 1
* new URL(AppUrl#3) num objects == 1
*/
42 public AppUrl(URL url) throws MalformedURLException {
43 handle = parseHandle(url);
44 URL endpoint = parseEndpoint(url);
45
46 entryUrl = new URL(endpoint + "/" + handle + "/entries");
47 resourceUrl = new URL(endpoint + "/" + handle + "/resources");
48 }
49
50 private String parseHandle(URL url) {
/*
P/P * Method: String parseHandle(URL)
*
* Preconditions:
* ID_PATTERN != null
* url != null
*
* Presumptions:
* java.util.regex.Pattern:matcher(...)@54 != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* java.util.regex.Matcher:matches(...)@56: {0}, {1}
*/
51 String urlString = url.toString();
52 String handle = null;
53
54 Matcher m = ID_PATTERN.matcher(urlString);
55
56 if (m.matches()) {
57 handle = m.group(1);
58 }
59
60 return handle;
61 }
62
63 private URL parseEndpoint(URL url) throws MalformedURLException {
/*
P/P * Method: URL parseEndpoint(URL)
*
* Preconditions:
* ENDPOINT_PATTERN != null
* url != null
*
* Presumptions:
* java.util.regex.Pattern:matcher(...)@67 != null
*
* Postconditions:
* return_value == One-of{null, &new URL(parseEndpoint#1)}
* return_value in Addr_Set{null,&new URL(parseEndpoint#1)}
* new URL(parseEndpoint#1) num objects <= 1
*
* Test Vectors:
* java.util.regex.Matcher:matches(...)@69: {0}, {1}
*/
64 String urlString = url.toString();
65 String endpointString = null;
66
67 Matcher m = ENDPOINT_PATTERN.matcher(urlString);
68
69 if (m.matches()) {
70 endpointString = m.group(1);
71 }
72
73 URL endpoint = null;
74 if (endpointString != null) {
75 endpoint = new URL(endpointString);
76 }
77
78 return endpoint;
79 }
80
81
82 public URL getEntryUrl() {
/*
P/P * Method: URL getEntryUrl()
*
* Preconditions:
* init'ed(this.entryUrl)
*
* Postconditions:
* return_value == this.entryUrl
* init'ed(return_value)
*/
83 return entryUrl;
84 }
85
86 public URL getResourceUrl() {
/*
P/P * Method: URL getResourceUrl()
*
* Preconditions:
* init'ed(this.resourceUrl)
*
* Postconditions:
* return_value == this.resourceUrl
* init'ed(return_value)
*/
87 return resourceUrl;
88 }
89
90 public String getHandle() {
/*
P/P * Method: String getHandle()
*
* Preconditions:
* init'ed(this.handle)
*
* Postconditions:
* return_value == this.handle
* init'ed(return_value)
*/
91 return handle;
92 }
93 }
SofCheck Inspector Build Version : 2.18479
| AppUrl.java |
2009-Jan-02 14:25:14 |
| AppUrl.class |
2009-Sep-04 03:12:45 |