Examples of PrefixService


Examples of org.apache.marmotta.platform.core.api.prefix.PrefixService

    @GET
    @Path("/namespaces")
    @Produces(Namespaces.MIME_TYPE_JSON)
    public Map<String, String> listKnownNamespaces(@Context UriInfo info) {
        final PrefixService prefixService = createLocalPrefixService(info);
        Map<String, String> nss = new HashMap<String, String>();

        try {
            RepositoryConnection con = sesameService.getConnection();
            try {
                con.begin();
                for (Namespace ns : iterable(con.getNamespaces())) {
                    nss.put(ns.getPrefix(), ns.getName());
                }
                // commit added
                con.commit();
            } finally {
                con.close();
            }

        } catch (RepositoryException e) {
            handleRepositoryException(e,LDPathUtilWebService.class);
        }

        for (Map.Entry<String, String> e : prefixService.getMappings().entrySet()) {
            nss.put(e.getKey(), e.getValue());
        }
        nss.put(FUNCTION_PREFIX, FUNCTION_NAMESPACE);
        return nss;
    }
View Full Code Here

Examples of org.apache.marmotta.platform.core.api.prefix.PrefixService

    @GET
    @Path("/prefix")
    @Produces(Namespaces.MIME_TYPE_JSON)
    public Map<String, String> resolvePrefix(@QueryParam("prefix") String prefix, @Context UriInfo info) {
        final PrefixService prefixService = createLocalPrefixService(info);
        if (prefixService.containsPrefix(prefix))
            return Collections.singletonMap(prefix, prefixService.getNamespace(prefix));

        // As a fallback, try prefix.cc
        if (prefix != null) {
            final String namespace = prefixCC.getNamespace(prefix);
            if (namespace != null)
View Full Code Here

Examples of org.apache.marmotta.platform.core.api.prefix.PrefixService

    @Path("/complete")
    @Produces(Namespaces.MIME_TYPE_JSON)
    public List<String> complete(@QueryParam("prefix") String prefix, @QueryParam("uri") String uri,
            @QueryParam("mode") @DefaultValue("path") String mode, @Context UriInfo info) {
        final int limit = 20;
        final PrefixService prefixService = createLocalPrefixService(info);
        if (uri != null) {
            // Complete <URI>
            final List<String> suggestions = new ArrayList<String>();
            for (String sug : getCompletions(uri, limit, mode)) {
                final String curie = prefixService.getCurie(sug);
                suggestions.add(curie != null ? curie : sug);
            }
            return suggestions;
        } else if (prefix != null) {
            Matcher m = CURIE_PATTERN.matcher(prefix);
            if (m.matches()) {
                String px = m.group(1);
                String local = m.group(2);

                if (px.equals(FUNCTION_PREFIX)) {
                    try {
                        final RepositoryConnection conn = sesameService.getConnection();
                        try {
                            conn.begin();
                            SesameConnectionBackend backend = SesameConnectionBackend.withConnection(conn);

                            final Set<SelectorFunction<Value>> functions = ldPathService.getFunctions();
                            List<String> suggestions = new ArrayList<String>();
                            for (SelectorFunction<Value> fn : functions) {
                                final String fName = fn.getPathExpression(backend);
                                if (fName.startsWith(local)) {
                                    suggestions.add(FUNCTION_PREFIX + ":" + fName + "()");
                                }
                            }
                            return suggestions;
                        } finally {
                            conn.commit();
                            conn.close();
                        }
                    } catch (RepositoryException e) {
                        return Collections.emptyList();
                    }
                } else if (prefixService.containsPrefix(px)) {
                    String resolved = prefixService.getNamespace(px) + (local != null ? local : "");
                    List<String> suggestions = new ArrayList<String>();
                    for (String c : getCompletions(resolved, limit, mode)) {
                        // CURIE urs MUST have a local part
                        if (c.length() <= resolved.length()) {
                            continue;
                        }
                        final String curie = prefixService.getCurie(c);
                        suggestions.add(curie != null ? curie : c);
                    }
                    return suggestions;
                }

            } else {
                List<String> suggestions = new ArrayList<String>();
                if (mode.equals(MODE_TRANSFORM)) {
                    for (String s : ldPathService.getTransformableTypes()) {
                        String px = prefixService.getPrefix(UriUtil.getNamespace(s));
                        if (px != null && px.startsWith(prefix) && !suggestions.contains(px)) {
                            suggestions.add(px);
                        }
                    }
                } else {
                    if (FUNCTION_PREFIX.startsWith(prefix)) {
                        suggestions.add(FUNCTION_PREFIX);
                    }
                    for (String px : prefixService.getMappings().keySet()) {
                        if (px.startsWith(prefix)) {
                            suggestions.add(px);
                        }
                    }
                }
View Full Code Here

Examples of org.apache.marmotta.platform.core.api.prefix.PrefixService

    @GET
    @Path("/path")
    @Produces(Namespaces.MIME_TYPE_JSON)
    public List<String> pathSuggestions(@QueryParam("path") String partialPath, @QueryParam("ctx") String[] ctx,
            @QueryParam("ctx[]") String[] ctx2, @Context UriInfo info) {
        final PrefixService prefixService = createLocalPrefixService(info);

        // Merge the contexts
        HashSet<String> context = new HashSet<String>();
        for (String c : ctx) {
            context.add(c);
        }
        for (String c : ctx2) {
            context.add(c);
        }

        // Clean the path
        String path = partialPath.replaceAll("/.*", "").trim();
        if (path.equals("")) {
            path = ".";
        }
        try {
            HashSet<URI> pathCandidates = new HashSet<URI>();
            try {
                RepositoryConnection con = sesameService.getConnection();
                try {
                    con.begin();
                    for (String rsc_uri : context) {
                        if (!ResourceUtils.isSubject(con, rsc_uri)) {
                            continue;
                        }

                        URI rsc = con.getValueFactory().createURI(rsc_uri);
                        Collection<Value> cPos = ldPathService.pathQuery(rsc, path, prefixService.getMappings());
                        for (Value cP : cPos) {
                            if (cP instanceof URI || cP instanceof BNode) {
                                for (Statement t : listOutgoing(con, (Resource) cP)) {
                                    pathCandidates.add(t.getPredicate());
                                }
View Full Code Here

Examples of org.apache.marmotta.platform.core.api.prefix.PrefixService

    @GET
    @Path("/prefix")
    @Produces(Namespaces.MIME_TYPE_JSON)
    public Map<String, String> resolvePrefix(@QueryParam("prefix") String prefix, @Context UriInfo info) {
        final PrefixService prefixService = createLocalPrefixService(info);
        if (prefixService.containsPrefix(prefix))
            return Collections.singletonMap(prefix, prefixService.getNamespace(prefix));

        // As a fallback, try prefix.cc
        if (prefix != null) {
            final String namespace = prefixCC.getNamespace(prefix);
            if (namespace != null)
View Full Code Here

Examples of org.apache.marmotta.platform.core.api.prefix.PrefixService

    @Path("/complete")
    @Produces(Namespaces.MIME_TYPE_JSON)
    public List<String> complete(@QueryParam("prefix") String prefix, @QueryParam("uri") String uri,
            @QueryParam("mode") @DefaultValue("path") String mode, @Context UriInfo info) {
        final int limit = 20;
        final PrefixService prefixService = createLocalPrefixService(info);
        if (uri != null) {
            // Complete <URI>
            final List<String> suggestions = new ArrayList<String>();
            for (String sug : getCompletions(uri, limit, mode)) {
                final String curie = prefixService.getCurie(sug);
                suggestions.add(curie != null ? curie : sug);
            }
            return suggestions;
        } else if (prefix != null) {
            Matcher m = CURIE_PATTERN.matcher(prefix);
            if (m.matches()) {
                String px = m.group(1);
                String local = m.group(2);

                if (px.equals(FUNCTION_PREFIX)) {
                    try {
                        final RepositoryConnection conn = sesameService.getConnection();
                        try {
                            conn.begin();
                            SesameConnectionBackend backend = SesameConnectionBackend.withConnection(conn);

                            final Set<SelectorFunction<Value>> functions = ldPathService.getFunctions();
                            List<String> suggestions = new ArrayList<String>();
                            for (SelectorFunction<Value> fn : functions) {
                                final String fName = fn.getPathExpression(backend);
                                if (fName.startsWith(local)) {
                                    suggestions.add(FUNCTION_PREFIX + ":" + fName + "()");
                                }
                            }
                            return suggestions;
                        } finally {
                            conn.commit();
                            conn.close();
                        }
                    } catch (RepositoryException e) {
                        return Collections.emptyList();
                    }
                } else if (prefixService.containsPrefix(px)) {
                    String resolved = prefixService.getNamespace(px) + (local != null ? local : "");
                    List<String> suggestions = new ArrayList<String>();
                    for (String c : getCompletions(resolved, limit, mode)) {
                        // CURIE urs MUST have a local part
                        if (c.length() <= resolved.length()) {
                            continue;
                        }
                        final String curie = prefixService.getCurie(c);
                        suggestions.add(curie != null ? curie : c);
                    }
                    return suggestions;
                }

            } else {
                List<String> suggestions = new ArrayList<String>();
                if (mode.equals(MODE_TRANSFORM)) {
                    for (String s : ldPathService.getTransformableTypes()) {
                        String px = prefixService.getPrefix(UriUtil.getNamespace(s));
                        if (px != null && px.startsWith(prefix) && !suggestions.contains(px)) {
                            suggestions.add(px);
                        }
                    }
                } else {
                    if (FUNCTION_PREFIX.startsWith(prefix)) {
                        suggestions.add(FUNCTION_PREFIX);
                    }
                    for (String px : prefixService.getMappings().keySet()) {
                        if (px.startsWith(prefix)) {
                            suggestions.add(px);
                        }
                    }
                }
View Full Code Here

Examples of org.apache.marmotta.platform.core.api.prefix.PrefixService

    @GET
    @Path("/path")
    @Produces(Namespaces.MIME_TYPE_JSON)
    public List<String> pathSuggestions(@QueryParam("path") String partialPath, @QueryParam("ctx") String[] ctx,
            @QueryParam("ctx[]") String[] ctx2, @Context UriInfo info) {
        final PrefixService prefixService = createLocalPrefixService(info);

        // Merge the contexts
        HashSet<String> context = new HashSet<String>();
        for (String c : ctx) {
            context.add(c);
        }
        for (String c : ctx2) {
            context.add(c);
        }

        // Clean the path
        String path = partialPath.replaceAll("/.*", "").trim();
        if (path.equals("")) {
            path = ".";
        }
        try {
            HashSet<URI> pathCandidates = new HashSet<URI>();
            try {
                RepositoryConnection con = sesameService.getConnection();
                try {
                    con.begin();
                    for (String rsc_uri : context) {
                        if (!ResourceUtils.isSubject(con, rsc_uri)) {
                            continue;
                        }

                        URI rsc = con.getValueFactory().createURI(rsc_uri);
                        Collection<Value> cPos = ldPathService.pathQuery(rsc, path, prefixService.getMappings());
                        for (Value cP : cPos) {
                            if (cP instanceof URI || cP instanceof BNode) {
                                for (Statement t : listOutgoing(con, (Resource) cP)) {
                                    pathCandidates.add(t.getPredicate());
                                }
View Full Code Here

Examples of org.apache.marmotta.platform.core.api.prefix.PrefixService

    @GET
    @Path("/namespaces")
    @Produces(Namespaces.MIME_TYPE_JSON)
    public Map<String, String> listKnownNamespaces(@Context UriInfo info) {
        final PrefixService prefixService = createLocalPrefixService(info);
        Map<String, String> nss = new HashMap<String, String>();

        try {
            RepositoryConnection con = sesameService.getConnection();
            try {
                con.begin();
                for (Namespace ns : iterable(con.getNamespaces())) {
                    nss.put(ns.getPrefix(), ns.getName());
                }
                // commit added
                con.commit();
            } finally {
                con.close();
            }

        } catch (RepositoryException e) {
            handleRepositoryException(e,LDPathUtilWebService.class);
        }

        for (Map.Entry<String, String> e : prefixService.getMappings().entrySet()) {
            nss.put(e.getKey(), e.getValue());
        }
        nss.put(FUNCTION_PREFIX, FUNCTION_NAMESPACE);
        return nss;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.