Package org.restlet.representation

Examples of org.restlet.representation.Variant


                // Set the list of extensions, due to the file name and the
                // default metadata.
                // TODO It seems we could handle more clearly the equivalence
                // between the file name space and the target resource (URI
                // completed by default metadata)
                Variant variant = new Variant();
                Entity.updateMetadata(file.getName(), variant, false,
                        getMetadataService());
                Collection<String> extensions = Entity.getExtensions(variant,
                        getMetadataService());
View Full Code Here


                Entity uniqueVariant = null;

                // 1- set up base name as the longest part of the name without
                // known extensions (beginning from the left)
                String baseName = entity.getBaseName();
                Variant entityVariant = entity.getVariant();

                // 2- looking for resources with the same base name
                Entity parent = entity.getParent();
                if (parent != null) {
                    Collection<Entity> files = parent.getChildren();

                    if (files != null) {
                        for (Entity entry : files) {
                            if (baseName.equals(entry.getBaseName())) {
                                Variant entryVariant = entry.getVariant();

                                if (entityVariant.isCompatible(entryVariant)) {
                                    // The right representation has been found.
                                    uniqueVariant = entry;
                                    break;
View Full Code Here

     * Returns a variant corresponding to the extensions of this entity.
     *
     * @return A variant corresponding to the extensions of this entity.
     */
    public Variant getVariant() {
        Variant result = new Variant();
        updateMetadata(getName(), result, true, getMetadataService());
        return result;
    }
View Full Code Here

                            if (result == null) {
                                result = new ArrayList<Variant>();
                            }

                            for (MediaType mediaType : mediaTypes) {
                                result.add(new Variant(mediaType));
                            }
                        }
                    }
                }
            }
View Full Code Here

                                    || (!result.contains(mediaType))) {
                                if (result == null) {
                                    result = new ArrayList<Variant>();
                                }

                                result.add(new Variant(mediaType));
                            }
                        }
                    }
                }
            }
View Full Code Here

* Simple resource that returns at least text/html and text/xml representations.
*/
public class UserAgentTestResource extends ServerResource {

    public UserAgentTestResource() {
        getVariants().add(new Variant(MediaType.TEXT_XML));
        getVariants().add(new Variant(MediaType.TEXT_HTML));
    }
View Full Code Here

public class ChunkedEncodingTestCase extends BaseConnectorsTestCase {

    public static class PutTestResource extends ServerResource {

        public PutTestResource() {
            getVariants().add(new Variant(MediaType.TEXT_XML));
            setNegotiated(false);

        }
View Full Code Here

                                            resource.getMetadataService());
                        } else {
                            target = variants.get(0);
                        }
                    } else {
                        target = new Variant();
                    }
                }

                result = ch.toRepresentation(source, target, resource);
View Full Code Here

    public static class RemoteClientAddressResource extends ServerResource {

        public RemoteClientAddressResource() {

            getVariants().add(new Variant(MediaType.TEXT_PLAIN));
        }
View Full Code Here

                new Preference<Language>(Language.FRENCH_FRANCE, 0.9F));
        ci.getAcceptedMediaTypes().add(
                new Preference<MediaType>(MediaType.TEXT_XML, 1.0F));

        List<Variant> variants = new ArrayList<Variant>();
        variants.add(new Variant(MediaType.TEXT_XML, Language.ENGLISH_US));
        variants.add(new Variant(MediaType.TEXT_XML, Language.FRENCH_FRANCE));
        Variant pv = ci.getPreferredVariant(variants, ms);

        assertEquals(MediaType.TEXT_XML, pv.getMediaType());
        assertEquals(Language.ENGLISH_US, pv.getLanguages().get(0));

        // Leveraging parent languages
        variants.clear();
        variants.add(new Variant(MediaType.TEXT_XML, Language.ENGLISH));
        variants.add(new Variant(MediaType.TEXT_XML, Language.FRENCH));
        pv = ci.getPreferredVariant(variants, ms);

        assertEquals(MediaType.TEXT_XML, pv.getMediaType());
        assertEquals(Language.ENGLISH, pv.getLanguages().get(0));

        // Testing quality priority over parent metadata
        variants.clear();
        variants.add(new Variant(MediaType.TEXT_PLAIN, Language.ENGLISH));
        variants.add(new Variant(MediaType.TEXT_XML, Language.FRENCH_FRANCE));
        pv = ci.getPreferredVariant(variants, ms);

        assertEquals(MediaType.TEXT_XML, pv.getMediaType());
        assertEquals(Language.FRENCH_FRANCE, pv.getLanguages().get(0));

        // Testing quality priority over parent metadata
        variants.clear();
        variants.add(new Variant(MediaType.APPLICATION_XML, Language.ENGLISH_US));
        variants.add(new Variant(MediaType.TEXT_XML, Language.FRENCH_FRANCE));
        pv = ci.getPreferredVariant(variants, ms);

        assertEquals(MediaType.TEXT_XML, pv.getMediaType());
        assertEquals(Language.FRENCH_FRANCE, pv.getLanguages().get(0));

        // Leveraging parent media types
        variants.clear();
        variants.add(new Variant(MediaType.APPLICATION_XML, Language.ENGLISH_US));
        variants.add(new Variant(MediaType.APPLICATION_XML,
                Language.FRENCH_FRANCE));
        pv = ci.getPreferredVariant(variants, ms);

        assertEquals(MediaType.APPLICATION_XML, pv.getMediaType());
        assertEquals(Language.ENGLISH_US, pv.getLanguages().get(0));

    }
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.