All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cat.inspiracio.html.URLUtilsImp Maven / Gradle / Ivy

Go to download

HTML-parser provides a parser for HTML 5 that produces HTML 5 document object model. It aims to be a Java-implementation of http://www.w3.org/TR/html5/. It is for use in the server. It does not implement features that are relevant in the client, like event handling. It is for use from javascript, via Java's scripting library.

The newest version!
/*
Copyright 2015 Alexander Bunkenburg 

Licensed 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.
*/
package cat.inspiracio.html;

import cat.inspiracio.url.URL;
import cat.inspiracio.url.URLSearchParams;
import cat.inspiracio.url.URLUtils;

/** An html element that has href and the URL methods.
 * 
 *  No state in this class. */
abstract class URLUtilsImp extends HTMLElementImp implements URLUtils{
    private static final long serialVersionUID = -621390515495599639L;

    // construction ----------------------------------------
    
    protected URLUtilsImp(HTMLDocumentImp owner, String tag){super(owner, tag);}
    
    // interface URLUtils --------------------------------------------

    private URL getURL(){return new URL(getHref());}
    
    @Override public String getHref(){return getAttribute("href");}
    @Override public void setHref(String href){setAttribute("href", href);}
    private void setHref(URL u){setHref(u.toString());}

    /** http://www.w3.org/TR/url/#concept-url-origin
     * Returns scheme://host:port */
    @Override public String getOrigin(){return getURL().getOrigin();}

    @Override public String getProtocol(){return getURL().getProtocol();}
    @Override public void setProtocol(String protocol){setHref(getURL().protocol(protocol));}
    
    @Override public String getUsername(){return getURL().getUsername();}
    @Override public void setUsername(String u){setHref(getURL().username(u));}
    
    @Override public String getPassword(){return getURL().getPassword();}
    @Override public void setPassword(String p){setHref(getURL().password(p));}
    
    @Override public String getHost(){return getURL().getHost();}
    @Override public void setHost(String host){
        URL u=getURL();
        u.setHost(host);
        setHref(u);
    }
    
    @Override public String getHostname(){return getURL().getHostname();}
    @Override public void setHostname(String name){
        URL u=getURL();
        u.setHostname(name);
        setHref(u);
    }
    
    @Override public String getPort(){return getURL().getPort();}
    @Override public int port(){return getURL().port();}
    @Override public void setPort(int port){setHref(getURL().port(port));}
    @Override public void setPort(String port){
        URL u=getURL();
        u.setPort(port);
        setHref(u);
    }
    
    @Override public String getPathname(){return getURL().getPathname();}
    @Override public void setPathname(String path){
        URL u=getURL();
        u.setPathname(path);
        setHref(u);
    }
    
    @Override public String getSearch(){return getURL().getSearch();}
    @Override public void setSearch(String search){
        URL u=getURL();
        u.setSearch(search);
        setHref(u);
    }
    
    @Override public URLSearchParams getSearchParams(){return getURL().getSearchParams();}
    @Override public void setSearchParams(URLSearchParams params){
        URL u=getURL();
        u.setSearchParams(params);
        setHref(u);
    }
    
    @Override public String getHash(){return getURL().getHash();}
    @Override public void setHash(String hash){
        URL u=getURL();
        u.setHash(hash);
        setHref(u);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy