Package org.apache.abdera.protocol.server

Examples of org.apache.abdera.protocol.server.TargetType


        Target target = request.getTarget();
        if (target == null || target.getType() == TargetType.TYPE_NOT_FOUND) {
            return ProviderHelper.notfound(request);
        }

        TargetType type = target.getType();
        RequestProcessor processor = this.requestProcessors.get(type);
        if (processor == null) {
            return ProviderHelper.notfound(request);
        }
View Full Code Here


  public ResponseContext filter(
    RequestContext request,
    FilterChain chain) {
   
      Target target = request.getTarget();
      TargetType type = target.getType();
      if (type == TYPE_OPENSEARCH_DESCRIPTION) {
        return getOpenSearchDescription(request);
      } else {
        for (Entry<String,String> entry : map.entrySet()) {
          String value = target.getParameter(entry.getKey());
View Full Code Here

 
  public RegexTargetResolver(Map<String, TargetType> patterns) {
    this.patterns = new HashMap<Pattern, TargetType>();
    this.fields = new HashMap<Pattern, String[]>();
    for (String p : patterns.keySet()) {
      TargetType type = patterns.get(p);
      setPattern(p,type);
    }
  }
View Full Code Here

    RequestContext context = (RequestContext) request;
    String uri = context.getTargetPath();
    for (Pattern pattern : patterns.keySet()) {
      Matcher matcher = pattern.matcher(uri);
      if (matcher.matches()) {
        TargetType type = this.patterns.get(pattern);
        String[] fields = this.fields.get(pattern);
        return getTarget(type, context, matcher, fields);
      }
    }
    return null;
View Full Code Here

 
  public String toString() {
    StringBuilder buf = new StringBuilder();
    buf.append("Regex Target Resolver:\n");
    for (Pattern pattern : patterns.keySet()) {
      TargetType type = this.patterns.get(pattern);
      String[] fields = this.fields.get(pattern);
      buf.append(pattern.toString() + ", Type: " + type + ", Fields: " + Arrays.toString(fields));
    }
    return buf.toString();
  }
View Full Code Here

            uri = uri.substring(uri.indexOf(RegistryConstants.PATH_SEPARATOR));
        }
        context.setAttribute("pathInfo", uri);
        String[] parts = splitPath(uri); // splits with "\;"
        boolean hasColon = false;
        TargetType type = null;

        // Let's just see if this is an import first - in which case we can just send it
        // on through.

        if (parts.length > 1) {
            String discriminator = parts[1];

            // If this is a version request, don't do anything special.  Otherwise process.
            if (discriminator.startsWith("version:")) {
                if (parts.length > 2) {
                    // Make sure this is a restore.
                    if (parts[2].equals("restore")) {
                        type = RESTORE_TYPE;
                        uri = parts[0] + RegistryConstants.URL_SEPARATOR + parts[1];
                    } else if (parts[2].equals(APPConstants.ASSOCIATIONS)) {
                        type = ASSOCIATIONS_TYPE;
                        uri = parts[0] + RegistryConstants.URL_SEPARATOR + parts[1];
                    } else {
                        // There's an extra semicolon here somewhere.
                        return null;
                    }
                }
            } else {
                // Store the split URL for later
                context.setAttribute("splitPath", parts);
                int idx = discriminator.indexOf("?");
                if (idx > -1) {
                    discriminator = discriminator.substring(0, idx);
                }

                String suffix = null;
                idx = discriminator.indexOf(":");
                if (idx > -1) {
                    suffix = discriminator.substring(idx + 1, discriminator.length());
                    discriminator = discriminator.substring(0, idx);
                    hasColon = true;
                }

                if (discriminator.startsWith("aspect")) {
                    type = ASPECT_TYPE;
                } else {
                    type = types.get(discriminator);
                }

                if (discriminator.equals("tag") && method.equals("DELETE") && hasColon) {
                    context.setAttribute("tagName", suffix);
                    type = DELETE_TYPE;
                } else if (discriminator.equals("comment") && method.equals("DELETE") && hasColon) {
                    context.setAttribute("commentId", suffix);
                    type = DELETE_TYPE;
                }

                // If we have a discriminator that we don't understand, return a 404
                if (type == null) {
                    return null;
                }

                // For the rest of this code, we'll want the "raw" resource URI
                if (!hasColon || !(type.equals(COMMENTS_TYPE) || type.equals(RATINGS_TYPE) ||
                        type.equals(TAGS_TYPE))) {
                    uri = parts[0];
                }
                if (hasColon && (type.equals(RATINGS_TYPE) || type.equals(TAGS_TYPE))) {
                    type = null;
                }
            }
        }

        int idx = uri.indexOf("?");
        if (idx > -1) {
            String queryString = uri.substring(idx + 1, uri.length());
            context.setAttribute("queryString", queryString);
            uri = uri.substring(0, idx);
        }

        try {
            uri = URLDecoder.decode(uri, "utf-8");
        } catch (UnsupportedEncodingException e) {
            log.error(e);
            return null;
        }

        boolean isMedia = false;
        if (uri.startsWith(APPConstants.RESOURCE)) {
            uri = uri.substring(APPConstants.RESOURCE.length());
            isMedia = true;
        } else if (uri.startsWith(APPConstants.ATOM)) {
            uri = uri.substring(APPConstants.ATOM.length());
        } else if (uri.startsWith("/tags") && (uri.length() == 5 || uri.charAt(5) == '/')) {
            return new SimpleTarget(TAG_URL_TYPE, context);
        } else {
            return null;
        }

        if (uri.length() == 0) {
            uri = "/";
        }

        // See if we're asking for a paginated collection
        String startParam = context.getParameter("start");
        String pageLenParam = context.getParameter("pageLen");
        int start = (startParam == null) ? -1 : Integer.parseInt(startParam);
        int pageLen = (pageLenParam == null) ? -1 : Integer.parseInt(pageLenParam);

        Resource resource = null;
        if (type != null && type.equals(DUMP_TYPE) &&
                method != null && method.equals("POST")) {
            // for restoring a dump we don't need to have available resource
            // here we will create a fake resource to store the path

            resource = new ResourceImpl();
View Full Code Here

     * @return a ResponseContext indicating the disposition of the request
     */
    @SuppressWarnings({"ConstantConditions"})
    public ResponseContext extensionRequest(RequestContext request) {
        Target target = request.getTarget();
        final TargetType type = target.getType();
        if (!(target instanceof ResourceTarget)) {
            if (type.equals(ResponseTarget.RESPONSE_TYPE)) {
                return ((ResponseTarget) target).getResponse();
            }
            // Deal with non-resource URLs, like "/tags..."
            if (type.equals(RegistryResolver.TAG_URL_TYPE)) {
                return processTagURLRequest(request);
            }
        }
        Resource resource = ((ResourceTarget) target).getResource();
        String path = resource.getPath();
        if (type.equals(RegistryResolver.TAGS_TYPE)) {
            return processTagsRequest(request, path);
        }
        if (type.equals(RegistryResolver.LOGS_TYPE)) {
            return processLogsRequest(request, path);
        }
        if (type.equals(RegistryResolver.RATINGS_TYPE)) {
            return processRatingsRequest(request, path);
        }
        if (type.equals(RegistryResolver.VERSIONS_TYPE)) {
            return processVersionsRequest(request, path);
        }
        if (type.equals(RegistryResolver.RENAME_TYPE)) {
            return processRenameRequest(request, path);
        }
        if (type.equals(RegistryResolver.COPY_TYPE)) {
            return processCopyRequest(request, path);
        }
        if (type.equals(RegistryResolver.MOVE_TYPE)) {
            return processMoveRequest(request, path);
        }
        if (type.equals(RegistryResolver.DELETE_TYPE)) {
            return processDeleteRequest(request, path);
        }
        if (type.equals(RegistryResolver.QUERY_TYPE)) {
            return processQueryRequest(request, path);
        }
        if (type.equals(RegistryResolver.COLLECTION_CUSTOM_TYPE)) {
            if (request.getMethod().equals("HEAD")) {
                // Doing a HEAD on a collection
                try {
                    return buildHeadEntryResponse(request, getId(resource),
                            resource.getLastModified());
                } catch (ResponseContextException e) {
                    log.error(e);
                    return e.getResponseContext();
                }
            }

            // Must be a PUT.
            return putCollection(request, path);
        }
        if (type.equals(RegistryResolver.ASSOCIATIONS_TYPE)) {
            String temp = resource.getPermanentPath();
            if (temp == null) {
                temp = resource.getPath();
            }
            return processAssociationRequest(request, temp);
        }
        if (type.equals(RegistryResolver.COMMENTS_TYPE)) {
            return processCommentsRequest(request, path);
        }
        if (type.equals(RegistryResolver.RESTORE_TYPE)) {
            try {
                getSecureRegistry(request).restoreVersion(resource.getPermanentPath());
            } catch (RegistryException e) {
                return new StackTraceResponseContext(e);
            }
            return new EmptyResponseContext(200);
        }
        if (type.equals(RegistryResolver.ASPECT_TYPE)) {
            return processAspectRequest(request, path);
        }
        if (type.equals(RegistryResolver.CHECKPOINT_TYPE)) {
            return processCheckpointRequest(request, path);
        }
        // Deal with imports
        if (type.equals(RegistryResolver.IMPORT_TYPE)) {
            return processImportRequest(request, path);
        }

        // handle dump, restore request.
        if (type.equals(RegistryResolver.DUMP_TYPE)) {
            return processDumpRequest(request, path);
        }

        return null;
    }
View Full Code Here

    }

    public ResponseContext filter(RequestContext request, FilterChain chain) {

        Target target = request.getTarget();
        TargetType type = target.getType();
        if (type == TYPE_OPENSEARCH_DESCRIPTION) {
            return getOpenSearchDescription(request);
        } else {
            for (Entry<String, String> entry : map.entrySet()) {
                String value = target.getParameter(entry.getKey());
View Full Code Here

        Target target = request.getTarget();
        if (target == null || target.getType() == TargetType.TYPE_NOT_FOUND) {
            return ProviderHelper.notfound(request);
        }

        TargetType type = target.getType();
        RequestProcessor processor = this.requestProcessors.get(type);
        if (processor == null) {
            return ProviderHelper.notfound(request);
        }
View Full Code Here

    public RegexTargetResolver(Map<String, TargetType> patterns) {
        this.patterns = new HashMap<Pattern, TargetType>();
        this.fields = new HashMap<Pattern, String[]>();
        for (String p : patterns.keySet()) {
            TargetType type = patterns.get(p);
            setPattern(p, type);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.abdera.protocol.server.TargetType

Copyright © 2018 www.massapicom. 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.