Package org.restlet.representation

Examples of org.restlet.representation.Variant


public class ConfigResource extends ServerResource {
  private final static Logger LOG = Logger.getLogger(ConfigResource.class);

  public ConfigResource() {
    getVariants().add(new Variant(MediaType.TEXT_PLAIN));
    getVariants().add(new Variant(MediaType.APPLICATION_JSON));
    setNegotiated(false);
  }
View Full Code Here


                        }
                    }

                    if (this.baseName != null) {
                        // Analyze extensions
                        this.baseVariant = new Variant();
                        Entity.updateMetadata(this.baseName, this.baseVariant,
                                true, getMetadataService());
                        this.protoVariant = new Variant();
                        Entity.updateMetadata(this.baseName, this.protoVariant,
                                false, getMetadataService());

                        // Remove stored extensions from the base name
                        this.baseName = Entity.getBaseName(this.baseName,
View Full Code Here

                        // Check if the current file is a valid variant
                        if (baseEntryName.equals(this.baseName)) {
                            // Test if the variant is included in the base
                            // prototype variant
                            Variant variant = new Variant();
                            Entity.updateMetadata(fullEntryName, variant, true,
                                    getMetadataService());
                            if (this.protoVariant.includes(variant)) {
                                result.add(ref);
                            }
View Full Code Here

    @Override
    public long getSize(Object object, Class<?> type, Type genericType,
            Annotation[] annotations, MediaType mediaType) {

        // Convert the object into a representation
        Variant targetVariant = new Variant(new org.restlet.data.MediaType(
                mediaType.toString()));
        Representation representation = getConverterService().toRepresentation(
                object, targetVariant, null);
        return (representation == null) ? -1 : representation.getSize();
    }
View Full Code Here

    @Override
    public boolean isReadable(Class<?> type, Type genericType,
            Annotation[] annotations, MediaType mediaType) {

        Variant sourceVariant = new Variant(new org.restlet.data.MediaType(
                mediaType.toString()));
        List<Class<?>> classes = getConverterService().getObjectClasses(
                sourceVariant);

        for (Class<?> clazz : classes) {
View Full Code Here

    }

    @Override
    public boolean isWriteable(Class<?> type, Type genericType,
            Annotation[] annotations, MediaType mediaType) {
        Variant targetVariant = new Variant(new org.restlet.data.MediaType(
                mediaType.toString()));
        List<? extends Variant> variants = getConverterService().getVariants(
                type, targetVariant);
        return (variants != null) && !variants.isEmpty();
    }
View Full Code Here

            Annotation[] annotations, MediaType mediaType,
            MultivaluedMap<String, Object> httpHeaders,
            OutputStream entityStream) throws IOException {

        // Convert the object into a representation
        Variant targetVariant = new Variant(new org.restlet.data.MediaType(
                mediaType.toString()));
        Representation representation = getConverterService().toRepresentation(
                object, targetVariant, null);

        // Copy entity headers (NOT SUPPORTED)
View Full Code Here

     * @see <a
     *      href="http://httpd.apache.org/docs/2.2/en/content-negotiation.html#algorithm">Apache
     *      content negotiation algorithm</a>
     */
    public Variant getPreferredVariant(List<? extends Variant> variants) {
        Variant result = null;

        if ((variants != null) && !variants.isEmpty()) {
            float bestScore = -1.0F;
            float current;

View Full Code Here

*/
public class JaxbBasicConverterTestCase extends RestletTestCase {

    public void testObjectionToRepresentation() {
        ConverterService cs = new ConverterService();
        Representation rep = cs.toRepresentation(new Sample(), new Variant(
                MediaType.APPLICATION_XML), null);
        assertTrue(rep instanceof JaxbRepresentation<?>);
    }
View Full Code Here

    private boolean checkMetadataConsistency(String fileName,
            Representation representation) {
        boolean result = true;

        if (representation != null) {
            Variant var = new Variant();
            Entity.updateMetadata(fileName, var, false, getMetadataService());

            // "var" contains the theoretical correct metadata
            if (!var.getLanguages().isEmpty()
                    && !representation.getLanguages().isEmpty()
                    && !var.getLanguages().containsAll(
                            representation.getLanguages())) {
                result = false;
            }

            if ((var.getMediaType() != null)
                    && (representation.getMediaType() != null)
                    && !(var.getMediaType().includes(representation
                            .getMediaType()))) {
                result = false;
            }

            if (!var.getEncodings().isEmpty()
                    && !representation.getEncodings().isEmpty()
                    && !var.getEncodings().containsAll(
                            representation.getEncodings())) {
                result = false;
            }
        }
        return result;
View Full Code Here

TOP

Related Classes of org.restlet.representation.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.