All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy