Package org.restlet.resource

Examples of org.restlet.resource.Variant


  // to be overridden by subclasses if needed

  public List<Variant> getVariants() {
    ArrayList<Variant> result = new ArrayList<Variant>();

    result.add(new Variant(MediaType.APPLICATION_XML));

    result.add(new Variant(MediaType.APPLICATION_JSON));

    return result;
  }
View Full Code Here


      MediaType variantMediaType = null;

      boolean compatibleLanguage = false;
      boolean compatibleMediaType = false;

      Variant currentVariant = null;
      Variant bestVariant = null;

      Preference<Language> currentLanguagePref = null;
      Preference<Language> bestLanguagePref = null;
      Preference<MediaType> currentMediaTypePref = null;
      Preference<MediaType> bestMediaTypePref = null;
View Full Code Here

     */
    private boolean checkMetadataConsistency(String fileName,
            MetadataService metadataService, Representation representation) {
        boolean result = true;
        if (representation != null) {
            Variant var = new Variant();
            updateMetadata(metadataService, fileName, var);
            // "rep" contains the theorical correct metadata
            if (!representation.getLanguages().isEmpty()
                    && !var.getLanguages().containsAll(
                            representation.getLanguages())) {
                result = false;
            }
            if (representation.getMediaType() != null
                    && !(var.getMediaType() != null && var.getMediaType()
                            .includes(representation.getMediaType()))) {
                result = false;
            }
            if (!representation.getEncodings().isEmpty()
                    && !var.getEncodings().containsAll(
                            representation.getEncodings())) {
                result = false;
            }
        }
        return result;
View Full Code Here

    private Configuration _templateConfiguration;
   
    public ScriptResource(Context ctx, Request req, Response res) throws ResourceException {
        super(ctx, req, res);
        setModifiable(true);
        getVariants().add(new Variant(MediaType.TEXT_HTML));
        getVariants().add(new Variant(MediaType.APPLICATION_XML));
       
        Configuration tmpltCfg = new Configuration();
        tmpltCfg.setClassForTemplateLoading(this.getClass(),"");
        tmpltCfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
        setTemplateConfiguration(tmpltCfg);
View Full Code Here

                variants = super.getVariants();
            }
            // wrap FileRepresentations in EditRepresentations
            ListIterator<Variant> iter = variants.listIterator();
            while(iter.hasNext()) {
                Variant v = iter.next();
                if(v instanceof FileRepresentation) {
                    File file = ((FileRepresentation)v).getFile();
                    if(getEnhDirectory().allowsEdit(file)) {
                        iter.remove();
                        // any editable file for our purposes should
                        // be XML/UTF-8
                        v.setCharacterSet(CharacterSet.UTF_8);
                        iter.add(new EditRepresentation((FileRepresentation)v,this));
                    };
                }
            }
        } else if("paged".equals(format)) {
            ListIterator<Variant> iter = variants.listIterator();
            while(iter.hasNext()) {
                Variant v = iter.next();
                if(v instanceof FileRepresentation) {
                    File file = ((FileRepresentation)v).getFile();
                    if(getEnhDirectory().allowsPaging(file)) {
                        iter.remove();
                        iter.add(new PagedRepresentation((
View Full Code Here

public class ReportGenResource extends JobRelatedResource {
    protected String reportClass;
   
    public ReportGenResource(Context ctx, Request req, Response res) throws ResourceException {
        super(ctx, req, res);
        getVariants().add(new Variant(MediaType.TEXT_PLAIN));
        reportClass = (String)req.getAttributes().get("reportClass");
    }
View Full Code Here

    protected String beanPath;
    private Configuration _templateConfiguration;
   
    public BeanBrowseResource(Context ctx, Request req, Response res) throws ResourceException {
        super(ctx, req, res);
        getVariants().add(new Variant(MediaType.TEXT_HTML));
        getVariants().add(new Variant(MediaType.APPLICATION_XML));
        setModifiable(true); // accept POSTs
        appCtx = cj.getJobContext();
        beanPath = (String)req.getAttributes().get("beanPath");
        if (beanPath!=null) {
            try {
View Full Code Here

    public JobResource(Context ctx, Request req, Response res)
            throws ResourceException {
        super(ctx, req, res);
        setModifiable(true);
        getVariants().add(new Variant(MediaType.TEXT_HTML));
        getVariants().add(new Variant(MediaType.APPLICATION_XML));
        cj = getEngine().getJob(
                TextUtils.urlUnescape((String) req.getAttributes().get("job")));
       
        Configuration tmpltCfg = new Configuration();
        tmpltCfg.setClassForTemplateLoading(this.getClass(),"");
View Full Code Here

    private Configuration _templateConfiguration;
    public EngineResource(Context ctx, Request req, Response res) {
        super(ctx, req, res);
        setModifiable(true);
        getVariants().add(new Variant(MediaType.TEXT_HTML));
        getVariants().add(new Variant(MediaType.APPLICATION_XML));
       
        Configuration tmpltCfg = new Configuration();
        tmpltCfg.setClassForTemplateLoading(this.getClass(),"");       
        tmpltCfg.setObjectWrapper(new DefaultObjectWrapper());
        setTemplateConfiguration(tmpltCfg);
View Full Code Here

    public static final Variant CSV = new Variant(CSV_MEDIA_TYPE);

    public static Optional<Variant> getVariantByExtension(Request request, List<Variant> supported) {
        String extension = RESTUtils.getStringAttribute(request, "extension");
        Variant v = null;
        if ("xml".equals(extension) && supported.contains(XML)) {
            v = XML;
        } else if ("json".equals(extension) && supported.contains(JSON)) {
            v = JSON;
        } else if ("csv".equals(extension) && supported.contains(CSV)) {
View Full Code Here

TOP

Related Classes of org.restlet.resource.Variant

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.