support env

This commit is contained in:
Looly 2019-10-27 07:56:19 +08:00
commit c891de1f17
4 changed files with 63 additions and 12 deletions

View File

@ -7,7 +7,9 @@
### 新特性 ### 新特性
* 【setting】 增加System.getenv变量替换支持 * 【setting】 增加System.getenv变量替换支持
* 【core】 XmlUtil中mapToStr支持namespacepr#599@Github
### Bug修复 ### Bug修复
* 【core】 解决ConcurrentHashSet不能序列化的问题issue#600@Github
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------

View File

@ -17,8 +17,8 @@ public class ConcurrentHashSet<E> extends AbstractSet<E> implements java.io.Seri
private static final long serialVersionUID = 7997886765361607470L; private static final long serialVersionUID = 7997886765361607470L;
/** 持有对象。如果值为此对象表示有数据,否则无数据 */ /** 持有对象。如果值为此对象表示有数据,否则无数据 */
private static final Object PRESENT = new Object(); private static final Boolean PRESENT = true;
private final ConcurrentHashMap<E, Object> map; private final ConcurrentHashMap<E, Boolean> map;
// ----------------------------------------------------------------------------------- Constructor start // ----------------------------------------------------------------------------------- Constructor start
/** /**

View File

@ -387,8 +387,7 @@ public class XmlUtil {
* @since 4.1.2 * @since 4.1.2
*/ */
public static DocumentBuilder createDocumentBuilder() { public static DocumentBuilder createDocumentBuilder() {
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); final DocumentBuilderFactory dbf = disableXXE(DocumentBuilderFactory.newInstance());
disableXXE(dbf);
DocumentBuilder builder; DocumentBuilder builder;
try { try {
builder = dbf.newDocumentBuilder(); builder = dbf.newDocumentBuilder();
@ -406,9 +405,21 @@ public class XmlUtil {
* @return XML文档 * @return XML文档
*/ */
public static Document createXml(String rootElementName) { public static Document createXml(String rootElementName) {
final Document doc = createXml(); return createXml(rootElementName, null);
doc.appendChild(doc.createElement(rootElementName)); }
/**
* 创建XML文档<br>
* 创建的XML默认是utf8编码修改编码的过程是在toStr和toFile方法里即XML在转为文本的时候才定义编码
*
* @param rootElementName 根节点名称
* @param namespace 命名空间无则传null
* @return XML文档
* @since 5.0.4
*/
public static Document createXml(String rootElementName, String namespace) {
final Document doc = createXml();
doc.appendChild(null == namespace ? doc.createElement(rootElementName) : doc.createElementNS(rootElementName, namespace));
return doc; return doc;
} }
@ -674,7 +685,7 @@ public class XmlUtil {
* @since 4.0.8 * @since 4.0.8
*/ */
public static Map<String, Object> xmlToMap(String xmlStr) { public static Map<String, Object> xmlToMap(String xmlStr) {
return xmlToMap(xmlStr, new HashMap<String, Object>()); return xmlToMap(xmlStr, new HashMap<>());
} }
/** /**
@ -685,7 +696,7 @@ public class XmlUtil {
* @since 4.0.8 * @since 4.0.8
*/ */
public static Map<String, Object> xmlToMap(Node node) { public static Map<String, Object> xmlToMap(Node node) {
return xmlToMap(node, new HashMap<String, Object>()); return xmlToMap(node, new HashMap<>());
} }
/** /**
@ -744,6 +755,18 @@ public class XmlUtil {
return toStr(mapToXml(data, rootName)); return toStr(mapToXml(data, rootName));
} }
/**
* 将Map转换为XML格式的字符串
*
* @param data Map类型数据
* @param rootName 根节点名
* @return XML格式的字符串
* @since 5.0.4
*/
public static String mapToXmlStr(Map<?, ?> data, String rootName,String namespace) {
return toStr(mapToXml(data, rootName, namespace));
}
/** /**
* 将Map转换为XML * 将Map转换为XML
* *
@ -753,8 +776,21 @@ public class XmlUtil {
* @since 4.0.9 * @since 4.0.9
*/ */
public static Document mapToXml(Map<?, ?> data, String rootName) { public static Document mapToXml(Map<?, ?> data, String rootName) {
return mapToXml(data, rootName, null);
}
/**
* 将Map转换为XML
*
* @param data Map类型数据
* @param rootName 根节点名
* @return XML
* @since 5.0.4
*/
public static Document mapToXml(Map<?, ?> data, String rootName,String namespace) {
final Document doc = createXml(); final Document doc = createXml();
final Element root = appendChild(doc, rootName); final Element root = appendChild(doc, rootName, namespace);
mapToXml(doc, root, data); mapToXml(doc, root, data);
return doc; return doc;
@ -780,8 +816,21 @@ public class XmlUtil {
* @since 4.0.9 * @since 4.0.9
*/ */
public static Element appendChild(Node node, String tagName) { public static Element appendChild(Node node, String tagName) {
return appendChild(node, tagName, null);
}
/**
* 在已有节点上创建子节点
*
* @param node 节点
* @param tagName 标签名
* @param namespace 命名空间无传null
* @return 子节点
* @since 5.0.4
*/
public static Element appendChild(Node node, String tagName, String namespace) {
Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument(); Document doc = (node instanceof Document) ? (Document) node : node.getOwnerDocument();
Element child = doc.createElement(tagName); Element child = (null == namespace) ? doc.createElement(tagName) : doc.createElementNS(namespace, tagName);
node.appendChild(child); node.appendChild(child);
return child; return child;
} }

View File

@ -42,7 +42,7 @@ public class Page implements Serializable {
* @param pageSize 每页结果数 * @param pageSize 每页结果数
*/ */
public Page(int pageNumber, int pageSize) { public Page(int pageNumber, int pageSize) {
this.pageNumber = pageNumber < 0 ? 0 : pageNumber; this.pageNumber = Math.max(pageNumber, 0);
this.pageSize = pageSize <= 0 ? DEFAULT_PAGE_SIZE : pageSize; this.pageSize = pageSize <= 0 ? DEFAULT_PAGE_SIZE : pageSize;
} }
@ -73,7 +73,7 @@ public class Page implements Serializable {
* @param pageNumber 页码 * @param pageNumber 页码
*/ */
public void setPageNumber(int pageNumber) { public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber < 0 ? 0 : pageNumber; this.pageNumber = Math.max(pageNumber, 0);
} }
/** /**