Package org.restlet.routing

Examples of org.restlet.routing.Template


     * @see javax.ws.rs.core.UriBuilder#buildFromEncoded(java.lang.Object[])
     */
    @Override
    public URI buildFromEncoded(Object... values)
            throws IllegalArgumentException, UriBuilderException {
        final Template template = new Template(toStringWithCheck(false));
        return buildUri(template
                .format(new ArrayVariableResolver(values, false)));
    }
View Full Code Here


     * @see javax.ws.rs.core.UriBuilder#build(java.util.Map)
     */
    private URI buildFromMap(final Map<String, ? extends Object> values,
            final boolean encode) throws IllegalArgumentException,
            UriBuilderException {
        final Template template = new Template(toStringWithCheck(false));
        return buildUri(template.format(new Resolver<String>() {
            @Override
            public String resolve(String variableName) {
                final Object varValue = values.get(variableName);
                if (varValue == null) {
                    throw new IllegalArgumentException(
View Full Code Here

     * @see javax.ws.rs.core.UriBuilder#build(java.lang.Object[])
     */
    @Override
    public URI build(Object... values) throws IllegalArgumentException,
            UriBuilderException {
        final Template template = new Template(toStringWithCheck(false));
        return buildUri(template
                .format(new ArrayVariableResolver(values, true)));
    }
View Full Code Here

        // Can only match entitySet and entity from the the target URI
        String entitySet = "{service}.svc/{entitySet}";
        String entity = entitySet + "({keyPredicate})";

        Template t = new Template(entity, Template.MODE_EQUALS);
        t.getVariables().put("entitySet",
                new Variable(Variable.TYPE_ALL, "", true, false));
        t.getVariables().put("keyPredicate",
                new Variable(Variable.TYPE_ALL, "", true, false));

        if (t.match(uri) != -1) {
            return TYPE_ENTITY;
        }

        t.setPattern(entitySet);
        if (t.match(uri) != -1) {
            return TYPE_ENTITY_SET;
        }

        return type;
    }
View Full Code Here

  
   public Representation get(final Identity identity,final Form form)
   {
      if (identity==null) {
         try {
            final Template template = new Template(LoginAction.toString(LoginView.class.getResourceAsStream("templates/login-form.xml")));
            String action = getRequest().getResourceRef().getPath();
            if (!getRequest().isConfidential()) {
               Reference base = ActionResource.getReferenceAttribute(getRequest(), "secure-base", confSecureBase);
               if (base==null) {
                  getLogger().warning("The secure-base link is missing login.");
               } else {
                  action = base+action.substring(1);
               }
            }
            final String formAction = action;
            final String url = form.getFirstValue("url")==null ? getRequest().getResourceRef().toString() : form.getFirstValue("url");
            final String result = template.format(new Resolver<String>() {
               public String resolve(String name) {
                  if (name.equals("action")) {
                     return formAction;
                  } else if (name.equals("url")) {
                     return url;
                  } else {
                     return form.getFirstValue(name);
                  }
               }
            });
            return new OutputRepresentation(MediaType.APPLICATION_XHTML_XML) {
               public void write(OutputStream os)
                  throws IOException
               {
                  OutputStreamWriter w = new OutputStreamWriter(os,"UTF-8");
                  w.write(result);
                  w.flush();
               }
            };
         } catch (IOException ex) {
            getLogger().log(Level.SEVERE,"Cannot get template.",ex);
            return null;
         }
      } else {
         try {
            final Template template = new Template(LoginAction.toString(LoginView.class.getResourceAsStream("templates/logged-in.xml")));
            final String result = template.format(new Resolver<String>() {
               public String resolve(String name) {
                  if (name.equals("id")) {
                     return identity.getId();
                  } else if (name.equals("alias")) {
                     return identity.getAlias();
View Full Code Here

            return null;
         }
         try {
            InputStream is = UploadApplication.class.getResourceAsStream("upload.html");
            Reader r = new InputStreamReader(is,"UTF-8");
            Template template = new Template(UploadApplication.toString(r));
            String result = template.format(new Resolver<String>() {
               public String resolve(String name) {
                  if (name.equals("action")) {
                     return getRequest().getResourceRef().getPath();
                  } else if (name.equals("submit")) {
                     return progress.submit;
View Full Code Here

         }
         if (entry.match!=null) {
            if (isFineLog) {
               log.fine("Checking "+entry.match+" against path "+path);
            }
            Template template = new Template(entry.match);
            if (template.match(path)<0) {
               continue;
            }
            if (isFineLog) {
               log.fine("Matched layout entry "+entry.getId()+" using URI match "+entry.match);
            }
View Full Code Here

      getLogger().info("resource template: "+resourceTemplate);
      if (resource==null && resourceTemplate!=null) {
         String href = null;
         String uri = null;
         try {
            Template t = new Template(resourceTemplate);
            href = t.format(request.getAttributes());
            String baseURISpec = resourceProperties.getProperty("base-uri");
            URI baseURI = null;
            if (baseURISpec!=null) {
               Template tbase = new Template(baseURISpec);
               uri = tbase.format(request.getAttributes());
               baseURI = new URI(uri);
            }

            resource = baseURI==null ? new URI(href) : baseURI.resolve(href);
         } catch (URISyntaxException ex) {
            getLogger().log(Level.SEVERE,"Cannot construct resource URI, href="+href+", base="+uri,ex);
            return null;
         }
      }
     
      String [] agents = null;
      if (agentsValue!=null) {
         agents = agentsValue.split(",");
      }
     
      MediaType forceType = null;

      if (type==null && extPos>=0) {
         String ext = path.substring(extPos+1);
         Metadata mdata = this.getApplication().getMetadataService().getMetadata(ext);
         if (mdata!=null) {
            type = MediaType.valueOf(mdata.getName());
         }
      } else if (path.length()==0 || path.charAt(path.length()-1)=='/') {
         // no extension and is a directory path, default to index.xml template
         script = baseClass.getResource(packageName+path+"index.ats");
         if (script==null) {
            script = baseClass.getResource(packageName+path+"index.xsl");
         }
         if (resource==null) {
            try {
               URL url = baseClass.getResource(packageName+path + "index.xml");
               /*
               if (url==null) {
                  getLogger().warning("Canot find resource via class path: "+path+"index.xml");
                  return null;
               }
               resource = url.toURI();
                */
               if (url!=null) {
                  resource = url.toURI();
               }
            } catch (URISyntaxException ex) {
               getLogger().log(Level.SEVERE,"Cannot convert URL to URI: "+path,ex);
               return null;
            }
         }
         if (type==null && agents!=null) {
            String agent = request.getClientInfo().getAgent();
            for (int i=0; i<agents.length; i++) {
               String exp = resourceProperties.getProperty(agents[i]+".match");
               if (agent.matches(exp)) {
                  if (getLogger().isLoggable(Level.FINE)) {
                     getLogger().fine("Matched agent "+agent+" with "+agents[i]);
                  }
                  stype = resourceProperties.getProperty(agents[i]+".content-type");
                  forceType = stype==null ? null : MediaType.valueOf(stype);
                  break;
               }
            }
         }
         if (type==null) {
            type = MediaType.APPLICATION_XHTML_XML;
         }
      } else {
         // no extension, so lookup based on xml file
         script = baseClass.getResource(packageName+path+defaultExtension);
         if (script==null) {
            script = baseClass.getResource(packageName+path+".xsl");
         }
         if (resource==null) {
            try {
               URL url = baseClass.getResource(packageName+path + ".xml");
               /*
               if (url==null) {
                  getLogger().warning("Canot find resource via class path: "+path+".xml");
                  return null;
               }
               resource = url.toURI();
                */
               if (url!=null) {
                  resource = url.toURI();
               }
            } catch (URISyntaxException ex) {
               getLogger().log(Level.SEVERE,"Cannot convert URL to URI: "+path);
               return null;
            }
         }
         if (type==null && agents!=null) {
            String agent = request.getClientInfo().getAgent();
            for (int i=0; i<agents.length; i++) {
               String exp = resourceProperties.getProperty(agents[i]+".match");
               if (agent.matches(exp)) {
                  stype = resourceProperties.getProperty(agents[i]+".content-type");
                  forceType = stype==null ? null : MediaType.valueOf(stype);
                  break;
               }
            }
         }
         if (type==null) {
            type = MediaType.APPLICATION_XHTML_XML;
         }
      }
      if (type==null) {
         type = app.getMetadataService().getDefaultMediaType();
      }
      boolean isResource = (type.getMainType().equals("image") || (script==null && type.getMainType().equals("text")) || (type.getMainType().equals("application") && !type.getName().equals("application/xml") && !type.getName().endsWith("+xml")));
      String sflag = resourceProperties.getProperty("force-resource");
      if (sflag!=null && sflag.equals("true")) {
         isResource = true;
      }
      sflag = resourceProperties.getProperty("force-script");
      if (sflag!=null && sflag.equals("true")) {
         isResource = false;
      }
      if (isResource) {
         if (getLogger().isLoggable(Level.FINE)) {
            getLogger().fine("Path is a resource: "+path+" "+type.getName());
         }
         path = packageName+path;
         return new ClassResource(baseClass,path);
      } else {
         if (forceType!=null) {
            type = forceType;
         }
         if (script==null) {
            String uri = resourceProperties.getProperty("script");
            if (uri!=null) {
               Template t = new Template(uri);
               String formatted = t.format(request.getAttributes());
               try {
                  script = new URL(formatted);
               } catch (MalformedURLException ex) {
                  getLogger().log(Level.SEVERE,"Cannot convert script to URL: "+uri,ex);
                  return null;
View Full Code Here

  
   public class SecureRoute {
      Template template;
      SecureArea area;
      SecureRoute(String uriPattern,SecureArea area) {
         this.template = new Template(uriPattern,Template.MODE_STARTS_WITH,Variable.TYPE_URI_SEGMENT,"",true,false);
         this.area = area;
      }
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.