Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yujianwangzivayy
MaxKey
提交
542ba8bc
MaxKey
项目概览
yujianwangzivayy
/
MaxKey
与 Fork 源项目一致
Fork自
MaxKey单点登录官方(MaxKeyTop) / MaxKey
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MaxKey
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
542ba8bc
编写于
12月 08, 2020
作者:
M
MaxKey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
opensaml 2.6.6
上级
12b9993a
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
287 addition
and
4 deletion
+287
-4
build.gradle
build.gradle
+5
-3
maxkey-core/src/main/java/org/maxkey/pretty/impl/XMLHelper.java
...-core/src/main/java/org/maxkey/pretty/impl/XMLHelper.java
+250
-0
maxkey-core/src/main/java/org/maxkey/pretty/impl/XmlPretty.java
...-core/src/main/java/org/maxkey/pretty/impl/XmlPretty.java
+1
-1
maxkey-core/src/test/java/org/maxkey/util/XMLHelperTest.java
maxkey-core/src/test/java/org/maxkey/util/XMLHelperTest.java
+31
-0
未找到文件。
build.gradle
浏览文件 @
542ba8bc
...
@@ -94,6 +94,7 @@ subprojects {
...
@@ -94,6 +94,7 @@ subprojects {
mavenCentral
()
mavenCentral
()
jcenter
()
jcenter
()
maven
{
url
"https://repo1.maven.org/maven2/"
}
maven
{
url
"https://repo1.maven.org/maven2/"
}
maven
{
url
"https://build.shibboleth.net/nexus/content/repositories/releases/"
}
maven
{
url
"https://mvnrepository.com/repos/central/"
}
maven
{
url
"https://mvnrepository.com/repos/central/"
}
maven
{
url
"http://jcenter.bintray.com"
}
maven
{
url
"http://jcenter.bintray.com"
}
maven
{
url
"http://mvn.gt.igexin.com/nexus/content/repositories/releases"
}
maven
{
url
"http://mvn.gt.igexin.com/nexus/content/repositories/releases"
}
...
@@ -212,9 +213,10 @@ subprojects {
...
@@ -212,9 +213,10 @@ subprojects {
compile
group:
'org.springframework.session'
,
name:
'spring-session-core'
,
version:
"${springSessionVersion}"
compile
group:
'org.springframework.session'
,
name:
'spring-session-core'
,
version:
"${springSessionVersion}"
compile
group:
'org.springframework.session'
,
name:
'spring-session-data-redis'
,
version:
"${springSessionVersion}"
compile
group:
'org.springframework.session'
,
name:
'spring-session-data-redis'
,
version:
"${springSessionVersion}"
//saml
//saml
compile
group:
'org.opensaml'
,
name:
'opensaml'
,
version:
'2.6.4'
compile
group:
'org.opensaml'
,
name:
'opensaml'
,
version:
'2.6.6'
compile
group:
'org.opensaml'
,
name:
'openws'
,
version:
'1.5.4'
compile
group:
'org.opensaml'
,
name:
'openws'
,
version:
'1.5.6'
compile
group:
'org.opensaml'
,
name:
'xmltooling'
,
version:
'1.4.4'
compile
group:
'org.opensaml'
,
name:
'xmltooling'
,
version:
'1.4.6'
compile
group:
'net.shibboleth.utilities'
,
name:
'java-support'
,
version:
'7.5.1'
//jose-jwt
//jose-jwt
compile
group:
'com.nimbusds'
,
name:
'nimbus-jose-jwt'
,
version:
'9.0.1'
compile
group:
'com.nimbusds'
,
name:
'nimbus-jose-jwt'
,
version:
'9.0.1'
compile
group:
'net.jcip'
,
name:
'jcip-annotations'
,
version:
'1.0'
compile
group:
'net.jcip'
,
name:
'jcip-annotations'
,
version:
'1.0'
...
...
maxkey-core/src/main/java/org/maxkey/pretty/impl/XMLHelper.java
0 → 100644
浏览文件 @
542ba8bc
package
org.maxkey.pretty.impl
;
import
java.io.OutputStream
;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
java.io.Writer
;
import
java.util.Map
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
javax.xml.transform.OutputKeys
;
import
javax.xml.transform.Transformer
;
import
javax.xml.transform.TransformerConfigurationException
;
import
javax.xml.transform.TransformerException
;
import
javax.xml.transform.TransformerFactory
;
import
javax.xml.transform.dom.DOMSource
;
import
javax.xml.transform.stream.StreamResult
;
import
org.w3c.dom.DOMConfiguration
;
import
org.w3c.dom.DOMImplementation
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
import
org.w3c.dom.Node
;
import
org.w3c.dom.ls.DOMImplementationLS
;
import
org.w3c.dom.ls.LSOutput
;
import
org.w3c.dom.ls.LSSerializer
;
import
org.w3c.dom.ls.LSSerializerFilter
;
import
org.xml.sax.InputSource
;
import
net.shibboleth.utilities.java.support.collection.LazyMap
;
public
class
XMLHelper
{
/**
* A string which contains the valid delimiters for the XML Schema 'list' type. These are: space, newline, carriage
* return, and tab.
*/
public
static
final
String
LIST_DELIMITERS
=
" \n\r\t"
;
/** DOM configuration parameters used by LSSerializer in pretty print format output. */
private
static
Map
<
String
,
Object
>
prettyPrintParams
;
/**
* Converts a Node into a String using the DOM, level 3, Load/Save serializer.
*
* @param node the node to be written to a string
*
* @return the string representation of the node
*/
public
static
String
nodeToString
(
Node
node
)
{
StringWriter
writer
=
new
StringWriter
();
writeNode
(
node
,
writer
);
return
writer
.
toString
();
}
/**
* Pretty prints the XML node.
*
* @param node xml node to print
*
* @return pretty-printed xml
*/
public
static
String
prettyPrintXML
(
Node
node
)
{
StringWriter
writer
=
new
StringWriter
();
writeNode
(
node
,
writer
,
getPrettyPrintParams
());
return
writer
.
toString
();
}
public
static
String
prettyPrintXML
(
String
xmlString
){
try
{
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
documentBuilder
=
documentBuilderFactory
.
newDocumentBuilder
();
Document
document
=
documentBuilder
.
parse
(
new
InputSource
(
new
StringReader
(
xmlString
)));
return
prettyPrintXML
(
document
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
null
;
}
}
/**
* Create the parameters set used in pretty print formatting of an LSSerializer.
*
* @return the params map
*/
private
static
Map
<
String
,
Object
>
getPrettyPrintParams
()
{
if
(
prettyPrintParams
==
null
)
{
prettyPrintParams
=
new
LazyMap
<
String
,
Object
>();
prettyPrintParams
.
put
(
"format-pretty-print"
,
Boolean
.
TRUE
);
}
return
prettyPrintParams
;
}
/**
* Writes a Node out to a Writer using the DOM, level 3, Load/Save serializer. The written content is encoded using
* the encoding specified in the writer configuration.
*
* @param node the node to write out
* @param output the writer to write the XML to
*/
public
static
void
writeNode
(
Node
node
,
Writer
output
)
{
writeNode
(
node
,
output
,
null
);
}
/**
* Writes a Node out to a Writer using the DOM, level 3, Load/Save serializer. The written content is encoded using
* the encoding specified in the writer configuration.
*
* @param node the node to write out
* @param output the writer to write the XML to
* @param serializerParams parameters to pass to the {@link DOMConfiguration} of the serializer
* instance, obtained via {@link LSSerializer#getDomConfig()}. May be null.
*/
public
static
void
writeNode
(
Node
node
,
Writer
output
,
Map
<
String
,
Object
>
serializerParams
)
{
DOMImplementationLS
domImplLS
=
getLSDOMImpl
(
node
);
LSSerializer
serializer
=
getLSSerializer
(
domImplLS
,
serializerParams
);
LSOutput
serializerOut
=
domImplLS
.
createLSOutput
();
serializerOut
.
setCharacterStream
(
output
);
serializer
.
write
(
node
,
serializerOut
);
}
/**
* Writes a Node out to an OutputStream using the DOM, level 3, Load/Save serializer. The written content
* is encoded using the encoding specified in the output stream configuration.
*
* @param node the node to write out
* @param output the output stream to write the XML to
*/
public
static
void
writeNode
(
Node
node
,
OutputStream
output
)
{
writeNode
(
node
,
output
,
null
);
}
/**
* Writes a Node out to an OutputStream using the DOM, level 3, Load/Save serializer. The written content
* is encoded using the encoding specified in the output stream configuration.
*
* @param node the node to write out
* @param output the output stream to write the XML to
* @param serializerParams parameters to pass to the {@link DOMConfiguration} of the serializer
* instance, obtained via {@link LSSerializer#getDomConfig()}. May be null.
*/
public
static
void
writeNode
(
Node
node
,
OutputStream
output
,
Map
<
String
,
Object
>
serializerParams
)
{
DOMImplementationLS
domImplLS
=
getLSDOMImpl
(
node
);
LSSerializer
serializer
=
getLSSerializer
(
domImplLS
,
serializerParams
);
LSOutput
serializerOut
=
domImplLS
.
createLSOutput
();
serializerOut
.
setByteStream
(
output
);
serializer
.
write
(
node
,
serializerOut
);
}
/**
* Obtain a the DOM, level 3, Load/Save serializer {@link LSSerializer} instance from the
* given {@link DOMImplementationLS} instance.
*
* <p>
* The serializer instance will be configured with the parameters passed as the <code>serializerParams</code>
* argument. It will also be configured with an {@link LSSerializerFilter} that shows all nodes to the filter,
* and accepts all nodes shown.
* </p>
*
* @param domImplLS the DOM Level 3 Load/Save implementation to use
* @param serializerParams parameters to pass to the {@link DOMConfiguration} of the serializer
* instance, obtained via {@link LSSerializer#getDomConfig()}. May be null.
*
* @return a new LSSerializer instance
*/
public
static
LSSerializer
getLSSerializer
(
DOMImplementationLS
domImplLS
,
Map
<
String
,
Object
>
serializerParams
)
{
LSSerializer
serializer
=
domImplLS
.
createLSSerializer
();
serializer
.
setFilter
(
new
LSSerializerFilter
()
{
public
short
acceptNode
(
Node
arg0
)
{
return
FILTER_ACCEPT
;
}
public
int
getWhatToShow
()
{
return
SHOW_ALL
;
}
});
if
(
serializerParams
!=
null
)
{
DOMConfiguration
serializerDOMConfig
=
serializer
.
getDomConfig
();
for
(
String
key
:
serializerParams
.
keySet
())
{
serializerDOMConfig
.
setParameter
(
key
,
serializerParams
.
get
(
key
));
}
}
return
serializer
;
}
/**
* Get the DOM Level 3 Load/Save {@link DOMImplementationLS} for the given node.
*
* @param node the node to evaluate
* @return the DOMImplementationLS for the given node
*/
public
static
DOMImplementationLS
getLSDOMImpl
(
Node
node
)
{
DOMImplementation
domImpl
;
if
(
node
instanceof
Document
)
{
domImpl
=
((
Document
)
node
).
getImplementation
();
}
else
{
domImpl
=
node
.
getOwnerDocument
().
getImplementation
();
}
DOMImplementationLS
domImplLS
=
(
DOMImplementationLS
)
domImpl
.
getFeature
(
"LS"
,
"3.0"
);
return
domImplLS
;
}
public
static
String
transformer
(
Element
element
)
{
String
xmlString
=
null
;
try
{
Transformer
transformer
=
TransformerFactory
.
newInstance
().
newTransformer
();
transformer
.
setOutputProperty
(
OutputKeys
.
INDENT
,
"yes"
);
transformer
.
setOutputProperty
(
"{http://xml.apache.org/xslt}indent-amount"
,
"4"
);
StreamResult
result
=
new
StreamResult
(
new
StringWriter
());
DOMSource
source
=
new
DOMSource
(
element
);
transformer
.
transform
(
source
,
result
);
xmlString
=
result
.
getWriter
().
toString
();
}
catch
(
TransformerConfigurationException
e
)
{
e
.
printStackTrace
();
}
catch
(
TransformerException
e
)
{
e
.
printStackTrace
();
}
return
xmlString
;
}
public
static
String
transformer
(
String
xmlString
){
try
{
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
documentBuilder
=
documentBuilderFactory
.
newDocumentBuilder
();
Document
document
=
documentBuilder
.
parse
(
new
InputSource
(
new
StringReader
(
xmlString
)));
return
transformer
(
document
.
getDocumentElement
());
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
null
;
}
}
}
maxkey-core/src/main/java/org/maxkey/pretty/impl/XmlPretty.java
浏览文件 @
542ba8bc
...
@@ -49,7 +49,7 @@ public class XmlPretty implements Pretty{
...
@@ -49,7 +49,7 @@ public class XmlPretty implements Pretty{
public
String
format
(
Node
node
){
public
String
format
(
Node
node
){
try
{
try
{
return
org
.
opensaml
.
xml
.
util
.
XMLHelper
.
prettyPrintXML
(
node
);
return
XMLHelper
.
prettyPrintXML
(
node
);
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
e
.
printStackTrace
();
e
.
printStackTrace
();
return
null
;
return
null
;
...
...
maxkey-core/src/test/java/org/maxkey/util/XMLHelperTest.java
0 → 100644
浏览文件 @
542ba8bc
package
org.maxkey.util
;
import
java.io.OutputStream
;
import
java.io.StringWriter
;
import
java.io.Writer
;
import
java.util.Map
;
import
org.junit.Test
;
import
org.maxkey.pretty.PrettyFactory
;
import
org.maxkey.pretty.impl.XMLHelper
;
import
org.w3c.dom.DOMConfiguration
;
import
org.w3c.dom.DOMImplementation
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Node
;
import
org.w3c.dom.ls.DOMImplementationLS
;
import
org.w3c.dom.ls.LSOutput
;
import
org.w3c.dom.ls.LSSerializer
;
import
org.w3c.dom.ls.LSSerializerFilter
;
import
net.shibboleth.utilities.java.support.collection.LazyMap
;
public
class
XMLHelperTest
{
@Test
public
void
testSqlFormat
()
{
String
sqlString
=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><xml><data><name>maxkey</name><age v=\"20\"/></data></xml>"
;
System
.
out
.
println
(
XMLHelper
.
prettyPrintXML
(
sqlString
));
System
.
out
.
println
(
XMLHelper
.
transformer
(
sqlString
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录