Example usage for org.apache.commons.httpclient URIException getLocalizedMessage

List of usage examples for org.apache.commons.httpclient URIException getLocalizedMessage

Introduction

In this page you can find the example usage for org.apache.commons.httpclient URIException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:gov.lanl.archive.rewrite.UrlOperations.java

/**
 * Find and return the parent directory of the URL argument
 * @param url to find the parent directory of
 * @return parent directory of URL, or null, if either the url argument is
 * invalid, or if the url is the root of the authority.
 *///from   w  w  w .j  a v  a2s .co m
public static String getUrlParentDir(String url) {

    try {
        UURI uri = UURIFactory.getInstance(url);
        String path = uri.getPath();
        if (path.length() > 1) {
            int startIdx = path.length() - 1;
            if (path.charAt(path.length() - 1) == '/') {
                startIdx--;
            }
            int idx = path.lastIndexOf('/', startIdx);
            if (idx >= 0) {
                uri.setPath(path.substring(0, idx + 1));
                uri.setQuery(null);
                return uri.toString();
            }
        }
    } catch (URIException e) {
        LOGGER.warning(e.getLocalizedMessage() + ": " + url);
    }
    return null;
}

From source file:gov.lanl.archive.rewrite.UrlOperations.java

/**
 * Resolve a possibly relative url argument against a base URL.
 * @param baseUrl the base URL against which the url should be resolved
 * @param url the URL, possibly relative, to make absolute.
 * @return url resolved against baseUrl, unless it is absolute already, and
 * further transformed by whatever escaping normally takes place with a 
 * UURI.//  w  w w  . ja v a 2s  .  c  om
 */
public static String resolveUrl(String baseUrl, String url) {
    for (final String scheme : ALL_SCHEMES) {
        if (url.startsWith(scheme)) {
            try {
                return UURIFactory.getInstance(url).getEscapedURI();
            } catch (URIException e) {
                LOGGER.warning(e.getLocalizedMessage() + ": " + url);
                // can't let a space exist... send back close to whatever came
                // in...
                return url.replace(" ", "%20");
            }
        }
    }
    UURI absBaseURI;
    UURI resolvedURI = null;
    try {
        absBaseURI = UURIFactory.getInstance(baseUrl);
        resolvedURI = UURIFactory.getInstance(absBaseURI, url);
    } catch (URIException e) {
        LOGGER.warning(e.getLocalizedMessage() + ": " + url);
        return url.replace(" ", "%20");
    }
    return resolvedURI.getEscapedURI();
}

From source file:org.archive.surt.SURTTokenizerTest.java

private SURTTokenizer toSurtT(final String u) {
    SURTTokenizer tok = null;/*from w  w w  .j a  va 2  s  .  com*/
    try {
        tok = new SURTTokenizer(u);
    } catch (URIException e) {
        e.printStackTrace();
        assertFalse("URL Exception " + e.getLocalizedMessage(), true);
    }
    return tok;
}

From source file:org.archive.wayback.surt.SURTTokenizerTest.java

private SURTTokenizer toSurtT(final String u) {
    SURTTokenizer tok = null;/*from  w ww  .j a  v a2 s. c  om*/
    try {
        tok = new SURTTokenizer(u, false);
    } catch (URIException e) {
        e.printStackTrace();
        assertFalse("URL Exception " + e.getLocalizedMessage(), true);
    }
    return tok;
}

From source file:org.archive.wayback.util.url.UrlOperations.java

/**
 * Resolve a possibly relative url argument against a base URL.
 * @param baseUrl the base URL against which the url should be resolved
 * @param url the URL, possibly relative, to make absolute.
 * @param defaultValue The default value to return if the supplied values can't be resolved.
 * @return url resolved against baseUrl, unless it is absolute already, and
 * further transformed by whatever escaping normally takes place with a 
 * UsableURI.//  w  w w . j a v  a2 s .  c om
 * In case of error, return the defaultValue
 */
public static String resolveUrl(String baseUrl, String url, String defaultValue) {

    for (final String scheme : ALL_SCHEMES) {
        if (url.startsWith(scheme)) {
            try {
                return UsableURIFactory.getInstance(url).getEscapedURI();
            } catch (URIException e) {
                LOGGER.warning(e.getLocalizedMessage() + ": " + url);
                // can't let a space exist... send back close to whatever came
                // in...
                return defaultValue;
            }
        }
    }
    UsableURI absBaseURI;
    UsableURI resolvedURI = null;
    try {
        absBaseURI = UsableURIFactory.getInstance(baseUrl);
        resolvedURI = UsableURIFactory.getInstance(absBaseURI, url);
    } catch (URIException e) {
        LOGGER.warning(e.getLocalizedMessage() + ": " + url);
        return defaultValue;
    }

    return resolvedURI.getEscapedURI();
}

From source file:org.archive.wayback.util.url.UrlOperations.java

/**
 * Find and return the parent directory of the URL argument
 * @param url to find the parent directory of
 * @return parent directory of URL, or null, if either the url argument is
 * invalid, or if the url is the root of the authority.
 */// w w w .j  av  a2s.com
public static String getUrlParentDir(String url) {

    try {
        UsableURI uri = UsableURIFactory.getInstance(url);
        String path = uri.getPath();
        if (path.length() > 1) {
            int startIdx = path.length() - 1;
            if (path.charAt(path.length() - 1) == '/') {
                startIdx--;
            }
            int idx = path.lastIndexOf('/', startIdx);
            if (idx >= 0) {
                uri.setPath(path.substring(0, idx + 1));
                uri.setQuery(null);
                return uri.toString();
            }
        }
    } catch (URIException e) {
        LOGGER.warning(e.getLocalizedMessage() + ": " + url);
    }
    return null;
}

From source file:org.kalypso.ui.wizards.results.editor.EditStyleDialog.java

private Symbolizer[] parseStyle() {
    InputStream inputStream = null;
    try {// w ww  . jav a 2  s. co  m
        inputStream = m_sldFile.getContents();
        final IUrlResolver2 resolver = new IUrlResolver2() {
            @Override
            @SuppressWarnings("synthetic-access")
            public URL resolveURL(final String relativeOrAbsolute) throws MalformedURLException {
                try {
                    final URL sldURL = ResourceUtilities.createURL(m_sldFile);
                    return new URL(sldURL, relativeOrAbsolute);
                } catch (final URIException e) {
                    e.printStackTrace();
                    throw new MalformedURLException(e.getLocalizedMessage());
                }
            }

        };
        m_sld = SLDFactory.createSLD(resolver, inputStream);
        final NamedLayer[] namedLayers = m_sld.getNamedLayers();
        // get always just the first layer
        final NamedLayer namedLayer = namedLayers[0];

        // get always the first style (we assume there is only one)
        final Style[] styles = namedLayer.getStyles();

        final Style style = styles[0];
        if (style instanceof UserStyle) {
            final UserStyle userStyle = (UserStyle) style;
            final FeatureTypeStyle[] featureTypeStyles = userStyle.getFeatureTypeStyles();
            // we assume, that there is only one feature type style and take the first we can get.
            final FeatureTypeStyle featureTypeStyle = featureTypeStyles[0];

            // we assume, that there is only one rule and take the first we can get.
            m_rules = featureTypeStyle.getRules();

            final List<Symbolizer> symbList = new ArrayList<>();

            for (final Rule rule : m_rules) {
                final Symbolizer[] symbolizers = rule.getSymbolizers();
                // and the first and only symbolizer is taken
                final Symbolizer symb = symbolizers[0];
                symbList.add(symb);
            }

            return symbList.toArray(new Symbolizer[symbList.size()]);
        }
    } catch (final CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (final XMLParsingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    finally {
        IOUtils.closeQuietly(inputStream);
    }
    return null;
}