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.xmlcalabash.core.XProcRuntime.java

public void setCollection(URI href, Vector<XdmNode> docs) {
    if (collections == null) {
        collections = new Hashtable<String, Vector<XdmNode>>();
    }//from ww w.  j  a  va2s.co m
    collections.put(href.toASCIIString(), docs);
}

From source file:msearch.filmlisten.MSFilmlisteLesen.java

private InputStream getInputStreamForLocation(String source) throws Exception {
    InputStream in;/* w ww  .  j  av a  2 s. c  o  m*/
    long size = 0;
    final URI uri;
    if (source.startsWith("http")) {
        uri = new URI(source);
        //remote address for internet download
        HttpURLConnection conn = (HttpURLConnection) uri.toURL().openConnection();
        conn.setConnectTimeout(TIMEOUT);
        conn.setReadTimeout(TIMEOUT);
        conn.setRequestProperty("User-Agent", MSConfig.getUserAgent());
        if (conn.getResponseCode() < 400) {
            size = conn.getContentLengthLong();
        }
        in = new SizeInputStream(conn.getInputStream(), size, uri.toASCIIString());
    } else {
        //local file
        notifyProgress(source, "Download", PROGRESS_MAX);
        in = new FileInputStream(source);
    }

    return in;
}

From source file:com.msopentech.odatajclient.engine.data.impl.AbstractODataBinder.java

@Override
@SuppressWarnings("unchecked")
public <T extends Entry> T getEntry(final ODataEntity entity, final Class<T> reference, final boolean setType) {

    final T entry = ResourceFactory.newEntry(reference);
    entry.setType(entity.getName());/*from  w  ww .  j ava2 s .  co m*/

    // -------------------------------------------------------------
    // Add edit and self link
    // -------------------------------------------------------------
    final URI editLink = entity.getEditLink();
    if (editLink != null) {
        final Link entryEditLink = ResourceFactory.newLinkForEntry(reference);
        entryEditLink.setTitle(entity.getName());
        entryEditLink.setHref(editLink.toASCIIString());
        entryEditLink.setRel(ODataConstants.EDIT_LINK_REL);
        entry.setEditLink(entryEditLink);
    }

    if (entity.isReadOnly()) {
        final Link entrySelfLink = ResourceFactory.newLinkForEntry(reference);
        entrySelfLink.setTitle(entity.getName());
        entrySelfLink.setHref(entity.getLink().toASCIIString());
        entrySelfLink.setRel(ODataConstants.SELF_LINK_REL);
        entry.setSelfLink(entrySelfLink);
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append navigation links (handling inline entry / feed as well)
    // -------------------------------------------------------------
    // handle navigation links
    for (ODataLink link : entity.getNavigationLinks()) {
        // append link 
        LOG.debug("Append navigation link\n{}", link);
        entry.addNavigationLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference)));
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append edit-media links
    // -------------------------------------------------------------
    for (ODataLink link : entity.getEditMediaLinks()) {
        LOG.debug("Append edit-media link\n{}", link);
        entry.addMediaEditLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference)));
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append association links
    // -------------------------------------------------------------
    for (ODataLink link : entity.getAssociationLinks()) {
        LOG.debug("Append association link\n{}", link);
        entry.addAssociationLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference)));
    }
    // -------------------------------------------------------------

    final Element content = newEntryContent();
    if (entity.isMediaEntity()) {
        entry.setMediaEntryProperties(content);
        entry.setMediaContentSource(entity.getMediaContentSource());
        entry.setMediaContentType(entity.getMediaContentType());
    } else {
        entry.setContent(content);
    }

    for (ODataProperty prop : entity.getProperties()) {
        content.appendChild(toDOMElement(prop, content.getOwnerDocument(), setType));
    }

    return entry;
}

From source file:ddf.catalog.data.impl.MetacardImpl.java

/**
 * Some types of metadata use different content types. If utilized, sets the {@link URI} of the
 * content type. <br/>// ww  w  .  j a v a2 s. c  om
 * Convenience method for <code>
 * {@link #setAttribute setAttribute}(new {@link AttributeImpl}({@link Metacard#TARGET_NAMESPACE}, targetNamespace))
 * </code>
 *
 * @param targetNamespace {@link URI} of the sub-type, null if unused
 * @see Metacard#TARGET_NAMESPACE
 */
public void setTargetNamespace(URI targetNamespace) {
    setAttribute(Metacard.TARGET_NAMESPACE, targetNamespace.toASCIIString());
}

From source file:org.opendatakit.aggregate.server.ServerDataServiceImpl.java

/**
 * This method more or less gets the user-friendly data to be displayed. It
 * adds the correct filename and returns only the non-deleted rows.
 *///  w  w w  .  j  a  va  2 s .co  m
@Override
public TableContentsForFilesClient getInstanceFileInfoContents(String tableId, String sortColumn,
        boolean ascending) throws AccessDeniedException, RequestFailureException, DatastoreFailureException,
        PermissionDeniedExceptionClient, EntityNotFoundExceptionClient {
    TableContentsForFilesClient tcc = new TableContentsForFilesClient();
    HttpServletRequest req = this.getThreadLocalRequest();
    CallingContext cc = ContextFactory.getCallingContext(this, req);
    try {
        TablesUserPermissions userPermissions = new TablesUserPermissionsImpl(cc);
        String appId = ServerPreferencesProperties.getOdkTablesAppId(cc);
        TableManager tm = new TableManager(appId, userPermissions, cc);
        TableEntry table = tm.getTable(tableId);
        if (table == null || table.getSchemaETag() == null) { // you couldn't find
                                                              // the table
            throw new ODKEntityNotFoundException();
        }
        String schemaETag = table.getSchemaETag();

        DbTableInstanceFiles blobStore = new DbTableInstanceFiles(tableId, cc);
        List<BinaryContent> contents = blobStore.getAllBinaryContents(cc);

        UriBuilder ub;
        try {
            ub = UriBuilder.fromUri(new URI(
                    cc.getServerURL() + BasicConsts.FORWARDSLASH + ServletConsts.ODK_TABLES_SERVLET_BASE_PATH));
        } catch (URISyntaxException e) {
            e.printStackTrace();
            throw new RequestFailureException(e);
        }
        ub.path(OdkTables.class, "getTablesService");

        ArrayList<FileSummaryClient> completedSummaries = new ArrayList<FileSummaryClient>();
        for (BinaryContent entry : contents) {
            if (entry.getUnrootedFilePath() == null) {
                continue;
            }

            // the rowId is the top-level auri for this record
            String rowId = entry.getTopLevelAuri();

            UriBuilder tmp = ub.clone().path(TableService.class, "getRealizedTable")
                    .path(RealizedTableService.class, "getInstanceFiles")
                    .path(InstanceFileService.class, "getFile");
            URI getFile = tmp.build(appId, tableId, schemaETag, rowId, entry.getUnrootedFilePath());
            String downloadUrl = getFile.toASCIIString() + "?" + FileService.PARAM_AS_ATTACHMENT + "=true";

            FileSummaryClient sum = new FileSummaryClient(entry.getUnrootedFilePath(), entry.getContentType(),
                    entry.getContentLength(), entry.getUri(), null, tableId, downloadUrl);
            sum.setInstanceId(entry.getTopLevelAuri());
            completedSummaries.add(sum);
        }

        Comparator<FileSummaryClient> columnSorter = FILENAME.getAscendingSort();
        if (StringUtils.isNotEmpty(sortColumn)) {
            FileInfoSortType columnType = FileInfoSortType.fromDbColumn(sortColumn);
            if (columnType != null) {
                if (ascending) {
                    columnSorter = columnType.getAscendingSort();
                } else {
                    columnSorter = columnType.getDescendingSort();
                }
            }
        }
        Collections.sort(completedSummaries, columnSorter);

        tcc.files = completedSummaries;
        return tcc;
    } catch (ODKEntityNotFoundException e) {
        e.printStackTrace();
        throw new EntityNotFoundExceptionClient(e);
    } catch (ODKDatastoreException e) {
        e.printStackTrace();
        throw new DatastoreFailureException(e);
    } catch (ODKTaskLockException e) {
        e.printStackTrace();
        throw new RequestFailureException(e);
    } catch (PermissionDeniedException e) {
        e.printStackTrace();
        throw new PermissionDeniedExceptionClient(e);
    }
}

From source file:com.msopentech.odatajclient.engine.data.AbstractODataBinder.java

@Override
public <T extends EntryResource> T getEntry(final ODataEntity entity, final Class<T> reference,
        final boolean setType) {

    final T entry = client.getResourceFactory().newEntry(reference);
    entry.setType(entity.getName());//  w ww  . j ava 2 s  .  c o m

    // -------------------------------------------------------------
    // Add edit and self link
    // -------------------------------------------------------------
    final URI editLink = entity.getEditLink();
    if (editLink != null) {
        final LinkResource entryEditLink = client.getResourceFactory().newLinkForEntry(reference);
        entryEditLink.setTitle(entity.getName());
        entryEditLink.setHref(editLink.toASCIIString());
        entryEditLink.setRel(ODataConstants.EDIT_LINK_REL);
        entry.setEditLink(entryEditLink);
    }

    if (entity.isReadOnly()) {
        final LinkResource entrySelfLink = client.getResourceFactory().newLinkForEntry(reference);
        entrySelfLink.setTitle(entity.getName());
        entrySelfLink.setHref(entity.getLink().toASCIIString());
        entrySelfLink.setRel(ODataConstants.SELF_LINK_REL);
        entry.setSelfLink(entrySelfLink);
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append navigation links (handling inline entry / feed as well)
    // -------------------------------------------------------------
    // handle navigation links
    for (ODataLink link : entity.getNavigationLinks()) {
        // append link
        LOG.debug("Append navigation link\n{}", link);
        entry.addNavigationLink(
                getLinkResource(link, client.getResourceFactory().linkClassForEntry(reference)));
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append edit-media links
    // -------------------------------------------------------------
    for (ODataLink link : entity.getEditMediaLinks()) {
        LOG.debug("Append edit-media link\n{}", link);
        entry.addMediaEditLink(getLinkResource(link, client.getResourceFactory().linkClassForEntry(reference)));
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append association links
    // -------------------------------------------------------------
    for (ODataLink link : entity.getAssociationLinks()) {
        LOG.debug("Append association link\n{}", link);
        entry.addAssociationLink(
                getLinkResource(link, client.getResourceFactory().linkClassForEntry(reference)));
    }
    // -------------------------------------------------------------

    final Element content = newEntryContent();
    if (entity.isMediaEntity()) {
        entry.setMediaEntryProperties(content);
        entry.setMediaContentSource(entity.getMediaContentSource());
        entry.setMediaContentType(entity.getMediaContentType());
    } else {
        entry.setContent(content);
    }

    for (ODataProperty prop : entity.getProperties()) {
        content.appendChild(toDOMElement(prop, content.getOwnerDocument(), setType));
    }

    return entry;
}

From source file:org.eclipse.osee.framework.core.util.HttpProcessor.java

private static void configureProxyData(URI uri, HostConfiguration config) {
    boolean proxyBypass = OseeProperties.getOseeProxyBypassEnabled();
    if (!proxyBypass) {
        if (proxyService == null) {
            BundleContext context = Activator.getBundleContext();
            if (context != null) {
                ServiceReference<IProxyService> reference = context.getServiceReference(IProxyService.class);
                proxyService = context.getService(reference);
            }//from  ww w  .j a v a  2 s .  com
            if (proxyService != null) {
                proxyService.addProxyChangeListener(new IProxyChangeListener() {

                    @Override
                    public void proxyInfoChanged(IProxyChangeEvent event) {
                        proxiedData.clear();
                    }
                });
            }
        }

        String key = String.format("%s_%s", uri.getScheme(), uri.getHost());
        IProxyData[] datas = proxiedData.get(key);
        if (datas == null && proxyService != null) {
            datas = proxyService.select(uri);
            proxiedData.put(key, datas);
        }
        if (datas != null) {
            for (IProxyData data : datas) {
                config.setProxy(data.getHost(), data.getPort());
            }
        }
    }
    OseeLog.logf(Activator.class, Level.INFO, "Http-Request: [%s] [%s]", requests++, uri.toASCIIString());
}

From source file:com.collaborne.jsonschema.generator.driver.GeneratorDriver.java

/**
 * Create a {@link SchemaLoader} with the provided {@code rootUri} and {@code baseDirectory}.
 *
 * All schemas from {@code schemaFiles} are pre-loaded into the schema loader.
 *
 * @param rootUri/*www. j a  v a  2  s  .c o  m*/
 * @param baseDirectory
 * @param schemaFiles
 * @return
 * @throws IOException
 */
public SchemaLoader createSchemaLoader(URI rootUri, Path baseDirectory, List<Path> schemaFiles)
        throws IOException {
    URI baseDirectoryUri = baseDirectory.toAbsolutePath().normalize().toUri();

    // We're not adding a path redirection here, because that changes the path of the loaded schemas to the redirected location.
    // FIXME: This really looks like a bug in the SchemaLoader itself!
    URITranslatorConfiguration uriTranslatorConfiguration = URITranslatorConfiguration.newBuilder()
            .setNamespace(rootUri).freeze();

    LoadingConfigurationBuilder loadingConfigurationBuilder = LoadingConfiguration.newBuilder()
            .setURITranslatorConfiguration(uriTranslatorConfiguration);

    // ... instead, we use a custom downloader which executes the redirect
    Map<String, URIDownloader> downloaders = loadingConfigurationBuilder.freeze().getDownloaderMap();
    URIDownloader redirectingDownloader = new URIDownloader() {
        @Override
        public InputStream fetch(URI source) throws IOException {
            URI relativeSourceUri = rootUri.relativize(source);
            if (!relativeSourceUri.isAbsolute()) {
                // Apply the redirect
                source = baseDirectoryUri.resolve(relativeSourceUri);
            }

            URIDownloader wrappedDownloader = downloaders.get(source.getScheme());
            return wrappedDownloader.fetch(source);
        }
    };
    for (Map.Entry<String, URIDownloader> entry : downloaders.entrySet()) {
        loadingConfigurationBuilder.addScheme(entry.getKey(), redirectingDownloader);
    }

    JsonNodeReader reader = new JsonNodeReader(objectMapper);
    for (Path schemaFile : schemaFiles) {
        URI schemaFileUri = schemaFile.toAbsolutePath().normalize().toUri();
        URI relativeSchemaUri = baseDirectoryUri.relativize(schemaFileUri);
        URI schemaUri = rootUri.resolve(relativeSchemaUri);

        logger.info("{}: loading from {}", schemaUri, schemaFile);
        JsonNode schemaNode = reader.fromReader(Files.newBufferedReader(schemaFile));
        // FIXME: (upstream?): the preloaded map is accessed via the "real URI", so we need that one here as well
        //        This smells really wrong, after all we want all these to look like they came from rootUri()
        loadingConfigurationBuilder.preloadSchema(schemaFileUri.toASCIIString(), schemaNode);
    }

    return new SchemaLoader(loadingConfigurationBuilder.freeze());
}

From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java

private void executeRemoteRequest(RequestMethod method, URI uri, HttpServletRequest req,
        HttpServletResponse rsp) throws IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("executeRemoteRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString()
                + "]" + " redirected to " + uri.toASCIIString());
    }/*from ww w  . j a v  a  2s.c  o  m*/

    HttpRequestBase request = resolveRequest(method, uri);
    executeRemoteRequest(request, req, rsp);
}

From source file:org.apache.olingo.commons.core.serialization.JsonEntityDeserializer.java

protected ResWrap<Entity> doDeserialize(final JsonParser parser) throws IOException {

    final ObjectNode tree = parser.getCodec().readTree(parser);

    if (tree.has(Constants.VALUE) && tree.get(Constants.VALUE).isArray()) {
        throw new JsonParseException("Expected OData Entity, found EntitySet", parser.getCurrentLocation());
    }//from  w  ww  . j a  v  a 2 s.  c  om

    final EntityImpl entity = new EntityImpl();

    final URI contextURL;
    if (tree.hasNonNull(Constants.JSON_CONTEXT)) {
        contextURL = URI.create(tree.get(Constants.JSON_CONTEXT).textValue());
        tree.remove(Constants.JSON_CONTEXT);
    } else if (tree.hasNonNull(Constants.JSON_METADATA)) {
        contextURL = URI.create(tree.get(Constants.JSON_METADATA).textValue());
        tree.remove(Constants.JSON_METADATA);
    } else {
        contextURL = null;
    }
    if (contextURL != null) {
        entity.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA));
    }

    final String metadataETag;
    if (tree.hasNonNull(Constants.JSON_METADATA_ETAG)) {
        metadataETag = tree.get(Constants.JSON_METADATA_ETAG).textValue();
        tree.remove(Constants.JSON_METADATA_ETAG);
    } else {
        metadataETag = null;
    }

    if (tree.hasNonNull(jsonETag)) {
        entity.setETag(tree.get(jsonETag).textValue());
        tree.remove(jsonETag);
    }

    if (tree.hasNonNull(jsonType)) {
        entity.setType(
                new EdmTypeInfo.Builder().setTypeExpression(tree.get(jsonType).textValue()).build().internal());
        tree.remove(jsonType);
    }

    if (tree.hasNonNull(jsonId)) {
        entity.setId(URI.create(tree.get(jsonId).textValue()));
        tree.remove(jsonId);
    }

    if (tree.hasNonNull(jsonReadLink)) {
        final LinkImpl link = new LinkImpl();
        link.setRel(Constants.SELF_LINK_REL);
        link.setHref(tree.get(jsonReadLink).textValue());
        entity.setSelfLink(link);

        tree.remove(jsonReadLink);
    }

    if (tree.hasNonNull(jsonEditLink)) {
        final LinkImpl link = new LinkImpl();
        if (serverMode) {
            link.setRel(Constants.EDIT_LINK_REL);
        }
        link.setHref(tree.get(jsonEditLink).textValue());
        entity.setEditLink(link);

        tree.remove(jsonEditLink);
    }

    if (tree.hasNonNull(jsonMediaReadLink)) {
        entity.setMediaContentSource(URI.create(tree.get(jsonMediaReadLink).textValue()));
        tree.remove(jsonMediaReadLink);
    }
    if (tree.hasNonNull(jsonMediaEditLink)) {
        entity.setMediaContentSource(URI.create(tree.get(jsonMediaEditLink).textValue()));
        tree.remove(jsonMediaEditLink);
    }
    if (tree.hasNonNull(jsonMediaContentType)) {
        entity.setMediaContentType(tree.get(jsonMediaContentType).textValue());
        tree.remove(jsonMediaContentType);
    }
    if (tree.hasNonNull(jsonMediaETag)) {
        entity.setMediaETag(tree.get(jsonMediaETag).textValue());
        tree.remove(jsonMediaETag);
    }

    final Set<String> toRemove = new HashSet<String>();

    final Map<String, List<Annotation>> annotations = new HashMap<String, List<Annotation>>();
    for (final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); itor.hasNext();) {
        final Map.Entry<String, JsonNode> field = itor.next();
        final Matcher customAnnotation = CUSTOM_ANNOTATION.matcher(field.getKey());

        links(field, entity, toRemove, tree, parser.getCodec());
        if (field.getKey().endsWith(getJSONAnnotation(jsonMediaEditLink))) {
            final LinkImpl link = new LinkImpl();
            link.setTitle(getTitle(field));
            link.setRel(version.getNamespace(ODataServiceVersion.NamespaceKey.MEDIA_EDIT_LINK_REL)
                    + getTitle(field));
            link.setHref(field.getValue().textValue());
            link.setType(ODataLinkType.MEDIA_EDIT.toString());
            entity.getMediaEditLinks().add(link);

            if (tree.has(link.getTitle() + getJSONAnnotation(jsonMediaETag))) {
                link.setMediaETag(tree.get(link.getTitle() + getJSONAnnotation(jsonMediaETag)).asText());
                toRemove.add(link.getTitle() + getJSONAnnotation(jsonMediaETag));
            }

            toRemove.add(field.getKey());
            toRemove.add(setInline(field.getKey(), getJSONAnnotation(jsonMediaEditLink), tree,
                    parser.getCodec(), link));
        } else if (field.getKey().endsWith(getJSONAnnotation(jsonMediaContentType))) {
            final String linkTitle = getTitle(field);
            for (Link link : entity.getMediaEditLinks()) {
                if (linkTitle.equals(link.getTitle())) {
                    ((LinkImpl) link).setType(field.getValue().asText());
                }
            }
            toRemove.add(field.getKey());
        } else if (field.getKey().charAt(0) == '#') {
            final ODataOperation operation = new ODataOperation();
            operation.setMetadataAnchor(field.getKey());

            final ObjectNode opNode = (ObjectNode) tree.get(field.getKey());
            operation.setTitle(opNode.get(Constants.ATTR_TITLE).asText());
            operation.setTarget(URI.create(opNode.get(Constants.ATTR_TARGET).asText()));

            entity.getOperations().add(operation);

            toRemove.add(field.getKey());
        } else if (customAnnotation.matches() && !"odata".equals(customAnnotation.group(2))) {
            final Annotation annotation = new AnnotationImpl();
            annotation.setTerm(customAnnotation.group(2) + "." + customAnnotation.group(3));
            try {
                value(annotation, field.getValue(), parser.getCodec());
            } catch (final EdmPrimitiveTypeException e) {
                throw new IOException(e);
            }

            if (!annotations.containsKey(customAnnotation.group(1))) {
                annotations.put(customAnnotation.group(1), new ArrayList<Annotation>());
            }
            annotations.get(customAnnotation.group(1)).add(annotation);
        }
    }

    for (Link link : entity.getNavigationLinks()) {
        if (annotations.containsKey(link.getTitle())) {
            link.getAnnotations().addAll(annotations.get(link.getTitle()));
            for (Annotation annotation : annotations.get(link.getTitle())) {
                toRemove.add(link.getTitle() + "@" + annotation.getTerm());
            }
        }
    }
    for (Link link : entity.getMediaEditLinks()) {
        if (annotations.containsKey(link.getTitle())) {
            link.getAnnotations().addAll(annotations.get(link.getTitle()));
            for (Annotation annotation : annotations.get(link.getTitle())) {
                toRemove.add(link.getTitle() + "@" + annotation.getTerm());
            }
        }
    }

    tree.remove(toRemove);

    try {
        populate(entity, entity.getProperties(), tree, parser.getCodec());
    } catch (final EdmPrimitiveTypeException e) {
        throw new IOException(e);
    }

    return new ResWrap<Entity>(contextURL, metadataETag, entity);
}