Examples of OutputRepresentation


Examples of org.restlet.representation.OutputRepresentation

         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Empty category set.");
      }
      final URI keyTerm = firstTerm;
      getResponse().setStatus(Status.SUCCESS_OK);
      return new OutputRepresentation(MediaType.APPLICATION_ATOM) {
         public void write(OutputStream os)
            throws IOException
         {
            setCharacterSet(CharacterSet.UTF_8);
            try {
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

         r.close();

         getResponse().setStatus(Status.SUCCESS_OK);
         final QueryContext context = new QueryContext(getLogger(),app.getDB(),query);
         final XMLRepresentationParser xmlParser = new XMLRepresentationParser();
         return new OutputRepresentation(MediaType.APPLICATION_ATOM) {
            public void write(OutputStream os)
               throws IOException
            {
               final ItemDestination dest = new WriterItemDestination(new OutputStreamWriter(os,"UTF-8"),"UTF-8");
               final ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

  
   public Representation getFeed(final String path,UUID id,final Iterator<Entry> entries)
      throws IOException
   {
      final File feedFile = makeCollectionReference(path);
      Representation rep = new OutputRepresentation(MediaType.APPLICATION_ATOM_XML) {
         public void write(OutputStream os)
            throws IOException
         {
            Writer out = new OutputStreamWriter(os,"UTF-8");
            ItemDestination dest = new WriterItemDestination(out,"UTF-8");
            FeedLoader feedLoader = new FeedLoader(getLogger(),loader,feedFile,entries);
            try {
               feedLoader.load(dest);
            } catch (XMLException ex) {
               throw new IOException("XML exception while loading feed: "+ex.getMessage());
            }
            out.flush();
         }
      };
      rep.setCharacterSet(CharacterSet.UTF_8);
      Date lastModified = new Date(makeFeedReference(path).lastModified());
      rep.setModificationDate(lastModified);
      return rep;
   }
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

  
   public Representation getEntry(final String feedBaseURI,String path,UUID feedId,UUID id)
      throws IOException
   {
      final File entry = makeEntryReference(path,id);
      Representation rep = new OutputRepresentation(MediaType.APPLICATION_ATOM_XML) {
         public void write(OutputStream os)
            throws IOException
         {
            Writer w = new OutputStreamWriter(os,"UTF-8");
            final WriterItemDestination dest = new WriterItemDestination(w,"UTF-8",true);
            dest.setOmitXMLDeclaration(true);
            try {
               loader.generate(entry.toURI(), new ItemDestination() {
                  int level = 0;
                  public void send(Item item)
                     throws XMLException
                  {
                     switch (item.getType()) {
                        case ElementItem:
                           if (level==0) {
                              Element e = (Element)item;
                              e.setAttributeValue(Attribute.XML_BASE, feedBaseURI);
                           } else {
                              Element e = (Element)item;
                              e.setBaseURI(null);
                           }
                           level++;
                           break;
                        case ElementEndItem:
                           level--;
                     }
                     dest.send(item);
                  }
               });
            } catch (XMLException ex) {
               throw new IOException(ex.getMessage());
            }
         }
      };
      rep.setCharacterSet(CharacterSet.UTF_8);
      rep.setModificationDate(new Date(entry.lastModified()));
      return rep;
   }
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

      this.app = app;
      this.term = term;
   }
  
   public Representation get() {
      return new OutputRepresentation(MediaType.APPLICATION_ATOM_XML) {
         public void write(OutputStream os)
            throws IOException
         {
            setCharacterSet(CharacterSet.UTF_8);
            try {
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

                  } else {
                     return form.getFirstValue(name);
                  }
               }
            });
            return new OutputRepresentation(MediaType.APPLICATION_XHTML_XML) {
               public void write(OutputStream os)
                  throws IOException
               {
                  OutputStreamWriter w = new OutputStreamWriter(os,"UTF-8");
                  w.write(result);
                  w.flush();
               }
            };
         } catch (IOException ex) {
            getLogger().log(Level.SEVERE,"Cannot get template.",ex);
            return null;
         }
      } else {
         try {
            final Template template = new Template(LoginAction.toString(LoginView.class.getResourceAsStream("templates/logged-in.xml")));
            final String result = template.format(new Resolver<String>() {
               public String resolve(String name) {
                  if (name.equals("id")) {
                     return identity.getId();
                  } else if (name.equals("alias")) {
                     return identity.getAlias();
                  } else if (name.equals("name")) {
                     return identity.getName();
                  } else if (name.equals("email")) {
                     return identity.getEmail();
                  }
                  return null;
               }
            });
           
            return new OutputRepresentation(MediaType.APPLICATION_XHTML_XML) {
               public void write(OutputStream os)
                  throws IOException
               {
                  OutputStreamWriter w = new OutputStreamWriter(os,"UTF-8");
                  w.write(result);
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

                     final Representation feedResource = remoteResponse.getEntity();
                     response.setStatus(Status.SUCCESS_OK);
                     final Identity identity = (Identity)request.getAttributes().get(Identity.IDENTITY_ATTR);
                     final Map<String,Object> attrs = request.getAttributes();
                     releaseScript = null;
                     Representation rep = new OutputRepresentation(script.getMediaType()) {
                        public void write(OutputStream os)
                           throws IOException
                        {
                           try {
                              Transformer xform = script.getTransformer();
                              xform.clearParameters();
                              if (identity!=null) {
                                 xform.setParameter("user.session",identity.getSession());
                                 xform.setParameter("user.id",identity.getId());
                                 xform.setParameter("user.alias",identity.getAlias());
                                 if (identity.getName()!=null) {
                                    xform.setParameter("user.name",identity.getName());
                                 }
                                 if (identity.getEmail()!=null) {
                                    xform.setParameter("user.email",identity.getEmail());
                                 }
                              }
                              xform.setParameter("request.resource.path",request.getResourceRef().getPath());
                              xform.setParameter("request.resource.authority",request.getResourceRef().getAuthority());
                              xform.setParameter("request.resource.scheme",request.getResourceRef().getScheme());
                              xform.setParameter("request.resource.query",request.getResourceRef().getQuery());
                              xform.setParameter("request.resource.fragment",request.getResourceRef().getFragment());
                              for (String name : attrs.keySet()) {
                                 Object value = attrs.get(name);
                                 if (value instanceof String) {
                                    xform.setParameter(name,value);
                                 }
                              }
                              for (Parameter param : getContext().getParameters()) {
                                 xform.setParameter(param.getName(),param.getValue());
                              }
                              xform.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                              Reader input = null;
                              try {
                                 input = feedResource.getReader();
                                 try {
                                    xform.transform(new StreamSource(input,resource.toString()),new StreamResult(new OutputStreamWriter(os,"UTF-8")))
                                 } catch (TransformerException ex) {
                                    getLogger().log(Level.SEVERE,"Cannot transform feed due to script error.",ex);
                                 }
                              } finally {
                                 if (input!=null) {
                                    input.close();
                                 }
                              }
                           } finally {
                              feedResource.release();
                           }
                        }
                        public void release() {
                           script.release();
                        }
                     };
                     rep.setCharacterSet(CharacterSet.UTF_8);
                     response.setEntity(rep);
                     response.setStatus(Status.SUCCESS_OK);
                  } else if (remoteResponse!=null) {
                     if (remoteResponse.isEntityAvailable()) {
                        remoteResponse.getEntity().release();
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

      if (path.length()>0 && !path.equals("/")) {
         response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST,"Extended paths (e.g. "+path+") are not supported.");
         return;
      }
      //getContext().getLogger().info("Path: '"+path+"'");
      Representation rep = new OutputRepresentation(Introspection.ATOM_SERVICE_XML) {
         public void write(OutputStream os) {
            try {
               String path = request.getResourceRef().getPath();
               if (path.charAt(path.length()-1)=='/') {
                  path = path.substring(0,path.length()-1);
               }
               Writer w = new OutputStreamWriter(os,"UTF-8");
               db.getIntrospection(
                  storage,
                  request.getResourceRef().toString(),
                  path,
                  new DB.CollectionLocator() {
                     public String makeHref(Feed feed)
                        throws SQLException
                     {
                        return resourceBase.toString()+feed.getPath();
                     }
                  },
                  new WriterItemDestination(w,"UTF-8")
               );
            } catch (Exception ex) {
               getContext().getLogger().log(Level.SEVERE,"Exception while getting feeds: "+ex.getMessage(),ex);
            }
         }
      };
      rep.setCharacterSet(CharacterSet.UTF_8);
      response.setEntity(rep);
      response.setStatus(Status.SUCCESS_OK);

   }
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

         }
         final int startRow = start;
         final int limitCount = limit;
         final Date sinceMarker = since==null ? new Date() : since;
         final Feed target = feed;
         return new OutputRepresentation(MediaType.APPLICATION_ATOM) {
            public void write(OutputStream os)
               throws IOException
            {
               setCharacterSet(CharacterSet.UTF_8);
               try {
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

         getLogger().fine("Feed ref: "+feedRef);
      }
      Response response = get(feedRef);
      if (response.getStatus().isSuccess()) {
         final Representation feedRep = response.getEntity();
         Representation rep = new OutputRepresentation(MediaType.APPLICATION_ATOM) {
            boolean released = false;
            public void write(OutputStream os)
               throws IOException
            {
               Writer out = new OutputStreamWriter(os,"UTF-8");
               ItemDestination dest = new WriterItemDestination(out,"UTF-8");
               FeedLoader feedLoader = new FeedLoader(getLogger(),loader,feedRep,entries);
               try {
                  feedLoader.load(XMLDBStorage.this,context.getClientDispatcher(),path,dest);
               } catch (XMLException ex) {
                  throw new IOException("XML exception while loading feed: "+ex.getMessage());
               }
               feedRep.release();
               released = true;
               out.flush();
               out.close();
            }
            public void release() {
               if (!released) {
                  feedRep.release();
               }
            }
         };
         rep.setCharacterSet(CharacterSet.UTF_8);
         return rep;
      } else {
         throw new IOException("Cannot get feed document "+feedRef+", status="+response.getStatus().getCode());
      }
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.