本文整理匯總了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 );
}
}