Package org.restlet.routing

Examples of org.restlet.routing.Template


     *            The identifier of a mail.
     * @return The URI of the mail.
     * @throws ResourceException
     */
    protected Reference getMailRef(String identifier) throws ResourceException {
        final Template mailTemplate = new Template(getMailUriTemplate());
        Reference result = new Reference(mailTemplate.format(new MailResolver(
                identifier)));

        if (result.isRelative()) {
            result.setBaseRef(getMailboxUri());
            result = result.getTargetRef();
View Full Code Here


     * @return The target reference.
     * @throws ResourceException
     */
    protected Reference getTargetRef(Resolver<String> resolver)
            throws ResourceException {
        final Template targetTemplate = new Template(getTargetUri());
        Reference result = new Reference(targetTemplate.format(resolver));

        if (result.isRelative()) {
            result.setBaseRef(getMailboxUri());
            result = result.getTargetRef();
        }
View Full Code Here

                                        "Both targetClass name and targetDescriptor are missing. Couldn't attach a new route.");
                    }
                }

                if (route != null) {
                    Template template = route.getTemplate();
                    item = childNode.getAttributes().getNamedItem(
                            "matchingMode");
                    template.setMatchingMode(getInt(item,
                            router.getDefaultMatchingMode()));
                    item = childNode.getAttributes().getNamedItem(
                            "defaultVariableType");
                    template.getDefaultVariable().setType(
                            getInt(item, Variable.TYPE_URI_SEGMENT));

                    // Parse possible parameters specific to this AttachType
                    final NodeList childNodes2 = childNode.getChildNodes();
                    for (int j = 0; j < childNodes2.getLength(); j++) {
View Full Code Here

* @author Jerome Louvel
*/
public class TemplateTestCase extends RestletTestCase {

    public void testEncodedCharacters() {
        Template template = new Template(
                "http://localhost/{token}/bookstore/{bookid}");
        String encodedToken = "FtDF91VSX%2F7AN6C39k51ZV510SW%2Fot6SIGstq8XGCcHfOfHbZOZLUD4u%2BGUNK0bBawVZ4GR5TgV7PtRbF%2Bnm9abYJN6AWycdj9J6CLyU4D7Zou36KEjkel%2B0LtlGGhFPVrCvpBuqPy8V8o5IZ9tDys0Py6sXXAtEVbXBYeRYzOvIBzOZkIviIyceVCU%2BlYv%2Fh9k7Fhlb1JGtKUCj3ZDg%2FvJ1Co7dOC1Ho3%2Fe0Fup7k9qgTuCvZRSHcpizaEFPNLp";
        String targetUri = "http://localhost/" + encodedToken
                + "/bookstore/1234";

        Map<String, Object> variables1 = new HashMap<String, Object>();
        int parsed1 = template.parse(targetUri, variables1);
        assertTrue("parsing of " + targetUri
                + " not successful, but it should be.", parsed1 >= 0);
        assertEquals(encodedToken, variables1.get("token"));
    }
View Full Code Here

                + " not successful, but it should be.", parsed1 >= 0);
        assertEquals(encodedToken, variables1.get("token"));
    }

    public void testPathMatching() {
        Template template = new Template("http://www.mydomain.com/abc/{v1}");
        template.setMatchingMode(Template.MODE_STARTS_WITH);
        template.getDefaultVariable().setType(Variable.TYPE_URI_PATH);

        Map<String, Object> variables1 = new HashMap<String, Object>();
        String string1 = "http://www.mydomain.com/abc/123/456";
        int parsed1 = template.parse(string1, variables1);
        assertTrue("parsing of " + string1
                + " not successful, but it should be.", parsed1 >= 0);
        assertEquals("123/456", variables1.get("v1"));

        Map<String, Object> variables2 = new HashMap<String, Object>();
        String string2 = "http://www.mydomain.com/abc/123/456?s=tuv";
        int parsed2 = template.parse(string2, variables2);
        assertTrue("parsing of " + string2
                + " not successful, but it should be.", parsed2 >= 0);
        assertEquals("123/456", variables2.get("v1"));

        Map<String, Object> variables3 = new HashMap<String, Object>();
        String string3 = "http://www.mydomain.com/abc/123/456#tuv";
        int parsed3 = template.parse(string3, variables3);
        assertTrue("parsing of " + string3
                + " not successful, but it should be.", parsed3 >= 0);
        assertEquals("123/456", variables3.get("v1"));
    }
View Full Code Here

                + " not successful, but it should be.", parsed3 >= 0);
        assertEquals("123/456", variables3.get("v1"));
    }

    public void testVariableNames() throws Exception {
        Template tpl = new Template(
                "http://{userId}.noelios.com/invoices/{invoiceId}");
        tpl.setLogger(Engine.getAnonymousLogger());
        List<String> names = tpl.getVariableNames();

        assertEquals(2, names.size());
        assertEquals("userId", names.get(0));
        assertEquals("invoiceId", names.get(1));
    }
View Full Code Here

        assertEquals("userId", names.get(0));
        assertEquals("invoiceId", names.get(1));
    }

    public void testWithPercentChars() {
        Template template = new Template("abc/{v1}");
        template.getDefaultVariable().setType(Variable.TYPE_URI_ALL);
        Map<String, Object> variables1 = new HashMap<String, Object>();
        String string1 = "abc/hff11kh";
        int parsed1 = template.parse(string1, variables1);
        assertTrue("parsing of " + string1
                + " not successful, but it should be.", parsed1 >= 0);
        assertEquals("hff11kh", variables1.get("v1"));

        Map<String, Object> variables2 = new HashMap<String, Object>();
        String string2 = "abc/hf%20kh";
        int parsed2 = template.parse(string2, variables2);
        assertTrue("parsing of " + string2
                + " not successful, but it should be.", parsed2 >= 0);
        assertEquals("hf%20kh", variables2.get("v1"));
    }
View Full Code Here

     *            The URI template of loggable resource references.
     * @see #setLoggableTemplate(Template)
     */
    public void setLoggableTemplate(String loggableTemplateRef) {
        if (loggableTemplateRef != null) {
            this.loggableTemplate = new Template(loggableTemplateRef);
        } else {
            this.loggableTemplate = null;
        }
    }
View Full Code Here

    @Override
    public synchronized void start() throws Exception {
        super.start();

        this.responseLogTemplate = (getLogFormat() == null) ? null
                : new Template(getLogFormat());

        if (getLogPropertiesRef() != null) {
            Representation logProperties = new ClientResource(getContext(),
                    getLogPropertiesRef()).get();
View Full Code Here

        String targetUri = request.getResourceRef().toString(true, false);

        if (targetUri.contains("{")) {
            // Template URI detected, create the template
            Template template = new Template(targetUri);

            // Set the formatted target URI
            request.setResourceRef(template.format(request, response));
        }

        // Actually handle the formatted URI
        doHandle(request, response);
View Full Code Here

TOP

Related Classes of org.restlet.routing.Template

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.