Commit a7847503 by s_guodong

update

parent a98a4dc6
......@@ -16,8 +16,6 @@ import static com.brilliance.mda.runtime.mda.Constants.NO_ERROR;
public class MdaContext implements IContext {
private static final String DISPLAY_TEMPLATE_PATH = "displayTemplate/";
private transient final IDaoSession daoSession;
private transient final EnvConfig config;
private transient final IDisplay display;
......
......@@ -5,17 +5,20 @@ import com.brilliance.mda.runtime.annotation.Transaction;
import com.brilliance.mda.runtime.mda.driver.MdaScanner;
import com.brilliance.mda.runtime.mda.driver.compile.processor.ModuleAnnotationProcess;
import com.brilliance.mda.runtime.mda.driver.compile.processor.TransAnnotationProcessor;
import com.brilliance.mda.runtime.mda.util.Systems;
import com.brilliance.mda.support.td.ModuleInfoManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.io.IOException;
import java.util.*;
@Component
public class EmitterFactory implements InitializingBean {
......@@ -63,5 +66,20 @@ public class EmitterFactory implements InitializingBean {
log.info("动态Emitter扫描包:{}", scanPackage);
String[] scanPackages = scanPackage.split(",");
this.buildEmitter(scanPackages);
log.info("加载配置文件包displayTemplate...");
loadConfigResources("classpath*:displayTemplate/*.*");
}
private void loadConfigResources(String scanPackage) {
List<Resource> resources = Systems.getResources();
// 加载配置文件
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
try {
resources.addAll(Arrays.asList(resourcePatternResolver.getResources(scanPackage)));
} catch (IOException e) {
log.error("加载配置文件{}出错", scanPackage, e);
}
}
}
......@@ -9,16 +9,15 @@ import com.brilliance.mda.runtime.mda.snapshot.bo.pack.*;
import com.brilliance.mda.runtime.mda.snapshot.bo.unpack.*;
import com.brilliance.mda.runtime.mda.util.DateUtils;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import com.brilliance.mda.runtime.mda.util.Systems;
import com.brilliance.mda.runtime.mda.util.XmlUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.*;
/**
......@@ -30,8 +29,6 @@ import java.util.*;
public class SnapshotServiceImpl implements SnapshotService {
private static Logger log = LoggerFactory.getLogger(SnapshotServiceImpl.class);
protected static final String DISPLAY_TEMPLATE_PATH = "displayTemplate/";
private static final Set<ValueVo> keySet = new HashSet<>();
@Override
......@@ -48,15 +45,9 @@ public class SnapshotServiceImpl implements SnapshotService {
@Override
public DocumentBo unpackTemplate(String panelPath) {
URL root = ClassLoader.getSystemResource("");
String filePath = null;
try {
filePath = java.net.URLDecoder.decode(root.getPath(), "utf-8");
} catch (UnsupportedEncodingException e) {
}
File file = new File(filePath + DISPLAY_TEMPLATE_PATH + panelPath + ".zul");
InputStream resourceInputStream = Systems.getResourceInputStream(panelPath + ".zul");
try {
DocumentBo documentBo = XmlUtil.unmarshToObjBinding(DocumentBo.class, file);
DocumentBo documentBo = XmlUtil.unmarshToObjBinding(DocumentBo.class, resourceInputStream);
return documentBo;
} catch (Exception e) {
log.error("模板{}解析失败", panelPath, e);
......
......@@ -68,8 +68,8 @@ public class MdaUtils {
if (!propfile.exists()) {
String pathToUse = StringUtils.cleanPath(name);
IContext ctx = MdaEnv.getContext();
String rootpath = ctx.getEnvConfig().getRootPath();
pathToUse = pathToUse.substring(rootpath.length());
String rootpath = StringUtils.cleanPath(ctx.getEnvConfig().getRootPath());
pathToUse = pathToUse.substring(pathToUse.indexOf(rootpath) + rootpath.length());
if (pathToUse.startsWith("/")) {
pathToUse = pathToUse.substring(1);
}
......
......@@ -17,12 +17,9 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.brilliance.mda.runtime.mda.IStream;
import org.springframework.core.io.Resource;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
......@@ -38,6 +35,10 @@ public class Systems {
private static final Logger log = LoggerFactory.getLogger(Systems.class);
private static final List<Resource> resources = new ArrayList<>();
private static final Map<String, InputStream> FILE_MAP = new HashMap<>();
public static void setAttribute(IDatafield field, String ATTR, Object val) {
setAttribute(field.getParent(), field.getName(), ATTR, val);
}
......@@ -1029,4 +1030,20 @@ public class Systems {
return MdaEnv.getLang();
}
public static List<Resource> getResources() {
return resources;
}
public static InputStream getResourceInputStream(String fileName) {
if (FILE_MAP.size() == 0) {
for (Resource resource : resources) {
try {
FILE_MAP.put(resource.getFilename(), resource.getInputStream());
} catch (IOException e) {
}
}
}
return FILE_MAP.get(fileName);
}
}
......@@ -7,8 +7,7 @@ import javax.xml.bind.*;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Source;
import javax.xml.transform.sax.SAXSource;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.concurrent.ConcurrentHashMap;
......@@ -19,7 +18,7 @@ public class XmlUtil {
/**
* 将XML格式的文件转换成JAXB实现对象
*/
public static <T> T unmarshToObjBinding(Class<T> tclz, File file) throws Exception {
public static <T> T unmarshToObjBinding(Class<T> tclz, InputStream inputStream) throws Exception {
JAXBContext jc = jaxbContextMap.get(tclz);
if (jc == null) {
jc = JAXBContext.newInstance(tclz);
......@@ -29,7 +28,7 @@ public class XmlUtil {
sax.setNamespaceAware(false);
XMLReader xmlReader = sax.newSAXParser().getXMLReader();
Source source = new SAXSource(xmlReader, new InputSource(
new FileInputStream(file)));
inputStream));
Object obj = un.unmarshal(source);
if (JAXBElement.class.isAssignableFrom(obj.getClass())) {
obj = (T) JAXBIntrospector.getValue(obj);
......
......@@ -17,9 +17,8 @@ public class ResponseSet<T> {
/**
* 成功代码
*/
public static final String CODE_SUCCESS = "AAAAAA";
public static final String CODE_FAILURE = "BBBBBB";
public static final String MSG_SUCESS = "操作成功!";
public static final String CODE_SUCCESS = "AAAAAAA";
public static final String CODE_FAILURE = "ERR9999";
private String retcod;
private String retmsg;
......@@ -27,7 +26,7 @@ public class ResponseSet<T> {
public ResponseSet(IContext ctx, Object t) {
this.retcod = CODE_SUCCESS;
this.retmsg = MSG_SUCESS;
this.retmsg = CODE_SUCCESS;
this.data = t;
ctx.visitValues();
MdaDriver.setValueToVO(ctx, this.data);
......@@ -46,7 +45,7 @@ public class ResponseSet<T> {
public ResponseSet(Object t) {
this.retcod = CODE_SUCCESS;
this.retmsg = MSG_SUCESS;
this.retmsg = CODE_SUCCESS;
if (MdaEnv.getContext() != null) {
MdaEnv.getContext().visitValues();
}
......@@ -101,10 +100,9 @@ public class ResponseSet<T> {
}
}
static final String FAIL_CODE = "999999";
public static ResponseSet fail(String message) {
ResponseSet responseSet = new ResponseSet(FAIL_CODE, message);
ResponseSet responseSet = new ResponseSet(CODE_FAILURE, message);
return responseSet;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment