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.kalypso.service.wps.client.NonBlockingWPSRequest.java

private IOValueType getInputValue(final Object inputValue, final String inputId, final String title,
        final String abstrakt) throws CoreException {
    final Object valueType;
    final String format;
    final String encoding;
    final String schema;
    final Object valueString;
    /* Build the complex value reference. */
    if (inputValue instanceof URI) {
        // this way we can probably not check the format, encoding and schema of the input
        final URI uri = (URI) inputValue;
        format = null;/* w w  w.  java  2 s  .c o  m*/
        encoding = null;
        schema = null;
        valueType = WPS040ObjectFactoryUtilities.buildComplexValueReference(uri.toASCIIString(), format,
                encoding, schema);
    }
    /* Build the complex value. */
    else {
        // TODO: support other complex types, e.g. regular XML, geometries, ...
        if (inputValue instanceof GMLWorkspace) {
            final GMLWorkspace gmlWorkspace = (GMLWorkspace) inputValue;
            final IGMLSchema gmlSchema = gmlWorkspace.getGMLSchema();
            final String schemaLocationString = gmlSchema.getContext().toString();

            format = WPSSimulationDataProvider.TYPE_GML;
            encoding = "UTF-8"; //$NON-NLS-1$

            // TODO: copy the schema to a place where the server can find it
            // REMARK: makes no sense to give platform: or bundleresource: urls; they do not exist on theother side
            if (schemaLocationString != null && !schemaLocationString.startsWith("bundleresource:") //$NON-NLS-1$
                    && !schemaLocationString.startsWith("platform:")) //$NON-NLS-1$
                schema = schemaLocationString;
            else
                schema = null;

            // enforce the schemaLocation
            // TODO: copy the schema to a place where the server can find it
            gmlWorkspace.setSchemaLocation(schemaLocationString);
            valueString = getGML(gmlWorkspace);
        } else {
            // do not know, maybe it can be marshalled by the binding framework?
            // TODO: this will probably throw an exception later, maybe throw it now?
            format = null;
            encoding = null;
            schema = null;
            valueString = inputValue;
        }

        // REMARK: hack/convention: the input must now be the raw input for the anyType element
        final List<Object> value = new ArrayList<>(1);
        value.add(valueString);
        valueType = WPS040ObjectFactoryUtilities.buildComplexValueType(format, encoding, schema, value);
    }

    final CodeType code = WPS040ObjectFactoryUtilities.buildCodeType(null, inputId);
    final IOValueType ioValue = WPS040ObjectFactoryUtilities.buildIOValueType(code, title, abstrakt, valueType);
    return ioValue;
}

From source file:com.msopentech.odatajclient.proxy.api.impl.BatchContainer.java

private int processEntityContext(final EntityTypeInvocationHandler handler, int pos,
        final TransactionItems items, final List<EntityLinkDesc> delayedUpdates,
        final ODataChangeset changeset) {

    LOG.debug("Process '{}'", handler);

    items.put(handler, null);//from  w ww . j  a v  a  2  s. c om

    //TODO: this change hasn't been tested as Exchange server doesn't support Batch requests.
    //final ODataEntity entity = (ODataEntity) xstream.fromXML(xstream.toXML(handler.getEntity()));
    final ODataEntity entity = handler.getEntity();

    entity.getNavigationLinks().clear();

    final AttachedEntityStatus currentStatus = EntityContainerFactory.getContext().entityContext()
            .getStatus(handler);

    if (AttachedEntityStatus.DELETED != currentStatus) {
        entity.getProperties().clear();
        EngineUtils.addProperties(client, factory.getMetadata(), handler.getPropertyChanges(), entity);
    }

    for (Map.Entry<NavigationProperty, Object> property : handler.getLinkChanges().entrySet()) {
        final ODataLinkType type = Collection.class.isAssignableFrom(property.getValue().getClass())
                ? ODataLinkType.ENTITY_SET_NAVIGATION
                : ODataLinkType.ENTITY_NAVIGATION;

        final Set<EntityTypeInvocationHandler> toBeLinked = new HashSet<EntityTypeInvocationHandler>();
        final String serviceRoot = factory.getServiceRoot();

        for (Object proxy : type == ODataLinkType.ENTITY_SET_NAVIGATION ? (Collection) property.getValue()
                : Collections.singleton(property.getValue())) {

            final EntityTypeInvocationHandler target = (EntityTypeInvocationHandler) Proxy
                    .getInvocationHandler(proxy);

            final AttachedEntityStatus status;

            try {
                status = EntityContainerFactory.getContext().entityContext().getStatus(target);
            } catch (IllegalStateException e) {
                // this case takes place if we iterate through collection and current item does not have any changes
                // TODO find another way to look for changes in collection
                continue;
            }

            final URI editLink = target.getEntity().getEditLink();

            if ((status == AttachedEntityStatus.ATTACHED || status == AttachedEntityStatus.LINKED)
                    && !target.isChanged()) {
                entity.addLink(buildNavigationLink(property.getKey().name(),
                        URIUtils.getURI(serviceRoot, editLink.toASCIIString()), type));
            } else {
                if (!items.contains(target)) {
                    pos = processEntityContext(target, pos, items, delayedUpdates, changeset);
                    pos++;
                }

                final Integer targetPos = items.get(target);
                if (targetPos == null) {
                    // schedule update for the current object
                    LOG.debug("Schedule '{}' from '{}' to '{}'", type.name(), handler, target);
                    toBeLinked.add(target);
                } else if (status == AttachedEntityStatus.CHANGED) {
                    entity.addLink(buildNavigationLink(property.getKey().name(),
                            URIUtils.getURI(serviceRoot, editLink.toASCIIString()), type));
                } else {
                    // create the link for the current object
                    LOG.debug("'{}' from '{}' to (${}) '{}'", type.name(), handler, targetPos, target);

                    entity.addLink(
                            buildNavigationLink(property.getKey().name(), URI.create("$" + targetPos), type));
                }
            }
        }

        if (!toBeLinked.isEmpty()) {
            delayedUpdates.add(new EntityLinkDesc(property.getKey().name(), handler, toBeLinked, type));
        }
    }

    // insert into the batch
    LOG.debug("{}: Insert '{}' into the batch", pos, handler);
    batch(handler, entity, changeset);

    items.put(handler, pos);

    int startingPos = pos;

    if (handler.getEntity().isMediaEntity()) {

        // update media properties
        if (!handler.getPropertyChanges().isEmpty()) {
            final URI targetURI = currentStatus == AttachedEntityStatus.NEW ? URI.create("$" + startingPos)
                    : URIUtils.getURI(factory.getServiceRoot(),
                            handler.getEntity().getEditLink().toASCIIString());
            batchUpdate(handler, targetURI, entity, changeset);
            pos++;
            items.put(handler, pos);
        }

        // update media content
        if (handler.getStreamChanges() != null) {
            final URI targetURI = currentStatus == AttachedEntityStatus.NEW
                    ? URI.create("$" + startingPos + "/$value")
                    : URIUtils.getURI(factory.getServiceRoot(),
                            handler.getEntity().getEditLink().toASCIIString() + "/$value");

            batchUpdateMediaEntity(handler, targetURI, handler.getStreamChanges(), changeset);

            // update media info (use null key)
            pos++;
            items.put(null, pos);
        }
    }

    for (Map.Entry<String, InputStream> streamedChanges : handler.getStreamedPropertyChanges().entrySet()) {
        final URI targetURI = currentStatus == AttachedEntityStatus.NEW ? URI.create("$" + startingPos)
                : URIUtils.getURI(factory.getServiceRoot(),
                        EngineUtils.getEditMediaLink(streamedChanges.getKey(), entity).toASCIIString());

        batchUpdateMediaResource(handler, targetURI, streamedChanges.getValue(), changeset);

        // update media info (use null key)
        pos++;
        items.put(handler, pos);
    }

    return pos;
}

From source file:org.rssowl.core.util.URIUtils.java

/**
 * Try to get the File Name of the given URI.
 *
 * @param uri The URI to parse the File from.
 * @param extension the file extension or <code>null</code> if unknown.
 * @return String The File Name or the URI in external Form.
 *///from   w ww .ja v a 2 s  .  c o  m
public static String getFile(URI uri, String extension) {

    /* Fallback if Extension not set */
    if (!StringUtils.isSet(extension))
        return getFile(uri);

    /* Prefix Extension if necessary */
    if (!extension.startsWith(".")) //$NON-NLS-1$
        extension = "." + extension; //$NON-NLS-1$

    /* Obtain Filename Candidates from Query and Path */
    String fileQuerySegment = getFileSegmentFromQuery(uri.getQuery(), extension);
    String lastPathSegment = getLastSegmentFromPath(uri.getPath());

    /* Favour Query over Path if Extension part of it */
    if (StringUtils.isSet(fileQuerySegment) && fileQuerySegment.contains(extension))
        return urlDecode(fileQuerySegment);

    /* Use Path if Extension part of it */
    if (StringUtils.isSet(lastPathSegment) && lastPathSegment.contains(extension))
        return urlDecode(lastPathSegment);

    /* Favour Path over Query otherwise */
    if (StringUtils.isSet(lastPathSegment))
        return urlDecode(lastPathSegment);

    /* Use Query as Fallback */
    if (StringUtils.isSet(fileQuerySegment))
        return urlDecode(fileQuerySegment);

    return uri.toASCIIString();
}

From source file:org.apache.fop.render.pdf.pdfbox.PSPDFGraphics2D.java

@Override
public boolean drawImage(Image img, int x1, int y1, ImageObserver observer) {
    PSGenerator tmp = gen;/*from   ww w. j a  va 2  s  .c  o  m*/
    if (gen instanceof PSDocumentHandler.FOPPSGenerator) {
        PSDocumentHandler.FOPPSGenerator fopGen = (PSDocumentHandler.FOPPSGenerator) tmp;
        PSDocumentHandler handler = fopGen.getHandler();
        if (handler.getPSUtil().isOptimizeResources()) {
            try {
                final int width = img.getWidth(observer);
                final int height = img.getHeight(observer);
                if (width == -1 || height == -1) {
                    return false;
                }
                BufferedImage buf = getImage(width, height, img, observer);
                if (buf == null) {
                    return false;
                }
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                DataBufferInt db = (DataBufferInt) buf.getRaster().getDataBuffer();
                DataOutputStream dos = new DataOutputStream(bos);
                dos.writeInt(width);
                dos.writeInt(height);
                for (int i : db.getData()) {
                    dos.writeInt(i);
                }
                String format = DataBufferInt.class.getName();
                int hash = Arrays.hashCode(bos.toByteArray());
                URI uri = fopGen.getImages().get(hash);
                if (uri == null) {
                    uri = new TempResourceURIGenerator("img" + hash + "." + format).generate();
                    fopGen.getImages().put(hash, uri);
                    BufferedOutputStream outputStream = fopGen.getTempStream(uri);
                    outputStream.write(bos.toByteArray());
                    outputStream.close();
                }
                PSResource form = handler.getFormForImage(uri.toASCIIString());
                ImageInfo info = new ImageInfo(uri.toASCIIString(), "image/" + format);
                ImageSize size = new ImageSize(width, height, handler.getUserAgent().getTargetResolution());
                size.calcSizeFromPixels();
                info.setSize(size);
                float res = handler.getUserAgent().getSourceResolution() / 72;
                Rectangle rect = new Rectangle(0, 0, (int) (size.getWidthMpt() * res),
                        (int) (size.getHeightMpt() * res));
                gen.saveGraphicsState();
                gen.concatMatrix(getTransform());
                writeClip(getClip());
                PSImageUtils.drawForm(form, info, rect, gen);
                gen.restoreGraphicsState();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return true;
        }
    }
    return super.drawImage(img, x1, y1, observer);
}

From source file:com.semagia.cassa.client.GraphClient.java

private URI getGraphURI(final URI graphURI) {
    if (graphURI == _DEFAULT_GRAPH) {
        return _endpoint.resolve("?default");
    }//w ww . ja v  a  2 s.com
    if (!_endpoint.relativize(graphURI).isAbsolute()) {
        // local graph
        return graphURI;
    }
    return _endpoint.resolve("?graph=" + graphURI.toASCIIString());
}

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

public void getFileInfoList(URI parentDirectory, Map<String, FileInfo> indexFileMap)
        throws SearchLibException, UnsupportedEncodingException, URISyntaxException {
    AbstractSearchRequest searchRequest = (AbstractSearchRequest) dbClient
            .getNewRequest(SearchTemplate.fileInfo.name());
    StringBuilder sb = new StringBuilder();
    String parentUriString = parentDirectory.toASCIIString();
    FileItemFieldEnum.INSTANCE.directory.addQuery(sb, parentUriString, true);
    searchRequest.setQueryString(sb.toString());
    searchRequest.setStart(0);/*from w w w  . j a  v  a  2 s.c om*/
    searchRequest.setRows(Integer.MAX_VALUE);
    AbstractResultSearch result = (AbstractResultSearch) dbClient.request(searchRequest);
    int l = result.getNumFound();
    for (int i = 0; i < l; i++) {
        FileInfo fileInfo = new FileInfo(result.getDocument(i));
        indexFileMap.put(fileInfo.getUri(), fileInfo);
    }
}

From source file:org.kalypso.service.wps.refactoring.DefaultWPSProcess.java

private IOValueType getInputValue(final Object inputValue, final String inputId, final String title,
        final String abstrakt) throws CoreException {
    final Object valueType;
    final String format;
    final String encoding;
    final String schema;
    final Object valueString;
    /* Build the complex value reference. */
    if (inputValue instanceof URI) {
        // this way we can probably not check the format, encoding and schema of the input
        final URI uri = (URI) inputValue;
        format = null;/*  www  .j  av  a2 s .  c  o m*/
        encoding = null;
        schema = null;
        valueType = WPS040ObjectFactoryUtilities.buildComplexValueReference(uri.toASCIIString(), format,
                encoding, schema);
    }
    /* Build the complex value. */
    else {
        // TODO: support other complex types, e.g. regular XML, geometries, ...
        if (inputValue instanceof GMLWorkspace) {
            final GMLWorkspace gmlWorkspace = (GMLWorkspace) inputValue;
            final IGMLSchema gmlSchema = gmlWorkspace.getGMLSchema();
            final String schemaLocationString = gmlSchema.getContext().toString();

            format = WPSSimulationDataProvider.TYPE_GML;
            encoding = "UTF-8"; //$NON-NLS-1$
            schema = schemaLocationString;

            // enforce the schemaLocation
            // TODO: copy the schema to a place where the server can find it
            gmlWorkspace.setSchemaLocation(schemaLocationString);
            valueString = getGML(gmlWorkspace);
        } else {
            // do not know, maybe it can be marshalled by the binding framework?
            // TODO: this will probably throw an exception later, maybe throw it now?
            format = null;
            encoding = null;
            schema = null;
            valueString = inputValue;
        }

        // REMARK: hack/convention: the input must now be the raw input for the anyType element
        final List<Object> value = new ArrayList<>(1);
        value.add(valueString);
        valueType = WPS040ObjectFactoryUtilities.buildComplexValueType(format, encoding, schema, value);
    }

    final CodeType code = WPS040ObjectFactoryUtilities.buildCodeType(null, inputId);
    final IOValueType ioValue = WPS040ObjectFactoryUtilities.buildIOValueType(code, title, abstrakt, valueType);
    return ioValue;
}

From source file:cn.com.loopj.android.http.AsyncHttpClient.java

/**
 * Will encode url, if not disabled, and adds params on the end of it
 *
 * @param url             String with URL, should be valid URL without params
 * @param params          RequestParams to be appended on the end of URL
 * @param shouldEncodeUrl whether url should be encoded (replaces spaces with %20)
 * @return encoded url if requested with params appended if any available
 */// www . j  a  va 2 s  . c  o  m
public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url, RequestParams params) {
    if (url == null)
        return null;

    if (shouldEncodeUrl) {
        try {
            String decodedURL = URLDecoder.decode(url, "UTF-8");
            URL _url = new URL(decodedURL);
            URI _uri = new URI(_url.getProtocol(), _url.getUserInfo(), _url.getHost(), _url.getPort(),
                    _url.getPath(), _url.getQuery(), _url.getRef());
            url = _uri.toASCIIString();
        } catch (Exception ex) {
            // Should not really happen, added just for sake of validity
            log.e(LOG_TAG, "getUrlWithQueryString encoding URL", ex);
        }
    }

    if (params != null) {
        // Construct the query string and trim it, in case it
        // includes any excessive white spaces.
        String paramString = params.getParamString().trim();

        // Only add the query string if it isn't empty and it
        // isn't equal to '?'.
        if (!paramString.equals("") && !paramString.equals("?")) {
            url += url.contains("?") ? "&" : "?";
            url += paramString;
        }
    }

    return url;
}

From source file:fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor.java

public String encodeURI(URI u) {
    return StringEscapeUtils.escapeXml10(u.toASCIIString());
}