Package org.restlet.data

Examples of org.restlet.data.Metadata


     *            The target metadata type.
     * @return The metadata associated to this extension.
     */
    public <T extends Metadata> T getMetadata(String extension,
            Class<T> metadataType) {
        Metadata metadata = getMetadata(extension);

        if (metadata != null
                && metadataType.isAssignableFrom(metadata.getClass())) {
            return metadataType.cast(metadata);
        }

        return null;
    }
View Full Code Here


     */
    public static void updateMetadata(String entryName, Variant variant,
            boolean applyDefault, MetadataService metadataService) {
        if (variant != null) {
            String[] tokens = entryName.split("\\.");
            Metadata current;

            // We found a potential variant
            for (int j = 1; j < tokens.length; j++) {
                current = metadataService.getMetadata(tokens[j]);

                if (current != null) {
                    // Metadata extension detected
                    if (current instanceof MediaType) {
                        variant.setMediaType((MediaType) current);
                    } else if (current instanceof CharacterSet) {
                        variant.setCharacterSet((CharacterSet) current);
                    } else if (current instanceof Encoding) {
                        // Do we need to add this metadata?
                        boolean found = false;
                        for (int i = 0; !found
                                && i < variant.getEncodings().size(); i++) {
                            found = current.includes(variant.getEncodings()
                                    .get(i));
                        }
                        if (!found) {
                            variant.getEncodings().add((Encoding) current);
                        }
                    } else if (current instanceof Language) {
                        // Do we need to add this metadata?
                        boolean found = false;
                        for (int i = 0; !found
                                && i < variant.getLanguages().size(); i++) {
                            found = current.includes(variant.getLanguages()
                                    .get(i));
                        }
                        if (!found) {
                            variant.getLanguages().add((Language) current);
                        }
View Full Code Here

                // encoding, one character set.
                while (true) {
                    final int lastIndexOfPoint = extensions.lastIndexOf('.');
                    final String extension = extensions
                            .substring(lastIndexOfPoint + 1);
                    final Metadata metadata = getMetadata(extension);

                    if (!mediaTypeFound && (metadata instanceof MediaType)) {
                        updateMetadata(clientInfo, metadata);
                        mediaTypeFound = true;
                    } else if (!languageFound && (metadata instanceof Language)) {
View Full Code Here

                String acceptedMediaType = query
                        .getFirstValue(mediaTypeParameter);

                // Updates the client preferences
                ClientInfo clientInfo = request.getClientInfo();
                Metadata metadata = getMetadata(acceptedCharSet);

                if ((metadata == null) && (acceptedCharSet != null)) {
                    metadata = CharacterSet.valueOf(acceptedCharSet);
                }
View Full Code Here

        MetadataService metadataService;
        metadataService = Application.getCurrent().getMetadataService();
        StringTokenizer stt = new StringTokenizer(extensions, ".");
        while (stt.hasMoreTokens()) {
            String extension = stt.nextToken();
            Metadata metadata = metadataService.getMetadata(extension);
            if (metadata instanceof Language) {
                this.extensionLanguage = extension;
            } else if (metadata instanceof MediaType) {
                this.extensionMedia = extension;
            } else {
View Full Code Here

     * @param metadatas
     * @return the name of the Metadata
     * @see #getOnlyElement(List)
     */
    public static String getOnlyMetadataName(List<? extends Metadata> metadatas) {
        final Metadata metadata = getOnlyElement(metadatas);
        if (metadata == null) {
            return null;
        }
        return metadata.getName();
    }
View Full Code Here

                        // create new media
                        try {
                           FileInputStream is = new FileInputStream(file);
                           int extPos = file.getName().lastIndexOf('.');
                           String ext = extPos<0 ? null : file.getName().substring(extPos+1);
                           Metadata metadata = ext==null ? null : metadataService.getMetadata(ext);
                           MediaType type = metadata==null ? MediaType.APPLICATION_OCTET_STREAM : MediaType.valueOf(metadata.getName());
                           Entry mediaEntry = feedClient.createMedia(file.getName(),new InputRepresentation(is,type));
                           is.close();
                        } catch (StatusException ex) {
                           log.log(Level.SEVERE,"Cannot create media entry from "+file+" due to status "+ex.getStatus().getCode(),ex);
                        } catch (Exception ex) {
View Full Code Here

      int extPos = path.lastIndexOf('.');
      Application app = this.getApplication();
      type = app.getMetadataService().getDefaultMediaType();
      if (extPos>=0) {
         String ext = path.substring(extPos+1);
         Metadata mdata = this.getApplication().getMetadataService().getMetadata(ext);
         if (mdata!=null) {
            type = MediaType.valueOf(mdata.getName());
         }
      }
   }
View Full Code Here

     
      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) {
View Full Code Here

      int extPos = path.lastIndexOf('.');
      Application app = this.getApplication();
      type = app.getMetadataService().getDefaultMediaType();
      if (extPos>=0) {
         String ext = path.substring(extPos+1);
         Metadata mdata = this.getApplication().getMetadataService().getMetadata(ext);
         if (mdata!=null) {
            type = MediaType.valueOf(mdata.getName());
         }
      }
   }
View Full Code Here

TOP

Related Classes of org.restlet.data.Metadata

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.