All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.alogic.vfs.service.FileList Maven / Gradle / Ivy
package com.alogic.vfs.service;
import java.util.HashMap;
import java.util.Map;
import com.alogic.vfs.context.FileSystemSource;
import com.alogic.vfs.core.VirtualFileSystem;
import com.logicbus.backend.AbstractServant;
import com.logicbus.backend.Context;
import com.logicbus.backend.ServantException;
import com.logicbus.backend.message.JsonMessage;
import com.logicbus.backend.message.YamlMessage;
import com.logicbus.models.servant.ServiceDescription;
/**
* 列出指定目录的文件列表
*
* @author duanyy
*
* @version 1.6.12.27 [20190403 duanyy]
* - 增加对yaml的支持
*/
public class FileList extends AbstractServant{
@Override
protected void onDestroy() {
// nothing to do
}
@Override
protected void onCreate(ServiceDescription sd) {
// nothing to do
}
protected int onXml(Context ctx){
throw new ServantException("core.e1000",
"Protocol XML is not suppurted.");
}
protected int onJson(Context ctx){
JsonMessage msg = (JsonMessage) ctx.asMessage(JsonMessage.class);
String path = getArgument("path","/",ctx);
String fsId = getArgument("domain","default",ctx);
String pattern = getArgument("pattern","[\\S]*",ctx);
int offset = getArgument("offset",0,ctx);
int limit = getArgument("limit",30,ctx);
VirtualFileSystem fs = FileSystemSource.get().get(fsId);
if (fs == null){
throw new ServantException("clnt.e2007","Can not find a vfs named " + fsId);
}
Map vfs = new HashMap();
fs.listFiles(path, pattern, vfs, offset, limit);
msg.getRoot().put("vfs", vfs);
return 0;
}
protected int onYaml(Context ctx){
YamlMessage msg = (YamlMessage) ctx.asMessage(YamlMessage.class);
String path = getArgument("path","/",ctx);
String fsId = getArgument("domain","default",ctx);
String pattern = getArgument("pattern","[\\S]*",ctx);
int offset = getArgument("offset",0,ctx);
int limit = getArgument("limit",30,ctx);
VirtualFileSystem fs = FileSystemSource.get().get(fsId);
if (fs == null){
throw new ServantException("clnt.e2007","Can not find a vfs named " + fsId);
}
Map vfs = new HashMap();
fs.listFiles(path, pattern, vfs, offset, limit);
msg.getRoot().put("vfs", vfs);
return 0;
}
}