Examples of OutputRepresentation


Examples of org.restlet.representation.OutputRepresentation

            }
         }
         final Response resourceResponse = remoteRequest==null ? null : client.handle(remoteRequest);
         if (resourceResponse==null || resourceResponse.getStatus().isSuccess() && resourceResponse.isEntityAvailable()) {
            getResponse().setStatus(Status.SUCCESS_OK);
            Representation rep = new OutputRepresentation(type) {
               public void write(OutputStream os)
                  throws IOException
               {
                  try {
                     xform.clearParameters();
                     final Identity identity = (Identity)getRequest().getAttributes().get(Identity.IDENTITY_ATTR);
                     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",getRequest().getResourceRef().getPath());
                     xform.setParameter("request.resource.authority",getRequest().getResourceRef().getAuthority());
                     xform.setParameter("request.resource.scheme",getRequest().getResourceRef().getScheme());
                     xform.setParameter("request.resource.query",getRequest().getResourceRef().getQuery());
                     xform.setParameter("request.resource.fragment",getRequest().getResourceRef().getFragment());
                     Map<String,Object> attrs = getRequest().getAttributes();
                     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 {
                        if (resourceResponse==null) {
                           input = resource==null ? new StringReader("<doc/>") : new InputStreamReader(resource.toURL().openStream());
                        } else {
                           input = resourceResponse.getEntity().getReader();
                        }
                        try {
                           xform.transform(new StreamSource(input,resource==null ? null : 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 {
                     if (resourceResponse!=null) {
                        resourceResponse.getEntity().release();
                     }
                  }
               }
               public void release() {
                  scriptCache.release(script, xform);
               }
            };
            rep.setCharacterSet(CharacterSet.UTF_8);
            return rep;
         } else {
            scriptCache.release(script, xform);
            getResponse().setStatus(resourceResponse.getStatus());
            getResponse().setEntity(resourceResponse.getEntity());
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

        throws ResourceException
    {
        try
        {
            final Iterable<EntityReference> query = entityFinder.findEntities( EntityComposite.class, null, null, null, null, Collections.<String, Object>emptyMap() );
            return new OutputRepresentation( MediaType.APPLICATION_JSON )
            {
                @Override
                public void write( OutputStream outputStream )
                    throws IOException
                {
View Full Code Here

Examples of org.restlet.representation.OutputRepresentation

                final TupleQueryResult queryResult = tQuery.evaluate();

                if( variant.getMediaType().equals( MediaType.TEXT_HTML ) )
                {
                    return new OutputRepresentation( MediaType.TEXT_XML )
                    {
                        @Override
                        public void write( OutputStream outputStream )
                            throws IOException
                        {
                            try
                            {
                                PrintWriter out = new PrintWriter( outputStream );
                                out.println( "<?xml version='1.0' encoding='UTF-8'?>" );
                                out.println( "<?xml-stylesheet type=\"text/xsl\" href=\"query/sparqlhtml.xsl\"?>" );
                                out.flush();
                                TupleQueryResultWriter qrWriter = new SPARQLResultsXMLWriter( new XMLWriter( outputStream )
                                {
                                    @Override
                                    public void startDocument()
                                        throws IOException
                                    {
                                        // Ignore
                                    }
                                } );
                                QueryResultUtil.report( queryResult, qrWriter );
                            }
                            catch( Exception e )
                            {
                                throw new IOException( e );
                            }
                            finally
                            {
                                try
                                {
                                    conn.close();
                                }
                                catch( RepositoryException e )
                                {
                                    // Ignore
                                }
                            }
                        }
                    };
                }
                else if( variant.getMediaType().equals( MediaType.APPLICATION_RDF_XML ) )
                {
                    return new OutputRepresentation( MediaType.APPLICATION_XML )
                    {
                        @Override
                        public void write( OutputStream outputStream )
                            throws IOException
                        {
                            try
                            {
                                TupleQueryResultWriter qrWriter = new SPARQLResultsXMLWriter( new XMLWriter( outputStream ) );
                                QueryResultUtil.report( queryResult, qrWriter );
                            }
                            catch( Exception e )
                            {
                                throw new IOException( e );
                            }
                            finally
                            {
                                try
                                {
                                    conn.close();
                                }
                                catch( RepositoryException e )
                                {
                                    // Ignore
                                }
                            }
                        }
                    };
                }
                else if( variant.getMediaType().equals( RestApplication.APPLICATION_SPARQL_JSON ) )
                {
                    return new OutputRepresentation( RestApplication.APPLICATION_SPARQL_JSON )
                    {
                        @Override
                        public void write( OutputStream outputStream )
                            throws IOException
                        {
View Full Code Here

Examples of org.restlet.resource.OutputRepresentation

    public JSONFormat(MediaType type){
        myType = type;
    }

    public Representation makeRepresentation(final Object o) {
        return new OutputRepresentation(myType) {
                public void write(OutputStream os) {
                    try {
                        Writer outWriter = new BufferedWriter(new OutputStreamWriter(os));

                        outWriter.flush();
View Full Code Here

Examples of org.restlet.resource.OutputRepresentation

    public Representation makeRepresentation(Object context) {
        Element root = new Element(myRootName);
        final Document doc = new Document(root);
        insert(root, context);
        return new OutputRepresentation(MediaType.APPLICATION_XML){
            public void write(OutputStream outputStream){
                try{
                    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
                    outputter.output(doc, outputStream);
                } catch(IOException ioe){
View Full Code Here

Examples of org.restlet.resource.OutputRepresentation

import org.opengis.referencing.crs.CoordinateReferenceSystem;

public class XStreamFormat implements DataFormat {

    public Representation makeRepresentation(final Object data) {
        return new OutputRepresentation(MediaType.APPLICATION_XML){
            public void write(OutputStream outputStream){
                XStream xstream = getXStream();
                xstream.toXML(data, outputStream);
            }
        };
View Full Code Here

Examples of org.restlet.resource.OutputRepresentation

            resp.setRedirectRef(new Reference(req.getResourceRef(), l.get(0)));
        }
    }

    private void listFiles(Request req, Response resp) throws Exception {
        resp.setEntity(new OutputRepresentation(MediaType.APPLICATION_JSON) {
            public InputStream getStream() {
                throw new UnsupportedOperationException();
            }

            public void write(OutputStream out) throws IOException {
View Full Code Here

Examples of org.restlet.resource.OutputRepresentation

            // delegate to wms reflector
            final GetMapResponse getMapResponse = webMapService
                    .reflect(getMapRequest);

            // wrap response in a reslet output rep
            OutputRepresentation output = new OutputRepresentation(
                    new MediaType("application/vnd.google-earth.kml+xml")) {
                public void write(OutputStream outputStream) throws IOException {
                    try {
                        getMapResponse.execute(getMapRequest);
                        getMapResponse.writeTo(outputStream);
View Full Code Here

Examples of org.restlet.resource.OutputRepresentation

   /**
    * Returns an {@link OutputRepresentation} which delegates to {@link #write(Object, OutputStream)}.
    */
   @Override
   public final Representation toRepresentation(final Object object) {
       return new OutputRepresentation(getMediaType()) {
           @Override
           public void write(OutputStream outputStream) throws IOException {
               StreamDataFormat.this.write(object, outputStream);
           }
       };
View Full Code Here

Examples of org.restlet.resource.OutputRepresentation

            }
           
            pi.setOut(out);
            pi.execfile(new FileInputStream(script));
           
            getResponse().setEntity(new OutputRepresentation(MediaType.TEXT_PLAIN) {
                @Override
                public void write(OutputStream output) throws IOException {
                    output.write(out.toByteArray());
                }
            });
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.