REOC-61 Upgrade to use dom4j for xml processor

This commit is contained in:
YuCheng Hu 2019-09-22 23:20:09 -04:00
parent 8c68231333
commit 77d496ccef
9 changed files with 181 additions and 184 deletions

View File

@ -32,6 +32,8 @@ dependencies {
compile group: 'commons-logging', name: 'commons-logging', version: '1.1.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'commons-codec', name: 'commons-codec', version: '1.3'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.1.1'
@ -39,7 +41,7 @@ dependencies {
compile group: 'com.google.guava', name: 'guava', version: '28.1-jre'
// XML
compile 'jdom:jdom:1.0'
compile group: 'org.dom4j', name: 'dom4j', version: '2.1.1'
// TEST
testCompile group: 'junit', name: 'junit', version: '4.12'

View File

@ -24,10 +24,9 @@
<dependencies>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
<optional>false</optional>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.1</version>
</dependency>
<!-- TEST -->

View File

@ -1,10 +1,11 @@
package com.ossez.reoc.rets.client;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.InputStream;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
/**
* dbt is lame and hasn't overridden the default
@ -12,10 +13,10 @@ import org.jdom.input.SAXBuilder;
*/
public class ChangePasswordResponse {
public ChangePasswordResponse(InputStream stream) throws RetsException {
SAXBuilder builder = new SAXBuilder();
SAXReader builder = new SAXReader();
Document document = null;
try {
document = builder.build(stream);
document = builder.read(stream);
} catch (Exception e) {
throw new RetsException(e);
}
@ -24,11 +25,11 @@ public class ChangePasswordResponse {
throw new RetsException("Invalid Change Password Response");
}
int replyCode = Integer.parseInt(rets.getAttributeValue("ReplyCode"));
int replyCode = Integer.parseInt(rets.attributeValue("ReplyCode"));
if (replyCode != 0) {
InvalidReplyCodeException exception;
exception = new InvalidReplyCodeException(replyCode);
exception.setRemoteMessage(rets.getAttributeValue("ReplyText"));
exception.setRemoteMessage(rets.attributeValue("ReplyText"));
throw exception;
}
}

View File

@ -9,24 +9,24 @@ import com.ossez.reoc.rets.common.metadata.JDomStandardBuilder;
import com.ossez.reoc.rets.common.metadata.MetaObject;
import com.ossez.reoc.rets.common.metadata.MetadataException;
import org.apache.commons.lang3.math.NumberUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
public class GetMetadataResponse {
private MetaObject[] mMetadataObjs;
public GetMetadataResponse(InputStream stream, boolean compact, boolean isStrict) throws RetsException {
try {
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(stream);
SAXReader builder = new SAXReader();
Document document = builder.read(stream);
Element retsElement = document.getRootElement();
if (!retsElement.getName().equals("RETS")) {
throw new RetsException("Expecting RETS");
}
int replyCode = NumberUtils.toInt(retsElement.getAttributeValue("ReplyCode"));
int replyCode = NumberUtils.toInt(retsElement.attributeValue("ReplyCode"));
if (ReplyCode.SUCCESS.equals(replyCode)) {
if (compact) {
handleCompactMetadata(document, isStrict);
@ -38,18 +38,16 @@ public class GetMetadataResponse {
handleNoMetadataFound(retsElement);
} else {
InvalidReplyCodeException e = new InvalidReplyCodeException(replyCode);
e.setRemoteMessage(retsElement.getAttributeValue(retsElement.getAttributeValue("ReplyText")));
e.setRemoteMessage(retsElement.attributeValue(retsElement.attributeValue("ReplyText")));
throw e;
}
} catch (JDOMException e) {
throw new RetsException(e);
} catch (IOException e) {
} catch (DocumentException e) {
throw new RetsException(e);
}
}
private void handleNoMetadataFound(Element retsElement) throws RetsException {
List children = retsElement.getChildren();
List children = retsElement.elements();
if (children.size() != 0) {
throw new RetsException("Expecting 0 children when results");
}

View File

@ -10,10 +10,11 @@ import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicHeaderValueParser;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.w3c.dom.DOMException;
public class GetObjectResponse{
private static final int DEFAULT_BUFFER_SIZE = 8192;
@ -59,11 +60,11 @@ public class GetObjectResponse{
try {
// GetObjectResponse is empty, because we have a Rets ReplyCode
this.emptyResponse = true;
SAXBuilder builder = new SAXBuilder();
Document mDocument = builder.build(in);
SAXReader builder = new SAXReader();
Document mDocument = builder.read(in);
Element root = mDocument.getRootElement();
if (root.getName().equals("RETS")) {
replyCode = NumberUtils.toInt(root.getAttributeValue("ReplyCode"));
replyCode = NumberUtils.toInt(root.attributeValue("ReplyCode"));
// success
if (ReplyCode.SUCCESS.equals(replyCode)) return;
@ -76,9 +77,7 @@ public class GetObjectResponse{
// no other possibilities
throw new RetsException("Malformed response [multipart="+this.isMultipart+", content-type=text/xml]. " +
"Content id did not exist in response and response was not valid rets response.");
} catch (JDOMException e) {
throw new RetsException(e);
} catch (IOException e) {
} catch (DocumentException e) {
throw new RetsException(e);
}
}

View File

@ -1,21 +1,21 @@
package com.ossez.reoc.rets.client;
import java.util.List;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.io.IOException;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.InputStream;
import java.util.List;
import java.util.StringTokenizer;
/**
*
*/
abstract public class KeyValueResponse {
protected static final String CRLF = "\r\n";
private static final Log LOG = LogFactory.getLog(KeyValueResponse.class);
@ -30,14 +30,14 @@ abstract public class KeyValueResponse {
public void parse(InputStream stream, RetsVersion mVersion) throws RetsException {
try {
SAXBuilder builder = new SAXBuilder();
this.mDoc = builder.build(stream);
SAXReader builder = new SAXReader();
this.mDoc = builder.read(stream);
Element retsElement = this.mDoc.getRootElement();
if (!retsElement.getName().equals("RETS")) {
throw new RetsException("Expecting RETS");
}
int replyCode = NumberUtils.toInt(retsElement.getAttributeValue("ReplyCode"));
int replyCode = NumberUtils.toInt(retsElement.attributeValue("ReplyCode"));
this.mReplyCode = replyCode;
if (!isValidReplyCode(replyCode)) {
throw new InvalidReplyCodeException(replyCode);
@ -46,7 +46,7 @@ abstract public class KeyValueResponse {
if (RetsVersion.RETS_10.equals(mVersion)) {
capabilityContainer = retsElement;
} else {
List children = retsElement.getChildren();
List children = retsElement.elements();
if (children.size() != 1) {
throw new RetsException("Invalid number of children: " + children.size());
}
@ -58,9 +58,7 @@ abstract public class KeyValueResponse {
}
}
this.handleRetsResponse(capabilityContainer);
} catch (JDOMException e) {
throw new RetsException(e);
} catch (IOException e) {
} catch (DocumentException e) {
throw new RetsException(e);
}
}

View File

@ -9,11 +9,11 @@ import com.ossez.reoc.rets.common.metadata.JDomCompactBuilder;
import com.ossez.reoc.rets.common.metadata.JDomStandardBuilder;
import com.ossez.reoc.rets.common.metadata.Metadata;
import com.ossez.reoc.rets.common.metadata.MetadataBuilder;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
/**
@ -278,13 +278,16 @@ public class RetsTransport {
Object monitorobj = null;
monitorobj = this.monitor.eventStart("Parsing metadata");
try {
SAXBuilder xmlBuilder = new SAXBuilder();
Document xmlDocument = xmlBuilder.build(httpResponse.getInputStream());
SAXReader xmlBuilder = new SAXReader();
Document xmlDocument = xmlBuilder.read(httpResponse.getInputStream());
if (!location.equals("null")){
XMLOutputter outputter = new XMLOutputter();
FileWriter writer = new FileWriter(location);
outputter.output(xmlDocument, writer);
outputter.outputString(xmlDocument);
XMLWriter outputter = new XMLWriter(writer);
outputter.write(xmlDocument);
outputter.close();
}
MetadataBuilder metadataBuilder;
if (req.isCompactFormat()) {

View File

@ -14,10 +14,8 @@ import java.util.StringTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.dom4j.*;
import com.ossez.reoc.rets.common.metadata.types.MClass;
import com.ossez.reoc.rets.common.metadata.types.MEditMask;
import com.ossez.reoc.rets.common.metadata.types.MLookup;
@ -34,6 +32,7 @@ import com.ossez.reoc.rets.common.metadata.types.MValidationExternal;
import com.ossez.reoc.rets.common.metadata.types.MValidationExternalType;
import com.ossez.reoc.rets.common.metadata.types.MValidationLookup;
import com.ossez.reoc.rets.common.metadata.types.MValidationLookupType;
import org.dom4j.io.SAXReader;
import org.xml.sax.InputSource;
public class JDomCompactBuilder extends MetadataBuilder {
@ -75,13 +74,11 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
public Metadata build(InputSource source) throws MetadataException {
SAXBuilder builder = new SAXBuilder();
SAXReader builder = new SAXReader();
Document document;
try {
document = builder.build(source);
} catch (JDOMException e) {
throw new MetadataException("Couldn't build document", e);
} catch (IOException e) {
document = builder.read(source);
} catch (DocumentException e) {
throw new MetadataException("Couldn't build document", e);
}
return build(document);
@ -97,72 +94,72 @@ public class JDomCompactBuilder extends MetadataBuilder {
if (!root.getName().equals(CONTAINER_ROOT)) {
throw new MetadataException("Invalid root element");
}
Element container = root.getChild(CONTAINER_SYSTEM);
Element container = root.element(CONTAINER_SYSTEM);
if (container != null) {
MSystem sys = processSystem(container);
if (root.getChild(CONTAINER_RESOURCE) != null) {
if (root.element(CONTAINER_RESOURCE) != null) {
Metadata m = new Metadata(sys);
recurseAll(m, root);
}
return new MetaObject[] { sys };
}
container = root.getChild(CONTAINER_RESOURCE);
container = root.element(CONTAINER_RESOURCE);
if (container != null) {
return processResource(container);
}
container = root.getChild(CONTAINER_CLASS);
container = root.element(CONTAINER_CLASS);
if (container != null) {
return processClass(container);
}
container = root.getChild(CONTAINER_TABLE);
container = root.element(CONTAINER_TABLE);
if (container != null) {
return processTable(container);
}
container = root.getChild(CONTAINER_UPDATE);
container = root.element(CONTAINER_UPDATE);
if (container != null) {
return processUpdate(container);
}
container = root.getChild(CONTAINER_UPDATETYPE);
container = root.element(CONTAINER_UPDATETYPE);
if (container != null) {
return processUpdateType(container);
}
container = root.getChild(CONTAINER_OBJECT);
container = root.element(CONTAINER_OBJECT);
if (container != null) {
return processObject(container);
}
container = root.getChild(CONTAINER_SEARCHHELP);
container = root.element(CONTAINER_SEARCHHELP);
if (container != null) {
return processSearchHelp(container);
}
container = root.getChild(CONTAINER_EDITMASK);
container = root.element(CONTAINER_EDITMASK);
if (container != null) {
return processEditMask(container);
}
container = root.getChild(CONTAINER_LOOKUP);
container = root.element(CONTAINER_LOOKUP);
if (container != null) {
return processLookup(container);
}
container = root.getChild(CONTAINER_LOOKUPTYPE);
container = root.element(CONTAINER_LOOKUPTYPE);
if (container != null) {
return processLookupType(container);
}
container = root.getChild(CONTAINER_VALIDATIONLOOKUP);
container = root.element(CONTAINER_VALIDATIONLOOKUP);
if (container != null) {
return processValidationLookup(container);
}
container = root.getChild(CONTAINER_VALIDATIONLOOKUPTYPE);
container = root.element(CONTAINER_VALIDATIONLOOKUPTYPE);
if (container != null) {
return processValidationLookupType(container);
}
container = root.getChild(CONTAINER_VALIDATIONEXTERNAL);
container = root.element(CONTAINER_VALIDATIONEXTERNAL);
if (container != null) {
return processValidationExternal(container);
}
container = root.getChild(CONTAINER_VALIDATIONEXTERNALTYPE);
container = root.element(CONTAINER_VALIDATIONEXTERNALTYPE);
if (container != null) {
return processValidationExternalType(container);
}
container = root.getChild(CONTAINER_VALIDATIONEXPRESSION);
container = root.element(CONTAINER_VALIDATIONEXPRESSION);
if (container != null) {
return processValidationExpression(container);
}
@ -174,7 +171,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
if (!root.getName().equals(CONTAINER_ROOT)) {
throw new MetadataException("Invalid root element");
}
Element element = root.getChild(CONTAINER_SYSTEM);
Element element = root.element(CONTAINER_SYSTEM);
if (element == null) {
throw new MetadataException("Missing element " + CONTAINER_SYSTEM);
}
@ -218,7 +215,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private String[] getColumns(Element el) {
Element cols = el.getChild(COLUMNS);
Element cols = el.element(COLUMNS);
return split(cols);
}
@ -256,7 +253,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
* @throws MetaParseException if the value is null.
*/
private String getNonNullAttribute(Element element, String name) throws MetaParseException {
String value = element.getAttributeValue(name);
String value = element.attributeValue(name);
if (value == null) {
throw new MetaParseException("Attribute '" + name + "' not found on tag " + toString(element));
}
@ -265,21 +262,21 @@ public class JDomCompactBuilder extends MetadataBuilder {
private String toString(Element element) {
StringBuffer buffer = new StringBuffer();
List attributes = element.getAttributes();
List attributes = element.attributes();
buffer.append("'").append(element.getName()).append("'");
buffer.append(", attributes: ").append(attributes);
return buffer.toString();
}
private MSystem processSystem(Element container) {
Element element = container.getChild(ELEMENT_SYSTEM);
Element element = container.element(ELEMENT_SYSTEM);
MSystem system = buildSystem();
// system metadata is such a hack. the first one here is by far my favorite
String comment = container.getChildText(MSystem.COMMENTS);
String systemId = element.getAttributeValue(MSystem.SYSTEMID);
String systemDescription = element.getAttributeValue(MSystem.SYSTEMDESCRIPTION);
String version = container.getAttributeValue(MSystem.VERSION);
String date = container.getAttributeValue(MSystem.DATE);
String comment = container.elementText(MSystem.COMMENTS);
String systemId = element.attributeValue(MSystem.SYSTEMID);
String systemDescription = element.attributeValue(MSystem.SYSTEMDESCRIPTION);
String version = container.attributeValue(MSystem.VERSION);
String date = container.attributeValue(MSystem.DATE);
setAttribute(system, MSystem.COMMENTS, comment);
setAttribute(system, MSystem.SYSTEMID, systemId);
setAttribute(system, MSystem.SYSTEMDESCRIPTION, systemDescription);
@ -290,7 +287,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private void attachResource(Metadata metadata, Element root) {
MSystem system = metadata.getSystem();
List containers = root.getChildren(CONTAINER_RESOURCE);
List containers = root.elements(CONTAINER_RESOURCE);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MResource[] resources = this.processResource(container);
@ -302,7 +299,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MResource[] processResource(Element resourceContainer) {
String[] columns = getColumns(resourceContainer);
List rows = resourceContainer.getChildren(DATA);
List rows = resourceContainer.elements(DATA);
MResource[] resources = new MResource[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -315,7 +312,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachClass(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_CLASS);
List containers = root.elements(CONTAINER_CLASS);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
String resourceId = getNonNullAttribute(container, ATTRIBUTE_RESOURCE);
@ -332,7 +329,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
String resourceId = getNonNullAttribute(classContainer, ATTRIBUTE_RESOURCE);
LOG.debug("resource name: " + resourceId + " for container " + name);
String[] columns = getColumns(classContainer);
List rows = classContainer.getChildren(DATA);
List rows = classContainer.elements(DATA);
MClass[] classes = new MClass[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -345,7 +342,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachTable(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_TABLE);
List containers = root.elements(CONTAINER_TABLE);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
String resourceId = getNonNullAttribute(container, ATTRIBUTE_RESOURCE);
@ -368,7 +365,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MTable[] processTable(Element tableContainer) {
String[] columns = getColumns(tableContainer);
List rows = tableContainer.getChildren(DATA);
List rows = tableContainer.elements(DATA);
MTable[] fieldMetadata = new MTable[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -381,7 +378,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachUpdate(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_UPDATE);
List containers = root.elements(CONTAINER_UPDATE);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MClass parent = metadata.getMClass(getNonNullAttribute(container, ATTRIBUTE_RESOURCE), getNonNullAttribute(
@ -395,7 +392,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MUpdate[] processUpdate(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MUpdate[] updates = new MUpdate[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -408,7 +405,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachUpdateType(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_UPDATETYPE);
List containers = root.elements(CONTAINER_UPDATETYPE);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MUpdate parent = metadata.getUpdate(getNonNullAttribute(container, ATTRIBUTE_RESOURCE),
@ -422,7 +419,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MUpdateType[] processUpdateType(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MUpdateType[] updateTypes = new MUpdateType[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -435,7 +432,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachObject(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_OBJECT);
List containers = root.elements(CONTAINER_OBJECT);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MResource parent = metadata.getResource(getNonNullAttribute(container, ATTRIBUTE_RESOURCE));
@ -448,7 +445,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MObject[] processObject(Element objectContainer) {
String[] columns = getColumns(objectContainer);
List rows = objectContainer.getChildren(DATA);
List rows = objectContainer.elements(DATA);
MObject[] objects = new MObject[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -461,7 +458,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachSearchHelp(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_SEARCHHELP);
List containers = root.elements(CONTAINER_SEARCHHELP);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MResource parent = metadata.getResource(getNonNullAttribute(container, ATTRIBUTE_RESOURCE));
@ -474,7 +471,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MSearchHelp[] processSearchHelp(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MSearchHelp[] searchHelps = new MSearchHelp[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -487,7 +484,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachEditMask(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_EDITMASK);
List containers = root.elements(CONTAINER_EDITMASK);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MResource parent = metadata.getResource(getNonNullAttribute(container, ATTRIBUTE_RESOURCE));
@ -500,7 +497,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MEditMask[] processEditMask(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MEditMask[] editMasks = new MEditMask[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -513,7 +510,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachLookup(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_LOOKUP);
List containers = root.elements(CONTAINER_LOOKUP);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MResource parent = metadata.getResource(getNonNullAttribute(container, ATTRIBUTE_RESOURCE));
@ -526,7 +523,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MLookup[] processLookup(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MLookup[] lookups = new MLookup[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -539,7 +536,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachLookupType(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_LOOKUPTYPE);
List containers = root.elements(CONTAINER_LOOKUPTYPE);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MLookup parent = metadata.getLookup(getNonNullAttribute(container, ATTRIBUTE_RESOURCE),
@ -559,7 +556,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MLookupType[] processLookupType(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MLookupType[] lookupTypes = new MLookupType[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -572,7 +569,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachValidationLookup(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_VALIDATIONLOOKUP);
List containers = root.elements(CONTAINER_VALIDATIONLOOKUP);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MResource parent = metadata.getResource(getNonNullAttribute(container, ATTRIBUTE_RESOURCE));
@ -585,7 +582,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MValidationLookup[] processValidationLookup(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MValidationLookup[] validationLookups = new MValidationLookup[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -598,7 +595,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachValidationLookupType(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_VALIDATIONLOOKUPTYPE);
List containers = root.elements(CONTAINER_VALIDATIONLOOKUPTYPE);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MValidationLookup parent = metadata.getValidationLookup(getNonNullAttribute(container, ATTRIBUTE_RESOURCE),
@ -612,7 +609,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MValidationLookupType[] processValidationLookupType(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MValidationLookupType[] validationLookupTypes = new MValidationLookupType[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -625,10 +622,10 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachValidationExternal(Metadata metadata, Element root) {
List containers = root.getChildren(CONTAINER_VALIDATIONEXTERNAL);
List containers = root.elements(CONTAINER_VALIDATIONEXTERNAL);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MResource parent = metadata.getResource(container.getAttributeValue(ATTRIBUTE_RESOURCE));
MResource parent = metadata.getResource(container.attributeValue(ATTRIBUTE_RESOURCE));
MValidationExternal[] validationExternals = processValidationExternal(container);
for (int j = 0; j < validationExternals.length; j++) {
parent.addChild(MetadataType.VALIDATION_EXTERNAL, validationExternals[j]);
@ -638,7 +635,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MValidationExternal[] processValidationExternal(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MValidationExternal[] validationExternals = new MValidationExternal[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -651,7 +648,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachValidationExternalType(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_VALIDATIONEXTERNALTYPE);
List containers = root.elements(CONTAINER_VALIDATIONEXTERNALTYPE);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MValidationExternal parent = metadata.getValidationExternal(getNonNullAttribute(container,
@ -665,7 +662,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MValidationExternalType[] processValidationExternalType(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MValidationExternalType[] validationExternalTypes = new MValidationExternalType[rows.size()];
for (int i = 0; i < rows.size(); i++) {
Element element = (Element) rows.get(i);
@ -678,7 +675,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
}
private void attachValidationExpression(Metadata metadata, Element root) throws MetaParseException {
List containers = root.getChildren(CONTAINER_VALIDATIONEXPRESSION);
List containers = root.elements(CONTAINER_VALIDATIONEXPRESSION);
for (int i = 0; i < containers.size(); i++) {
Element container = (Element) containers.get(i);
MResource parent = metadata.getResource(getNonNullAttribute(container, ATTRIBUTE_RESOURCE));
@ -691,7 +688,7 @@ public class JDomCompactBuilder extends MetadataBuilder {
private MValidationExpression[] processValidationExpression(Element container) {
String[] columns = getColumns(container);
List rows = container.getChildren(DATA);
List rows = container.elements(DATA);
MValidationExpression[] expressions = new MValidationExpression[rows.size()];
for (int i = 0; i < expressions.length; i++) {
Element element = (Element) rows.get(i);

View File

@ -13,9 +13,6 @@ import java.util.List;
import java.util.Map;
import java.util.HashMap;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import com.ossez.reoc.rets.common.metadata.types.MClass;
import com.ossez.reoc.rets.common.metadata.types.MEditMask;
import com.ossez.reoc.rets.common.metadata.types.MForeignKey;
@ -34,6 +31,9 @@ import com.ossez.reoc.rets.common.metadata.types.MValidationExternal;
import com.ossez.reoc.rets.common.metadata.types.MValidationExternalType;
import com.ossez.reoc.rets.common.metadata.types.MValidationLookup;
import com.ossez.reoc.rets.common.metadata.types.MValidationLookupType;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
/** Parses apart a complete Standard-XML response, returns a Metadata object */
public class JDomStandardBuilder extends MetadataBuilder {
@ -105,7 +105,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
expectElement(element, CONTAINER_ROOT);
Element container = getElement(element, CONTAINER_METADATA);
boolean recurse = checkForRecursion(container);
List list = container.getChildren();
List list = container.elements();
if (list.size() == 0) {
return null;
}
@ -130,15 +130,15 @@ public class JDomStandardBuilder extends MetadataBuilder {
* we fall all the way to the end then there probably wasn't that
* much to look through.
*/
Iterator children = top.getChildren().iterator();
Iterator children = top.elements().iterator();
while (children.hasNext()) {
/* each of these is a container (METADATA-*) type */
Element element = (Element) children.next();
Iterator iterator = element.getChildren().iterator();
Iterator iterator = element.elements().iterator();
while (iterator.hasNext()) {
/* each of these is an item element */
Element child = (Element) iterator.next();
Iterator subtypes = child.getChildren().iterator();
Iterator subtypes = child.elements().iterator();
while (subtypes.hasNext()) {
Element subtype = (Element) subtypes.next();
if (subtype.getName().startsWith(CONTAINER_PREFIX)) {
@ -155,7 +155,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
if (type == null) {
throw new RuntimeException("no matching type for container " + container.getName());
}
List elements = container.getChildren((String) sType2Element.get(type));
List elements = container.elements((String) sType2Element.get(type));
String path = getPath(container);
List output = null;
if (parent == null) {
@ -185,7 +185,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
MetadataType[] childTypes = obj.getChildTypes();
for (int j = 0; j < childTypes.length; j++) {
MetadataType childType = childTypes[j];
Element childContainer = element.getChild(CONTAINER_PREFIX + childType.name());
Element childContainer = element.element(CONTAINER_PREFIX + childType.name());
if (childContainer == null) {
obj.addChild(childType, null);
} else {
@ -201,27 +201,27 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
String getPath(Element container) {
String resource = container.getAttributeValue(ATTRIBUTE_RESOURCEID);
String resource = container.attributeValue(ATTRIBUTE_RESOURCEID);
if (resource == null) {
return null;
}
String classname = container.getAttributeValue(ATTRIBUTE_CLASSNAME);
String classname = container.attributeValue(ATTRIBUTE_CLASSNAME);
if (classname != null) {
String update = container.getAttributeValue(ATTRIBUTE_UPDATE);
String update = container.attributeValue(ATTRIBUTE_UPDATE);
if (update != null) {
return resource + ":" + classname + ":" + update;
}
return resource + ":" + classname;
}
String lookup = container.getAttributeValue(ATTRIBUTE_LOOKUP);
String lookup = container.attributeValue(ATTRIBUTE_LOOKUP);
if (lookup != null) {
return resource + ":" + lookup;
}
String vallkp = container.getAttributeValue(ATTRIBUTE_VALIDATIONLOOKUP);
String vallkp = container.attributeValue(ATTRIBUTE_VALIDATIONLOOKUP);
if (vallkp != null) {
return resource + ":" + vallkp;
}
String vale = container.getAttributeValue(ATTRIBUTE_VALIDATIONEXTERNAL);
String vale = container.attributeValue(ATTRIBUTE_VALIDATIONEXTERNAL);
if (vale != null) {
return resource + ":" + vale;
}
@ -237,7 +237,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private Element getElement(Element parent, String type) throws MetadataException {
Element element = parent.getChild(type);
Element element = parent.element(type);
if (element == null) {
throw new MetadataException("Missing element " + type);
}
@ -253,7 +253,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
private void setAttributes(MetaObject obj, Element el) {
List children = el.getChildren();
List children = el.elements();
for (int i = 0; i < children.size(); i++) {
Element child = (Element) children.get(i);
String name = child.getName();
@ -269,7 +269,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
//when atrributes from the xml element are needed
public void setAttributesFromXMLAttr(MetaObject obj, Element el) {
Iterator attrIter = el.getParentElement().getAttributes().iterator();
Iterator attrIter = el.getParent().attributes().iterator();
while(attrIter.hasNext()){
Attribute attr = (Attribute) attrIter.next();
@ -293,20 +293,20 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private MSystem processSystem(Element container) {
Element element = container.getChild(ELEMENT_SYSTEM);
Element element = container.element(ELEMENT_SYSTEM);
if (element == null){
element = container.getChild(ELEMENT_SYSTEM.toUpperCase());
element = container.element(ELEMENT_SYSTEM.toUpperCase());
}
MSystem system = buildSystem();
init(system);
setAttributesFromXMLAttr(system, element);
setAttributes(system, element);
Element child;
child = element.getChild(CONTAINER_RESOURCE);
child = element.element(CONTAINER_RESOURCE);
if (child != null) {
processResource(system, child);
}
child = element.getChild(CONTAINER_FOREIGNKEY);
child = element.element(CONTAINER_FOREIGNKEY);
if (child != null) {
processForeignKey(system, child);
}
@ -314,7 +314,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processResource(MSystem system, Element container) {
List resources = container.getChildren(ELEMENT_RESOURCE);
List resources = container.elements(ELEMENT_RESOURCE);
for (int i = 0; i < resources.size(); i++) {
Element element = (Element) resources.get(i);
MResource resource = buildResource();
@ -322,39 +322,39 @@ public class JDomStandardBuilder extends MetadataBuilder {
setAttributes(resource, element);
system.addChild(MetadataType.RESOURCE, resource);
Element child;
child = element.getChild(CONTAINER_CLASS);
child = element.element(CONTAINER_CLASS);
if (child != null) {
processClass(resource, child);
}
child = element.getChild(CONTAINER_OBJECT);
child = element.element(CONTAINER_OBJECT);
if (child != null) {
processObject(resource, child);
}
child = element.getChild(CONTAINER_SEARCH_HELP);
child = element.element(CONTAINER_SEARCH_HELP);
if (child != null) {
processSearchHelp(resource, child);
}
child = element.getChild(CONTAINER_EDITMASK);
child = element.element(CONTAINER_EDITMASK);
if (child != null) {
processEditMask(resource, child);
}
child = element.getChild(CONTAINER_LOOKUP);
child = element.element(CONTAINER_LOOKUP);
if (child != null) {
processLookup(resource, child);
}
child = element.getChild(CONTAINER_UPDATEHELP);
child = element.element(CONTAINER_UPDATEHELP);
if (child != null) {
processUpdateHelp(resource, child);
}
child = element.getChild(CONTAINER_VALIDATIONLOOKUP);
child = element.element(CONTAINER_VALIDATIONLOOKUP);
if (child != null) {
processValidationLookup(resource, child);
}
child = element.getChild(CONTAINER_VALIDATIONEXPRESSION);
child = element.element(CONTAINER_VALIDATIONEXPRESSION);
if (child != null) {
processValidationExpression(resource, child);
}
child = element.getChild(CONTAINER_VALIDATIONEXTERNAL);
child = element.element(CONTAINER_VALIDATIONEXTERNAL);
if (child != null) {
processValidationExternal(resource, child);
}
@ -362,7 +362,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processEditMask(MResource parent, Element container) {
List elements = container.getChildren(ELEMENT_EDITMASK);
List elements = container.elements(ELEMENT_EDITMASK);
for (int i = 0; i < elements.size(); i++) {
Element element = (Element) elements.get(i);
MEditMask mask = buildEditMask();
@ -372,8 +372,8 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processLookup(MResource parent, Element container) {
List elements15 = container.getChildren(ELEMENT_LOOKUP);
List elements17 = container.getChildren(ELEMENT_LOOKUPTYPE);
List elements15 = container.elements(ELEMENT_LOOKUP);
List elements17 = container.elements(ELEMENT_LOOKUPTYPE);
List elements;
//some Rets Servers have lookuptype and lookup elements interchanged
if (elements15.isEmpty()){
@ -387,7 +387,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
init(lookup);
setAttributes(lookup, element);
parent.addChild(MetadataType.LOOKUP, lookup);
Element child = element.getChild(CONTAINER_LOOKUPTYPE);
Element child = element.element(CONTAINER_LOOKUPTYPE);
if (child != null) {
processLookupType(lookup, child);
}
@ -396,8 +396,8 @@ public class JDomStandardBuilder extends MetadataBuilder {
private void processLookupType(MLookup parent, Element container) {
List elements15 = container.getChildren(ELEMENT_LOOKUPTYPE);// check spec
List elements17 = container.getChildren(ELEMENT_LOOKUP);
List elements15 = container.elements(ELEMENT_LOOKUPTYPE);// check spec
List elements17 = container.elements(ELEMENT_LOOKUP);
List elements;
//some Rets Servers have lookuptype and lookup elements interchanged
if (elements15.isEmpty()){
@ -414,7 +414,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processUpdateHelp(MResource parent, Element container) {
List elements = container.getChildren(ELEMENT_UPDATEHELP);
List elements = container.elements(ELEMENT_UPDATEHELP);
for (int i = 0; i < elements.size(); i++) {
Element element = (Element) elements.get(i);
MUpdateHelp help = buildUpdateHelp();
@ -424,14 +424,14 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processValidationLookup(MResource parent, Element container) {
List elements = container.getChildren(ELEMENT_VALIDATIONLOOKUP);
List elements = container.elements(ELEMENT_VALIDATIONLOOKUP);
for (int i = 0; i < elements.size(); i++) {
Element element = (Element) elements.get(i);
MValidationLookup lookup = buildValidationLookup();
init(lookup);
setAttributes(lookup, element);
parent.addChild(MetadataType.VALIDATION_LOOKUP, lookup);
Element child = element.getChild(CONTAINER_VALIDATIONLOOKUPTYPE);
Element child = element.element(CONTAINER_VALIDATIONLOOKUPTYPE);
if (child != null) {
processValidationLookupType(lookup, child);
}
@ -439,7 +439,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processValidationLookupType(MValidationLookup parent, Element container) {
List elements = container.getChildren(ELEMENT_VALIDATIONLOOKUPTYPE);
List elements = container.elements(ELEMENT_VALIDATIONLOOKUPTYPE);
for (int i = 0; i < elements.size(); i++) {
Element element = (Element) elements.get(i);
MValidationLookupType lookupType = buildValidationLookupType();
@ -449,7 +449,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processValidationExpression(MResource parent, Element container) {
List elements = container.getChildren(ELEMENT_VALIDATIONEXPRESSION);
List elements = container.elements(ELEMENT_VALIDATIONEXPRESSION);
for (int i = 0; i < elements.size(); i++) {
Element element = (Element) elements.get(i);
MValidationExpression expression = buildValidationExpression();
@ -459,14 +459,14 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processValidationExternal(MResource parent, Element container) {
List elements = container.getChildren(ELEMENT_VALIDATIONEXTERNAL);
List elements = container.elements(ELEMENT_VALIDATIONEXTERNAL);
for (int i = 0; i < elements.size(); i++) {
Element element = (Element) elements.get(i);
MValidationExternal external = buildValidationExternal();
init(external);
setAttributes(external, element);
parent.addChild(MetadataType.VALIDATION_EXTERNAL, external);
Element child = element.getChild(CONTAINER_VALIDATIONEXTERNALTYPE);
Element child = element.element(CONTAINER_VALIDATIONEXTERNALTYPE);
if (child != null) {
processValidationExternalType(external, child);
}
@ -474,7 +474,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processValidationExternalType(MValidationExternal parent, Element container) {
List elements = container.getChildren(ELEMENT_VALIDATIONEXTERNALTYPE);
List elements = container.elements(ELEMENT_VALIDATIONEXTERNALTYPE);
for (int i = 0; i < elements.size(); i++) {
Element element = (Element) elements.get(i);
MValidationExternalType type = buildValidationExternalType();
@ -484,7 +484,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processSearchHelp(MResource parent, Element container) {
List searchhelps = container.getChildren(ELEMENT_SEARCHHELP);
List searchhelps = container.elements(ELEMENT_SEARCHHELP);
for (int i = 0; i < searchhelps.size(); i++) {
Element element = (Element) searchhelps.get(i);
MSearchHelp searchhelp = buildSearchHelp();
@ -494,7 +494,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processObject(MResource parent, Element container) {
List objects = container.getChildren(ELEMENT_OBJECT);
List objects = container.elements(ELEMENT_OBJECT);
for (int i = 0; i < objects.size(); i++) {
Element element = (Element) objects.get(i);
MObject obj = buildObject();
@ -504,7 +504,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processClass(MResource parent, Element container) {
List classes = container.getChildren(ELEMENT_CLASS);
List classes = container.elements(ELEMENT_CLASS);
for (int i = 0; i < classes.size(); i++) {
Element element = (Element) classes.get(i);
MClass clazz = buildClass();
@ -512,11 +512,11 @@ public class JDomStandardBuilder extends MetadataBuilder {
setAttributes(clazz, element);
parent.addChild(MetadataType.CLASS, clazz);
Element child;
child = element.getChild(CONTAINER_TABLE);
child = element.element(CONTAINER_TABLE);
if (child != null) {
processTable(clazz, child);
}
child = element.getChild(CONTAINER_UPDATE);
child = element.element(CONTAINER_UPDATE);
if (child != null) {
processUpdate(clazz, child);
}
@ -524,7 +524,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processTable(MClass parent, Element container) {
List tables = container.getChildren(ELEMENT_TABLE);
List tables = container.elements(ELEMENT_TABLE);
for (int i = 0; i < tables.size(); i++) {
Element element = (Element) tables.get(i);
MTable table = buildTable();
@ -534,14 +534,14 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processUpdate(MClass parent, Element container) {
List updates = container.getChildren(ELEMENT_UPDATE);
List updates = container.elements(ELEMENT_UPDATE);
for (int i = 0; i < updates.size(); i++) {
Element element = (Element) updates.get(i);
MUpdate update = buildUpdate();
init(update);
setAttributes(update, element);
parent.addChild(MetadataType.UPDATE, update);
Element child = element.getChild(CONTAINER_UPDATE_TYPE);
Element child = element.element(CONTAINER_UPDATE_TYPE);
if (child != null) {
processUpdateType(update, child);
}
@ -549,7 +549,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processUpdateType(MUpdate parent, Element container) {
List updateFields = container.getChildren(ELEMENT_UPDATETYPE);
List updateFields = container.elements(ELEMENT_UPDATETYPE);
for (int i = 0; i < updateFields.size(); i++) {
Element element = (Element) updateFields.get(i);
MUpdateType updateType = buildUpdateType();
@ -559,7 +559,7 @@ public class JDomStandardBuilder extends MetadataBuilder {
}
private void processForeignKey(MSystem system, Element container) {
List fkeys = container.getChildren("ForeignKey");
List fkeys = container.elements("ForeignKey");
for (int i = 0; i < fkeys.size(); i++) {
Element element = (Element) fkeys.get(i);
MForeignKey foreignKey = buildForeignKey();