Package org.restlet.ext.freemarker

Examples of org.restlet.ext.freemarker.TemplateRepresentation


        myConfig.setClassForTemplateLoading(c, "");
        myType = type;
    }

    public Representation makeRepresentation(Object context){
        return new TemplateRepresentation(myTemplateFileName, myConfig, context, myType);
    }
View Full Code Here


        throw new UnsupportedOperationException();
    }
   
    @Override
    public Representation toRepresentation(Object object) {
        return new TemplateRepresentation(myTemplateFileName, myConfig, object, mediaType);
    }
View Full Code Here

        else {
            //use a fallback
            templateName = "Object.ftl";
        }
       
        return new TemplateRepresentation( templateName, configuration, object, getMediaType() );
    }
View Full Code Here

        final Configuration fmc = new Configuration();
        fmc.setDirectoryForTemplateLoading(testDir);
        final Map<String, Object> map = new TreeMap<String, Object>();
        map.put("value", "myValue");

        final String result = new TemplateRepresentation(testFile.getName(),
                fmc, map, MediaType.TEXT_PLAIN).getText();
        assertEquals("Value=myValue", result);

        // Clean-up
        BioUtils.delete(testFile);
View Full Code Here

     * @return the representation.
     */
    protected Representation getTemplateRepresentation(String templateName,
            Map<String, Object> dataModel, MediaType mediaType) {
        // The template representation is based on Freemarker.
        return new TemplateRepresentation(templateName, getFmcConfiguration(),
                dataModel, mediaType);
    }
View Full Code Here

        ContextTemplateLoader ctl = new ContextTemplateLoader(getContext(),
                "clap:///");
        config.setTemplateLoader(ctl);
        getLogger().info("loading: " + authPage);
        TemplateRepresentation result = new TemplateRepresentation(authPage,
                config, MediaType.TEXT_HTML);

        // Build the model
        HashMap<String, Object> data = new HashMap<String, Object>();

        data.put("target", getRootRef() + OAuthHelper.getAuthPage(getContext()));

        // TODO check with Restlet lead
        data.put("clientId", clientId);
        data.put("clientDescription", client.toString());
        data.put("clientCallback", client.getRedirectUri());
        data.put("clientName", client.getApplicationName());
        // scopes
        data.put("requestingScopes", scopes);
        data.put("grantedScopes", previousScopes);

        result.setDataModel(data);
        return result;
    }
View Full Code Here

                    dataModel.put("schema", schema);
                    dataModel.put("metadata", metadata);
                    dataModel.put("className", className);
                    dataModel.put("packageName", packageName);

                    TemplateRepresentation templateRepresentation = new TemplateRepresentation(
                            entityTmpl, fmc, dataModel, MediaType.TEXT_PLAIN);
                    templateRepresentation.setCharacterSet(CharacterSet.UTF_8);

                    // Write the template representation as a Java class
                    templateRepresentation.write(new FileOutputStream(new File(
                            packageDir, type.getClassName() + ".java")));
                }
                for (ComplexType type : schema.getComplexTypes()) {
                    String className = type.getClassName();
                    Map<String, Object> dataModel = new HashMap<String, Object>();
                    dataModel.put("type", type);
                    dataModel.put("schema", schema);
                    dataModel.put("metadata", metadata);
                    dataModel.put("className", className);
                    dataModel.put("packageName", packageName);

                    TemplateRepresentation templateRepresentation = new TemplateRepresentation(
                            complexTmpl, fmc, dataModel, MediaType.TEXT_PLAIN);
                    templateRepresentation.setCharacterSet(CharacterSet.UTF_8);

                    // Write the template representation as a Java class
                    templateRepresentation.write(new FileOutputStream(new File(
                            packageDir, type.getClassName() + ".java")));
                }
            }
        }
        if (metadata.getContainers() != null
                && !metadata.getContainers().isEmpty()) {
            for (EntityContainer entityContainer : metadata.getContainers()) {
                Schema schema = entityContainer.getSchema();
                // Generate Service subclass
                StringBuffer className = new StringBuffer();

                if (serviceClassName != null) {
                    // Try to use the Client preference
                    if (entityContainer.isDefaultEntityContainer()) {
                        className.append(serviceClassName);
                    } else if (metadata.getContainers().size() == 1) {
                        className.append(serviceClassName);
                    } else {
                        className.append(schema.getNamespace()
                                .getNormalizedName().substring(0, 1)
                                .toUpperCase());
                        className.append(schema.getNamespace()
                                .getNormalizedName().substring(1));
                        className.append("Service");
                    }
                } else {
                    className.append(schema.getNamespace().getNormalizedName()
                            .substring(0, 1).toUpperCase());
                    className.append(schema.getNamespace().getNormalizedName()
                            .substring(1));
                    className.append("Service");
                }

                Map<String, Object> dataModel = new HashMap<String, Object>();
                dataModel.put("schema", schema);
                dataModel.put("metadata", metadata);
                dataModel.put("className", className);
                dataModel.put("dataServiceUri", this.serviceRef.getTargetRef());
                dataModel.put("entityContainer", entityContainer);

                TemplateRepresentation templateRepresentation = new TemplateRepresentation(
                        serviceTmpl, fmc, dataModel, MediaType.TEXT_PLAIN);
                templateRepresentation.setCharacterSet(CharacterSet.UTF_8);

                // Write the template representation as a Java class
                templateRepresentation.write(new FileOutputStream(new File(
                        outputDir, className + ".java")));
            }
        }
    }
View Full Code Here

        MediaType actualMediaType = mediaType;
        if (actualMediaType == null) {
            actualMediaType = defaultMediaType;
        }
        try {
            return new TemplateRepresentation(freemarkerConfig.getTemplate(templateName), dataModel, actualMediaType);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here

        else {
            //use a fallback
            templateName = "Object.ftl";
        }
       
        return new TemplateRepresentation( templateName, configuration, object, getMediaType() );
    }
View Full Code Here

        throw new UnsupportedOperationException();
    }
   
    @Override
    public Representation toRepresentation(Object object) {
        return new TemplateRepresentation(myTemplateFileName, myConfig, object, mediaType);
    }
View Full Code Here

TOP

Related Classes of org.restlet.ext.freemarker.TemplateRepresentation

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.