Example usage for java.net URI isAbsolute

List of usage examples for java.net URI isAbsolute

Introduction

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

Prototype

public boolean isAbsolute() 

Source Link

Document

Tells whether or not this URI is absolute.

Usage

From source file:org.kitodo.services.data.LdapServerService.java

/**
 * Retrieve home directory of given user.
 *
 * @param user//from  ww  w .  j  a  va2 s .  c  om
 *            User object
 * @return path as URI
 */
public URI getUserHomeDirectory(User user) {

    URI userFolderBasePath = URI.create("file:///" + ConfigCore.getParameter(Parameters.DIR_USERS));

    if (ConfigCore.getBooleanParameter(Parameters.LDAP_USE_LOCAL_DIRECTORY)) {
        return userFolderBasePath.resolve(user.getLogin());
    }
    Hashtable<String, String> env = initializeWithLdapConnectionSettings(user.getLdapGroup().getLdapServer());
    if (ConfigCore.getBooleanParameter(Parameters.LDAP_USE_TLS)) {

        env.put("java.naming.ldap.version", "3");
        LdapContext ctx = null;
        StartTlsResponse tls = null;
        try {
            ctx = new InitialLdapContext(env, null);

            // Authentication must be performed over a secure channel
            tls = (StartTlsResponse) ctx.extendedOperation(new StartTlsRequest());
            tls.negotiate();

            ctx.reconnect(null);

            Attributes attrs = ctx.getAttributes(buildUserDN(user));
            Attribute la = attrs.get("homeDirectory");
            return URI.create((String) la.get(0));

            // Perform search for privileged attributes under authenticated
            // context

        } catch (IOException e) {
            logger.error("TLS negotiation error:", e);

            return userFolderBasePath.resolve(user.getLogin());
        } catch (NamingException e) {

            logger.error("JNDI error:", e);

            return userFolderBasePath.resolve(user.getLogin());
        } finally {
            if (tls != null) {
                try {
                    // Tear down TLS connection
                    tls.close();
                } catch (IOException e) {
                    logger.error(e.getMessage(), e);
                }
            }
            if (ctx != null) {
                try {
                    // Close LDAP connection
                    ctx.close();
                } catch (NamingException e) {
                    logger.error(e.getMessage(), e);
                }
            }
        }
    }
    if (ConfigCore.getBooleanParameter("useSimpleAuthentification", false)) {
        env.put(Context.SECURITY_AUTHENTICATION, "none");
    }
    DirContext ctx;
    URI userFolderPath = null;
    try {
        ctx = new InitialDirContext(env);
        Attributes attrs = ctx.getAttributes(buildUserDN(user));
        Attribute ldapAttribute = attrs.get("homeDirectory");
        userFolderPath = URI.create((String) ldapAttribute.get(0));
        ctx.close();
    } catch (NamingException e) {
        logger.error(e.getMessage(), e);
    }

    if (userFolderPath != null && !userFolderPath.isAbsolute()) {
        if (userFolderPath.getPath().startsWith("/")) {
            userFolderPath = serviceManager.getFileService().deleteFirstSlashFromPath(userFolderPath);
        }
        return userFolderBasePath.resolve(userFolderPath);
    } else {
        return userFolderPath;
    }
}

From source file:org.structr.schema.export.StructrTypeDefinition.java

protected SchemaNode resolveSchemaNode(final App app, final URI uri) throws FrameworkException {

    // find schema nodes for the given source and target nodes
    final Object source = root.resolveURI(uri);
    if (source != null && source instanceof StructrTypeDefinition) {

        return (SchemaNode) ((StructrTypeDefinition) source).getSchemaNode();

    } else {/*from w w w . j  a  v a  2s  .  com*/

        if (uri.isAbsolute()) {

            final Class type = StructrApp.resolveSchemaId(uri);
            if (type != null) {

                return app.nodeQuery(SchemaNode.class).andName(type.getSimpleName()).getFirst();
            }
        }
    }

    return null;
}

From source file:org.apache.streams.plugins.cassandra.StreamsCassandraResourceGenerator.java

private StringBuilder appendPropertiesNode(StringBuilder builder, Schema schema, ObjectNode propertiesNode,
        Character seperator) {//from   w w  w.  j  av a  2 s  . co  m
    Objects.requireNonNull(builder);
    Objects.requireNonNull(propertiesNode);
    Iterator<Map.Entry<String, JsonNode>> fields = propertiesNode.fields();
    List<String> fieldStrings = new ArrayList<>();
    for (; fields.hasNext();) {
        Map.Entry<String, JsonNode> field = fields.next();
        String fieldId = field.getKey();
        if (!config.getExclusions().contains(fieldId) && field.getValue().isObject()) {
            ObjectNode fieldNode = (ObjectNode) field.getValue();
            FieldType fieldType = FieldUtil.determineFieldType(fieldNode);
            if (fieldType != null) {
                switch (fieldType) {
                case ARRAY:
                    ObjectNode itemsNode = (ObjectNode) fieldNode.get("items");
                    if (currentDepth <= config.getMaxDepth()) {
                        StringBuilder arrayItemsBuilder = appendArrayItems(new StringBuilder(), schema, fieldId,
                                itemsNode, seperator);
                        if (StringUtils.isNotBlank(arrayItemsBuilder.toString())) {
                            fieldStrings.add(arrayItemsBuilder.toString());
                        }
                    }
                    break;
                case OBJECT:
                    Schema objectSchema = null;
                    URI parentUri = null;
                    if (fieldNode.has("$ref") || fieldNode.has("extends")) {
                        JsonNode refNode = fieldNode.get("$ref");
                        JsonNode extendsNode = fieldNode.get("extends");
                        if (refNode != null && refNode.isValueNode()) {
                            parentUri = URI.create(refNode.asText());
                        } else if (extendsNode != null && extendsNode.isObject()) {
                            parentUri = URI.create(extendsNode.get("$ref").asText());
                        }
                        URI absoluteUri;
                        if (parentUri.isAbsolute()) {
                            absoluteUri = parentUri;
                        } else {
                            absoluteUri = schema.getUri().resolve(parentUri);
                            if (!absoluteUri.isAbsolute() || (absoluteUri.isAbsolute()
                                    && !schemaStore.getByUri(absoluteUri).isPresent())) {
                                absoluteUri = schema.getParentUri().resolve(parentUri);
                            }
                        }
                        if (absoluteUri != null && absoluteUri.isAbsolute()) {
                            Optional<Schema> schemaLookup = schemaStore.getByUri(absoluteUri);
                            if (schemaLookup.isPresent()) {
                                objectSchema = schemaLookup.get();
                            }
                        }
                    }
                    //ObjectNode childProperties = schemaStore.resolveProperties(schema, fieldNode, fieldId);
                    if (currentDepth < config.getMaxDepth()) {
                        StringBuilder structFieldBuilder = appendSchemaField(new StringBuilder(), objectSchema,
                                fieldId, seperator);
                        if (StringUtils.isNotBlank(structFieldBuilder.toString())) {
                            fieldStrings.add(structFieldBuilder.toString());
                        }
                    }
                    break;
                default:
                    StringBuilder valueFieldBuilder = appendValueField(new StringBuilder(), schema, fieldId,
                            fieldType, seperator);
                    if (StringUtils.isNotBlank(valueFieldBuilder.toString())) {
                        fieldStrings.add(valueFieldBuilder.toString());
                    }
                }
            }
        }
    }
    builder.append(String.join("," + LS, fieldStrings)).append(LS);
    Objects.requireNonNull(builder);
    return builder;
}

From source file:org.apache.streams.plugins.elasticsearch.StreamsElasticsearchResourceGenerator.java

private StringBuilder appendPropertiesNode(StringBuilder builder, Schema schema, ObjectNode propertiesNode,
        Character seperator) {//from   w ww .j a va2  s.c o  m
    Objects.requireNonNull(builder);
    Objects.requireNonNull(propertiesNode);
    Iterator<Map.Entry<String, JsonNode>> fields = propertiesNode.fields();
    List<String> fieldStrings = new ArrayList<>();
    for (; fields.hasNext();) {
        Map.Entry<String, JsonNode> field = fields.next();
        String fieldId = field.getKey();
        if (!config.getExclusions().contains(fieldId) && field.getValue().isObject()) {
            ObjectNode fieldNode = (ObjectNode) field.getValue();
            FieldType fieldType = FieldUtil.determineFieldType(fieldNode);
            if (fieldType != null) {
                switch (fieldType) {
                case ARRAY:
                    ObjectNode itemsNode = (ObjectNode) fieldNode.get("items");
                    if (currentDepth <= config.getMaxDepth()) {
                        StringBuilder arrayItemsBuilder = appendArrayItems(new StringBuilder(), schema, fieldId,
                                itemsNode, seperator);
                        if (StringUtils.isNotBlank(arrayItemsBuilder.toString())) {
                            fieldStrings.add(arrayItemsBuilder.toString());
                        }
                    }
                    break;
                case OBJECT:
                    Schema objectSchema = null;
                    URI parentUri = null;
                    if (fieldNode.has("$ref") || fieldNode.has("extends")) {
                        JsonNode refNode = fieldNode.get("$ref");
                        JsonNode extendsNode = fieldNode.get("extends");
                        if (refNode != null && refNode.isValueNode()) {
                            parentUri = URI.create(refNode.asText());
                        } else if (extendsNode != null && extendsNode.isObject()) {
                            parentUri = URI.create(extendsNode.get("$ref").asText());
                        }
                        URI absoluteUri;
                        if (parentUri.isAbsolute()) {
                            absoluteUri = parentUri;
                        } else {
                            absoluteUri = schema.getUri().resolve(parentUri);
                            if (!absoluteUri.isAbsolute() || (absoluteUri.isAbsolute()
                                    && !schemaStore.getByUri(absoluteUri).isPresent())) {
                                absoluteUri = schema.getParentUri().resolve(parentUri);
                            }
                        }
                        if (absoluteUri.isAbsolute()) {
                            Optional<Schema> schemaLookup = schemaStore.getByUri(absoluteUri);
                            if (schemaLookup.isPresent()) {
                                objectSchema = schemaLookup.get();
                            }
                        }
                    }
                    //ObjectNode childProperties = schemaStore.resolveProperties(schema, fieldNode, fieldId);
                    if (currentDepth < config.getMaxDepth()) {
                        StringBuilder structFieldBuilder = appendSchemaField(new StringBuilder(), objectSchema,
                                fieldId, seperator);
                        if (StringUtils.isNotBlank(structFieldBuilder.toString())) {
                            fieldStrings.add(structFieldBuilder.toString());
                        }
                    }
                    break;
                default:
                    StringBuilder valueFieldBuilder = appendValueField(new StringBuilder(), schema, fieldId,
                            fieldType, seperator);
                    if (StringUtils.isNotBlank(valueFieldBuilder.toString())) {
                        fieldStrings.add(valueFieldBuilder.toString());
                    }
                }
            }
        }
    }
    builder.append(String.join("," + LS, fieldStrings)).append(LS);
    Objects.requireNonNull(builder);
    return builder;
}

From source file:com.google.dart.engine.services.internal.correction.QuickFixProcessorImpl.java

private void addFix_createPart() throws Exception {
    if (node instanceof SimpleStringLiteral && node.getParent() instanceof PartDirective) {
        SimpleStringLiteral uriLiteral = (SimpleStringLiteral) node;
        String uriString = uriLiteral.getValue();
        // prepare referenced File
        File newFile;/*www . j  a v a  2s. c o  m*/
        {
            URI uri = URI.create(uriString);
            if (uri.isAbsolute()) {
                return;
            }
            newFile = new File(unitLibraryFolder, uriString);
        }
        if (!newFile.exists()) {
            // prepare new source
            String source;
            {
                String eol = utils.getEndOfLine();
                String libraryName = unitLibraryElement.getDisplayName();
                source = "part of " + libraryName + ";" + eol + eol;
            }
            // add proposal
            proposals.add(new CreateFileCorrectionProposal(newFile, source, CorrectionKind.QF_CREATE_PART,
                    uriString));
        }
    }
}

From source file:org.rssowl.core.internal.connection.DefaultProtocolHandler.java

public byte[] getFeedIcon(URI link, IProgressMonitor monitor) {

    /* Try to load the Favicon directly from the supplied Link */
    byte[] favicon = loadFavicon(link, false, false, monitor);

    /* Fallback: Scan the Homepage of the Link for a Favicon entry */
    if (favicon == null || favicon.length == 0) {
        try {//from  www  . j a  v  a2 s  . c om
            URI topLevelUri = URIUtils.toTopLevel(link);
            if (topLevelUri != null) {
                URI faviconUri = getFavicon(topLevelUri, monitor);
                if (faviconUri != null && faviconUri.isAbsolute())
                    return loadFavicon(faviconUri, true, false, monitor);
            }
        } catch (ConnectionException e) {
        } catch (URISyntaxException e) {
        } catch (Throwable t) {
            Activator.getDefault().logError(t.getMessage(), t);
        }
    }

    return favicon;
}

From source file:org.dita.dost.module.GenMapAndTopicListModule.java

/**
 * Update uplevels if needed. If the parameter contains a {@link org.dita.dost.util.Constants#STICK STICK}, it and
 * anything following it is removed./*from w  w w .  j  a v a 2  s . c  o  m*/
 * 
 * @param file file path
 */
private void updateUplevels(final URI file) {
    assert file.isAbsolute();
    if (file.getPath() != null) {
        final URI f = file.toString().contains(STICK)
                ? toURI(file.toString().substring(0, file.toString().indexOf(STICK)))
                : file;
        final URI relative = getRelativePath(rootFile, f).normalize();
        final int lastIndex = relative.getPath().lastIndexOf(".." + URI_SEPARATOR);
        if (lastIndex != -1) {
            final int newUplevels = lastIndex / 3 + 1;
            uplevels = Math.max(newUplevels, uplevels);
        }
    }
}

From source file:org.dita.dost.module.GenMapAndTopicListModule.java

/**
 * Add the given file the wait list if it has not been parsed.
 * /*  w ww  .j  av  a2s . c o m*/
 * @param ref reference to absolute system path
 */
private void addToWaitList(final Reference ref) {
    final URI file = ref.filename;
    assert file.isAbsolute() && file.getFragment() == null;
    if (doneList.contains(file) || waitList.contains(ref) || file.equals(currentFile)) {
        return;
    }

    waitList.add(ref);
}

From source file:org.dita.dost.module.GenMapAndTopicListModule.java

/**
 * Get pipe line filters/*from  w  w  w .j ava  2 s .c  o  m*/
 * 
 * @param fileToParse absolute path to current file being processed
 */
private List<XMLFilter> getProcessingPipe(final URI fileToParse) {
    assert fileToParse.isAbsolute();
    final List<XMLFilter> pipe = new ArrayList<>();

    if (genDebugInfo) {
        final DebugFilter debugFilter = new DebugFilter();
        debugFilter.setLogger(logger);
        debugFilter.setCurrentFile(currentFile);
        pipe.add(debugFilter);
    }

    if (filterUtils != null) {
        final ProfilingFilter profilingFilter = new ProfilingFilter();
        profilingFilter.setLogger(logger);
        profilingFilter.setJob(job);
        profilingFilter.setFilterUtils(filterUtils);
        pipe.add(profilingFilter);
    }

    if (INDEX_TYPE_ECLIPSEHELP.equals(transtype)) {
        exportAnchorsFilter.setCurrentFile(fileToParse);
        exportAnchorsFilter.setErrorHandler(new DITAOTXMLErrorHandler(fileToParse.toString(), logger));
        pipe.add(exportAnchorsFilter);
    }

    keydefFilter.setCurrentDir(fileToParse.resolve("."));
    keydefFilter.setErrorHandler(new DITAOTXMLErrorHandler(fileToParse.toString(), logger));
    pipe.add(keydefFilter);

    listFilter.setCurrentFile(fileToParse);
    listFilter.setErrorHandler(new DITAOTXMLErrorHandler(fileToParse.toString(), logger));
    pipe.add(listFilter);

    return pipe;
}