本文整理汇总了Java中org.restlet.representation.WriterRepresentation类的典型用法代码示例。如果您正苦于以下问题:Java WriterRepresentation类的具体用法?Java WriterRepresentation怎么用?Java WriterRepresentation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WriterRepresentation类属于org.restlet.representation包,在下文中一共展示了WriterRepresentation类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createTextHtmlRepresentation
import org.restlet.representation.WriterRepresentation; //导入依赖的package包/类
private Representation createTextHtmlRepresentation( final Object result, final Response response )
{
return new WriterRepresentation( MediaType.TEXT_HTML )
{
@Override
public void write( Writer writer )
throws IOException
{
Map<String, Object> context = new HashMap<>();
context.put( "request", response.getRequest() );
context.put( "response", response );
context.put( "result", result );
try
{
cfg.getTemplate( "links.htm" ).process( context, writer );
}
catch( TemplateException e )
{
throw new IOException( e );
}
}
};
}
开发者ID:apache,项目名称:polygene-java,代码行数:24,代码来源:LinksResponseWriter.java
示例2: createAtomRepresentation
import org.restlet.representation.WriterRepresentation; //导入依赖的package包/类
private Representation createAtomRepresentation( final Object result, final Response response )
{
return new WriterRepresentation( MediaType.APPLICATION_ATOM )
{
@Override
public void write( Writer writer )
throws IOException
{
Map<String, Object> context = new HashMap<>();
context.put( "request", response.getRequest() );
context.put( "response", response );
context.put( "result", result );
try
{
cfg.getTemplate( "links.atom" ).process( context, writer );
}
catch( TemplateException e )
{
throw new IOException( e );
}
}
};
}
开发者ID:apache,项目名称:polygene-java,代码行数:24,代码来源:LinksResponseWriter.java
示例3: representRdfXml
import org.restlet.representation.WriterRepresentation; //导入依赖的package包/类
private Representation representRdfXml( final EntityState entity )
throws ResourceException
{
Representation representation = new WriterRepresentation( MediaType.APPLICATION_RDF_XML )
{
@Override
public void write( Writer writer )
throws IOException
{
try
{
Iterable<Statement> statements = entitySerializer.serialize( entity );
new RdfXmlSerializer().serialize( statements, writer );
}
catch( RDFHandlerException e )
{
throw new IOException( e );
}
}
};
representation.setCharacterSet( CharacterSet.UTF_8 );
return representation;
}
开发者ID:apache,项目名称:polygene-java,代码行数:24,代码来源:EntityResource.java
示例4: representRdf
import org.restlet.representation.WriterRepresentation; //导入依赖的package包/类
private Representation representRdf()
throws ResourceException
{
try
{
final Stream<EntityReference> query = entityFinder.findEntities( EntityComposite.class, null, null, null, null, Collections.emptyMap() );
WriterRepresentation representation = new WriterRepresentation( MediaType.APPLICATION_RDF_XML )
{
@Override
public void write( Writer writer )
throws IOException
{
PrintWriter out = new PrintWriter( writer );
out.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<rdf:RDF\n"
+ "\txmlns=\"urn:polygene:\"\n" + "\txmlns:polygene=\"http://polygene.apache.org/rdf/model/1.0/\"\n"
+ "\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"
+ "\txmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\">" );
query.forEach( qualifiedIdentity -> out.println( "<polygene:entity rdf:about=\""
+ getRequest().getResourceRef().getPath() + "/"
+ qualifiedIdentity.identity() + ".rdf\"/>" ) );
out.println( "</rdf:RDF>" );
}
};
representation.setCharacterSet( CharacterSet.UTF_8 );
return representation;
}
catch( EntityFinderException e )
{
throw new ResourceException( Status.SERVER_ERROR_INTERNAL, e );
}
}
开发者ID:apache,项目名称:polygene-java,代码行数:35,代码来源:EntitiesResource.java
示例5: representHtml
import org.restlet.representation.WriterRepresentation; //导入依赖的package包/类
private Representation representHtml()
throws ResourceException
{
try
{
Stream<EntityReference> query = entityFinder.findEntities( EntityComposite.class, null, null, null, null, Collections.emptyMap() );
Representation representation = new WriterRepresentation( MediaType.TEXT_HTML )
{
@Override
public void write( Writer buf )
throws IOException
{
PrintWriter out = new PrintWriter( buf );
out.println( "<html><head><title>All entities</title></head><body><h1>All entities</h1><ul>" );
query.forEach( entity -> out.println( "<li><a href=\""
+ getRequest().getResourceRef().clone().addSegment( entity.identity() + ".html" )
+ "\">" + entity.identity() + "</a></li>" ) );
out.println( "</ul></body></html>" );
}
};
representation.setCharacterSet( CharacterSet.UTF_8 );
return representation;
}
catch( EntityFinderException e )
{
throw new ResourceException( e );
}
}
开发者ID:apache,项目名称:polygene-java,代码行数:30,代码来源:EntitiesResource.java
示例6: writeResponse
import org.restlet.representation.WriterRepresentation; //导入依赖的package包/类
@Override
public boolean writeResponse( final Object result, final Response response )
throws ResourceException
{
if( result instanceof ValueDescriptor )
{
MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType();
if( APPLICATION_JSON.equals( type ) )
{
ValueDescriptor vd = (ValueDescriptor) result;
JsonObjectBuilder builder = json.builderFactory().createObjectBuilder();
vd.state().properties().forEach(
property ->
{
try
{
Object o = property.resolveInitialValue( module );
if( o == null )
{
builder.add( property.qualifiedName().name(), JsonValue.NULL );
}
else
{
builder.add( property.qualifiedName().name(), jsonSerializer.toJson( o ) );
}
}
catch( JsonException ex )
{
throw new RestResponseException( "Unable to serialize " + vd, ex );
}
} );
StringRepresentation representation = new StringRepresentation( builder.build().toString(),
APPLICATION_JSON );
response.setEntity( representation );
return true;
}
else if( TEXT_HTML.equals( type ) )
{
Representation rep = new WriterRepresentation( TEXT_HTML )
{
@Override
public void write( Writer writer )
throws IOException
{
Map<String, Object> context = new HashMap<>();
context.put( "request", response.getRequest() );
context.put( "response", response );
context.put( "result", result );
try
{
cfg.getTemplate( "form.htm" ).process( context, writer );
}
catch( TemplateException e )
{
throw new IOException( e );
}
}
};
response.setEntity( rep );
return true;
}
}
return false;
}
开发者ID:apache,项目名称:polygene-java,代码行数:65,代码来源:ValueDescriptorResponseWriter.java
示例7: writeResponse
import org.restlet.representation.WriterRepresentation; //导入依赖的package包/类
@Override
public boolean writeResponse( final Object result, final Response response )
throws ResourceException
{
if( result instanceof Resource )
{
Resource resourceValue = (Resource) result;
// Allowed methods
response.getAllowedMethods().add( Method.GET );
if( resourceValue.commands().get().stream().anyMatch( LinksUtil.withRel( "delete" ) ) )
{
response.getAllowedMethods().add( Method.DELETE );
}
if( resourceValue.commands().get().stream().anyMatch( LinksUtil.withRel( "update" ) ) )
{
response.getAllowedMethods().add( Method.PUT );
}
// Response according to what client accepts
MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType();
if( MediaType.APPLICATION_JSON.equals( type ) )
{
String json = jsonSerializer.serialize( resourceValue );
response.setEntity( new StringRepresentation( json, MediaType.APPLICATION_JSON ) );
return true;
}
else if( MediaType.TEXT_HTML.equals( type ) )
{
Representation rep = new WriterRepresentation( MediaType.TEXT_HTML )
{
@Override
public void write( Writer writer )
throws IOException
{
Map<String, Object> context = new HashMap<>();
context.put( "request", response.getRequest() );
context.put( "response", response );
context.put( "result", result );
try
{
cfg.getTemplate( "resource.htm" ).process( context, writer );
}
catch( TemplateException e )
{
throw new IOException( e );
}
}
};
response.setEntity( rep );
return true;
}
}
return false;
}
开发者ID:apache,项目名称:polygene-java,代码行数:57,代码来源:ResourceResponseWriter.java
示例8: writeRequest
import org.restlet.representation.WriterRepresentation; //导入依赖的package包/类
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
if (requestObject instanceof ValueComposite)
{
// Value as parameter
final ValueComposite valueObject = (ValueComposite) requestObject;
if (request.getMethod().equals(Method.GET))
{
StateHolder holder = spi.stateOf( valueObject );
final ValueDescriptor descriptor = spi.valueDescriptorFor( valueObject );
final Reference ref = request.getResourceRef();
ref.setQuery( null );
descriptor.state().properties().forEach( propertyDescriptor -> {
try
{
Object value = holder.propertyFor( propertyDescriptor.accessor() ).get();
String param;
if( value == null )
{
param = null;
}
else
{
param = serializer.serialize( value );
}
ref.addQueryParameter( propertyDescriptor.qualifiedName().name(), param );
}
catch( SerializationException e )
{
throw new ResourceException( e );
}
} );
}
else
{
request.setEntity(new WriterRepresentation( MediaType.APPLICATION_JSON )
{
@Override
public void write( Writer writer )
throws IOException
{
setCharacterSet( CharacterSet.UTF_8 );
serializer.serialize( writer, valueObject );
}
});
}
return true;
}
return false;
}
开发者ID:apache,项目名称:polygene-java,代码行数:55,代码来源:ValueCompositeRequestWriter.java
示例9: convert
import org.restlet.representation.WriterRepresentation; //导入依赖的package包/类
@Override
public Representation convert(DataHandler handler, final Reference ref, CcData data) throws Exception {
Query query = handler.getQuery();
DocumentBuilder db = DBF.newDocumentBuilder();
final Document doc = db.newDocument();
final Element root = appendElement(doc, "data", doc);
if (handler.isPrintColumns()) {
Element cols = appendElement(doc, "cols", root);
for (MdColumn c: query.getColumns()) {
Element col = appendElement(doc, "col", cols);
appendElement(doc, "name", col).setTextContent(c.getName());
appendElement(doc, "type", col).setTextContent(c.getType().name());
appendElement(doc, "cname", col).setTextContent(c.getCName());
appendElement(doc, "jname", col).setTextContent(c.getJName());
}
}
new DataVisitor(handler) {
private Element row;
@Override
public void startRow() {
row = doc.createElement("row");
}
@Override
public void visitCol() {
if (value != null) {
String svalue = null;
switch (column.getType()) {
case DATE:
Calendar cal = (Calendar) value;
svalue = DATE_FORMAT.format(cal.getTime());
break;
case NUMBER:
svalue = ((BigDecimal) value).toPlainString();
break;
case STRING:
svalue = (String) value;
break;
case BLOB:
svalue = getLobReference(ref).toString();
break;
case CLOB:
svalue = getLobReference(ref).toString();
break;
}
if (svalue != null) {
appendElement(doc, column.getCName(), row).setTextContent(svalue);
}
}
}
@Override
public void endRow() {
root.appendChild(row);
}
}.visit(data.getValue());
return new WriterRepresentation(MediaType.TEXT_XML) {
@Override
public void write(Writer writer) throws IOException {
try {
Transformer tr = TRF.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(writer);
tr.transform(source, result);
} catch (TransformerException ex) {
throw new IOException(ex);
}
}
};
}
开发者ID:valdasraps,项目名称:resthub,代码行数:80,代码来源:XMLConverter.java
示例10: convert
import org.restlet.representation.WriterRepresentation; //导入依赖的package包/类
@Override
public Representation convert(DataHandler handler, final Reference ref, CcData data) throws Exception {
final StringBuilder sb = new StringBuilder();
Query query = handler.getQuery();
sb.setLength(0);
String sep = "";
for (MdColumn c : query.getColumns()) {
sb.append(sep).append(escapeStr(c.getCName()));
sep = FS;
}
sb.append(NL);
new DataVisitor(handler) {
@Override
public void startRow() { }
@Override
public void visitCol() {
if (colNumber > 0) {
sb.append(FS);
}
if (value != null) {
switch (column.getType()) {
case DATE:
Calendar cal = (Calendar) value;
sb.append(DATE_FORMAT.format(cal.getTime()));
break;
case STRING:
sb.append(escapeStr((String) value));
break;
case BLOB:
case CLOB:
sb.append("[file]");
break;
default:
sb.append(value);
}
}
}
@Override
public void endRow() {
sb.append(NL);
}
}.visit(data.getValue());
return new WriterRepresentation(MediaType.TEXT_CSV) {
@Override
public void write(Writer writer) throws IOException {
writer.write(sb.toString());
}
};
}
开发者ID:valdasraps,项目名称:resthub,代码行数:60,代码来源:CSVConverter.java
注:本文中的org.restlet.representation.WriterRepresentation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论