本文整理汇总了Java中org.restlet.routing.Template.format方法的典型用法代码示例。如果您正苦于以下问题:Java Template.format方法的具体用法?Java Template.format怎么用?Java Template.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.routing.Template
的用法示例。
在下文中一共展示了Template.format方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTargetRef
import org.restlet.routing.Template; //导入方法依赖的package包/类
@Override
protected Reference getTargetRef( Request request, Response response )
{
// This is essentially the original Restlet code modified to use
// ResolvingTemplate.
// Create the template
Template rt = new ResolvingTemplate( this.targetTemplate );
rt.setLogger( getLogger() );
// Return the formatted target URI
if( new Reference( this.targetTemplate ).isRelative() )
// Be sure to keep the resource's base reference.
return new Reference( request.getResourceRef(), rt.format( request, response ) );
return new Reference( rt.format( request, response ) );
}
示例2: get
import org.restlet.routing.Template; //导入方法依赖的package包/类
public Representation get() {
UploadApplication app = (UploadApplication)getContext().getAttributes().get("upload.app");
String id = getRequest().getAttributes().get("upload.id").toString();
final UploadProgress progress = app.getUpload(id);
if (progress==null) {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return null;
}
try {
InputStream is = UploadApplication.class.getResourceAsStream("upload.html");
Reader r = new InputStreamReader(is,"UTF-8");
Template template = new Template(UploadApplication.toString(r));
String result = template.format(new Resolver<String>() {
public String resolve(String name) {
if (name.equals("action")) {
return getRequest().getResourceRef().getPath();
} else if (name.equals("submit")) {
return progress.submit;
} else if (name.equals("cancel")) {
return progress.cancel;
} else {
return "";
}
}
});
getResponse().setStatus(Status.SUCCESS_OK);
return new StringRepresentation(result,MediaType.TEXT_HTML);
} catch (IOException ex) {
getLogger().log(Level.SEVERE,"Cannot get upload.html resource.",ex);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return null;
}
}
示例3: castKey
import org.restlet.routing.Template; //导入方法依赖的package包/类
/**
* Casts the cache key template for an executable.
*
* @param documentDescriptor
* The document descriptor
* @param suffix
* The optional attribute suffix
* @param parserName
* The parser to use, or null for the default parser
* @param conversationService
* The conversation service
* @param encoding
* The encoding
* @return The cache key or null
*/
public String castKey( DocumentDescriptor<Executable> documentDescriptor, String suffix, String parserName, ResourceConversationServiceBase<R> conversationService, Encoding encoding )
{
Executable executable = documentDescriptor.getDocument();
String cacheKeyTemplate = getKeyTemplate( executable, suffix );
if( cacheKeyTemplate == null )
return null;
Request request = resource.getRequest();
Response response = resource.getResponse();
if( !ProgramParser.NAME.equals( parserName ) )
{
// Set initial media type according to the document's tag (might
// be used by resolver)
if( conversationService.getMediaType() == null )
conversationService.setMediaTypeExtension( documentDescriptor.getTag() );
}
// Template and its resolver
Template template = new Template( cacheKeyTemplate );
CachingKeyTemplateResolver<R> resolver = new CachingKeyTemplateResolver<R>( documentDescriptor, resource, conversationService, encoding, request, response );
// Cache key template plugins
callKeyTemplatePlugins( template, executable, suffix );
Reference captiveReference = CapturingRedirector.getCapturedReference( request );
Reference resourceReference = request.getResourceRef();
try
{
// Temporarily use captive reference as the resource reference
if( captiveReference != null )
request.setResourceRef( captiveReference );
// Cast it
return template.format( resolver );
}
finally
{
// Return to original reference
if( captiveReference != null )
request.setResourceRef( resourceReference );
}
}