Package org.restlet.data

Examples of org.restlet.data.Reference


                this.relativePart = this.relativePart.substring(1);
            }

            // 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 (getClientDispatcher() == null) {
                getLogger().warning(
                        "No client dispatcher is available on the context. Can't get the target URI: "
                                + this.targetUri);
            } else {
                // Try to detect the presence of a directory
                Response contextResponse = getRepresentation(this.targetUri);

                if (contextResponse.getEntity() != null) {
                    // As a convention, underlying client connectors return the
                    // directory listing with the media-type
                    // "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
View Full Code Here


     * @param categoriesUri
     *            The feed URI.
     * @throws IOException
     */
    public Categories(String categoriesUri) throws IOException {
        this(new Client(new Reference(categoriesUri).getSchemeProtocol()),
                categoriesUri);

    }
View Full Code Here

     * Returns a reference that is initialized with http://www.restlet.org.
     *
     * @return Reference instance.
     */
    protected Reference getDefaultReference() {
        final Reference ref = getReference();
        ref.setHostDomain("www.restlet.org");
        return ref;
    }
View Full Code Here

     * Returns a reference with uri == http://
     *
     * @return Reference instance.
     */
    protected Reference getReference() {
        final Reference ref = new Reference();
        ref.setScheme(DEFAULT_SCHEME);
        ref.setSchemeSpecificPart(DEFAULT_SCHEMEPART);
        return ref;
    }
View Full Code Here

    /**
     * @param expectedCut
     * @param expectedExtensions
     */
    private void check(String expectedCut, String expectedExtensions) {
        final Reference resourceRef = this.request.getResourceRef();
        assertEquals(expectedCut, resourceRef.toString());

        final Reference originalRef = this.request.getOriginalRef();
        assertEquals(originalRef, new Reference(this.lastCreatedReference));
        assertEquals(expectedCut, resourceRef.toString());
        assertEquals(expectedExtensions, resourceRef.getExtensions());
    }
View Full Code Here

    /**
     * Test addition methods.
     */
    public void testAdditions() throws Exception {
        final Reference ref = new Reference("http://www.restlet.org");
        ref.addQueryParameter("abc", "123");
        assertEquals("http://www.restlet.org?abc=123", ref.toString());
        ref.addQueryParameter("def", null);
        assertEquals("http://www.restlet.org?abc=123&def", ref.toString());
        ref.addSegment("root");
        assertEquals("http://www.restlet.org/root?abc=123&def", ref.toString());
        ref.addSegment("dir");
        assertEquals("http://www.restlet.org/root/dir?abc=123&def",
                ref.toString());
    }
View Full Code Here

     * @see #createGet(String)
     * @see #createGetFromPath(String)
     */
    void createRequest(Method method, String reference) {
        this.request = new Request(method, reference);
        this.request.setOriginalRef(new Reference(reference));
        this.response = new Response(this.request);
        this.lastCreatedReference = reference;
        setPrefs();
        this.request.getClientInfo().setAgent(this.userAgent);
    }
View Full Code Here

        assertEquals("http://www.restlet.org/root/dir?abc=123&def",
                ref.toString());
    }

    public void testEmptyRef() {
        Reference reference = new Reference();
        reference.setAuthority("testAuthority"); // must not produce NPE

        reference = new Reference();
        reference.setBaseRef("http://localhost"); // must not produce NPE

        reference = new Reference();
        reference.setFragment("fragment"); // must not produce NPE

        reference = new Reference();
        reference.setHostDomain("localhost"); // must not produce NPE
        assertEquals("localhost", reference.getAuthority());
        reference.setHostPort(new Integer(4711)); // must not produce NPE
        assertEquals("localhost:4711", reference.getAuthority());
        reference.setUserInfo("sdgj:skdfj"); // must not produce NPE
        assertEquals("sdgj:skdfj@localhost:4711", reference.getAuthority());

        reference = new Reference();
        reference.setIdentifier("http://host/abc/wkj"); // must not produce NPE

        reference = new Reference();
        reference.setPath("loc/alhost"); // must not produce NPE

        reference = new Reference();
        reference.setProtocol(Protocol.HTTPS); // must not produce NPE

        reference = new Reference();
        reference.setQuery("a=b&c=&g=1"); // must not produce NPE

        reference = new Reference();
        reference.setRelativePart("http://localhost"); // must not produce NPE

        reference = new Reference();
        reference.setScheme("skjf"); // must not produce NPE

        reference = new Reference();
        reference.setSchemeSpecificPart("host/afjhsd"); // must not produce NPE

        reference = new Reference();
        final List<String> segments = new ArrayList<String>();
        segments.add("skhf");
        segments.add("sgdfg");
        segments.add("xiz");
        reference.setSegments(segments); // must not produce NPE
    }
View Full Code Here

                        item = childNode.getAttributes()
                                .getNamedItem("homeRef");

                        if (item != null) {
                            getComponent().getStatusService().setHomeRef(
                                    new Reference(item.getNodeValue()));
                        }

                        item = childNode.getAttributes().getNamedItem(
                                "overwrite");
View Full Code Here

    /**
     * Equality tests.
     */
    public void testEquals() throws Exception {
        final Reference ref1 = getDefaultReference();
        final Reference ref2 = getDefaultReference();
        assertEquals(ref1, ref2);
        assertTrue(ref1.equals(ref2));
    }
View Full Code Here

TOP

Related Classes of org.restlet.data.Reference

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.