Example usage for java.net URISyntaxException getInput

List of usage examples for java.net URISyntaxException getInput

Introduction

In this page you can find the example usage for java.net URISyntaxException getInput.

Prototype

public String getInput() 

Source Link

Document

Returns the input string.

Usage

From source file:nl.flotsam.calendar.web.UriListHttpMessageConverter.java

@Override
protected List<URI> readInternal(Class<? extends List<URI>> clazz, HttpInputMessage inputMessage)
        throws IOException, HttpMessageNotReadableException {
    InputStream in = inputMessage.getBody();
    try {// ww  w  . j  a va2  s .  c o m
        String text = IOUtils.toString(in, "UTF-8");
        List<URI> result = parseURIs(text);
        logger.info("Produced a list of " + result.size() + " items: " + result);
        return result;
    } catch (URISyntaxException e) {
        throw new HttpMessageNotReadableException("Illegal URI in list of URIs: " + e.getInput());
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.jolokia.client.J4pClient.java

private J4pException mapException(Exception pException) throws J4pException {
    if (pException instanceof ConnectException) {
        return new J4pConnectException(
                "Cannot connect to " + requestHandler.getJ4pServerUrl() + ": " + pException.getMessage(),
                (ConnectException) pException);
    } else if (pException instanceof ConnectTimeoutException) {
        return new J4pTimeoutException("Read timeout while request " + requestHandler.getJ4pServerUrl() + ": "
                + pException.getMessage(), (ConnectTimeoutException) pException);
    } else if (pException instanceof IOException) {
        return new J4pException("IO-Error while contacting the server: " + pException, pException);
    } else if (pException instanceof URISyntaxException) {
        URISyntaxException sExp = (URISyntaxException) pException;
        return new J4pException("Invalid URI " + sExp.getInput() + ": " + sExp.getReason(), pException);
    } else {/* w  w w . j av  a  2 s  . c  o  m*/
        return new J4pException("Exception " + pException, pException);
    }
}

From source file:com.google.caja.plugin.Config.java

public boolean processArguments(String[] argv) {
    try {//ww  w  .  j  a  v a  2s.c  om
        CommandLine cl;
        try {
            cl = new BasicParser().parse(options, argv, false);
        } catch (org.apache.commons.cli.ParseException e) {
            usage(e.getMessage(), stderr);
            return false;
        }

        inputUris = Lists.newArrayList();
        for (String input : getOptionValues(cl, INPUT)) {
            URI inputUri;
            try {
                if (input.indexOf(':') >= 0) {
                    inputUri = new URI(input);
                } else {
                    File inputFile = new File(input);

                    if (!inputFile.exists()) {
                        usage("File \"" + input + "\" does not exist", stderr);
                        return false;
                    }
                    if (!inputFile.canRead() || inputFile.isDirectory()) {
                        usage("File \"" + input + "\" is not a regular file", stderr);
                        return false;
                    }

                    inputUri = inputFile.getAbsoluteFile().toURI();
                }
            } catch (URISyntaxException ex) {
                usage("Input \"" + input + "\" is not a valid URI", stderr);
                return false;
            }

            inputUris.add(inputUri);
        }
        if (inputUris.isEmpty()) {
            usage("Option \"--" + INPUT.getLongOpt() + "\" missing", stderr);
            return false;
        }

        if (cl.getOptionValue(OUTPUT_BASE.getOpt()) != null) {
            outputBase = new File(cl.getOptionValue(OUTPUT_BASE.getOpt()));

            outputJsFile = substituteExtension(outputBase, ".out.js");
            outputHtmlFile = substituteExtension(outputBase, ".out.html");

            if (cl.getOptionValue(OUTPUT_JS.getOpt()) != null) {
                usage("Can't specify both --out and --output_js", stderr);
                return false;
            }
            if (cl.getOptionValue(OUTPUT_HTML.getOpt()) != null) {
                usage("Can't specify both --out and --output_html", stderr);
                return false;
            }
        } else {
            outputJsFile = cl.getOptionValue(OUTPUT_JS.getOpt()) == null ? null
                    : new File(cl.getOptionValue(OUTPUT_JS.getOpt()));

            outputHtmlFile = cl.getOptionValue(OUTPUT_HTML.getOpt()) == null ? null
                    : new File(cl.getOptionValue(OUTPUT_HTML.getOpt()));

            if (outputJsFile == null && outputHtmlFile == null) {
                usage("Please specify js output via " + OUTPUT_JS.getLongOpt() + " &| html output via "
                        + OUTPUT_HTML.getLongOpt(), stderr);
                return false;
            }
        }

        try {
            cssPropertyWhitelistUri = new URI(cl.getOptionValue(CSS_PROPERTY_WHITELIST.getOpt(),
                    "resource:///com/google/caja/lang/css/css-extensions.json"));
            htmlAttributeWhitelistUri = new URI(cl.getOptionValue(HTML_ATTRIBUTE_WHITELIST.getOpt(),
                    "resource:///com/google/caja/lang/html" + "/html4-attributes-extensions.json"));
            htmlElementWhitelistUri = new URI(cl.getOptionValue(HTML_ELEMENT_WHITELIST.getOpt(),
                    "resource:///com/google/caja/lang/html" + "/html4-elements-extensions.json"));

            if (cl.getOptionValue(BASE_URI.getOpt()) != null) {
                baseUri = new URI(cl.getOptionValue(BASE_URI.getOpt()));
            } else {
                baseUri = inputUris.get(0);
            }
        } catch (URISyntaxException ex) {
            stderr.println("Invalid whitelist URI: " + ex.getInput() + "\n    " + ex.getReason());
            return false;
        }

        if (cl.getOptionValue(FETCHER_BASE.getOpt()) != null) {
            fetcherBase = new File(cl.getOptionValue(FETCHER_BASE.getOpt()));
        } else if (Strings.equalsIgnoreCase(baseUri.getScheme(), "file")) {
            fetcherBase = new File(baseUri).getParentFile();
        }

        idClass = cl.getOptionValue(ID_CLASS.getOpt(), null);

        String servicePortString;
        try {
            servicePortString = cl.getOptionValue(SERVICE_PORT.getOpt(), "8887");
            servicePort = Integer.parseInt(servicePortString);
        } catch (NumberFormatException e) {
            stderr.println("Invalid service port: " + SERVICE_PORT.getOpt() + "\n    " + e.getMessage());
            return false;
        }

        fUris = Sets.immutableSet(getOptionValues(cl, F_URI));
        lUris = Sets.immutableSet(getOptionValues(cl, L_URI));

        String renderString = cl.getOptionValue(RENDERER.getOpt());
        if (renderString != null) {
            renderer = SourceRenderMode.valueOf(renderString.toUpperCase());
            if (renderer == null) {
                stderr.println("Invalid renderer: " + renderString);
                return false;
            }
        } else {
            renderer = SourceRenderMode.PRETTY;
        }

        boolean debugMode = cl.hasOption(DEBUG_MODE.getOpt());
        boolean onlyJsEmitted = cl.hasOption(OUTPUT_JS.getOpt()) && !cl.hasOption(OUTPUT_HTML.getOpt());
        if (debugMode) {
            negGoals = negGoals.with(PipelineMaker.ONE_CAJOLED_MODULE);
            posGoals = posGoals.with(PipelineMaker.ONE_CAJOLED_MODULE_DEBUG);
        }
        if (onlyJsEmitted) {
            negGoals = negGoals.with(PipelineMaker.HTML_SAFE_STATIC);
        }

        String preconds = cl.getOptionValue(PIPELINE_PRECONDITIONS.getOpt());
        if (preconds != null) {
            Pair<Planner.PlanState, Planner.PlanState> deltas = planDeltas(preconds);
            negPreconds = negPreconds.with(deltas.a);
            posPreconds = posPreconds.with(deltas.b);
        }

        String goals = cl.getOptionValue(PIPELINE_GOALS.getOpt());
        if (goals != null) {
            Pair<Planner.PlanState, Planner.PlanState> deltas = planDeltas(goals);
            negGoals = negGoals.with(deltas.a);
            posGoals = posGoals.with(deltas.b);
        }

        return true;
    } finally {
        stderr.flush();
    }
}