You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/04/11 15:33:25 UTC
[groovy] 14/20: Trivial refactoring: extract common code
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 3fd91d1da1def10a6442c203fe058845be68c39b
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Apr 11 22:03:27 2020 +0800
Trivial refactoring: extract common code
(cherry picked from commit f885f10441a6fe666e03caeca5feb2d9a1eda4a6)
---
.../src/main/groovy/groovy/xml/StreamingDOMBuilder.groovy | 10 +---------
.../src/main/groovy/groovy/xml/StreamingSAXBuilder.groovy | 9 +--------
.../streamingmarkupsupport/AbstractStreamingBuilder.groovy | 11 +++++++++++
3 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingDOMBuilder.groovy b/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingDOMBuilder.groovy
index 8f61ec2..8441f7a 100644
--- a/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingDOMBuilder.groovy
+++ b/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingDOMBuilder.groovy
@@ -37,15 +37,7 @@ class StreamingDOMBuilder extends AbstractStreamingBuilder {
attrs.each {target, instruction ->
def pi = null
if (instruction instanceof Map) {
- def buf = new StringBuffer()
- instruction.each { name, value ->
- if (value.toString().contains('"')) {
- buf.append(" $name='$value'")
- } else {
- buf.append(" $name=\"$value\"" )
- }
- }
- pi = dom.document.createProcessingInstruction(target, buf.toString())
+ pi = dom.document.createProcessingInstruction(target, toMapString(instruction))
} else {
pi = dom.document.createProcessingInstruction(target, instruction)
}
diff --git a/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingSAXBuilder.groovy b/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingSAXBuilder.groovy
index 05faf23..917d1ba 100644
--- a/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingSAXBuilder.groovy
+++ b/subprojects/groovy-xml/src/main/groovy/groovy/xml/StreamingSAXBuilder.groovy
@@ -35,14 +35,7 @@ class StreamingSAXBuilder extends AbstractStreamingBuilder {
def piClosure = {doc, pendingNamespaces, namespaces, namespaceSpecificTags, prefix, attrs, body, contentHandler ->
attrs.each {target, instruction ->
if (instruction instanceof Map) {
- def buf = new StringBuffer()
- instruction.each {name, value ->
- if (value.toString().contains('"'))
- buf.append(" $name='$value'")
- else
- buf.append(" $name=\"$value\"")
- }
- contentHandler.processingInstruction(target, buf.toString())
+ contentHandler.processingInstruction(target, toMapString(instruction))
} else {
contentHandler.processingInstruction(target, instruction)
}
diff --git a/subprojects/groovy-xml/src/main/groovy/groovy/xml/streamingmarkupsupport/AbstractStreamingBuilder.groovy b/subprojects/groovy-xml/src/main/groovy/groovy/xml/streamingmarkupsupport/AbstractStreamingBuilder.groovy
index a49d4fe..91a3057 100644
--- a/subprojects/groovy-xml/src/main/groovy/groovy/xml/streamingmarkupsupport/AbstractStreamingBuilder.groovy
+++ b/subprojects/groovy-xml/src/main/groovy/groovy/xml/streamingmarkupsupport/AbstractStreamingBuilder.groovy
@@ -62,6 +62,17 @@ class AbstractStreamingBuilder {
}
def getNamespaceClosure = {doc, pendingNamespaces, namespaces, Object[] rest -> [namespaces, pendingNamespaces]}
+ def toMapString = { Map instruction ->
+ def buf = new StringBuilder()
+ instruction.each { name, value ->
+ if (value.toString().contains('"'))
+ buf.append(" $name='$value'")
+ else
+ buf.append(" $name=\"$value\"")
+ }
+ return buf.toString()
+ }
+
def specialTags = ['declareNamespace':namespaceSetupClosure,
'declareAlias':aliasSetupClosure,
'getNamespaces':getNamespaceClosure]