Example usage for java.net URI getSchemeSpecificPart

List of usage examples for java.net URI getSchemeSpecificPart

Introduction

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

Prototype

public String getSchemeSpecificPart() 

Source Link

Document

Returns the decoded scheme-specific part of this URI.

Usage

From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java

@Override
protected Builder buildEntry(Builder builder, Resource resource, boolean insert) {
    Event event = (Event) resource;

    builder = builder.withValue(Events.CALENDAR_ID, id).withValue(entryColumnRemoteName(), event.getName())
            .withValue(entryColumnETag(), event.getETag()).withValue(entryColumnUID(), event.getUid())
            .withValue(Events.ALL_DAY, event.isAllDay() ? 1 : 0)
            .withValue(Events.DTSTART, event.getDtStartInMillis())
            .withValue(Events.EVENT_TIMEZONE, event.getDtStartTzID())
            .withValue(Events.HAS_ATTENDEE_DATA, event.getAttendees().isEmpty() ? 0 : 1)
            .withValue(Events.GUESTS_CAN_INVITE_OTHERS, 1).withValue(Events.GUESTS_CAN_MODIFY, 1)
            .withValue(Events.GUESTS_CAN_SEE_GUESTS, 1);

    boolean recurring = false;
    if (event.getRrule() != null) {
        recurring = true;//from  w w w  .  j  av a 2 s  .  c  o m
        builder = builder.withValue(Events.RRULE, event.getRrule().getValue());
    }
    if (event.getRdate() != null) {
        recurring = true;
        builder = builder.withValue(Events.RDATE, event.getRdate().getValue());
    }
    if (event.getExrule() != null)
        builder = builder.withValue(Events.EXRULE, event.getExrule().getValue());
    if (event.getExdate() != null)
        builder = builder.withValue(Events.EXDATE, event.getExdate().getValue());

    // set either DTEND for single-time events or DURATION for recurring events
    // because that's the way Android likes it (see docs)
    if (recurring) {
        // calculate DURATION from start and end date
        Duration duration = new Duration(event.getDtStart().getDate(), event.getDtEnd().getDate());
        builder = builder.withValue(Events.DURATION, duration.getValue());
    } else {
        builder = builder.withValue(Events.DTEND, event.getDtEndInMillis()).withValue(Events.EVENT_END_TIMEZONE,
                event.getDtEndTzID());
    }

    if (event.getSummary() != null)
        builder = builder.withValue(Events.TITLE, event.getSummary());
    if (event.getLocation() != null)
        builder = builder.withValue(Events.EVENT_LOCATION, event.getLocation());
    if (event.getDescription() != null)
        builder = builder.withValue(Events.DESCRIPTION, event.getDescription());

    if (event.getOrganizer() != null && event.getOrganizer().getCalAddress() != null) {
        URI organizer = event.getOrganizer().getCalAddress();
        if (organizer.getScheme() != null && organizer.getScheme().equalsIgnoreCase("mailto"))
            builder = builder.withValue(Events.ORGANIZER, organizer.getSchemeSpecificPart());
    }

    Status status = event.getStatus();
    if (status != null) {
        int statusCode = Events.STATUS_TENTATIVE;
        if (status == Status.VEVENT_CONFIRMED)
            statusCode = Events.STATUS_CONFIRMED;
        else if (status == Status.VEVENT_CANCELLED)
            statusCode = Events.STATUS_CANCELED;
        builder = builder.withValue(Events.STATUS, statusCode);
    }

    builder = builder.withValue(Events.AVAILABILITY,
            event.isOpaque() ? Events.AVAILABILITY_BUSY : Events.AVAILABILITY_FREE);

    if (event.getForPublic() != null)
        builder = builder.withValue(Events.ACCESS_LEVEL,
                event.getForPublic() ? Events.ACCESS_PUBLIC : Events.ACCESS_PRIVATE);

    return builder;
}

From source file:org.apache.cxf.maven_plugin.AbstractCodegenMoho.java

protected void addPluginArtifact(Set<URI> artifactsPath) {
    // for Maven 2.x, the actual artifact isn't in the list.... need to try and find it
    URL url = getClass().getResource(getClass().getSimpleName() + ".class");

    try {/*from  www  .j av  a2s. co m*/
        if ("jar".equals(url.getProtocol())) {
            String s = url.getPath();
            if (s.contains("!")) {
                s = s.substring(0, s.indexOf('!'));
                url = new URL(s);
            }
        }
        URI uri = new URI(url.getProtocol(), null, url.getPath(), null, null);
        if (uri.getSchemeSpecificPart().endsWith(".class")) {
            String s = uri.toString();
            s = s.substring(0, s.length() - 6 - getClass().getName().length());
            uri = new URI(s);
        }
        File file = new File(uri);
        if (file.exists()) {
            artifactsPath.add(file.toURI());
        }
    } catch (Exception ex) {
        // ex.printStackTrace();
    }

}

From source file:com.almende.eve.transport.pubnub.PubNubTransport.java

@Override
public <T> void send(final URI receiverUri, final String message, final String tag,
        final AsyncCallback<T> callback) throws IOException {

    // Check and deliver local shortcut.
    if (sendLocal(receiverUri, message)) {
        return;/*from   w w  w .  jav a 2  s . co m*/
    }

    final Callback pubnubCB = new Callback() {
        public void successCallback(String channel, Object response) {
            LOG.warning("successfully send:" + message + " to:" + channel + " response:" + response);
        }

        public void errorCallback(String channel, PubnubError error) {
            LOG.warning("PubNub returned an error for:" + message + " to:" + channel + " response:" + error);
            if (callback != null) {
                callback.onFailure(new IOException(error.getErrorString()));
            }
        }
    };
    pubnub.publish(receiverUri.getSchemeSpecificPart(), JSONEnvelop.wrapAsJSONObject(
            getAddress().getSchemeSpecificPart(), receiverUri.getSchemeSpecificPart(), message), pubnubCB);
}

From source file:org.codice.ddf.catalog.content.impl.FileSystemStorageProvider.java

private Path getContentFilePath(URI uri) throws StorageException {
    Path contentIdDir = getContentItemDir(uri);
    List<Path> contentFiles;
    if (Files.exists(contentIdDir)) {
        try {/*from   w  w w. j a  v  a2  s.co m*/
            contentFiles = listPaths(contentIdDir);
        } catch (IOException e) {
            throw new StorageException(e);
        }

        contentFiles.removeIf(Files::isDirectory);

        if (contentFiles.size() != 1) {
            throw new StorageException(
                    "Content ID: " + uri.getSchemeSpecificPart() + " storage folder is corrupted.");
        }

        //there should only be one file
        return contentFiles.get(0);
    }
    return null;
}

From source file:org.jbpm.bpel.tools.WsdlServiceTool.java

protected String generateSoapAction(Operation operation, Definition bindingDefinition) {
    try {/*from  w  ww .j ava 2 s .c om*/
        // target namespace
        URI targetNamespaceURI = new URI(bindingDefinition.getTargetNamespace());

        // set the operation name as the fragment of the target namespace URI
        URI soapActionURI = new URI(targetNamespaceURI.getScheme(), targetNamespaceURI.getSchemeSpecificPart(),
                operation.getName());
        return soapActionURI.toString();
    } catch (URISyntaxException e) {
        // target namespace is not a valid URI - generate an empty action
        return "";
    }
}

From source file:jasdl.bridge.JASDLOntologyManager.java

/**
 * Gets the alias corresponding to a URI. URI corresponds to a known entity, its alias is returned.
 * Otherwise, the label is taken from (scheme concat scheme specific part) and the functor from the fragment (minus the #).
 * Additionally, applied default mapping strategies to URI fragment to prevent invalid functors being generated.
 * /*  w w w .j a  v  a2 s .com*/
 * Note: Ontology referenced by URI must be a known ontology!
 * @param uri
 * @return
 */
public Alias toAlias(URI uri, List<MappingStrategy> strategies) throws JASDLUnknownMappingException {
    try {
        OWLEntity entity = toEntity(uri);
        return getAliasManager().getLeft(entity);
    } catch (JASDLUnknownMappingException e) {
        // unknown uri, create a new alias
        OWLOntology ontology = getLogicalURIManager()
                .getLeft(URI.create(uri.getScheme() + ":" + uri.getSchemeSpecificPart()));
        Atom label = getLabelManager().getLeft(ontology);
        String _functor = uri.getFragment();

        // apply mapping strategies to fragment of URI to generate a valid functor
        for (MappingStrategy strategy : strategies) {
            _functor = strategy.apply(_functor);
        }
        return AliasFactory.INSTANCE.create(new Atom(_functor), label);

    }
}

From source file:org.sakaiproject.blti.ProviderServlet.java

protected void validate(Map payload, boolean isTrustedConsumer) throws LTIException {

    //check parameters
    String lti_message_type = (String) payload.get(BasicLTIConstants.LTI_MESSAGE_TYPE);
    String lti_version = (String) payload.get(BasicLTIConstants.LTI_VERSION);
    String oauth_consumer_key = (String) payload.get("oauth_consumer_key");
    String resource_link_id = (String) payload.get(BasicLTIConstants.RESOURCE_LINK_ID);
    String user_id = (String) payload.get(BasicLTIConstants.USER_ID);
    String context_id = (String) payload.get(BasicLTIConstants.CONTEXT_ID);

    if (!BasicLTIUtil.equals(lti_message_type, "basic-lti-launch-request")) {
        throw new LTIException("launch.invalid", "lti_message_type=" + lti_message_type, null);
    }/*from  ww  w  . j av  a2  s  .c o m*/

    if (!BasicLTIUtil.equals(lti_version, "LTI-1p0")) {
        throw new LTIException("launch.invalid", "lti_version=" + lti_version, null);

    }

    if (BasicLTIUtil.isBlank(oauth_consumer_key)) {
        throw new LTIException("launch.missing", "oauth_consumer_key", null);

    }

    if (BasicLTIUtil.isBlank(resource_link_id)) {
        throw new LTIException("launch.missing", "resource_link_id", null);

    }

    if (BasicLTIUtil.isBlank(user_id)) {
        throw new LTIException("launch.missing", "user_id", null);

    }
    if (M_log.isDebugEnabled()) {
        M_log.debug("user_id=" + user_id);
    }

    //check tool_id
    String tool_id = (String) payload.get("tool_id");
    if (tool_id == null) {
        throw new LTIException("launch.tool_id.required", null, null);
    }

    // Trim off the leading slash and any trailing space
    tool_id = tool_id.substring(1).trim();
    if (M_log.isDebugEnabled()) {
        M_log.debug("tool_id=" + tool_id);
    }
    // store modified tool_id back in payload
    payload.put("tool_id", tool_id);
    final String allowedToolsConfig = ServerConfigurationService.getString("basiclti.provider.allowedtools",
            "");

    final String[] allowedTools = allowedToolsConfig.split(":");
    final List<String> allowedToolsList = Arrays.asList(allowedTools);

    if (allowedTools != null && !allowedToolsList.contains(tool_id)) {
        throw new LTIException("launch.tool.notallowed", tool_id, null);
    }
    final Tool toolCheck = ToolManager.getTool(tool_id);
    if (toolCheck == null) {
        throw new LTIException("launch.tool.notfound", tool_id, null);
    }

    // Check for the ext_sakai_provider_eid param. If set, this will contain the eid that we are to use
    // in place of using the user_id parameter
    // WE still need that parameter though, so translate it from the given eid.
    boolean useProvidedEid = false;
    String ext_sakai_provider_eid = (String) payload.get(BasicLTIConstants.EXT_SAKAI_PROVIDER_EID);
    if (BasicLTIUtil.isNotBlank(ext_sakai_provider_eid)) {
        useProvidedEid = true;
        try {
            user_id = UserDirectoryService.getUserId(ext_sakai_provider_eid);
        } catch (Exception e) {
            M_log.error(e.getLocalizedMessage(), e);
            throw new LTIException("launch.provided.eid.invalid",
                    "ext_sakai_provider_eid=" + ext_sakai_provider_eid, e);
        }
    }

    if (M_log.isDebugEnabled()) {
        M_log.debug("ext_sakai_provider_eid=" + ext_sakai_provider_eid);
    }

    // Contextualize the context_id with the OAuth consumer key
    // Also use the resource_link_id for the context_id if we did not get a context_id
    // BLTI-31: if trusted, context_id is required and use the param without modification
    if (BasicLTIUtil.isBlank(context_id)) {
        if (isTrustedConsumer) {
            throw new LTIException("launch.missing", context_id, null);
        } else {
            context_id = "res:" + resource_link_id;
            payload.put(BasicLTIConstants.CONTEXT_ID, context_id);
        }
    }

    // Check if context_id is simply a ~. If so, get the id of that user's My Workspace site
    // and use that to construct the full context_id
    if (BasicLTIUtil.equals(context_id, "~")) {
        if (useProvidedEid) {
            String userSiteId = null;
            try {
                userSiteId = SiteService.getUserSiteId(user_id);
            } catch (Exception e) {
                M_log.warn("Failed to get My Workspace site for user_id:" + user_id);
                M_log.error(e.getLocalizedMessage(), e);
                throw new LTIException("launch.user.site.unknown", "user_id=" + user_id, e);
            }
            context_id = userSiteId;
            payload.put(BasicLTIConstants.CONTEXT_ID, context_id);
        }
    }

    if (M_log.isDebugEnabled()) {
        M_log.debug("context_id=" + context_id);
    }

    // Lookup the secret
    final String configPrefix = "basiclti.provider." + oauth_consumer_key + ".";
    final String oauth_secret = ServerConfigurationService.getString(configPrefix + "secret", null);
    if (oauth_secret == null) {
        throw new LTIException("launch.key.notfound", oauth_consumer_key, null);
    }
    final OAuthMessage oam = (OAuthMessage) payload.get("oauth_message");

    final String forcedURIScheme = ServerConfigurationService.getString("basiclti.provider.forcedurischeme",
            null);

    if (forcedURIScheme != null) {
        try {
            URI testURI = new URI(oam.URL);
            URI newURI = new URI(forcedURIScheme, testURI.getSchemeSpecificPart(), null);
            oam.URL = newURI.toString();
        } catch (URISyntaxException use) {
        }
    }
    final OAuthValidator oav = new SimpleOAuthValidator();
    final OAuthConsumer cons = new OAuthConsumer("about:blank#OAuth+CallBack+NotUsed", oauth_consumer_key,
            oauth_secret, null);

    final OAuthAccessor acc = new OAuthAccessor(cons);

    String base_string = null;
    try {
        base_string = OAuthSignatureMethod.getBaseString(oam);
    } catch (Exception e) {
        M_log.error(e.getLocalizedMessage(), e);
        base_string = null;
    }

    try {
        oav.validateMessage(oam, acc);
    } catch (Exception e) {
        M_log.warn("Provider failed to validate message");
        M_log.warn(e.getLocalizedMessage(), e);
        if (base_string != null) {
            M_log.warn(base_string);
        }
        throw new LTIException("launch.no.validate", context_id, e);
    }

    final Session sess = SessionManager.getCurrentSession();

    if (sess == null) {
        throw new LTIException("launch.no.session", context_id, null);
    }

}

From source file:org.sonatype.flexmojos.htmlwrapper.HtmlWrapperMojo.java

private void extractTemplate() throws MojoExecutionException {
    getLog().info("Extracting template");
    templateOutputDirectory.mkdirs();//from   w w  w .  j av a  2 s. c  om

    URI uri;
    try {
        if (MavenUtils.isWindows()) {
            // Shake bars to avoid URI syntax problems
            templateURI = templateURI.replace('\\', '/');
        }
        templateURI = URIUtil.encodePath(templateURI);
        uri = new URI(templateURI);
    } catch (Exception e) {
        throw new MojoExecutionException("Invalid template URI.", e);
    }

    String scheme = uri.getScheme();
    if ("embed".equals(scheme)) {
        copyEmbedTemplate(uri.getSchemeSpecificPart());
    } else if ("zip".equals(scheme)) {
        copyZipTemplate(uri.getSchemeSpecificPart());
    } else if ("folder".equals(scheme)) {
        copyFolderTemplate(uri.getSchemeSpecificPart());
    } else {
        throw new MojoExecutionException("Invalid URI scheme: " + scheme);
    }

}

From source file:com.bluexml.xforms.actions.AbstractAction.java

/**
 * Gets the request parameters. This function builds a map of parameters for the action.
 * Parameters are those declared in {@link #getParamNames()}.
 * <p/>//from   w ww. j a v  a2s. c o  m
 * NOTE: <b>DO NOT</b> use transaction here. Otherwise, it would be null and cause an exception.
 * (Amenel)
 * 
 * @param fragments
 *            the fragments
 * @param realUri
 * 
 * @return the request parameters
 */
private void getRequestParameters(String[] fragments, URI realUri) {
    requestParameters = new TreeMap<String, String>();

    String sessionIdPageId = fragments[2];
    String[] sessionFragments = sessionIdPageId.split(";");
    sessionId = sessionFragments[0];

    session = NavigationSessionListener.getSession(sessionId);
    if (session != null) {
        Object receiptAsObject = session.getAttribute(CASFilter.CAS_FILTER_RECEIPT);
        if (receiptAsObject != null) {
            CASReceipt receipt = (CASReceipt) receiptAsObject;
            transactionLogin = receipt.getUserName();
        }
    }
    pageId = sessionFragments[1];

    navigationPath = NavigationSessionListener.getNavigationPath(sessionId, pageId);

    String[] paramNames = getParamNames();

    String schemePart = realUri.getSchemeSpecificPart();
    for (String paramName : paramNames) {
        String paramValue = extractParamValue(paramName, schemePart);
        requestParameters.put(paramName, paramValue);
    }
}

From source file:com.bluexml.xforms.controller.navigation.NavigationManager.java

/**
 * Inits the action./*  www  . j av a  2  s  . co  m*/
 * 
 * @param uri
 *            the uri
 * @return the abstract action
 * @throws Exception
 *             the exception
 */
private AbstractAction initAction(String uri) throws Exception {
    URI realUri = new URI(uri);
    String[] fragments = realUri.getSchemeSpecificPart().split("/");

    String actionAndParams = fragments[3];
    int pos = actionAndParams.indexOf('?');
    if (pos == -1) {
        pos = actionAndParams.length();
    }
    String actionName = actionAndParams.substring(0, pos);

    AbstractAction action = actions.get(actionName).newInstance();
    return action;
}