mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-04 04:37:59 +08:00
support env
This commit is contained in:
commit
c891de1f17
@ -7,7 +7,9 @@
|
||||
|
||||
### 新特性
|
||||
* 【setting】 增加System.getenv变量替换支持
|
||||
* 【core】 XmlUtil中mapToStr支持namespace(pr#599@Github)
|
||||
### Bug修复
|
||||
* 【core】 解决ConcurrentHashSet不能序列化的问题(issue#600@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -17,8 +17,8 @@ public class ConcurrentHashSet<E> extends AbstractSet<E> implements java.io.Seri
|
||||
private static final long serialVersionUID = 7997886765361607470L;
|
||||
|
||||
/** 持有对象。如果值为此对象表示有数据,否则无数据 */
|
||||
private static final Object PRESENT = new Object();
|
||||
private final ConcurrentHashMap<E, Object> map;
|
||||
private static final Boolean PRESENT = true;
|
||||
private final ConcurrentHashMap<E, Boolean> map;
|
||||
|
||||
// ----------------------------------------------------------------------------------- Constructor start
|
||||
/**
|
||||
|
@ -387,8 +387,7 @@ public class XmlUtil {
|
||||
* @since 4.1.2
|
||||
*/
|
||||
public static DocumentBuilder createDocumentBuilder() {
|
||||
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
disableXXE(dbf);
|
||||
final DocumentBuilderFactory dbf = disableXXE(DocumentBuilderFactory.newInstance());
|
||||
DocumentBuilder builder;
|
||||
try {
|
||||
builder = dbf.newDocumentBuilder();
|
||||
@ -406,9 +405,21 @@ public class XmlUtil {
|
||||
* @return XML文档
|
||||
*/
|
||||
public static Document createXml(String rootElementName) {
|
||||
final Document doc = createXml();
|
||||
doc.appendChild(doc.createElement(rootElementName));
|
||||
return createXml(rootElementName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建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;
|
||||
}
|
||||
|
||||
@ -674,7 +685,7 @@ public class XmlUtil {
|
||||
* @since 4.0.8
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将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
|
||||
*
|
||||
@ -753,8 +776,21 @@ public class XmlUtil {
|
||||
* @since 4.0.9
|
||||
*/
|
||||
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 Element root = appendChild(doc, rootName);
|
||||
final Element root = appendChild(doc, rootName, namespace);
|
||||
|
||||
mapToXml(doc, root, data);
|
||||
return doc;
|
||||
@ -780,8 +816,21 @@ public class XmlUtil {
|
||||
* @since 4.0.9
|
||||
*/
|
||||
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();
|
||||
Element child = doc.createElement(tagName);
|
||||
Element child = (null == namespace) ? doc.createElement(tagName) : doc.createElementNS(namespace, tagName);
|
||||
node.appendChild(child);
|
||||
return child;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class Page implements Serializable {
|
||||
* @param 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;
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public class Page implements Serializable {
|
||||
* @param pageNumber 页码
|
||||
*/
|
||||
public void setPageNumber(int pageNumber) {
|
||||
this.pageNumber = pageNumber < 0 ? 0 : pageNumber;
|
||||
this.pageNumber = Math.max(pageNumber, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user