Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.apache.marmotta.platform.core.webservices.prefix;
 
 
 
 import java.util.Map;

Prefix web service

Author(s):
Sergio Fernández
 
 @Path("/prefix")
 public class PrefixWebService {
 
     @Inject
     private Logger log;
 
     @Inject
     private PrefixService prefixService;
 
     private static final String PREFIX_PATTERN = "{prefix: [a-z][a-zA-Z0-9\\._-]+}";

    
Get all prefixes mappings

Returns:
all current prefixes mappings
 
     @GET
     @Produces("application/json")
     public Response getMappings() {
         Map<StringStringmappings = ( != null ? .getMappings() : new HashMap<String,String>());
         return Response.ok().entity(mappings).build();
     }

    
Get namespace

Parameters:
prefix prefix
Returns:
Response with the mapping, if exists
 
     @GET
     @Path("/" + )
     @Produces("application/json")
     public Response getMapping(@PathParam("prefix"String prefix) {
         if (.containsPrefix(prefix)) {
             Map<StringStringresult = new HashMap<StringString>();
             result.put(prefix.getNamespace(prefix));
             return Response.ok().entity(result).build();
         } else {
             .error("prefix " + prefix + " mapping not found");
             return Response.status(..).entity("prefix " + prefix + " mapping not found").build();
         }
     }
    
    
Removes a prefix

Parameters:
prefix prefix
Returns:
Response with the result of the operation
 
     @DELETE
     @Path("/" + )
     public Response deleteMapping(@PathParam("prefix"String prefix) {
        if (.remove(prefix)) {
            return Response.status(.).build();
        } else {
            return Response.status(..).entity("prefix " + prefix + " mapping not found").build();
        }
    }    

    
Add new mapping

Parameters:
prefix prefix
namespace uri
Returns:
operation result
    @POST
    @Path("/" + )
    public Response addMapping(@PathParam("prefix"String prefix, @QueryParam("uri") @NotNull String namespace) {
        try {
            .add(prefixnamespace);
            return Response.status(..).build();
        } catch (URISyntaxException e) {
            return Response.status(..).entity(e.getMessage()).build();
        } catch (IllegalArgumentException e) {
            return Response.status(..).entity(e.getMessage()).build();
        }
    }

    
Reverse prefix lookup

Parameters:
uri namespace
Returns:
Response with the result of the reverse search
    @GET
    @Path("/reverse")
    @Produces("application/json")
    public Response getPrefix(@QueryParam("uri") @NotNull String uri) {
        if (StringUtils.isNotBlank(uri)) {
            if (.containsNamespace(uri)) {
                Map<StringStringresult = new HashMap<StringString>();
                result.put(uri.getPrefix(uri));
                return Response.ok().entity(result).build();
            } else {
                .error("namespace " + uri + " mapping not found");
                return Response.status(..).entity("namespace " + uri + " mapping not found").build();
            }
        } else {
            .error("Empty namespace requested");
            return Response.status(..).build();
        }
    }
New to GrepCode? Check out our FAQ X