Package org.restlet.data

Examples of org.restlet.data.MediaType


                        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


      String file = slug;
     
      try {
         InputStream is = entity.getStream();
         MediaType mediaType = entity.getMediaType();
         if (mediaType==null) {
            throw new AppException(Status.CLIENT_ERROR_BAD_REQUEST,"The media type is missing.");
         }
         MediaType baseMediaType = mediaType.valueOf(mediaType.getName());
        
         // Make sure we have a filename for the media resource
         if (file==null) {
            String ext = metaService.getExtension(baseMediaType);
            if (ext!=null) {
View Full Code Here

      throws AppException
   {
      try {
         EntryMedia media = feed.findEntryResource(file);

         MediaType mediaType = entity.getMediaType();
         mediaType = MediaType.valueOf(mediaType.getName());
         media.setMediaType(mediaType);
         storage.storeMedia(feed.getPath(),feed.getUUID(),media.getName(),mediaType,entity.getStream());
         media.edited();
      } catch (IOException ex) {
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot update entry media "+file,ex);
View Full Code Here

         } else {
            rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
            // Don't trust the storage to get the modification right
            rep.setModificationDate(entry.getEdited());
         }
         MediaType entryType = new MediaType(rep.getMediaType().getName(),rep.getMediaType().getParameters().createSeries(entryParameters));
         rep.setMediaType(entryType);
         getResponse().setStatus(Status.SUCCESS_OK);
         return rep;
      } catch (AppException ex) {
         getResponse().setStatus(ex.getStatus());
View Full Code Here

         String type = linkE.getAttributeValue("type");
         String href = linkE.getAttributeValue("href");
         if (rel!=null && href!=null) {
            URI base = linkE.getBaseURI();
            URI location = base!=null ? base.resolve(href) : URI.create(href);
            MediaType mtype = type==null ? null : MediaType.valueOf(type);
            Link link = new Link(rel,mtype,location);
            List<Link> list = (List<Link>)linkset.get(rel);
            if (list==null) {
               list = new ArrayList<Link>();
               linkset.put(rel,list);
View Full Code Here

               log.info("Entry: "+entryId);
               EntryClient entryClient = new EntryClient(new Reference(targetClient.getEntryLocation(entryId).toString()),target.getIdentity());
               String src = null;
               Element content = entryDoc.getDocumentElement().getFirstElementNamed(CONTENT_NAME);
               URI baseURI = null;
               MediaType contentType = null;
               if (content!=null) {
                  src = content.getAttributeValue("src");
                  String type = content.getAttributeValue("type");
                  if (type!=null) {
                     contentType = MediaType.valueOf(type);
View Full Code Here

   public Representation post(Representation entity) {
      if (entity==null) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Missing post body.");
      }
      MediaType postType = entity.getMediaType();
     
      if (postType.getName().equals("application/sparql-query")) {
         return handleSparqlPost(entity);
      } else if (!postType.getName().equals(MediaType.APPLICATION_XML.getName())) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Non-xml media type "+postType.getName());
      }
      String charset = postType.getParameters().getValues("charset");
      if (charset==null) {
         charset = "UTF-8";
      }
      Document doc = null;
      DocumentLoader loader = new SAXDocumentLoader();
View Full Code Here

         }
      };
   }
  
   public Representation handleSparqlPost(Representation entity) {
      MediaType postType = entity.getMediaType();
      String charset = postType.getParameters().getValues("charset");
      if (charset==null) {
         charset = "UTF-8";
      }
      try {
         Reader r = new InputStreamReader(entity.getStream(),charset);
View Full Code Here

         // create entry
         Entry entry = parent.createEntry(id);
        
         if (media!=null) {
            // create entry media
            MediaType type = MediaType.APPLICATION_OCTET_STREAM;
            int dot = media.getName().lastIndexOf('.');
            if (dot>0) {
               String ext = media.getName().substring(dot+1);
               type = MediaType.valueOf(metaService.getMetadata(ext).getName());
            }
View Full Code Here

   protected void importMedia(final org.atomojo.app.db.Feed parent,File file)
      throws SQLException,IOException,XMLException
   {
      // get media type
      String name = file.getName();
      MediaType type = MediaType.APPLICATION_OCTET_STREAM;
      int dot = name.lastIndexOf('.');
      if (dot>0) {
         String ext = name.substring(dot+1);
         type = MediaType.valueOf(metaService.getMetadata(ext).getName());
      }
View Full Code Here

TOP

Related Classes of org.restlet.data.MediaType

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.