//# 0 errors, 122 messages
//#
/*
    //#AppUrl.java:1:1: class: org.apache.roller.weblogger.webservices.adminprotocol.AppUrl
* Licensed to the Apache Software Foundation (ASF) under one or more
*  contributor license agreements.  The ASF licenses this file to You
* under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.  For additional information regarding
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/
package org.apache.roller.weblogger.webservices.adminprotocol;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
/**
 * This class generates Atom Publishing Protocol (APP) URls.
 */
public class AppUrl {
    private static final String ENDPOINT = "/app";
    private static Pattern ID_PATTERN = Pattern.compile("^http://.*/(.*)/(?:entries|resources)$");
    //#AppUrl.java:29: method: org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init
    //#output(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): ENDPOINT_PATTERN
    //#output(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): ID_PATTERN
    //#output(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Descendant_Table[org/apache/roller/weblogger/webservices/adminprotocol/AppUrl]
    //#output(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Dispatch_Table.getEntryUrl()Ljava/net/URL;
    //#output(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Dispatch_Table.getHandle()Ljava/lang/String;
    //#output(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Dispatch_Table.getResourceUrl()Ljava/net/URL;
    //#output(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Dispatch_Table.parseEndpoint(Ljava/net/URL;)Ljava/net/URL;
    //#output(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Dispatch_Table.parseHandle(Ljava/net/URL;)Ljava/lang/String;
    //#post(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): init'ed(ENDPOINT_PATTERN)
    //#post(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): init'ed(ID_PATTERN)
    //#post(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Descendant_Table[org/apache/roller/weblogger/webservices/adminprotocol/AppUrl] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Dispatch_Table.getEntryUrl()Ljava/net/URL; == &getEntryUrl
    //#post(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Dispatch_Table.getHandle()Ljava/lang/String; == &getHandle
    //#post(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Dispatch_Table.getResourceUrl()Ljava/net/URL; == &getResourceUrl
    //#post(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Dispatch_Table.parseEndpoint(Ljava/net/URL;)Ljava/net/URL; == &parseEndpoint
    //#post(org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init): __Dispatch_Table.parseHandle(Ljava/net/URL;)Ljava/lang/String; == &parseHandle
    private static Pattern ENDPOINT_PATTERN = Pattern.compile("^(http://.*)/.*/(?:entries|resources)$");
    //#AppUrl.java:30: end of method: org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.org.apache.roller.weblogger.webservices.adminprotocol.AppUrl__static_init
    
    private URL entryUrl;
    private URL resourceUrl;
    private String handle;
    
    public AppUrl(String urlPrefix, String handle) throws MalformedURLException {
    //#AppUrl.java:36: method: void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): "."._tainted
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): ".app"._tainted
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): ".entries"._tainted
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): ".resources"._tainted
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): ".roller-services"._tainted
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): handle
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): handle._tainted
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): this
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): urlPrefix
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): urlPrefix._tainted
    //#output(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): new URL(AppUrl#1) num objects
    //#output(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): new URL(AppUrl#3) num objects
    //#output(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): this.entryUrl
    //#output(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): this.resourceUrl
    //#new obj(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): new URL(AppUrl#1)
    //#new obj(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): new URL(AppUrl#3)
    //#post(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): this.entryUrl == &new URL(AppUrl#1)
    //#post(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): this.resourceUrl == &new URL(AppUrl#3)
    //#post(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): new URL(AppUrl#1) num objects == 1
    //#post(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)): new URL(AppUrl#3) num objects == 1
        //TODO: is this the right thing to do? hardcode roller-services?
        entryUrl = new URL(urlPrefix + "/roller-services" + ENDPOINT + "/" + handle + "/entries");
        resourceUrl = new URL(urlPrefix + "/roller-services" + ENDPOINT + "/" + handle + "/resources");        
    }    
    //#AppUrl.java:40: end of method: void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(String, String)

    public AppUrl(URL url) throws MalformedURLException {
    //#AppUrl.java:42: method: void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): "."._tainted
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): ".entries"._tainted
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): ".resources"._tainted
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): ENDPOINT_PATTERN
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): ID_PATTERN
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): this
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): url
    //#input(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): url._tainted
    //#output(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): new URL(AppUrl#1) num objects
    //#output(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): new URL(AppUrl#3) num objects
    //#output(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): this.entryUrl
    //#output(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): this.handle
    //#output(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): this.resourceUrl
    //#new obj(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): new URL(AppUrl#1)
    //#new obj(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): new URL(AppUrl#3)
    //#pre[1] (void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): ENDPOINT_PATTERN != null
    //#pre[2] (void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): ID_PATTERN != null
    //#pre[4] (void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): url != null
    //#post(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): this.entryUrl == &new URL(AppUrl#1)
    //#post(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): init'ed(this.handle)
    //#post(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): this.resourceUrl == &new URL(AppUrl#3)
    //#post(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): new URL(AppUrl#1) num objects == 1
    //#post(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): new URL(AppUrl#3) num objects == 1
    //#unanalyzed(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): Effects-of-calling:java.net.URL
    //#unanalyzed(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): Effects-of-calling:java.net.URL:toString
    //#unanalyzed(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): Effects-of-calling:java.util.regex.Pattern:matcher
    //#unanalyzed(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): Effects-of-calling:java.util.regex.Matcher:matches
    //#unanalyzed(void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)): Effects-of-calling:java.util.regex.Matcher:group
        handle = parseHandle(url);
        URL endpoint = parseEndpoint(url);
        
        entryUrl = new URL(endpoint + "/" + handle + "/entries");
        resourceUrl = new URL(endpoint + "/" + handle + "/resources");        
    }    
    //#AppUrl.java:48: end of method: void org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.org.apache.roller.weblogger.webservices.adminprotocol.AppUrl(URL)
    
    private String parseHandle(URL url) {
        String urlString = url.toString();
    //#AppUrl.java:51: method: String org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.parseHandle(URL)
    //#input(String parseHandle(URL)): ID_PATTERN
    //#input(String parseHandle(URL)): url
    //#input(String parseHandle(URL)): url._tainted
    //#output(String parseHandle(URL)): return_value
    //#pre[1] (String parseHandle(URL)): ID_PATTERN != null
    //#pre[2] (String parseHandle(URL)): url != null
    //#presumption(String parseHandle(URL)): java.util.regex.Pattern:matcher(...)@54 != null
    //#post(String parseHandle(URL)): init'ed(return_value)
    //#test_vector(String parseHandle(URL)): java.util.regex.Matcher:matches(...)@56: {0}, {1}
        String handle = null;
        
        Matcher m = ID_PATTERN.matcher(urlString);
        
        if (m.matches()) {
            handle = m.group(1);
        }
        
        return handle;
    //#AppUrl.java:60: end of method: String org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.parseHandle(URL)
    }
    
    private URL parseEndpoint(URL url) throws MalformedURLException {
        String urlString = url.toString();
    //#AppUrl.java:64: method: URL org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.parseEndpoint(URL)
    //#input(URL parseEndpoint(URL)): ENDPOINT_PATTERN
    //#input(URL parseEndpoint(URL)): url
    //#input(URL parseEndpoint(URL)): url._tainted
    //#output(URL parseEndpoint(URL)): new URL(parseEndpoint#1) num objects
    //#output(URL parseEndpoint(URL)): return_value
    //#new obj(URL parseEndpoint(URL)): new URL(parseEndpoint#1)
    //#pre[1] (URL parseEndpoint(URL)): ENDPOINT_PATTERN != null
    //#pre[2] (URL parseEndpoint(URL)): url != null
    //#presumption(URL parseEndpoint(URL)): java.util.regex.Pattern:matcher(...)@67 != null
    //#post(URL parseEndpoint(URL)): return_value == One-of{null, &new URL(parseEndpoint#1)}
    //#post(URL parseEndpoint(URL)): return_value in Addr_Set{null,&new URL(parseEndpoint#1)}
    //#post(URL parseEndpoint(URL)): new URL(parseEndpoint#1) num objects <= 1
    //#test_vector(URL parseEndpoint(URL)): java.util.regex.Matcher:matches(...)@69: {0}, {1}
        String endpointString = null;
        
        Matcher m = ENDPOINT_PATTERN.matcher(urlString);
        
        if (m.matches()) {
            endpointString = m.group(1);
        }
        
        URL endpoint = null;
        if (endpointString != null) {
            endpoint = new URL(endpointString);
        }
        
        return endpoint;
    //#AppUrl.java:78: end of method: URL org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.parseEndpoint(URL)
    }
    
    
    public URL getEntryUrl() {
        return entryUrl;
    //#AppUrl.java:83: method: URL org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.getEntryUrl()
    //#input(URL getEntryUrl()): this
    //#input(URL getEntryUrl()): this.entryUrl
    //#output(URL getEntryUrl()): return_value
    //#pre[2] (URL getEntryUrl()): init'ed(this.entryUrl)
    //#post(URL getEntryUrl()): return_value == this.entryUrl
    //#post(URL getEntryUrl()): init'ed(return_value)
    //#AppUrl.java:83: end of method: URL org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.getEntryUrl()
    }

    public URL getResourceUrl() {
        return resourceUrl;
    //#AppUrl.java:87: method: URL org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.getResourceUrl()
    //#input(URL getResourceUrl()): this
    //#input(URL getResourceUrl()): this.resourceUrl
    //#output(URL getResourceUrl()): return_value
    //#pre[2] (URL getResourceUrl()): init'ed(this.resourceUrl)
    //#post(URL getResourceUrl()): return_value == this.resourceUrl
    //#post(URL getResourceUrl()): init'ed(return_value)
    //#AppUrl.java:87: end of method: URL org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.getResourceUrl()
    }
    
    public String getHandle() {
        return handle;
    //#AppUrl.java:91: method: String org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.getHandle()
    //#input(String getHandle()): this
    //#input(String getHandle()): this.handle
    //#output(String getHandle()): return_value
    //#pre[2] (String getHandle()): init'ed(this.handle)
    //#post(String getHandle()): return_value == this.handle
    //#post(String getHandle()): init'ed(return_value)
    //#AppUrl.java:91: end of method: String org.apache.roller.weblogger.webservices.adminprotocol.AppUrl.getHandle()
    }
}
    //#AppUrl.java:: end of class: org.apache.roller.weblogger.webservices.adminprotocol.AppUrl
