You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2013/07/23 19:24:02 UTC
svn commit: r1506169 -
/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/BaseRepositoryHandler.java
Author: marrs
Date: Tue Jul 23 17:24:02 2013
New Revision: 1506169
URL: http://svn.apache.org/r1506169
Log:
ACE-399 Collects all characters when characters() method is invoked multiple times. Defers parsing to the end tag method.
Modified:
ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/BaseRepositoryHandler.java
Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/BaseRepositoryHandler.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/BaseRepositoryHandler.java?rev=1506169&r1=1506168&r2=1506169&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/BaseRepositoryHandler.java (original)
+++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/BaseRepositoryHandler.java Tue Jul 23 17:24:02 2013
@@ -45,6 +45,8 @@ class BaseRepositoryHandler extends Defa
private XmlDeploymentArtifact m_currentArtifact;
/** Denotes the directive key of the current deployment artifact. */
private String m_currentDirectiveKey;
+ /** To collect characters() */
+ private StringBuffer m_buffer = new StringBuffer();
/**
* Creates a new {@link BaseRepositoryHandler} instance.
@@ -84,22 +86,49 @@ class BaseRepositoryHandler extends Defa
}
@Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ XmlTag tag = XmlTag.asXmlTag(qName);
+ // If the given element is an expected child of the current tag, we
+ // traverse deeper into the XML-hierarchy; otherwise, consider it an
+ // "unknown"/uninteresting child and keep the current tag as-is...
+ if (m_currentTag.isExpectedChild(tag)) {
+ m_currentTag = tag;
+ }
+
+ m_currentDirectiveKey = null;
+ // If we're parsing the directives of an artifact, take the name for
+ // later use (the literal text in this tag will be used as value)...
+ if (XmlTag.directives.equals(m_currentTag)) {
+ m_currentDirectiveKey = qName;
+ }
+ m_buffer = new StringBuffer();
+ }
+
+ @Override
public void characters(char[] ch, int start, int length) throws SAXException {
+ // just collect whatever comes along into our buffer (ACE-399)
+ // see: http://stackoverflow.com/questions/4567636/java-sax-parser-split-calls-to-characters
+ m_buffer.append(new String(ch, start, length));
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ String text = m_buffer.toString();
if (XmlTag.targetID.equals(m_currentTag)) {
// verify whether we're in the DP for the requested target...
- m_targetFound = m_targetID.equals(new String(ch, start, length));
+ m_targetFound = m_targetID.equals(text);
}
else if (XmlTag.version.equals(m_currentTag)) {
// Don't assume we've got the desired version (yet)...
m_currentVersion = null;
if (m_targetFound) {
- m_currentVersion = parseAsVersion(new String(ch, start, length));
+ m_currentVersion = parseAsVersion(text);
}
}
else if (XmlTag.url.equals(m_currentTag)) {
try {
- URL artifactUrl = new URL(new String(ch, start, length));
+ URL artifactUrl = new URL(text);
m_currentArtifact = new XmlDeploymentArtifact(artifactUrl);
}
catch (MalformedURLException e) {
@@ -110,33 +139,12 @@ class BaseRepositoryHandler extends Defa
if (m_currentArtifact == null) {
throw new SAXException("Unexpected directive tag!");
}
- String value = new String(ch, start, length).trim();
+ String value = text.trim();
if (m_currentDirectiveKey != null && !value.equals("")) {
m_currentArtifact.m_directives.put(m_currentDirectiveKey, value);
}
}
- }
-
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- XmlTag tag = XmlTag.asXmlTag(qName);
- // If the given element is an expected child of the current tag, we
- // traverse deeper into the XML-hierarchy; otherwise, consider it an
- // "unknown"/uninteresting child and keep the current tag as-is...
- if (m_currentTag.isExpectedChild(tag)) {
- m_currentTag = tag;
- }
-
- m_currentDirectiveKey = null;
- // If we're parsing the directives of an artifact, take the name for
- // later use (the literal text in this tag will be used as value)...
- if (XmlTag.directives.equals(m_currentTag)) {
- m_currentDirectiveKey = qName;
- }
- }
-
- @Override
- public void endElement(String uri, String localName, String qName) throws SAXException {
+
XmlTag tag = XmlTag.asXmlTag(qName);
// When we're ending the current tag, traverse up to its parent...
if (!XmlTag.unknown.equals(tag) && (m_currentTag == tag)) {