Example usage for java.net URI toASCIIString

List of usage examples for java.net URI toASCIIString

Introduction

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

Prototype

public String toASCIIString() 

Source Link

Document

Returns the content of this URI as a US-ASCII string.

Usage

From source file:com.smartitengineering.cms.ws.resources.content.WorkspaceContentContainerResource.java

@PUT
@Consumes(TextURIListProvider.TEXT_URI_LIST)
public Response replaceContainerContents(final Collection<URI> contentUris) {
    SmartContentAPI.getInstance().getWorkspaceApi().removeAllRootContents(workspace.getId());
    if (contentUris != null && contentUris.size() > 0) {
        List<ContentId> ids = new ArrayList<ContentId>(contentUris.size());
        for (URI uri : contentUris) {
            if (logger.isDebugEnabled()) {
                logger.debug("URI to parse " + uri.toASCIIString());
            }//from  w  w  w. j a  v a2 s  . c o  m
            ContentId id = getResourceContext().matchResource(uri, ContentResource.class).getContent()
                    .getContentId();
            if (id == null) {
                return Response.status(Response.Status.BAD_REQUEST)
                        .entity("Some URIs could not be resolved internally!").build();
            }
            ids.add(id);
        }
        SmartContentAPI.getInstance().getWorkspaceApi().addRootContent(workspace.getId(),
                ids.toArray(new ContentId[ids.size()]));
    }
    ResponseBuilder builder = Response.status(Response.Status.OK);
    builder.location(getUriInfo().getAbsolutePath());
    return builder.build();
}

From source file:org.dspace.identifier.ezid.EZIDRequest.java

/**
 * Alter the metadata bound to an identifier.
 *
 * @param metadata fields to be altered. Leave the value of a field's empty
 *                 to delete the field.//from  ww  w  .  j av  a 2  s  .co m
 * @return
 */
public EZIDResponse modify(String name, Map<String, String> metadata)
        throws IOException, IdentifierException, URISyntaxException {
    if (null == metadata) {
        throw new IllegalArgumentException("metadata must not be null");
    }
    // POST path +metadata
    HttpPost request;
    URI uri = new URI(scheme, host, ID_PATH + authority + name, null);
    log.debug("EZID modify {}", uri.toASCIIString());
    request = new HttpPost(uri);
    request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8));
    HttpResponse response = client.execute(request);
    return new EZIDResponse(response);
}

From source file:org.apache.taverna.examples.JsonExport.java

public ObjectNode toJson(WorkflowBundle wfBundle) {

    ObjectNode root = mapper.createObjectNode();
    ArrayNode contextList = root.arrayNode();
    root.put("@context", contextList);
    ObjectNode context = root.objectNode();
    contextList.add("https://w3id.org/scufl2/context");
    contextList.add(context);// w w  w. j  av a2 s  . c om
    URI base = wfBundle.getGlobalBaseURI();
    context.put("@base", base.toASCIIString());
    root.put("id", base.toASCIIString());

    //        root.put("name", wfBundle.getName());
    //        root.put("revisions", toJson(wfBundle.getCurrentRevision()));

    root.put("workflow", toJson(wfBundle.getMainWorkflow()));
    root.put("profile", toJson(wfBundle.getMainProfile()));

    return root;
}

From source file:org.gradle.internal.resource.transfer.DefaultCacheAwareExternalResourceAccessor.java

private HashValue getResourceSha1(URI location) {
    try {/*  w  ww . j a  v a2 s . co  m*/
        URI sha1Location = new URI(location.toASCIIString() + ".sha1");
        ExternalResource resource = delegate.getResource(sha1Location);
        if (resource == null) {
            return null;
        }
        try {
            return resource.withContent(new Transformer<HashValue, InputStream>() {
                @Override
                public HashValue transform(InputStream inputStream) {
                    try {
                        String sha = IOUtils.toString(inputStream, "us-ascii");
                        return HashValue.parse(sha);
                    } catch (IOException e) {
                        throw new UncheckedIOException(e);
                    }
                }
            });
        } finally {
            resource.close();
        }
    } catch (Exception e) {
        throw new ResourceException(location,
                String.format("Failed to download SHA1 for resource '%s'.", location), e);
    }
}

From source file:com.whizzosoftware.hobson.wemo.WeMoPlugin.java

@Override
protected void onHttpResponse(int statusCode, List<Map.Entry<String, String>> headers, String response,
        Object context) {/*from   w  w  w  . j av a2  s . c  o  m*/
    logger.trace("Got HTTP response with context: {}", context);
    // if the context is an SSDPPacket, then this is the response from a new device setup.xml request
    if (context instanceof URI) {
        try {
            URI uri = (URI) context;
            pendingRequests.remove(uri.toASCIIString());
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            Document document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(response)));
            logger.trace("Got HTTP response: " + document);
            WeMoDevice device = WeMoDeviceFactory.createWeMoDevice(this, uri, document);
            if (device != null) {
                logger.info("Found WeMo device: " + device.getName());
                publishDevice(device);
                addWeMoURIToConfiguration(uri);
            } else {
                logger.warn("Unable to identify WeMo device; ignoring");
            }
        } catch (Exception e) {
            logger.error("Error parsing device setup.xml response", e);
        }
        // if the context is a WeMoDeviceRequestContext, then this is a response for a specific device -- deliver it
    } else if (context instanceof WeMoDeviceRequestContext) {
        WeMoDeviceRequestContext wdrc = (WeMoDeviceRequestContext) context;
        wdrc.getDevice().onHttpResponse(statusCode, headers, response, wdrc.getContext());
    }
}

From source file:nl.salp.warcraft4j.battlenet.api.BattlenetHttpApi.java

@Override
protected <T> String execute(BattlenetRegion region, BattlenetLocale locale, BattlenetApiRequest<T> method)
        throws IOException {
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        URI methodUri = createUri(region, locale, method);
        LOGGER.debug("Calling Battle.NET method {} with URI {}", method.getClass().getName(),
                methodUri.toASCIIString());
        HttpUriRequest request = new HttpGet(methodUri);
        return execute(request, httpClient);
    }//  w  w  w . j  av a 2  s .  co m
}

From source file:com.jaeksoft.searchlib.crawler.file.database.FileInfo.java

private void setUriFileNameExtension(URI uri) {
    String path = uri.getPath();/* ww w  . ja  v a 2 s . c  o  m*/
    setUri(uri.toASCIIString());
    setFileName(LinkUtils.lastPart(path));
    setFileExtension(FilenameUtils.getExtension(fileName));
}

From source file:org.dspace.identifier.ezid.EZIDRequest.java

/**
 * Create an identifier with a given name. The name is the end of the
 * request path. Note: to "reserve" a given identifier, include "_status =
 * reserved" in {@link metadata}./*from w  w w.jav  a  2s  .  c  o m*/
 *
 * @param metadata ANVL-encoded key/value pairs.
 * @return
 */
public EZIDResponse create(String name, Map<String, String> metadata)
        throws IOException, IdentifierException, URISyntaxException {
    // PUT path [+metadata]
    HttpPut request;
    URI uri = new URI(scheme, host, ID_PATH + authority + '/' + name, null);
    log.debug("EZID create {}", uri.toASCIIString());
    request = new HttpPut(uri);
    if (null != metadata) {
        try {
            request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8));
        } catch (UnsupportedEncodingException ex) {
            /* SNH */ }
    }
    HttpResponse response = client.execute(request);
    return new EZIDResponse(response);
}

From source file:org.eclipse.buckminster.p2.remote.client.RemoteRepositoryFactory.java

protected File getCacheLocation(URI location) {
    File cacheArea = new File(org.eclipse.buckminster.p2.remote.Activator.getAgentLocation(), "cache");
    cacheArea.mkdir();//  w ww . ja  va 2  s.  co m
    UUID uuid;
    try {
        uuid = UUID.nameUUIDFromBytes(location.toASCIIString().getBytes("US-ASCII"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
    return new File(cacheArea, uuid.toString());
}

From source file:org.apache.fop.afp.util.DefaultFOPResourceAccessor.java

/** {@inheritDoc} */
public InputStream createInputStream(URI uri) throws IOException {
    //Step 1: resolve against local base URI --> URI
    URI resolved = resolveAgainstBase(uri);

    //Step 2: resolve against the user agent --> stream
    String base = (this.categoryBaseURI != null ? this.categoryBaseURI : this.userAgent.getBaseURL());
    Source src = userAgent.resolveURI(resolved.toASCIIString(), base);

    if (src == null) {
        throw new FileNotFoundException("Resource not found: " + uri.toASCIIString());
    } else if (src instanceof StreamSource) {
        StreamSource ss = (StreamSource) src;
        InputStream in = ss.getInputStream();
        if (in != null) {
            return in;
        }//from   w ww .java 2 s  . c o  m
        if (ss.getReader() != null) {
            //Don't support reader, retry using system ID below
            IOUtils.closeQuietly(ss.getReader());
        }
    }
    URL url = new URL(src.getSystemId());
    return url.openStream();
}