本文整理了Java中org.restlet.resource.Directory
类的一些代码示例,展示了Directory
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Directory
类的具体详情如下:
包路径:org.restlet.resource.Directory
类名称:Directory
[英]Finder mapping a directory of local resources. Those resources have representations accessed by the file system, the class loaders or other URI accessible protocols. Here is some sample code illustrating how to attach a directory to a router:
Directory directory = new Directory(getContext(), "file:///user/data/files/");
Router router = new Router(getContext());
router.attach("/static/", directory);
An automatic content negotiation mechanism (similar to the one in Apache HTTP server) is used to select the best representation of a resource based on the available variants and on the client capabilities and preferences.
The directory can be used in read-only or modifiable mode. In the latter case, you just need to set the "modifiable" property to true. The currently supported methods are PUT and DELETE.
When no index is available in a given directory, a representation can be automatically generated by the #getIndexRepresentation(Variant,ReferenceList) method, unless the "listingAllowed" property is turned off. You can even customize the way the index entries are sorted by using the #setComparator(Comparator)method. The default sorting uses the friendly Alphanum algorithm based on David Koelle's original idea, using a different and faster implementation contributed by Rob Heittman.
Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.
[中]查找器映射本地资源的目录。这些资源具有由文件系统、类装入器或其他URI可访问协议访问的表示。下面是一些示例代码,说明如何将目录附加到路由器:
Directory directory = new Directory(getContext(), "file:///user/data/files/");
Router router = new Router(getContext());
router.attach("/static/", directory);
一种自动内容协商机制(类似于Apache HTTP server中的机制)用于根据可用的变体以及客户端功能和首选项选择资源的最佳表示形式。
该目录可以在只读或可修改模式下使用。在后一种情况下,只需将“modifiable”属性设置为true。当前支持的方法是PUT和DELETE。
如果给定目录中没有可用的索引,则可以通过#getIndexRepresentation(Variant,ReferenceList)方法自动生成表示,除非关闭“listingAllowed”属性。您甚至可以使用#setComparator(Comparator)方法自定义索引项的排序方式。默认排序使用友好的Alphanum算法,该算法基于David Koelle的original idea,使用Rob Heittman提供的另一种更快的实现。
并发性注意:此类或其子类的实例可以由多个线程同时调用,因此必须是线程安全的。在成员变量中存储状态时,应该特别小心。
代码示例来源:origin: org.restlet.osgi/org.restlet.ext.osgi
/**
* Creates the Restlet Directory instance using the rootUri, indexName,
* deeplyAccessible, modifiable, and negotiatingContent service properties
*
* @param context
* the Restlet application context
* @return the configured Restlet Directory
*/
protected Directory createDirectory(Context context) {
Directory directory = new Directory(context, rootUri);
directory.setIndexName(indexName);
directory.setDeeplyAccessible(deeplyAccessible);
directory.setModifiable(modifiable);
directory.setNegotiatingContent(negotiatingContent);
return directory;
}
代码示例来源:origin: com.github.ansell.restlet-utils/restlet-utils
@Override
public void handle(final Request request, final Response response)
{
final ClassLoader saveCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this._cl);
super.handle(request, response);
Thread.currentThread().setContextClassLoader(saveCL);
}
代码示例来源:origin: gofore/aws-training
private Directory rootTarget() {
Directory directory = new UtfDirectory(getContext(), "clap://class/static/");
directory.setDeeplyAccessible(true);
directory.setIndexName(INDEX);
return directory;
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public Restlet createInboundRoot() {
getConnectorService().getClientProtocols().add(Protocol.CLAP);
getConnectorService().getServerProtocols().add(Protocol.HTTP);
final Directory directory = new Directory(getContext(),
"clap://class");
directory.setListingAllowed(true);
directory.setDeeplyAccessible(true);
return directory;
}
};
代码示例来源:origin: org.restlet.jee/org.restlet.ext.apispark
resource.setName(directory.getName());
resource.setDescription(directory.getDescription());
代码示例来源:origin: org.restlet.jee/org.restlet.ext.platform
public static void collectResource(CollectInfo collectInfo,
Directory directory, String basePath, ChallengeScheme scheme,
List<? extends IntrospectionHelper> introspectionHelper) {
Resource resource = getResource(collectInfo, directory, basePath,
scheme);
// add operations
ArrayList<Operation> operations = new ArrayList<>();
operations.add(getOperationFromMethod(Method.GET));
if (directory.isModifiable()) {
operations.add(getOperationFromMethod(Method.DELETE));
operations.add(getOperationFromMethod(Method.PUT));
}
resource.setOperations(operations);
for (IntrospectionHelper helper : introspectionHelper) {
helper.processResource(resource, directory.getClass());
}
addSectionsForResource(collectInfo, resource);
collectInfo.addResource(resource);
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public Restlet createInboundRoot() {
Router router = new Router(getContext());
// Serve static files (images, etc.)
String rootUri = "file:///" + System.getProperty("user.home");
Directory directory = new Directory(getContext(), rootUri);
directory.setListingAllowed(true);
router.attach("/home", directory);
// Attach the hello web service
router.attach("/hello", HelloServerResource.class);
return router;
}
}
代码示例来源:origin: org.restlet.osgi/org.restlet
public void doInit() throws ResourceException {
this.directory = (Directory) getRequestAttributes().get("org.restlet.directory");
this.directoryClientDispatcher = getDirectory().getContext() != null ?
getDirectory().getContext().getClientDispatcher() :
null;
if (getClientDispatcher() == null) {
setNegotiated(this.directory.isNegotiatingContent());
this.relativePart = getReference().getRemainingPart(false, false);
this.originalRef = getOriginalRef();
this.targetUri = new Reference(directory.getRootRef().toString() + this.relativePart).toString(false, false);
preventUpperDirectoryAccess();
if (!StringUtils.isNullOrEmpty(getDirectory().getIndexName())) {
this.directoryUri = this.targetUri;
this.baseName = getDirectory().getIndexName();
this.targetUri = this.directoryUri + this.baseName;
this.indexTarget = true;
if (!StringUtils.isNullOrEmpty(getDirectory().getIndexName())) {
this.directoryUri = this.targetUri;
this.directoryTarget = true;
contextResponse = getRepresentation(this.directoryUri + getDirectory().getIndexName());
if (contextResponse.getEntity() != null) {
this.baseName = getDirectory().getIndexName();
this.targetUri = this.directoryUri + this.baseName;
this.directoryContent = new ReferenceList();
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public Restlet createInboundRoot() {
return new Directory(getContext(), ROOT_URI);
}
};
代码示例来源:origin: stackoverflow.com
final Component component = new Component();
component.getClients().add(Protocol.CLAP);
final Directory dir = new Directory(component.getContext(), "clap://class/META-INF/resources/webjars");
dir.setDeeplyAccessible(true);
this.attach("/webjars", dir);
//access via http://example.com/webjars/jquery/1.9.0/jquery.min.js
代码示例来源:origin: stackoverflow.com
Directory directory = new Directory(getContext(), "war:///doc");
directory.setIndexName("index.html");
代码示例来源:origin: com.whizzosoftware.hobson.hub/hobson-hub-setup
public Context getContext() {
// Get the context from the parent
Context context = super.getContext();
// Wrapper the context's client dispatcher in an object that will force it to use the OSGi bundle classloader
// rather than the classloader that created the dispatcher. Also, the same Context object may run through
// this many times so we have to make sure we don't wrapper multiple times -- otherwise evil hilarity will ensue
// (i.e stack overflows)
if (!(context.getClientDispatcher() instanceof CLAPCustomClassLoaderDispatcher)) {
context.setClientDispatcher(new CLAPCustomClassLoaderDispatcher(context.getClientDispatcher(), bundleClassloader));
}
return context;
}
}
代码示例来源:origin: org.restlet.jee/org.restlet.ext.platform
resource.setName(directory.getName());
resource.setDescription(directory.getDescription());
代码示例来源:origin: org.restlet.jee/org.restlet.ext.apispark
public static void collectResource(CollectInfo collectInfo,
Directory directory, String basePath, ChallengeScheme scheme,
List<? extends IntrospectionHelper> introspectionHelper) {
Resource resource = getResource(collectInfo, directory, basePath,
scheme);
// add operations
ArrayList<Operation> operations = new ArrayList<>();
operations.add(getOperationFromMethod(Method.GET));
if (directory.isModifiable()) {
operations.add(getOperationFromMethod(Method.DELETE));
operations.add(getOperationFromMethod(Method.PUT));
}
resource.setOperations(operations);
for (IntrospectionHelper helper : introspectionHelper) {
helper.processResource(resource, directory.getClass());
}
addSectionsForResource(collectInfo, resource);
collectInfo.addResource(resource);
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public Restlet createInboundRoot() {
// Create a simple password verifier
MapVerifier verifier = new MapVerifier();
verifier.getLocalSecrets().put("scott", "tiger".toCharArray());
// Create a Guard
ChallengeAuthenticator authenticator = new ChallengeAuthenticator(
getContext(), ChallengeScheme.HTTP_BASIC, "Tutorial");
authenticator.setVerifier(verifier);
// Create a Directory able to return a deep hierarchy of files
Directory directory = new Directory(getContext(), ROOT_URI);
directory.setListingAllowed(true);
authenticator.setNext(directory);
return authenticator;
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public Restlet createInboundRoot() {
final Router router = new Router(getContext());
// Redirect by defaul to the lst of users.
router.attachDefault(new Redirector(getContext(), "/users",
Redirector.MODE_CLIENT_PERMANENT));
final Directory imgDirectory = new Directory(getContext(),
LocalReference.createFileReference(webRootPath + "/images"));
// Add a route for the image resources
router.attach("/images", imgDirectory);
final Directory cssDirectory = new Directory(getContext(),
LocalReference
.createFileReference(webRootPath + "/stylesheets"));
// Add a route for the CSS resources
router.attach("/stylesheets", cssDirectory);
// Add a route for a Users resource
router.attach("/users", UsersResource.class);
// Add a route for a User resource
router.attach("/users/{userId}", UserResource.class);
// Add a route for a Contacts resource
router.attach("/users/{userId}/contacts", ContactsResource.class);
// Add a route for a Contact resource
router.attach("/users/{userId}/contacts/{contactId}",
ContactResource.class);
return router;
}
代码示例来源:origin: org.restlet.jse/org.restlet.ext.platform
resource.setName(directory.getName());
resource.setDescription(directory.getDescription());
代码示例来源:origin: org.restlet.osgi/org.restlet.ext.platform
public static void collectResource(CollectInfo collectInfo,
Directory directory, String basePath, ChallengeScheme scheme,
List<? extends IntrospectionHelper> introspectionHelper) {
Resource resource = getResource(collectInfo, directory, basePath,
scheme);
// add operations
ArrayList<Operation> operations = new ArrayList<>();
operations.add(getOperationFromMethod(Method.GET));
if (directory.isModifiable()) {
operations.add(getOperationFromMethod(Method.DELETE));
operations.add(getOperationFromMethod(Method.PUT));
}
resource.setOperations(operations);
for (IntrospectionHelper helper : introspectionHelper) {
helper.processResource(resource, directory.getClass());
}
addSectionsForResource(collectInfo, resource);
collectInfo.addResource(resource);
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
@Override
public Restlet createInboundRoot() {
// Create a simple password verifier
MapVerifier verifier = new MapVerifier();
verifier.getLocalSecrets().put("scott", "tiger".toCharArray());
// Create a guard
ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(),
ChallengeScheme.HTTP_BASIC, "Tutorial");
guard.setVerifier(verifier);
// Create a Directory able to return a deep hierarchy of files
Directory directory = new Directory(getContext(), "file:///tmp");
directory.setListingAllowed(true);
guard.setNext(directory);
return guard;
}
代码示例来源:origin: org.restlet.jse/org.restlet.example
Directory directory = new Directory(getContext(), ROOT_URI);
guard.setNext(directory);
内容来源于网络,如有侵权,请联系作者删除!