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:org.lmnl.AbstractXMLTest.java

protected synchronized void load(String resource) {
    try {/*from  ww w .  j  av a2 s  . c  om*/
        if (RESOURCES.contains(resource) && !documents.containsKey(resource)) {

            Text xml = annotationFactory.newText();
            final URI uri = AbstractXMLTest.class.getResource("/" + resource).toURI();

            xmlParser.load(xml, new StreamSource(uri.toASCIIString()));
            sources.put(resource, xml);

            final Text text = annotationFactory.newText();
            xmlParser.parse(xml, text, parserConfiguration);

            documents.put(resource, text);
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.osiam.resources.controller.UserController.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)//from   www  . j a  va 2s.  c om
@ResponseBody
public User create(HttpServletRequest request, HttpServletResponse response) throws IOException {
    User user = jsonInputValidator.validateJsonUser(request);
    User createdUser = scimUserProvisioning.create(user);

    String requestUrl = request.getRequestURL().toString();
    URI uri = new UriTemplate("{requestUrl}{internalId}").expand(requestUrl + "/", createdUser.getId());
    response.setHeader("Location", uri.toASCIIString());
    Meta newMeta = new Meta.Builder(createdUser.getMeta()).setLocation(uri.toASCIIString()).build();

    return new User.Builder(createdUser).setMeta(newMeta).build();
}

From source file:org.sift.batch.tag.service.TagCloudMarshallerService.java

/**
 * Interface method implementation. Persists the specified TagCloud a marshalled file on the file system. Uses the {@link TagCloud#getSubject()} as the file name
 * @see org.sift.tagcloud.spi.service.PersistenceService#persistTagCloud(org.sift.tagcloud.TagCloud)
 *//*from   w w  w  . ja v  a2 s.c o  m*/
public void persistTagCloud(S tagCloud) throws RuntimeException {
    if (tagCloud.getSubject() == null || tagCloud.getSubject().trim().length() == 0) {
        throw new RuntimeException(
                "Tag cloud's subject cannot be empty! File cannot be created with empty name.");
    }
    // write the tag cloud data by creating the TagCloudModel from the specified TagCloud 
    TagCloudModel tagCloudModel = new TagCloudModel();
    tagCloudModel.setSubject(tagCloud.getSubject());
    for (T tag : tagCloud.getTagsList()) {
        TagModel tModel = new TagModel();
        tModel.setDisplayText(tag.getDisplayText());
        tModel.setWeight(tag.getWeight());
        tModel.setDescription(tag.getDescription());
        if (tag.getTagURL() != null) {
            tModel.setTagURL(tag.getTagURL().toExternalForm());
        }
        if (tag.getTagSourcesURIs() != null) {
            //URIs from tag to tagmodel
            List<String> tagSourceURIs = tModel.getTagSourcesURIs();
            for (URI uri : tag.getTagSourcesURIs()) {
                tagSourceURIs.add(uri.toASCIIString());
            }
        }
        tModel.setTitle(tag.getTitle());
        tagCloudModel.getTags().add(tModel);
    }

    try {
        this.marshallTagCloud(
                this.getTagCloudsDirectory() + File.separator + tagCloud.getSubject() + this.fileExtensionPart,
                tagCloudModel);
    } catch (RuntimeException pe) {
        throw new RuntimeException("Error persisting tag cloud with subject : " + tagCloud.getSubject(), pe);
    }
}

From source file:de.slub.index.DatastreamIndexJob.java

private void indexDatastreamContent(FedoraClient fedoraClient, DatastreamProfile profile, XContentBuilder jb)
        throws Exception {
    jb.startObject("CONTENT");
    URI contentURI = new URI(
            String.format("objects/%s/datastreams/%s/content", profile.getPid(), profile.getDsID()));
    jb.field("_uri", contentURI.toASCIIString());
    FedoraResponse dsResponse = fedoraClient
            .execute(new GetDatastreamDissemination(profile.getPid(), profile.getDsID()));

    if (dsResponse.getStatus() != 200) {
        throw new Exception("Couldn't get datastream content for indexing. Fedora server status: "
                + dsResponse.getStatus());
    }/*  w w  w.j  a v  a  2 s  . c om*/

    InputStream contentInputStream = dsResponse.getEntityInputStream();
    try {
        Reader reader = new ParsingReader(contentInputStream);
        jb.field("_content", IOUtils.toString(reader));
    } finally {
        contentInputStream.close();
    }

    jb.endObject();
}

From source file:com.smartitengineering.cms.ws.resources.workspace.WorkspaceFriendliesResource.java

@PUT
@Consumes(TextURIListProvider.TEXT_URI_LIST)
public Response replaceWorkspaceAsFriendlies(final Collection<URI> uris) {
    SmartContentAPI.getInstance().getWorkspaceApi().removeAllFriendlies(workspace.getId());
    if (uris != null && uris.size() > 0) {
        List<WorkspaceId> ids = new ArrayList<WorkspaceId>(uris.size());
        for (URI uri : uris) {
            if (logger.isDebugEnabled()) {
                logger.debug("URI to parse " + uri.toASCIIString());
            }//  w  w w  .  j av a  2s .  c om
            WorkspaceId id = getWorkspaceResource(uri.toASCIIString()).getWorkspace().getId();
            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().addFriend(workspace.getId(),
                ids.toArray(new WorkspaceId[ids.size()]));
    }
    ResponseBuilder builder = Response.status(Response.Status.OK);
    builder.location(getUriInfo().getAbsolutePath());
    return builder.build();
}

From source file:org.openmastery.logging.LoggingFilter.java

private void appendRequestUri(StringBuilder b, String method, URI uri) {
    b.append(method).append(" ").append(uri.toASCIIString());
}

From source file:net.itransformers.ws.rs.TopologyManagementResource.java

public String getNodesAsHtml() throws IOException, SAXException, ParserConfigurationException {
    if (graph == null) {
        File graphmlFile = new File(context.getInitParameter("config.file"));
        this.init(DirectedSparseGraph.<String, String>getFactory(), graphmlFile);
    }//  w  w w.  j av a  2s.co m
    // Return some cliched textual content
    StringBuilder sb = new StringBuilder();
    sb.append(String.format("<pre>&lt;nodes size=\"%s\"&gt;<br/>", graph.getVertices().size()));

    for (String vertex : graph.getVertices()) {
        UriBuilder ub = uriInfo.getAbsolutePathBuilder();
        URI userUri = ub.path(vertex).build();
        sb.append(String.format("\t&lt;node id=\"<a href=\"%s\">%s</a>\"/&gt;<br/>", userUri.toASCIIString(),
                vertex));
    }
    sb.append("&lt;/nodes&gt;</pre>");
    return sb.toString();
}

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

@Override
protected void onHttpRequestFailure(Throwable cause, Object context) {
    logger.error("HTTP request error", cause);
    if (context instanceof URI) {
        URI uri = (URI) context;
        pendingRequests.remove(uri.toASCIIString());
    } else if (context instanceof WeMoDeviceRequestContext) {
        WeMoDeviceRequestContext wdrc = (WeMoDeviceRequestContext) context;
        wdrc.getDevice().onHttpRequestFailure(cause, wdrc.getContext());
    }//w w  w .  j av a2s  . com
}

From source file:de.fiz.akubra.hdfs.HDFSBlobStoreConnection.java

/**
 * fetch a {@link HDFSBlob} from the {@link HDFSBlobStore}
 * //from   w ww.  ja v a  2 s  . co m
 * @param uri
 *            the {@link URI} of the {@link HDFSBlob}
 * @param hints
 *            not used
 * @throws UnsupportedIdException
 *             if the supplied {@link URI} was not valid
 */
public Blob getBlob(final URI uri, final Map<String, String> hints) throws UnsupportedIdException, IOException {
    if (isClosed()) {
        throw new IllegalStateException("Connection to hdfs is closed");
    }
    if (uri == null) {
        URI tmp = URI.create(store.getId() + UUID.randomUUID().toString());
        log.debug("creating new Blob uri " + tmp.toASCIIString());
        // return getBlob(new ByteArrayInputStream(new byte[0]),0, null);
        return new HDFSBlob(tmp, this);
    }
    log.debug("fetching blob " + uri);
    if (uri.getRawSchemeSpecificPart().startsWith("info:")) {
        log.debug("special object " + uri);
    }
    if (!uri.toASCIIString().startsWith("hdfs:")) {
        throw new UnsupportedIdException(uri, "HDFS URIs have to start with 'hdfs:'");
    }
    HDFSBlob blob = new HDFSBlob(uri, this);
    return blob;
}

From source file:org.gatherdata.alert.dao.neo4j.internal.NeoAlertServiceDao.java

public ActionPlan get(URI uidOfActionPlan) {
    ActionPlan foundEntity = null;//from   w ww  .j  av a2 s . com
    Node foundNode = neo.indexService().getSingleNode(UniqueNodeWrapper.UID_PROPERTY,
            uidOfActionPlan.toASCIIString());
    if (foundNode != null) {
        foundEntity = actionPlanAdapter.adaptFromNode(foundNode, neo.neo());
    }
    return foundEntity;
}