Example usage for java.net URI toString

List of usage examples for java.net URI toString

Introduction

In this page you can find the example usage for java.net URI toString.

Prototype

public String toString() 

Source Link

Document

Returns the content of this URI as a string.

Usage

From source file:dk.netarkivet.viewerproxy.distribute.HTTPControllerServer.java

/**
 * Helper method to handle getRecordedURIs command.
 *
 * @param request The HTTP request we are working on
 * @param response Response to handle result
 *//*  ww w. j av  a  2s  .  co m*/
private void doGetRecordedURIs(Request request, Response response) {
    checkParameters(request);
    Set<URI> uris = c.getRecordedURIs();
    response.addHeaderField(CONTENT_TYPE_HEADER, TEXT_PLAIN_MIMETYPE);
    OutputStream os = response.getOutputStream();
    try {
        for (URI recordedUri : uris) {
            os.write(recordedUri.toString().getBytes());
            os.write('\n');
        }
    } catch (IOException e) {
        throw new IOFailure("Error trying to write missing " + "uris to http response!", e);
    }
    response.setStatus(OK_RESPONSE_CODE);
}

From source file:org.brekka.stillingar.spring.resource.ScanningResourceSelector.java

/**
 * Search the specified base directory for files with names matching those in <code>names</code>. If the location
 * gets rejected then it should be added to the list of rejected locations.
 * //  w  ww .  ja va  2  s. c  o  m
 * @param locationBase
 *            the location to search
 * @param names
 *            the names of files to find within the base location
 * @param rejected
 *            collects failed locations.
 * @return the resource or null if one cannot be found.
 */
protected Resource findInBaseDir(BaseDirectory locationBase, Set<String> names,
        List<RejectedSnapshotLocation> rejected) {
    Resource dir = locationBase.getDirResource();
    if (dir instanceof UnresolvableResource) {
        UnresolvableResource res = (UnresolvableResource) dir;
        rejected.add(new Rejected(locationBase.getDisposition(), null, res.getMessage()));
    } else {
        String dirPath = null;
        try {
            URI uri = dir.getURI();
            if (uri != null) {
                dirPath = uri.toString();
            }
        } catch (IOException e) {
            if (log.isWarnEnabled()) {
                log.warn(format("Resource dir '%s' has a bad uri", locationBase), e);
            }
        }
        String message;
        if (dir.exists()) {
            StringBuilder messageBuilder = new StringBuilder();
            for (String name : names) {
                try {
                    Resource location = dir.createRelative(name);
                    if (location.exists()) {
                        if (location.isReadable()) {
                            // We have found a file
                            return location;
                        }
                        if (messageBuilder.length() > 0) {
                            messageBuilder.append(" ");
                        }
                        messageBuilder.append("File '%s' exists but cannot be read.");
                    } else {
                        // Fair enough, it does not exist
                    }
                } catch (IOException e) {
                    // Location could not be resolved, log as warning, then move on to the next one.
                    if (log.isWarnEnabled()) {
                        log.warn(format("Resource location '%s' encountered problem", locationBase), e);
                    }
                }
            }
            if (messageBuilder.length() == 0) {
                message = "no configuration files found";
            } else {
                message = messageBuilder.toString();
            }
        } else {
            message = "Directory does not exist";
        }
        rejected.add(new Rejected(locationBase.getDisposition(), dirPath, message));
    }
    // No resource found
    return null;
}

From source file:com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheckTest.java

@Test
public void testRegexpHeaderURL() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(RegexpHeaderCheck.class);
    URI uri = new File(getPath("regexp.header")).toURI();
    checkConfig.addAttribute("headerFile", uri.toString());
    final String[] expected = { "3: " + getCheckMessage(MSG_MISMATCH, "// Created: 2002"), };
    verify(checkConfig, getPath("InputRegexpHeader7.java"), expected);
}

From source file:de.l3s.boilerpipe.sax.HtmlArticleExtractor.java

private String removeNotAllowedTags(String htmlFragment, URI docUri) {
    Source source = new Source(htmlFragment);
    OutputDocument outputDocument = new OutputDocument(source);
    List<Element> elements = source.getAllElements();

    for (Element element : elements) {
        Attributes attrs = element.getAttributes();
        Map<String, String> attrsUpdate = outputDocument.replace(attrs, true);
        if (!element.getName().contains("a")) {
            attrsUpdate.clear();/*from   w  ww. j av a 2 s  . c o m*/
        } else {
            if (attrsUpdate.get("href") != null) {
                String link = attrsUpdate.get("href");
                if (!link.contains("http")) {
                    URI documentUri = docUri;

                    URI anchorUri;
                    try {
                        anchorUri = new URI(link);
                        URI result = documentUri.resolve(anchorUri);

                        attrsUpdate.put("href", result.toString());
                    } catch (URISyntaxException e) {
                        outputDocument.remove(element);
                    }
                }
            }
        }

        if (NOT_ALLOWED_HTML_TAGS.contains(element.getName())) {
            Segment content = element.getContent();
            if (element.getName() == "script" || element.getName() == "style" || element.getName() == "form") {
                outputDocument.remove(content);
            }
            outputDocument.remove(element.getStartTag());

            if (!element.getStartTag().isSyntacticalEmptyElementTag()) {
                outputDocument.remove(element.getEndTag());
            }
        }
    }

    String out = outputDocument.toString();
    out = out.replaceAll("\\n", "");
    out = out.replaceAll("\\t", "");

    return out;
}

From source file:net.sourceforge.dita4publishers.tools.dxp.DxpFileOrganizingBosVisitor.java

public void visit(BoundedObjectSet bos) throws Exception {
    // If there is a root map, then everything is
    // handled relative to it and there may not be a need
    // for a manifest, otherwise we need to generate 
    // a manifest map or reorganize the files to put
    // everything below the root map.

    BosMember rootMember = bos.getRoot();
    if (rootMember != null && rootMember instanceof DitaMapBosMemberImpl) {
        this.rootMap = rootMember;
    } else {/*  ww w . j  a va2  s. c o  m*/
        this.rootMap = constructDxpManifestMap(bos);
    }

    this.rootMapUri = rootMap.getEffectiveUri();
    try {
        this.baseUri = AddressingUtil.getParent(rootMapUri);
    } catch (URISyntaxException e) {
        throw new BosException("URI syntax exception calculating base URI for root map: " + e.getMessage());
    } catch (MalformedURLException e) {
        throw new BosException("MalformedURLException calculating base URI for root map: " + e.getMessage());
    } catch (IOException e) {
        throw new BosException("IOException calculating base URI for root map: " + e.getMessage());
    }

    this.rewriteRequired = false;

    for (BosMember member : bos.getMembers()) {
        if (member.equals(rootMap))
            continue;
        URI memberUri = member.getEffectiveUri();
        URI memberBase = null;
        try {
            memberBase = AddressingUtil.getParent(memberUri);
        } catch (URISyntaxException e) {
            throw new BosException(
                    "URI syntax exception: " + e.getMessage() + " getting base URI for member " + member);
        } catch (MalformedURLException e) {
            throw new BosException(
                    "MalformedURLException: " + e.getMessage() + " getting base URI for member " + member);
        } catch (IOException e) {
            throw new BosException("IOException: " + e.getMessage() + " getting base URI for member " + member);
        }
        URI relativeUri = baseUri.relativize(memberUri);
        boolean isAbsolute = relativeUri.isAbsolute();
        if (isAbsolute || relativeUri.toString().startsWith("..") || relativeUri.toString().startsWith("/")
                || memberBase.equals(baseUri)) {
            // URI is not below the root map, need to rewrite it.
            rewriteRequired = true;
            try {
                URL newUrl = new URL(baseUri.toURL(), "dependencies/" + member.getFileName());
                member.setEffectiveUri(newUrl.toURI());
            } catch (MalformedURLException e) {
                throw new BosException("Malformed URL exception: " + e.getMessage()
                        + " constructing new URL for member " + member);
            } catch (URISyntaxException e) {
                throw new BosException("URI syntax exception: " + e.getMessage()
                        + " constructing new URI for member " + member);
            }
        }
    }

    if (rewriteRequired) {
        UriToUriPointerRewritingBosVisitor rewritingVisitor = new UriToUriPointerRewritingBosVisitor();
        rewritingVisitor.visit(bos);
    }

}

From source file:org.geosdi.geoplatform.experimental.openam.support.config.connector.OpenAMConnector.java

/**
 * @return {@link IOpenAMServerInfo}//  ww w .j  a  v a  2 s. com
 * @throws Exception
 */
@Override
public IOpenAMServerInfo serverInfo() throws Exception {
    logger.debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@TRYING TO HAVE SERVER_INFO WITH "
            + "OPENAM_CONNECTOR_SETTINGS : {}\n", this.openAMConnectorSettings);
    OpenAMServerInfoRequest serverInfoRequest = this.openAMRequestMediator.getRequest(SERVER_INFO);
    URI serverInfoURI = this.buildURI(this.openAMConnectorSettings, serverInfoRequest).build();

    logger.debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@OPENAM_SERVER_INFO_CONNECTOR_URI : {}\n",
            URLDecoder.decode(serverInfoURI.toString(), "UTF-8"));

    HttpGet httpGet = new HttpGet(serverInfoURI);
    httpGet.addHeader("Content-Type", "application/json");
    CloseableHttpResponse response = this.httpClient.execute(httpGet);

    if (response.getStatusLine().getStatusCode() != 200) {
        throw new IllegalStateException(
                "OpenAMServerInfo Error Code : " + response.getStatusLine().getStatusCode());
    }

    return this.openAMReader.readValue(response.getEntity().getContent(), OpenAMServerInfo.class);
}

From source file:com.github.dozermapper.core.builder.xml.SchemaLSResourceResolver.java

/**
 * Attempt to resolve systemId resource from classpath by checking:
 *
 * 1. Try {@link SchemaLSResourceResolver#getClass()#getClassLoader()}
 * 2. Try {@link BeanContainer#getClassLoader()}
 * 3. Try {@link Activator#getBundle()}//from ww w . ja  v  a 2 s  . c  o m
 *
 * @param systemId systemId used by XSD
 * @return stream to XSD
 * @throws IOException if fails to find XSD
 */
private InputStream resolveFromClassPath(String systemId) throws IOException, URISyntaxException {
    InputStream source;

    String xsdPath;
    URI uri = new URI(systemId);
    if (uri.getScheme().equalsIgnoreCase("file")) {
        xsdPath = uri.toString();
    } else {
        xsdPath = uri.getPath();
        if (xsdPath.charAt(0) == '/') {
            xsdPath = xsdPath.substring(1);
        }
    }

    ClassLoader localClassLoader = getClass().getClassLoader();

    LOG.debug("Trying to locate [{}] via ClassLoader [{}]", xsdPath,
            localClassLoader.getClass().getSimpleName());

    //Attempt to find within this JAR
    URL url = localClassLoader.getResource(xsdPath);
    if (url == null) {
        //Attempt to find via user defined class loader
        DozerClassLoader dozerClassLoader = beanContainer.getClassLoader();

        LOG.debug("Trying to locate [{}] via DozerClassLoader [{}]", xsdPath,
                dozerClassLoader.getClass().getSimpleName());

        url = dozerClassLoader.loadResource(xsdPath);
    }

    if (url == null) {
        //Attempt to find via OSGi
        Bundle bundle = Activator.getBundle();
        if (bundle != null) {
            LOG.debug("Trying to locate [{}] via Bundle [{}]", xsdPath, bundle.getClass().getSimpleName());

            url = bundle.getResource(xsdPath);
        }
    }

    if (url == null) {
        throw new IOException("Could not resolve bean-mapping XML Schema [" + systemId
                + "]: not found in classpath; " + xsdPath);
    }

    try {
        source = url.openStream();
    } catch (IOException ex) {
        throw new IOException("Could not resolve bean-mapping XML Schema [" + systemId
                + "]: not found in classpath; " + xsdPath, ex);
    }

    LOG.debug("Found bean-mapping XML Schema [{}] in classpath @ [{}]", systemId, url.toString());

    return source;
}

From source file:at.ac.univie.isc.asio.integration.RequestSpecAssembler.java

private RequestSpecBuilder managementRequest(final URI baseUri) {
    final PreemptiveBasicAuthScheme scheme = new PreemptiveBasicAuthScheme();
    scheme.setUserName(config.rootCredentials.getUserName());
    scheme.setPassword(config.rootCredentials.getPassword());
    return new RequestSpecBuilder().setBaseUri(baseUri.toString()).setAuth(scheme);
}

From source file:craterdog.marketplace.DigitalMarketplaceClient.java

@Override
public RetrieveBatchResponse retrieveBatch(URI batchLocation) {
    logger.entry(batchLocation);/*from  w w w  .  j a  v  a 2 s.  c  o  m*/
    RetrieveBatchResponse response = restTemplate.getForObject(batchLocation.toString(),
            RetrieveBatchResponse.class);
    logger.exit(response);
    return response;
}