Examples of ReferenceList


Examples of org.restlet.data.ReferenceList

     *
     * @return The list of variants references
     */
    private ReferenceList getVariantsReferences() {
        uniqueReference = null;
        ReferenceList result = new ReferenceList(0);
        try {
            Request contextCall = new Request(Method.GET, this.targetUri);
            contextCall.getClientInfo().getAcceptedMediaTypes().add(
                    new Preference<MediaType>(MediaType.TEXT_URI_LIST));
            Response contextResponse = getDispatcher().handle(contextCall);
            if (contextResponse.getEntity() != null) {
                ReferenceList listVariants = new ReferenceList(contextResponse
                        .getEntity());
                Set<String> extensions = null;
                String entryUri;
                String fullEntryName;
                String baseEntryName;
View Full Code Here

Examples of org.restlet.data.ReferenceList

                contextRequest.setResourceRef(this.targetUri);
                getClientDispatcher().handle(contextRequest, contextResponse);
            } else {
                // Check if there is only one representation
                // Try to get the unique representation of the resource
                ReferenceList references = getVariantsReferences();
                if (!references.isEmpty()) {
                    if (this.uniqueReference != null) {
                        contextRequest.setResourceRef(this.uniqueReference);
                        getClientDispatcher().handle(contextRequest,
                                contextResponse);
                    } else {
View Full Code Here

Examples of org.restlet.data.ReferenceList

                    // "MediaType.TEXT_URI_LIST" when handling directories
                    if (MediaType.TEXT_URI_LIST.equals(contextResponse
                            .getEntity().getMediaType())) {
                        this.directoryTarget = true;
                        this.fileTarget = false;
                        this.directoryContent = new ReferenceList(
                                contextResponse.getEntity());

                        if (!getReference().getPath().endsWith("/")) {
                            // All requests will be automatically redirected
                            this.directoryRedirection = true;
                        }

                        if (!this.targetUri.endsWith("/")) {
                            this.targetUri += "/";
                            this.relativePart += "/";
                        }

                        // Append the index name
                        if ((getDirectory().getIndexName() != null)
                                && (getDirectory().getIndexName().length() > 0)) {
                            this.directoryUri = this.targetUri;
                            this.baseName = getDirectory().getIndexName();
                            this.targetUri = this.directoryUri + this.baseName;
                            this.indexTarget = true;
                        } else {
                            this.directoryUri = this.targetUri;
                            this.baseName = null;
                        }
                    } else {
                        // Allows underlying helpers that do not support
                        // "content negotiation" to return the targeted file.
                        // Sometimes we immediately reach the target entity, so
                        // we return it directly.
                        this.directoryTarget = false;
                        this.fileTarget = true;
                        this.fileContent = contextResponse.getEntity();
                    }
                } else {
                    this.directoryTarget = false;
                    this.fileTarget = false;

                    // Let's try with the optional index, in case the underlying
                    // client connector does not handle directory listing.
                    if (this.targetUri.endsWith("/")) {
                        // In this case, the trailing "/" shows that the URI
                        // must point to a directory
                        if ((getDirectory().getIndexName() != null)
                                && (getDirectory().getIndexName().length() > 0)) {
                            this.directoryUri = this.targetUri;
                            this.directoryTarget = true;

                            contextResponse = getRepresentation(this.directoryUri
                                    + getDirectory().getIndexName());
                            if (contextResponse.getEntity() != null) {
                                this.baseName = getDirectory().getIndexName();
                                this.targetUri = this.directoryUri
                                        + this.baseName;
                                this.directoryContent = new ReferenceList();
                                this.directoryContent.add(new Reference(
                                        this.targetUri));
                                this.indexTarget = true;
                            }
                        }
                    } else {
                        // Try to determine if this target URI with no trailing
                        // "/" is a directory, in order to force the
                        // redirection.
                        if ((getDirectory().getIndexName() != null)
                                && (getDirectory().getIndexName().length() > 0)) {
                            // Append the index name
                            contextResponse = getRepresentation(this.targetUri
                                    + "/" + getDirectory().getIndexName());
                            if (contextResponse.getEntity() != null) {
                                this.directoryUri = this.targetUri + "/";
                                this.baseName = getDirectory().getIndexName();
                                this.targetUri = this.directoryUri
                                        + this.baseName;
                                this.directoryTarget = true;
                                this.directoryRedirection = true;
                                this.directoryContent = new ReferenceList();
                                this.directoryContent.add(new Reference(
                                        this.targetUri));
                                this.indexTarget = true;
                            }
                        }
                    }
                }

                // In case the request does not target a directory and the file
                // has not been found, try with the tunneled URI.
                if (isNegotiated() && !this.directoryTarget && !this.fileTarget
                        && (this.originalRef != null)) {
                    this.relativePart = getReference().getRemainingPart();

                    // The target URI does not take into account the query and
                    // fragment parts of the resource.
                    this.targetUri = new Reference(directory.getRootRef()
                            .toString() + this.relativePart).normalize()
                            .toString(false, false);
                    if (!this.targetUri.startsWith(directory.getRootRef()
                            .toString())) {
                        // Prevent the client from accessing resources in upper
                        // directories
                        this.targetUri = directory.getRootRef().toString();
                    }
                }

                if (!fileTarget || (fileContent == null)
                        || !getRequest().getMethod().isSafe()) {
                    // Try to get the directory content, in case the request
                    // does not target a directory
                    if (!this.directoryTarget) {
                        int lastSlashIndex = this.targetUri.lastIndexOf('/');
                        if (lastSlashIndex == -1) {
                            this.directoryUri = "";
                            this.baseName = this.targetUri;
                        } else {
                            this.directoryUri = this.targetUri.substring(0,
                                    lastSlashIndex + 1);
                            this.baseName = this.targetUri
                                    .substring(lastSlashIndex + 1);
                        }

                        contextResponse = getRepresentation(this.directoryUri);
                        if ((contextResponse.getEntity() != null)
                                && MediaType.TEXT_URI_LIST
                                        .equals(contextResponse.getEntity()
                                                .getMediaType())) {
                            this.directoryContent = new ReferenceList(
                                    contextResponse.getEntity());
                        }
                    }

                    if (this.baseName != null) {
View Full Code Here

Examples of org.restlet.data.ReferenceList

            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        } else {
            if (variants.size() == 1) {
                result = (Representation) variants.get(0);
            } else {
                ReferenceList variantRefs = new ReferenceList();

                for (Variant variant : variants) {
                    if (variant.getLocationRef() != null) {
                        variantRefs.add(variant.getLocationRef());
                    } else {
                        getLogger()
                                .warning(
                                        "A resource with multiple variants should provide a location for each variant when content negotiation is turned off");
                    }
                }

                if (variantRefs.size() > 0) {
                    // Return the list of variants
                    setStatus(Status.REDIRECTION_MULTIPLE_CHOICES);
                    result = variantRefs.getTextRepresentation();
                } else {
                    setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                }
            }
        }
View Full Code Here

Examples of org.restlet.data.ReferenceList

                    }

                    if (resultSet.isEmpty()) {
                        if (this.directoryTarget
                                && getDirectory().isListingAllowed()) {
                            ReferenceList userList = new ReferenceList(
                                    this.directoryContent.size());
                            // Set the list identifier
                            userList.setIdentifier(baseRef);

                            SortedSet<Reference> sortedSet = new TreeSet<Reference>(
                                    getDirectory().getComparator());
                            sortedSet.addAll(this.directoryContent);

                            for (Reference ref : sortedSet) {
                                String filePart = ref.toString(false, false)
                                        .substring(rootLength);
                                StringBuilder filePath = new StringBuilder();
                                if ((!baseRef.endsWith("/"))
                                        && (!filePart.startsWith("/"))) {
                                    filePath.append('/');
                                }
                                filePath.append(filePart);
                                userList.add(baseRef + filePath);
                            }
                            List<Variant> list = getDirectory()
                                    .getIndexVariants(userList);
                            for (Variant variant : list) {
                                if (result == null) {
View Full Code Here

Examples of org.restlet.data.ReferenceList

     * according to the directory handler property
     *
     * @return The list of variants references
     */
    private ReferenceList getVariantsReferences() {
        ReferenceList result = new ReferenceList(0);

        try {
            this.uniqueReference = null;

            // Ask for the list of all variants of this resource
            Response contextResponse = getRepresentation(this.targetUri,
                    MediaType.TEXT_URI_LIST);
            if (contextResponse.getEntity() != null) {
                // Test if the given response is the list of all variants for
                // this resource
                if (MediaType.TEXT_URI_LIST.equals(contextResponse.getEntity()
                        .getMediaType())) {
                    ReferenceList listVariants = new ReferenceList(
                            contextResponse.getEntity());
                    String entryUri;
                    String fullEntryName;
                    String baseEntryName;
                    int lastSlashIndex;
View Full Code Here

Examples of org.restlet.data.ReferenceList

            if (parent != null) {
                Collection<Entity> entities = parent.getChildren();

                if (entities != null) {
                    ReferenceList rl = new ReferenceList(entities.size());
                    String scheme = request.getResourceRef().getScheme();
                    String path = request.getResourceRef().getPath();
                    String encodedParentDirectoryURI = path.substring(0, path
                            .lastIndexOf("/"));
                    String encodedEntityName = path.substring(path
                            .lastIndexOf("/") + 1);

                    for (Entity entry : entities) {
                        if (baseName.equals(entry.getBaseName())) {
                            rl.add(createReference(scheme,
                                    encodedParentDirectoryURI,
                                    encodedEntityName, entry.getName()));
                        }
                    }

                    output = rl.getTextRepresentation();
                }
            }
        } else {
            if (entity.exists()) {
                if (entity.isDirectory()) {
                    // Return the directory listing
                    Collection<Entity> children = entity.getChildren();
                    ReferenceList rl = new ReferenceList(children.size());
                    String directoryUri = request.getResourceRef()
                            .getTargetRef().toString();

                    // Ensures that the directory URI ends with a slash
                    if (!directoryUri.endsWith("/")) {
                        directoryUri += "/";
                    }

                    for (Entity entry : children) {
                        if (entry.isDirectory()) {
                            rl.add(directoryUri
                                    + Reference.encode(entry.getName()) + "/");
                        } else {
                            rl.add(directoryUri
                                    + Reference.encode(entry.getName()));
                        }
                    }

                    output = rl.getTextRepresentation();
                } else {
                    // Return the file content
                    output = entity.getRepresentation(getMetadataService()
                            .getDefaultMediaType(), getTimeToLive());
                    output.setLocationRef(request.getResourceRef());
View Full Code Here

Examples of org.restlet.data.ReferenceList

                final Representation output;

                if (entity.isDirectory()) {
                    // Return the directory listing
                    final Collection<Entity> children = entity.getChildren();
                    final ReferenceList rl = new ReferenceList(children.size());
                    String fileUri = LocalReference.createFileReference(file)
                            .toString();
                    String scheme = request.getResourceRef().getScheme();
                    String baseUri = scheme + ":" + fileUri + "!/";

                    for (final Entity entry : children) {
                        rl.add(baseUri + entry.getName());
                    }

                    output = rl.getTextRepresentation();

                    try {
                        zipFile.close();
                    } catch (IOException e) {
                        // Do something ???
View Full Code Here

Examples of org.restlet.data.ReferenceList

    public Representation get(Variant variant) throws ResourceException {
        Representation result = null;

        if (variant.getMediaType().equals(MediaType.TEXT_HTML)) {
            int code = checkAuthorization();
            ReferenceList rl = new ReferenceList();

            // Copy the bookmark URIs into a reference list. Make sure that we
            // only expose public bookmarks if the client isn't the owner.
            for (Bookmark bookmark : getUser().getBookmarks()) {
                if (!bookmark.isRestricting() || (code == 1)) {
                    rl.add(bookmark.getUri());
                }
            }

            result = rl.getWebRepresentation();
        }

        return result;
    }
View Full Code Here

Examples of org.restlet.data.ReferenceList

                            warEntries.add(entries.nextElement().getName());
                        }
                    }

                    // Return the directory listing
                    ReferenceList rl = new ReferenceList();
                    rl.setIdentifier(request.getResourceRef());

                    for (String warEntry : warEntries) {
                        if (warEntry.startsWith(path)) {
                            rl.add(new Reference(warEntry));
                        }
                    }

                    response.setEntity(rl.getTextRepresentation());
                    response.setStatus(Status.SUCCESS_OK);
                } else {
                    // Return the file content
                    Representation output = new InputRepresentation(war
                            .getInputStream(entry), null);
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.