Java Code Examples for org.eclipse.jetty.util.URIUtil#encodePath()

The following examples show how to use org.eclipse.jetty.util.URIUtil#encodePath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileResource.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
@Override
public Resource addPath(String path)
    throws IOException,MalformedURLException
{
    URLResource r=null;
    String url=null;

    path = org.eclipse.jetty.util.URIUtil.canonicalPath(path);
   
    if ("/".equals(path))
        return this;
    else if (!isDirectory())
    {
        r=(FileResource)super.addPath(path);
        url=r._urlString;
    }
    else
    {
        if (path==null)
            throw new MalformedURLException();   
        
        // treat all paths being added as relative
        String rel=path;
        if (path.startsWith("/"))
            rel = path.substring(1);
        
        url=URIUtil.addPaths(_urlString,URIUtil.encodePath(rel));
        r=(URLResource)Resource.newResource(url);
    }
    
    // Check for encoding aliases
    // The encoded path should be a suffix of the resource (give or take a directory / )
    String encoded=URIUtil.encodePath(path);
    int expected=r.toString().length()-encoded.length();
    int index = r._urlString.lastIndexOf(encoded, expected);
    if (expected!=index && ((expected-1)!=index || path.endsWith("/") || !r.isDirectory()))
    {
        if (r instanceof FileResource)
        {
            ((FileResource)r)._alias=((FileResource)r)._file.getCanonicalFile().toURI().toURL();
            ((FileResource)r)._aliasChecked=true;
        }
    }                             
    return r;
}
 
Example 2
Source File: FileResource.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
@Override
public Resource addPath(String path)
    throws IOException,MalformedURLException
{
    URLResource r=null;
    String url=null;

    path = org.eclipse.jetty.util.URIUtil.canonicalPath(path);
   
    if ("/".equals(path))
        return this;
    else if (!isDirectory())
    {
        r=(FileResource)super.addPath(path);
        url=r._urlString;
    }
    else
    {
        if (path==null)
            throw new MalformedURLException();   
        
        // treat all paths being added as relative
        String rel=path;
        if (path.startsWith("/"))
            rel = path.substring(1);
        
        url=URIUtil.addPaths(_urlString,URIUtil.encodePath(rel));
        r=(URLResource)Resource.newResource(url);
    }
    
    // Check for encoding aliases
    // The encoded path should be a suffix of the resource (give or take a directory / )
    String encoded=URIUtil.encodePath(path);
    int expected=r.toString().length()-encoded.length();
    int index = r._urlString.lastIndexOf(encoded, expected);
    if (expected!=index && ((expected-1)!=index || path.endsWith("/") || !r.isDirectory()))
    {
        if (r instanceof FileResource)
        {
            ((FileResource)r)._alias=((FileResource)r)._file.getCanonicalFile().toURI().toURL();
            ((FileResource)r)._aliasChecked=true;
        }
    }                             
    return r;
}
 
Example 3
Source File: Resource.java    From IoTgo_Android_App with MIT License 2 votes vote down vote up
/** Encode according to this resource type.
 * The default implementation calls URI.encodePath(uri)
 * @param uri 
 * @return String encoded for this resource type.
 */
public String encode(String uri)
{
    return URIUtil.encodePath(uri);
}
 
Example 4
Source File: Resource.java    From IoTgo_Android_App with MIT License 2 votes vote down vote up
/** Encode according to this resource type.
 * The default implementation calls URI.encodePath(uri)
 * @param uri 
 * @return String encoded for this resource type.
 */
public String encode(String uri)
{
    return URIUtil.encodePath(uri);
}