aboutsummaryrefslogtreecommitdiff
path: root/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java')
-rw-r--r--moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java895
1 files changed, 426 insertions, 469 deletions
diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java
index 0740a73..b8d4df5 100644
--- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java
+++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/invoke/DataObjectFactory.java
@@ -21,10 +21,8 @@
* that you distribute must include a readable copy of the "NOTICE" text file.
*/
-
package at.gv.egovernment.moa.spss.server.invoke;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -84,8 +82,8 @@ import iaik.server.modules.xml.XMLDataObject;
import iaik.xml.crypto.utils.URIDereferencerImpl;
/**
- * A class to create <code>DataObject</code>s contained in different
- * locations of the MOA XML request format.
+ * A class to create <code>DataObject</code>s contained in different locations
+ * of the MOA XML request format.
*
* @author Patrick Peck
* @author Gregor Karlinger
@@ -94,15 +92,15 @@ import iaik.xml.crypto.utils.URIDereferencerImpl;
public class DataObjectFactory {
/**
- * XPATH for registering ID attributes of known schemas if
- * validating parsing fails.
+ * XPATH for registering ID attributes of known schemas if validating parsing
+ * fails.
*/
private static final String XPATH =
- "descendant-or-self::node()[" +
- "namespace-uri()='http://www.w3.org/2000/09/xmldsig#' " +
- "or namespace-uri()='http://reference.e-government.gv.at/namespace/persondata/20020228#' " +
- "or starts-with(namespace-uri(), 'http://uri.etsi.org/01903/')" +
- "]/attribute::Id";
+ "descendant-or-self::node()[" +
+ "namespace-uri()='http://www.w3.org/2000/09/xmldsig#' " +
+ "or namespace-uri()='http://reference.e-government.gv.at/namespace/persondata/20020228#' " +
+ "or starts-with(namespace-uri(), 'http://uri.etsi.org/01903/')" +
+ "]/attribute::Id";
/** The single instance of this class. */
private static DataObjectFactory instance = null;
@@ -128,26 +126,27 @@ public class DataObjectFactory {
}
/**
- * Return the signature environment, i.e., the root element of the
- * document, into which the signature will be inserted (if created) or which
- * contains the signature (if verified).
+ * Return the signature environment, i.e., the root element of the document,
+ * into which the signature will be inserted (if created) or which contains the
+ * signature (if verified).
*
- * @param content The <code>Content</code> object containing the signature
- * environment.
+ * @param content The <code>Content</code> object containing the signature
+ * environment.
* @param supplements Additional schema or DTD information.
- * @return The signature environment or <code>null</code>, if no
- * signature environment exists.
- * @throws MOASystemException A system error occurred building the signature
- * environment (see message for details).
+ * @return The signature environment or <code>null</code>, if no signature
+ * environment exists.
+ * @throws MOASystemException A system error occurred building the
+ * signature environment (see message for
+ * details).
* @throws MOAApplicationException An error occurred building the signature
- * environment (see message for details).
+ * environment (see message for details).
*/
public XMLDataObject createSignatureEnvironment(
- Content content,
- List supplements)
- throws MOASystemException, MOAApplicationException {
+ Content content,
+ List supplements)
+ throws MOASystemException, MOAApplicationException {
- String reference = content.getReference();
+ final String reference = content.getReference();
EntityResolver entityResolver;
byte[] contentBytes;
@@ -155,10 +154,10 @@ public class DataObjectFactory {
checkAllowContentAndReference(content, false);
// build the EntityResolver for validating parsing
- if ((supplements == null) || supplements.isEmpty()) {
+ if (supplements == null || supplements.isEmpty()) {
entityResolver = new MOASPSSEntityResolver();
} else {
- EntityResolverChain chain = new EntityResolverChain();
+ final EntityResolverChain chain = new EntityResolverChain();
chain.addEntityResolver(buildSupplementEntityResolver(supplements));
chain.addEntityResolver(new MOASPSSEntityResolver());
@@ -168,83 +167,70 @@ public class DataObjectFactory {
// convert the content into a byte array
try {
switch (content.getContentType()) {
- case Content.BINARY_CONTENT :
- {
- InputStream is = ((ContentBinary) content).getBinaryContent();
- contentBytes = StreamUtils.readStream(is);
- break;
- }
- case Content.LOCREF_CONTENT:
- {
- String locRefURI = ((ContentLocRef) content).getLocationReferenceURI();
- InputStream is = null;
- try
- {
- TransactionContext context = TransactionContextManager.getInstance().getTransactionContext();
- is = context.ResolveURI(locRefURI);
- if (is == null) {
- ExternalURIResolver uriResolver = new ExternalURIResolver();
- is = uriResolver.resolve(locRefURI);
- }
- contentBytes = StreamUtils.readStream(is);
- }
- catch (MOAApplicationException e)
- {
- throw new MOAApplicationException("3203", new Object[]{reference, locRefURI}, e);
- }
- finally
- {
- closeInputStream(is);
+ case Content.BINARY_CONTENT: {
+ final InputStream is = ((ContentBinary) content).getBinaryContent();
+ contentBytes = StreamUtils.readStream(is);
+ break;
+ }
+ case Content.LOCREF_CONTENT: {
+ final String locRefURI = ((ContentLocRef) content).getLocationReferenceURI();
+ InputStream is = null;
+ try {
+ final TransactionContext context = TransactionContextManager.getInstance()
+ .getTransactionContext();
+ is = context.ResolveURI(locRefURI);
+ if (is == null) {
+ final ExternalURIResolver uriResolver = new ExternalURIResolver();
+ is = uriResolver.resolve(locRefURI);
}
- break;
+ contentBytes = StreamUtils.readStream(is);
+ } catch (final MOAApplicationException e) {
+ throw new MOAApplicationException("3203", new Object[] { reference, locRefURI }, e);
+ } finally {
+ closeInputStream(is);
}
- case Content.REFERENCE_CONTENT :
- {
- ExternalURIResolver uriResolver = new ExternalURIResolver();
- InputStream is = null;
- try
- {
- is = uriResolver.resolve(reference);
- contentBytes = StreamUtils.readStream(is);
- }
- catch (Exception e)
- {
- throw e;
- }
- finally
- {
- closeInputStream(is);
- }
- break;
+ break;
+ }
+ case Content.REFERENCE_CONTENT: {
+ final ExternalURIResolver uriResolver = new ExternalURIResolver();
+ InputStream is = null;
+ try {
+ is = uriResolver.resolve(reference);
+ contentBytes = StreamUtils.readStream(is);
+ } catch (final Exception e) {
+ throw e;
+ } finally {
+ closeInputStream(is);
}
- case Content.XML_CONTENT :
- {
- Element element =
+ break;
+ }
+ case Content.XML_CONTENT: {
+ final Element element =
checkForSingleElement(((ContentXML) content).getXMLContent());
- contentBytes = DOMUtils.serializeNode(element, "UTF-8");
+ contentBytes = DOMUtils.serializeNode(element, "UTF-8");
- break;
- }
- default : {
+ break;
+ }
+ default: {
contentBytes = null; // this will not happen
}
}
- } catch (MOAApplicationException e) {
+ } catch (final MOAApplicationException e) {
throw e;
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new MOAApplicationException("2219", null);
}
if (Logger.isTraceEnabled()) {
// For logging in Debug-Mode: Mask baseid with xxx
- String logString = new String(contentBytes);
+ final String logString = new String(contentBytes);
// TODO use RegExp
- String startS = "<pr:Identification><pr:Value>";
- String endS = "</pr:Value><pr:Type>urn:publicid:gv.at:baseid</pr:Type>";
+ final String startS = "<pr:Identification><pr:Value>";
+ final String endS = "</pr:Value><pr:Type>urn:publicid:gv.at:baseid</pr:Type>";
String logWithMaskedBaseid = logString;
- int start = logString.indexOf(startS);
+ final int start = logString.indexOf(startS);
if (start > -1) {
- int end = logString.indexOf(endS);
+ final int end = logString.indexOf(endS);
if (end > -1) {
logWithMaskedBaseid = logString.substring(0, start);
logWithMaskedBaseid += startS;
@@ -257,37 +243,37 @@ public class DataObjectFactory {
Logger.trace(">>> parsing the following content: \n" + logWithMaskedBaseid);
}
try {
- ByteArrayInputStream is = new ByteArrayInputStream(contentBytes);
- Document doc =
- DOMUtils.parseDocument(
- is,
- true,
- Constants.ALL_SCHEMA_LOCATIONS,
- null,
- entityResolver,
- new MOAErrorHandler());
+ final ByteArrayInputStream is = new ByteArrayInputStream(contentBytes);
+ final Document doc =
+ DOMUtils.parseDocument(
+ is,
+ true,
+ Constants.ALL_SCHEMA_LOCATIONS,
+ null,
+ entityResolver,
+ new MOAErrorHandler());
Logger.trace("<<< parsed");
return new XMLDataObjectImpl(doc.getDocumentElement());
- } catch (Exception e) {
+ } catch (final Exception e) {
// never mind, we'll try non-validating
- MessageProvider msg = MessageProvider.getInstance();
+ final MessageProvider msg = MessageProvider.getInstance();
Logger.info(new LogMsg(msg.getMessage("invoker.00", null)));
Logger.info(new LogMsg(e.getMessage()));
}
// try to parse non-validating
try {
- ByteArrayInputStream is = new ByteArrayInputStream(contentBytes);
- Document doc = DOMUtils.parseDocument(is, false, null, null);
+ final ByteArrayInputStream is = new ByteArrayInputStream(contentBytes);
+ final Document doc = DOMUtils.parseDocument(is, false, null, null);
// Since the parse tree will not contain any post schema validation information,
// we need to register any attributes known to be of type xsd:Id manually.
- NodeList idAttributes = XPathUtils.selectNodeList(doc.getDocumentElement(), XPATH);
+ final NodeList idAttributes = XPathUtils.selectNodeList(doc.getDocumentElement(), XPATH);
for (int i = 0; i < idAttributes.getLength(); i++) {
- Node item = idAttributes.item(i);
+ final Node item = idAttributes.item(i);
if (item instanceof Attr) {
- Attr attr = (Attr) item;
- Element owner = attr.getOwnerElement();
+ final Attr attr = (Attr) item;
+ final Element owner = attr.getOwnerElement();
// Only available in DOM-Level 3 (Java 1.5):
// owner.setIdAttributeNode(attr, true);
if (doc instanceof CoreDocumentImpl) {
@@ -296,7 +282,7 @@ public class DataObjectFactory {
}
}
return new XMLDataObjectImpl(doc.getDocumentElement());
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new MOAApplicationException("2218", null);
}
}
@@ -305,68 +291,69 @@ public class DataObjectFactory {
* Create an <code>XMLDataObject</code> from the given signature environment.
*
* @param signatureEnvironment The signature environment contained in the
- * result.
- * @param uri The URI identifying the data. This must be either the empty
- * URI, an URI starting with <code>"#xpointer"</code>, <code>"#xmlns"</code>
- * or <code>"#element"</code>; or an URI starting with <code>"#"</code> and
- * followed by an element ID.
- * @param referenceID The reference ID to set for the data object.
+ * result.
+ * @param uri The URI identifying the data. This must be either
+ * the empty URI, an URI starting with
+ * <code>"#xpointer"</code>, <code>"#xmlns"</code>
+ * or <code>"#element"</code>; or an URI starting
+ * with <code>"#"</code> and followed by an element
+ * ID.
+ * @param referenceID The reference ID to set for the data object.
* @return A data object containing the signature environment.
*/
public DataObject createFromSignatureEnvironment(
- Element signatureEnvironment,
- String uri,
- String referenceID)
- throws MOAApplicationException {
+ Element signatureEnvironment,
+ String uri,
+ String referenceID)
+ throws MOAApplicationException {
DataObjectImpl dataObject = null;
if ("".equals(uri)) {
dataObject = new XMLDataObjectImpl(signatureEnvironment);
- } else if (
- uri.startsWith("#xpointer")
+ } else if (uri.startsWith("#xpointer")
|| uri.startsWith("#xmlns")
|| uri.startsWith("#element")) {
try {
- // CHANGE IXSIL to XSECT
- // maybe use URIDereferencerImpl or XPath ...??
- //XPointerReferenceResolver resolver = new XPointerReferenceResolver();
- URIDereferencerImpl uriDereferencer = new URIDereferencerImpl();
- URIReference uriReference = new URIReferenceImpl(uri, null, signatureEnvironment);
- Data returnedData = uriDereferencer.dereference(uriReference, null);
-
- if(returnedData instanceof NodeSetData) {
- NodeSetData nodeSetData = (NodeSetData)returnedData;
- Iterator nodesIterator = nodeSetData.iterator();
- List nodeList = new ArrayList();
-
- while(nodesIterator.hasNext()) {
- nodeList.add(nodesIterator.next());
- }
-
- NodeList nodes = new NodeListImplementation(nodeList);
- dataObject = new XMLNodeListDataObjectImpl(nodes);
- } else if(returnedData instanceof OctetStreamData) {
- OctetStreamData streamData = (OctetStreamData)returnedData;
- dataObject = new ByteStreamDataObjectImpl(streamData.getOctetStream());
+ // CHANGE IXSIL to XSECT
+ // maybe use URIDereferencerImpl or XPath ...??
+ // XPointerReferenceResolver resolver = new XPointerReferenceResolver();
+ final URIDereferencerImpl uriDereferencer = new URIDereferencerImpl();
+ final URIReference uriReference = new URIReferenceImpl(uri, null, signatureEnvironment);
+ final Data returnedData = uriDereferencer.dereference(uriReference, null);
+
+ if (returnedData instanceof NodeSetData) {
+ final NodeSetData nodeSetData = (NodeSetData) returnedData;
+ final Iterator nodesIterator = nodeSetData.iterator();
+ final List nodeList = new ArrayList();
+
+ while (nodesIterator.hasNext()) {
+ nodeList.add(nodesIterator.next());
+ }
+
+ final NodeList nodes = new NodeListImplementation(nodeList);
+ dataObject = new XMLNodeListDataObjectImpl(nodes);
+ } else if (returnedData instanceof OctetStreamData) {
+ final OctetStreamData streamData = (OctetStreamData) returnedData;
+ dataObject = new ByteStreamDataObjectImpl(streamData.getOctetStream());
} else {
- throw new MOAApplicationException("2237", new Object[] { uri });
+ throw new MOAApplicationException("2237", new Object[] { uri });
}
-
- //URI uriObj = new URI(uri);
- //NodeList nodes =
- // resolver.resolveForest(
- // uriObj,
- // signatureEnvironment.getOwnerDocument(),
- // null);
-
- } catch (Exception e) {
+
+ // URI uriObj = new URI(uri);
+ // NodeList nodes =
+ // resolver.resolveForest(
+ // uriObj,
+ // signatureEnvironment.getOwnerDocument(),
+ // null);
+
+ } catch (final Exception e) {
throw new MOAApplicationException("2237", new Object[] { uri });
}
} else if (uri.startsWith("#")) {
- String id = uri.substring(1);
- Element refElem =
- signatureEnvironment.getOwnerDocument().getElementById(id);
+ final String id = uri.substring(1);
+ final Element refElem =
+ signatureEnvironment.getOwnerDocument().getElementById(id);
if (refElem == null) {
throw new MOAApplicationException("2237", new Object[] { id });
@@ -385,87 +372,75 @@ public class DataObjectFactory {
* supplements.
*
* @param supplements The supplements, given as
- * <code>XMLDataObjectAssociation</code>s.
- * @return A <code>StreamEntityResolver</code> mapping the supplements by
- * their reference URI to an <code>InputStream</code> of their respective
- * content.
+ * <code>XMLDataObjectAssociation</code>s.
+ * @return A <code>StreamEntityResolver</code> mapping the supplements by their
+ * reference URI to an <code>InputStream</code> of their respective
+ * content.
*/
private static StreamEntityResolver buildSupplementEntityResolver(List supplements)
- throws MOAApplicationException
- {
- Map entities = new HashMap();
+ throws MOAApplicationException {
+ final Map entities = new HashMap();
Iterator iter;
for (iter = supplements.iterator(); iter.hasNext();) {
- XMLDataObjectAssociation supplement =
- (XMLDataObjectAssociation) iter.next();
- Content content = supplement.getContent();
- String reference = content.getReference();
+ final XMLDataObjectAssociation supplement =
+ (XMLDataObjectAssociation) iter.next();
+ final Content content = supplement.getContent();
+ final String reference = content.getReference();
switch (content.getContentType()) {
- case Content.BINARY_CONTENT :
- {
- entities.put(reference, ((ContentBinary) content).getBinaryContent());
- break;
+ case Content.BINARY_CONTENT: {
+ entities.put(reference, ((ContentBinary) content).getBinaryContent());
+ break;
+ }
+ case Content.LOCREF_CONTENT: {
+ final String locRefURI = ((ContentLocRef) content).getLocationReferenceURI();
+
+ final TransactionContext context = TransactionContextManager.getInstance().getTransactionContext();
+ if (context.FindResolvedEntity(locRefURI) == null) {
+
+ final ExternalURIResolver uriResolver = new ExternalURIResolver();
+ InputStream uriStream = null;
+ byte[] contentBytes;
+ String contentType = null;
+ try {
+ uriStream = uriResolver.resolve(locRefURI);
+ contentBytes = StreamUtils.readStream(uriStream);
+ contentType = uriResolver.getContentType();
+ } catch (final Exception e) {
+ throw new MOAApplicationException("3202", new Object[] { reference, locRefURI }, e);
+ } finally {
+ closeInputStream(uriStream);
+ }
+ context.PutResolvedEntity(locRefURI, contentBytes, contentType);
}
- case Content.LOCREF_CONTENT:
- {
- String locRefURI = ((ContentLocRef) content).getLocationReferenceURI();
-
- TransactionContext context = TransactionContextManager.getInstance().getTransactionContext();
- if (context.FindResolvedEntity(locRefURI)==null) {
-
- ExternalURIResolver uriResolver = new ExternalURIResolver();
- InputStream uriStream = null;
- byte[] contentBytes;
- String contentType = null;
- try
- {
- uriStream = uriResolver.resolve(locRefURI);
- contentBytes = StreamUtils.readStream(uriStream);
- contentType = uriResolver.getContentType();
- }
- catch (Exception e)
- {
- throw new MOAApplicationException("3202", new Object[]{reference, locRefURI}, e);
- }
- finally
- {
- closeInputStream(uriStream);
- }
- context.PutResolvedEntity(locRefURI, contentBytes, contentType);
- }
- InputStream contentIS = context.ResolveURI(locRefURI);
- entities.put(reference, contentIS);
- break;
+ final InputStream contentIS = context.ResolveURI(locRefURI);
+ entities.put(reference, contentIS);
+ break;
+ }
+ case Content.XML_CONTENT: {
+ // serialize the first element node that is found in the supplement
+ // and make it available as a stream
+ final NodeList nodes = ((ContentXML) content).getXMLContent();
+ int i = 0;
+
+ // find the first element node
+ while (i < nodes.getLength()
+ && nodes.item(i).getNodeType() != Node.ELEMENT_NODE) {
+ i++;
}
- case Content.XML_CONTENT :
- {
- // serialize the first element node that is found in the supplement
- // and make it available as a stream
- NodeList nodes = ((ContentXML) content).getXMLContent();
- int i = 0;
-
- // find the first element node
- while ((i < nodes.getLength())
- && (nodes.item(i).getNodeType() != Node.ELEMENT_NODE)) {
- i++;
- }
- // serialize the node
- if (i < nodes.getLength()) {
- try
- {
- byte[] serialized = DOMUtils.serializeNode(nodes.item(i), "UTF-8");
- entities.put(reference, new ByteArrayInputStream(serialized));
- }
- catch (Exception e)
- {
- throw new MOAApplicationException("2281", new Object[]{reference}, e);
- }
+ // serialize the node
+ if (i < nodes.getLength()) {
+ try {
+ final byte[] serialized = DOMUtils.serializeNode(nodes.item(i), "UTF-8");
+ entities.put(reference, new ByteArrayInputStream(serialized));
+ } catch (final Exception e) {
+ throw new MOAApplicationException("2281", new Object[] { reference }, e);
}
- break;
}
+ break;
+ }
}
}
@@ -475,82 +450,87 @@ public class DataObjectFactory {
/**
* Create a <code>DataObject</code> from a <code>Content</code> object.
*
- * @param content The <code>Content</code> object containing the data.
- * @param finalDataMetaInfo The meta information corresponding with <code>content</code>.
- * @param referenceID The reference ID to set in the resulting
- * <code>DataObject</code>. May be <code>null</code>.
+ * @param content The <code>Content</code> object containing
+ * the data.
+ * @param finalDataMetaInfo The meta information corresponding with
+ * <code>content</code>.
+ * @param referenceID The reference ID to set in the resulting
+ * <code>DataObject</code>. May be
+ * <code>null</code>.
* @param allowContentAndReference If <code>true</code>, then
- * <code>content</code> is allowed to contain both a <code>Reference</code>
- * attribute and content. Otherwise, either a <code>Reference</code>
- * attribute or content must be set.
- * @param binaryAsXml If <code>true</code>, a content child given as
- * <code>Base64Content</code> must contain XML data.
- * @param xmlAsNodeList If <code>true</code>, the children of a
- * <code>XMLContent</code> child element are returned as a
- * <code>XMLNodeListDataObject</code>. Otherwise, <code>XMLContent</code> may
- * only contain a single child node, which must be an element and which is
- * returned as an <code>XMLDataObject</code>.
- * @param referenceAsXml If <code>true</code>, then content loaded from the
- * URI given as the <code>Reference</code> attribute must be XML data.
- * If <code>false</code>, an attempt is made to parse the data as XML and
- * return an <code>XMLDataObject</code> but if this fails, a
- * <code>BinaryDataObject</code> is returned containing a byte stream to the
- * data.
+ * <code>content</code> is allowed to contain
+ * both a <code>Reference</code> attribute and
+ * content. Otherwise, either a
+ * <code>Reference</code> attribute or content
+ * must be set.
+ * @param binaryAsXml If <code>true</code>, a content child given
+ * as <code>Base64Content</code> must contain
+ * XML data.
+ * @param xmlAsNodeList If <code>true</code>, the children of a
+ * <code>XMLContent</code> child element are
+ * returned as a
+ * <code>XMLNodeListDataObject</code>.
+ * Otherwise, <code>XMLContent</code> may only
+ * contain a single child node, which must be an
+ * element and which is returned as an
+ * <code>XMLDataObject</code>.
+ * @param referenceAsXml If <code>true</code>, then content loaded
+ * from the URI given as the
+ * <code>Reference</code> attribute must be XML
+ * data. If <code>false</code>, an attempt is
+ * made to parse the data as XML and return an
+ * <code>XMLDataObject</code> but if this fails,
+ * a <code>BinaryDataObject</code> is returned
+ * containing a byte stream to the data.
* @return A <code>DataObject</code> representing the data in
- * <code>content</code>. If <code>base64AsXml==true</code> and
- * <code>xmlAsNodeList==false</code> and <code>referenceAsXml==true</code>,
- * then the result can safely be cast to an <code>XMLDataObject</code>.
- * @throws MOASystemException An error indicating an internal problem. See the
- * wrapped exception for details.
+ * <code>content</code>. If <code>base64AsXml==true</code> and
+ * <code>xmlAsNodeList==false</code> and
+ * <code>referenceAsXml==true</code>, then the result can safely be cast
+ * to an <code>XMLDataObject</code>.
+ * @throws MOASystemException An error indicating an internal problem. See
+ * the wrapped exception for details.
* @throws MOAApplicationException An error occurred handling the content
- * (probably while opening a reference or parsing the data). See the wrapped
- * exception for details.
+ * (probably while opening a reference or
+ * parsing the data). See the wrapped exception
+ * for details.
*/
public DataObject createFromContentOptionalRefType(
- Content content,
- MetaInfo finalDataMetaInfo,
- String referenceID,
- boolean allowContentAndReference,
- boolean binaryAsXml,
- boolean xmlAsNodeList,
- boolean referenceAsXml)
- throws MOASystemException, MOAApplicationException {
-
- String reference = content.getReference();
+ Content content,
+ MetaInfo finalDataMetaInfo,
+ String referenceID,
+ boolean allowContentAndReference,
+ boolean binaryAsXml,
+ boolean xmlAsNodeList,
+ boolean referenceAsXml)
+ throws MOASystemException, MOAApplicationException {
+
+ final String reference = content.getReference();
DataObjectImpl dataObject = null;
checkAllowContentAndReference(content, allowContentAndReference);
// ok, build the data object; use content first, if available
- switch (content.getContentType())
- {
- case Content.XML_CONTENT :
- {
- ContentXML contentXml = (ContentXML) content;
+ switch (content.getContentType()) {
+ case Content.XML_CONTENT: {
+ final ContentXML contentXml = (ContentXML) content;
dataObject = createFromXmlContent(contentXml, xmlAsNodeList);
break;
}
- case Content.BINARY_CONTENT :
- {
- ContentBinary contentBinary = (ContentBinary) content;
+ case Content.BINARY_CONTENT: {
+ final ContentBinary contentBinary = (ContentBinary) content;
dataObject = createFromBinaryContent(contentBinary, binaryAsXml, false);
break;
}
- case Content.LOCREF_CONTENT :
- {
- String locRefURI = ((ContentLocRef) content).getLocationReferenceURI();
- try
- {
+ case Content.LOCREF_CONTENT: {
+ final String locRefURI = ((ContentLocRef) content).getLocationReferenceURI();
+ try {
dataObject = createFromURIImpl(locRefURI, referenceAsXml);
- }
- catch (MOAApplicationException e)
- {
- throw new MOAApplicationException("3201", new Object[]{reference, locRefURI}, e);
+ } catch (final MOAApplicationException e) {
+ throw new MOAApplicationException("3201", new Object[] { reference, locRefURI }, e);
}
break;
}
- case Content.REFERENCE_CONTENT :
- {
+ case Content.REFERENCE_CONTENT: {
dataObject = createFromURIImpl(reference, referenceAsXml);
break;
}
@@ -567,97 +547,91 @@ public class DataObjectFactory {
}
/**
- * Check, if content and reference URIs are allowed in the content an throw
- * an exception if an illegal combination of the two occurs.
+ * Check, if content and reference URIs are allowed in the content an throw an
+ * exception if an illegal combination of the two occurs.
*
- * @param content The <code>Content</code> to check.
- * @param allowContentAndReference Whether explicit content and a reference
- * are allowed at the same time.
- * @throws MOAApplicationException If <code>allowContentAndRefernece</code>
- * is <code>false</code> and both explicit content and reference are set,
- * an exception is thrown.
+ * @param content The <code>Content</code> to check.
+ * @param allowContentAndReference Whether explicit content and a reference are
+ * allowed at the same time.
+ * @throws MOAApplicationException If <code>allowContentAndRefernece</code> is
+ * <code>false</code> and both explicit content
+ * and reference are set, an exception is
+ * thrown.
*/
private static void checkAllowContentAndReference(
- Content content,
- boolean allowContentAndReference)
- throws MOAApplicationException {
- String reference = content.getReference();
+ Content content,
+ boolean allowContentAndReference)
+ throws MOAApplicationException {
+ final String reference = content.getReference();
// check for content and reference not being set
- if ((content.getContentType() == Content.REFERENCE_CONTENT)
- && (reference == null)) {
- String errorCode = allowContentAndReference ? "1111" : "1110";
+ if (content.getContentType() == Content.REFERENCE_CONTENT
+ && reference == null) {
+ final String errorCode = allowContentAndReference ? "1111" : "1110";
throw new MOAApplicationException(errorCode, null);
}
// if we only allow either content or reference being set at once, check
if (!allowContentAndReference
- && (content.getContentType() != Content.REFERENCE_CONTENT)
- && (reference != null)) {
+ && content.getContentType() != Content.REFERENCE_CONTENT
+ && reference != null) {
throw new MOAApplicationException("1110", null);
}
}
/**
- * Create a <code>DataObject</code> from a
- * <code>XMLDataObjectAssociation</code> object.
+ * Create a <code>DataObject</code> from a <code>XMLDataObjectAssociation</code>
+ * object.
*
- * @param xmlDataObjAssoc The <code>XMLDataObjectAssociation</code> object.
- * @param xmlContentAllowed Whether the content contained in the
- * <code>xmlDataObjAssoc</code> is allowed to be of type
- * <code>XML_CONTENT</code>.
+ * @param xmlDataObjAssoc The <code>XMLDataObjectAssociation</code>
+ * object.
+ * @param xmlContentAllowed Whether the content contained in the
+ * <code>xmlDataObjAssoc</code> is allowed to be
+ * of type <code>XML_CONTENT</code>.
* @param binaryContentRepeatable If binary content must be provided as a
- * <code>DataObject</code> that can be read multiple times.
+ * <code>DataObject</code> that can be read
+ * multiple times.
* @return A <code>DataObject</code> representing the data in
- * <code>xmlDataObjAssoc</code>.
- * @throws MOASystemException An error indicating an internal problem. See the
- * wrapped exception for details.
+ * <code>xmlDataObjAssoc</code>.
+ * @throws MOASystemException An error indicating an internal problem. See
+ * the wrapped exception for details.
* @throws MOAApplicationException An error occurred handling the content
- * (probably while parsing the data). See the wrapped exception for details.
+ * (probably while parsing the data). See the
+ * wrapped exception for details.
*/
public DataObject createFromXmlDataObjectAssociation(
- XMLDataObjectAssociation xmlDataObjAssoc,
- boolean xmlContentAllowed,
- boolean binaryContentRepeatable)
- throws MOASystemException, MOAApplicationException {
-
- Content content = xmlDataObjAssoc.getContent();
- MetaInfo metaInfo = xmlDataObjAssoc.getMetaInfo();
- String mimeType = metaInfo != null ? metaInfo.getMimeType() : null;
+ XMLDataObjectAssociation xmlDataObjAssoc,
+ boolean xmlContentAllowed,
+ boolean binaryContentRepeatable)
+ throws MOASystemException, MOAApplicationException {
+
+ final Content content = xmlDataObjAssoc.getContent();
+ final MetaInfo metaInfo = xmlDataObjAssoc.getMetaInfo();
+ final String mimeType = metaInfo != null ? metaInfo.getMimeType() : null;
DataObjectImpl dataObject = null;
- switch (content.getContentType())
- {
- case Content.XML_CONTENT :
- {
- if (xmlContentAllowed)
- {
+ switch (content.getContentType()) {
+ case Content.XML_CONTENT: {
+ if (xmlContentAllowed) {
dataObject = createFromXmlContent((ContentXML) content, true);
- }
- else
- {
+ } else {
throw new MOAApplicationException("2280", null);
}
break;
}
- case Content.BINARY_CONTENT :
- {
+ case Content.BINARY_CONTENT: {
dataObject = createFromBinaryContent(
- (ContentBinary) content,
- false,
- binaryContentRepeatable);
+ (ContentBinary) content,
+ false,
+ binaryContentRepeatable);
break;
}
- case Content.LOCREF_CONTENT :
- {
- String locRefURI = ((ContentLocRef) content).getLocationReferenceURI();
- try
- {
+ case Content.LOCREF_CONTENT: {
+ final String locRefURI = ((ContentLocRef) content).getLocationReferenceURI();
+ try {
dataObject = createFromURIImpl(locRefURI, false);
- }
- catch (MOAApplicationException e)
- {
- throw new MOAApplicationException("3201", new Object[]{content.getReference(), locRefURI}, e);
+ } catch (final MOAApplicationException e) {
+ throw new MOAApplicationException("3201", new Object[] { content.getReference(), locRefURI }, e);
}
break;
}
@@ -673,53 +647,49 @@ public class DataObjectFactory {
* object.
*
* @param transformParameter The <code>TransformParameter</code> object
- * containing the data.
- * @return A <code>DataObject</code> representing the data in
- * <code>root</code>.
- * @throws MOASystemException An error indicating an internal problem. See the
- * wrapped exception for details.
+ * containing the data.
+ * @return A <code>DataObject</code> representing the data in <code>root</code>.
+ * @throws MOASystemException An error indicating an internal problem. See
+ * the wrapped exception for details.
* @throws MOAApplicationException An error occurred handling the content
- * (probably while opening a reference or parsing the data). See the wrapped
- * exception for details.
+ * (probably while opening a reference or
+ * parsing the data). See the wrapped exception
+ * for details.
*/
public DataObject createFromTransformParameter(TransformParameter transformParameter)
- throws MOASystemException, MOAApplicationException {
+ throws MOASystemException, MOAApplicationException {
DataObjectImpl dataObject;
switch (transformParameter.getTransformParameterType()) {
- case TransformParameter.BINARY_TRANSFORMPARAMETER :
- TransformParameterBinary tpBinary =
- (TransformParameterBinary) transformParameter;
+ case TransformParameter.BINARY_TRANSFORMPARAMETER:
+ final TransformParameterBinary tpBinary =
+ (TransformParameterBinary) transformParameter;
try {
- //dataObject = new ByteArrayDataObjectImpl(Base64Utils.encode(tpBinary.getBinaryContent()));
+ // dataObject = new
+ // ByteArrayDataObjectImpl(Base64Utils.encode(tpBinary.getBinaryContent()));
dataObject =
- new ByteArrayDataObjectImpl(
- StreamUtils.readStream(tpBinary.getBinaryContent()));
- } catch (Exception e) {
+ new ByteArrayDataObjectImpl(
+ StreamUtils.readStream(tpBinary.getBinaryContent()));
+ } catch (final Exception e) {
return null;
}
- //dataObject = new ByteStreamDataObjectImpl(tpBinary.getBinaryContent());
+ // dataObject = new ByteStreamDataObjectImpl(tpBinary.getBinaryContent());
break;
- default :
+ default:
// resolve uri and build the content
- ExternalURIResolver resolver = new ExternalURIResolver();
- InputStream is = resolver.resolve(transformParameter.getURI());
+ final ExternalURIResolver resolver = new ExternalURIResolver();
+ final InputStream is = resolver.resolve(transformParameter.getURI());
ByteArrayInputStream bis;
- try
- {
+ try {
bis = new ByteArrayInputStream(StreamUtils.readStream(is));
- }
- catch (IOException e)
- {
- throw new MOAApplicationException("2238", new Object[] {transformParameter.getURI()}, e);
- }
- finally
- {
+ } catch (final IOException e) {
+ throw new MOAApplicationException("2238", new Object[] { transformParameter.getURI() }, e);
+ } finally {
closeInputStream(is);
}
- String contentType = resolver.getContentType();
+ final String contentType = resolver.getContentType();
dataObject = new ByteStreamDataObjectImpl(bis);
dataObject.setMimeType(contentType);
break;
@@ -733,62 +703,65 @@ public class DataObjectFactory {
/**
* Create a <code>DataObject</code> from data located at the given URI.
*
- * @param uri The <code>URI</code> where the data is located. This method uses
- * an <code>ExternalURIResolver</code> to resolve URIs.
+ * @param uri The <code>URI</code> where the data is located. This method uses
+ * an <code>ExternalURIResolver</code> to resolve URIs.
* @param asXml If <code>true</code>, a <code>DataObject</code> is only
- * returned, if the content consists of XML data. If it does not consist of
- * XML data, an <code>MOAApplicationException</code> will be thrown. If this
- * parameter is <code>false</code> and the content consists of XML data, this
- * method will still attempt to parse it.
+ * returned, if the content consists of XML data. If it does not
+ * consist of XML data, an <code>MOAApplicationException</code>
+ * will be thrown. If this parameter is <code>false</code> and the
+ * content consists of XML data, this method will still attempt to
+ * parse it.
* @return The <code>DataObject</code> contained at the URI.
- * @throws MOASystemException A system error parsing the XML content.
+ * @throws MOASystemException A system error parsing the XML content.
* @throws MOAApplicationException An error occurred on opening, reading or
- * parsing the data behind the URI.
+ * parsing the data behind the URI.
*/
public DataObject createFromURI(String uri, boolean asXml)
- throws MOASystemException, MOAApplicationException {
+ throws MOASystemException, MOAApplicationException {
return createFromURIImpl(uri, asXml);
}
/**
* Create a <code>DataObject</code> from data located at the given URI.
*
- * @param uri The <code>URI</code> where the data is located. This method uses
- * an <code>ExternalURIResolver</code> to resolve URIs.
+ * @param uri The <code>URI</code> where the data is located. This method uses
+ * an <code>ExternalURIResolver</code> to resolve URIs.
* @param asXml If <code>true</code>, a <code>DataObject</code> is only
- * returned, if the content consists of XML data. If it does not consist of
- * XML data, an <code>MOAApplicationException</code> will be thrown. If this
- * parameter is <code>false</code> and the content type is detected as being
- * XML data, this method will still attemt to parse it.
+ * returned, if the content consists of XML data. If it does not
+ * consist of XML data, an <code>MOAApplicationException</code>
+ * will be thrown. If this parameter is <code>false</code> and the
+ * content type is detected as being XML data, this method will
+ * still attemt to parse it.
* @return The <code>DataObject</code> contained at the URI.
- * @throws MOASystemException A system error parsing the XML content.
+ * @throws MOASystemException A system error parsing the XML content.
* @throws MOAApplicationException An error occurred on opening, reading or
- * parsing the data behind the URI.
+ * parsing the data behind the URI.
*/
private DataObjectImpl createFromURIImpl(String uri, boolean asXml)
- throws MOASystemException, MOAApplicationException {
+ throws MOASystemException, MOAApplicationException {
Logger.trace(">>> resolving uri \"" + uri + "\"");
- ExternalURIResolver resolver = new ExternalURIResolver();
+ final ExternalURIResolver resolver = new ExternalURIResolver();
- TransactionContext context = TransactionContextManager.getInstance().getTransactionContext();
+ final TransactionContext context = TransactionContextManager.getInstance().getTransactionContext();
InputStream is = context.ResolveURI(uri);
String contentType = null;
boolean foundURI = false;
if (is == null) {
- is = resolver.resolve(uri);
- contentType = resolver.getContentType();
+ is = resolver.resolve(uri);
+ contentType = resolver.getContentType();
} else {
- foundURI = true;
- contentType = (String) context.FindResolvedEntity(uri).get(1);
- Logger.trace("found \"" + uri + "\" InputStream in preread Supplements!, do not read any more. Content=" + contentType);
+ foundURI = true;
+ contentType = (String) context.FindResolvedEntity(uri).get(1);
+ Logger.trace("found \"" + uri + "\" InputStream in preread Supplements!, do not read any more. Content="
+ + contentType);
}
DataObjectImpl dataObject;
// read the content
- if ((contentType != null) && contentTypeIsXml(contentType)) {
+ if (contentType != null && contentTypeIsXml(contentType)) {
Document doc;
if (asXml) {
@@ -798,15 +771,13 @@ public class DataObjectFactory {
is = resolver.resolve(uri);
doc = DOMUtils.parseDocument(is, false, null, null);
dataObject = new XMLDataObjectImpl(doc.getDocumentElement());
- } catch (ParserConfigurationException e) {
+ } catch (final ParserConfigurationException e) {
throw new MOASystemException("1106", null, e);
- } catch (SAXException e) {
+ } catch (final SAXException e) {
throw new MOAApplicationException("2209", null, e);
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new MOAApplicationException("2210", null, e);
- }
- finally
- {
+ } finally {
closeInputStream(is);
}
} else {
@@ -816,22 +787,17 @@ public class DataObjectFactory {
doc = DOMUtils.parseDocument(is, false, null, null);
closeInputStream(is);
dataObject = new XMLDataObjectImpl(doc.getDocumentElement());
- } catch (Exception e) {
+ } catch (final Exception e) {
// this is the last chance: return the data as a byte stream
Logger.trace(">>> reading stream for \"" + uri + "\"");
is = resolver.resolve(uri);
ByteArrayInputStream bis;
- try
- {
+ try {
bis = new ByteArrayInputStream(StreamUtils.readStream(is));
dataObject = new ByteStreamDataObjectImpl(bis);
- }
- catch (IOException e1)
- {
+ } catch (final IOException e1) {
throw new MOAApplicationException("2210", new Object[] { uri }, e1);
- }
- finally
- {
+ } finally {
closeInputStream(is);
}
Logger.trace(">>> read stream for \"" + uri + "\"");
@@ -839,34 +805,26 @@ public class DataObjectFactory {
}
}
- else if (asXml)
- {
+ else if (asXml) {
// if we need XML data, we're in the wrong place here
closeInputStream(is);
throw new MOAApplicationException("2211", new Object[] { uri });
- }
- else
- {
+ } else {
// content is binary: make it available as a binary input stream
Logger.trace(">>> getting binary input for \"" + uri + "\"");
byte[] contentBytes;
ByteArrayInputStream bis;
- try
- {
- contentBytes = StreamUtils.readStream(is);
- bis = new ByteArrayInputStream(contentBytes);
- }
- catch (IOException e)
- {
+ try {
+ contentBytes = StreamUtils.readStream(is);
+ bis = new ByteArrayInputStream(contentBytes);
+ } catch (final IOException e) {
throw new MOAApplicationException("2210", null, e);
- }
- finally
- {
+ } finally {
closeInputStream(is);
}
- if (!foundURI) {
- context.PutResolvedEntity(uri, contentBytes, contentType);
- }
+ if (!foundURI) {
+ context.PutResolvedEntity(uri, contentBytes, contentType);
+ }
dataObject = new ByteStreamDataObjectImpl(bis);
Logger.trace("<<< got binary input for \"" + uri + "\"");
}
@@ -884,16 +842,12 @@ public class DataObjectFactory {
*
* @param is The input stream to be closed.
*/
- private static void closeInputStream(InputStream is)
- {
- try
- {
+ private static void closeInputStream(InputStream is) {
+ try {
if (is != null) {
is.close();
}
- }
- catch (Throwable t)
- {
+ } catch (final Throwable t) {
// Intentionally do nothing here
}
}
@@ -905,42 +859,43 @@ public class DataObjectFactory {
* <code>application/xml</code>.
*
* @param contentType The content MIME type.
- * @return boolean If <code>true</code>, the content type is XML, otherwise
- * not.
+ * @return boolean If <code>true</code>, the content type is XML, otherwise not.
*/
private static boolean contentTypeIsXml(String contentType) {
return contentType.startsWith("text/xml")
- || (contentType.startsWith("application/xml"));
+ || contentType.startsWith("application/xml");
}
/**
* Create a <code>DataObject</code> from a <code>ContentXML</code> object.
*
- * @param xmlContent The <code>ContentXML</code> object from
- * which the <code>DataObject</code> is to be built.
+ * @param xmlContent The <code>ContentXML</code> object from which the
+ * <code>DataObject</code> is to be built.
* @param xmlAsNodeList If <code>true</code>, the children of
- * <code>xmlContent</code> are returned as a
- * <code>XMLNodeListDataObject</code>. Otherwise,
- * <code>xmlContent</code> may only contain a single child node, which must be
- * an element and which is returned as an <code>XMLDataObject</code>.
+ * <code>xmlContent</code> are returned as a
+ * <code>XMLNodeListDataObject</code>. Otherwise,
+ * <code>xmlContent</code> may only contain a single child
+ * node, which must be an element and which is returned as
+ * an <code>XMLDataObject</code>.
* @return A <code>DataObject</code> representing the XML content in
- * <code>xmlContent</code>.
+ * <code>xmlContent</code>.
* @throws MOAApplicationException If <code>xmlAsNodeList</code> is
- * <code>false</code> and <code>xmlContent</code> does not have a single child
- * element.
+ * <code>false</code> and
+ * <code>xmlContent</code> does not have a
+ * single child element.
*/
private DataObjectImpl createFromXmlContent(
- ContentXML xmlContent,
- boolean xmlAsNodeList)
- throws MOAApplicationException {
+ ContentXML xmlContent,
+ boolean xmlAsNodeList)
+ throws MOAApplicationException {
DataObjectImpl dataObject;
if (xmlAsNodeList) {
dataObject = new XMLNodeListDataObjectImpl(xmlContent.getXMLContent());
} else {
- NodeList nodes = xmlContent.getXMLContent();
- Element element = checkForSingleElement(nodes);
+ final NodeList nodes = xmlContent.getXMLContent();
+ final Element element = checkForSingleElement(nodes);
// build the XMLDataObject
dataObject = new XMLDataObjectImpl(element);
@@ -955,10 +910,10 @@ public class DataObjectFactory {
* @param nodes The <code>NodeList</code> to check for a single element.
* @return The single element contained in <code>nodes</code>.
* @throws MOAApplicationException Thrown, if <code>nodes</code> does not
- * contain exactly 1 element node.
+ * contain exactly 1 element node.
*/
private Element checkForSingleElement(NodeList nodes)
- throws MOAApplicationException {
+ throws MOAApplicationException {
Element element = null;
int i;
@@ -986,26 +941,28 @@ public class DataObjectFactory {
* Create a <code>DataObject</code> from a <code>ContentBinary</code> object.
*
* @param binaryContent The <code>ContentBinary</code> object containing the
- * data.
- * @param asXml If <code>true</code>, <code>binaryContent</code> must
- * contain XML data. Otherwise, a <code>BinaryDataObject</code> will be
- * returned containing a byte stream to the decoded Base64 data.
- * @param repeatable If multiple calls to <code>getInputStream()</code> must
- * repeatedly return the content of the data object.
+ * data.
+ * @param asXml If <code>true</code>, <code>binaryContent</code> must
+ * contain XML data. Otherwise, a
+ * <code>BinaryDataObject</code> will be returned
+ * containing a byte stream to the decoded Base64 data.
+ * @param repeatable If multiple calls to <code>getInputStream()</code> must
+ * repeatedly return the content of the data object.
* @return A <code>DataObject</code> representing the content contained in
- * <code>binaryContent</code>.
- * @throws MOASystemException An error indicating an internal problem. See the
- * wrapped exception for details.
+ * <code>binaryContent</code>.
+ * @throws MOASystemException An error indicating an internal problem. See
+ * the wrapped exception for details.
* @throws MOAApplicationException An error occurred handling the content
- * (probably while parsing the data). See the wrapped exception for details.
+ * (probably while parsing the data). See the
+ * wrapped exception for details.
*/
private DataObjectImpl createFromBinaryContent(
- ContentBinary binaryContent,
- boolean asXml,
- boolean repeatable)
- throws MOASystemException, MOAApplicationException {
+ ContentBinary binaryContent,
+ boolean asXml,
+ boolean repeatable)
+ throws MOASystemException, MOAApplicationException {
- InputStream byteStream = binaryContent.getBinaryContent();
+ final InputStream byteStream = binaryContent.getBinaryContent();
DataObjectImpl dataObject;
if (asXml) {
@@ -1014,19 +971,19 @@ public class DataObjectFactory {
try {
doc = DOMUtils.parseDocument(byteStream, false, null, null);
dataObject = new XMLDataObjectImpl(doc.getDocumentElement());
- } catch (ParserConfigurationException e) {
+ } catch (final ParserConfigurationException e) {
throw new MOASystemException("1106", null, e);
- } catch (SAXException e) {
+ } catch (final SAXException e) {
throw new MOAApplicationException("2209", null, e);
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new MOAApplicationException("2210", null, e);
}
} else {
if (repeatable) {
try {
dataObject =
- new ByteArrayDataObjectImpl(StreamUtils.readStream(byteStream));
- } catch (IOException e) {
+ new ByteArrayDataObjectImpl(StreamUtils.readStream(byteStream));
+ } catch (final IOException e) {
throw new MOAApplicationException("2210", null);
}
} else {