Commit a7847503 by s_guodong

update

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