aboutsummaryrefslogtreecommitdiff
path: root/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateCMSSignatureRequestParser.java
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2015-11-03 14:38:34 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2015-11-03 14:38:34 +0100
commit0872d2d8a64fd701776b272f49222428d8def07f (patch)
tree0954a523ad2cc7ad615dbbae5282dd56497e4c6e /moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateCMSSignatureRequestParser.java
parente635718b8d6a12e4e80207c8bdf30b02eed3f2ab (diff)
downloadmoa-sig-0872d2d8a64fd701776b272f49222428d8def07f.tar.gz
moa-sig-0872d2d8a64fd701776b272f49222428d8def07f.tar.bz2
moa-sig-0872d2d8a64fd701776b272f49222428d8def07f.zip
initial commit
Diffstat (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateCMSSignatureRequestParser.java')
-rw-r--r--moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateCMSSignatureRequestParser.java261
1 files changed, 261 insertions, 0 deletions
diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateCMSSignatureRequestParser.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateCMSSignatureRequestParser.java
new file mode 100644
index 0000000..a8cae9c
--- /dev/null
+++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/api/xmlbind/CreateCMSSignatureRequestParser.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright 2003 Federal Chancellery Austria
+ * MOA-SPSS has been developed in a cooperation between BRZ, the Federal
+ * Chancellery Austria - ICT staff unit, and Graz University of Technology.
+ *
+ * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
+ * the European Commission - subsequent versions of the EUPL (the "Licence");
+ * You may not use this work except in compliance with the Licence.
+ * You may obtain a copy of the Licence at:
+ * http://www.osor.eu/eupl/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the Licence is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the Licence for the specific language governing permissions and
+ * limitations under the Licence.
+ *
+ * This product combines work with different licenses. See the "NOTICE" text
+ * file for details on the various modules and licenses.
+ * The "NOTICE" text file is part of the distribution. Any derivative works
+ * that you distribute must include a readable copy of the "NOTICE" text file.
+ */
+
+
+package at.gv.egovernment.moa.spss.api.xmlbind;
+
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.traversal.NodeIterator;
+
+import at.gv.egovernment.moa.spss.MOAApplicationException;
+import at.gv.egovernment.moa.spss.api.SPSSFactory;
+import at.gv.egovernment.moa.spss.api.cmssign.CreateCMSSignatureRequest;
+import at.gv.egovernment.moa.spss.api.cmssign.DataObjectInfo;
+import at.gv.egovernment.moa.spss.api.cmssign.SingleSignatureInfo;
+import at.gv.egovernment.moa.spss.api.cmsverify.CMSContent;
+import at.gv.egovernment.moa.spss.api.cmsverify.CMSDataObject;
+import at.gv.egovernment.moa.spss.api.common.MetaInfo;
+import at.gv.egovernment.moa.util.Base64Utils;
+import at.gv.egovernment.moa.util.BoolUtils;
+import at.gv.egovernment.moa.util.Constants;
+import at.gv.egovernment.moa.util.DOMUtils;
+import at.gv.egovernment.moa.util.XPathUtils;
+
+/**
+ * A parser to parse <code>CreateCMSSignatureRequest</code> DOM trees into
+ * <code>CreateCMSSignatureRequest</code> API objects.
+ *
+ * @author Patrick Peck
+ * @version $Id$
+ */
+public class CreateCMSSignatureRequestParser {
+
+ //
+ // XPath expresssions to select elements in the CreateCMSSignatureRequest
+ //
+ private static final String MOA = Constants.MOA_PREFIX + ":";
+ private static final String KEY_IDENTIFIER_XPATH =
+ "/" + MOA + "CreateCMSSignatureRequest/" + MOA + "KeyIdentifier";
+ private static final String SINGLE_SIGNATURE_INFO_XPATH =
+ "/" + MOA + "CreateCMSSignatureRequest/" + MOA + "SingleSignatureInfo";
+ private static final String DATA_OBJECT_INFO_XPATH = MOA + "DataObjectInfo";
+ private static final String DATA_OBJECT_XPATH = MOA + "DataObject";
+
+ private static final String SL_CONFORM_ATTR_NAME = "SecurityLayerConformity";
+
+ private static final String META_INFO_XPATH = MOA + "MetaInfo";
+ private static final String CONTENT_XPATH = MOA + "Content";
+ private static final String BASE64_CONTENT_XPATH = MOA + "Base64Content";
+ private static final String EXCLUDEBYTERANGE_FROM_XPATH = MOA + "ExcludedByteRange/" + MOA + "From";
+ private static final String EXCLUDEBYTERANGE_TO_XPATH = MOA + "ExcludedByteRange/" + MOA + "To";
+
+
+
+ /** The factory to create API objects. */
+ private SPSSFactory factory;
+
+ /**
+ * Create a new <code>CreateCMSSignatureRequestParser</code>.
+ */
+ public CreateCMSSignatureRequestParser() {
+ this.factory = SPSSFactory.getInstance();
+ }
+
+ /**
+ * Parse a <code>CreateCMSSignatureRequest</code> DOM element, as defined
+ * by the MOA schema.
+ *
+ * @param requestElem The <code>CreateCMSSignatureRequest</code> to parse. The
+ * request must have been successfully parsed against the schema for this
+ * method to succeed.
+ * @return A <code>CreateCMSSignatureRequest</code> API object containing
+ * the data from the DOM element.
+ * @throws MOAApplicationException An error occurred parsing the request.
+ */
+ public CreateCMSSignatureRequest parse(Element requestElem)
+ throws MOAApplicationException {
+
+ List singleSignatureInfos = parseSingleSignatureInfos(requestElem);
+ String keyIdentifier =
+ XPathUtils.getElementValue(requestElem, KEY_IDENTIFIER_XPATH, null);
+
+ return factory.createCreateCMSSignatureRequest(
+ keyIdentifier,
+ singleSignatureInfos);
+ }
+
+ /**
+ * Parse all <code>SingleSignatureInfo</code> elements of the
+ * <code>CreateCMSSignatureRequest</code>.
+ *
+ * @param requestElem The <code>CreateCMSSignatureRequest</code> to parse.
+ * @return A <code>List</code> of <code>SingleSignatureInfo</code> API
+ * objects.
+ * @throws MOAApplicationException An error occurred parsing on of the
+ * <code>SingleSignatureInfo</code> elements.
+ */
+ private List parseSingleSignatureInfos(Element requestElem)
+ throws MOAApplicationException {
+
+ List singleSignatureInfos = new ArrayList();
+ NodeIterator sigInfoElems =
+ XPathUtils.selectNodeIterator(requestElem, SINGLE_SIGNATURE_INFO_XPATH);
+ Element sigInfoElem;
+
+ while ((sigInfoElem = (Element) sigInfoElems.nextNode()) != null) {
+ singleSignatureInfos.add(parseSingleSignatureInfo(sigInfoElem));
+ }
+
+ return singleSignatureInfos;
+ }
+
+ /**
+ * Parse a <code>SingleSignatureInfo</code> DOM element.
+ *
+ * @param sigInfoElem The <code>SingleSignatureInfo</code> DOM element to
+ * parse.
+ * @return A <code>SingleSignatureInfo</code> API object containing the
+ * information of <code>sigInfoElem</code>.
+ * @throws MOAApplicationException An error occurred parsing the
+ * <code>SingleSignatureInfo</code>.
+ */
+ private SingleSignatureInfo parseSingleSignatureInfo(Element sigInfoElem)
+ throws MOAApplicationException {
+
+ DataObjectInfo dataObjectInfo = parseDataObjectInfo(sigInfoElem);
+ boolean securityLayerConform;
+
+ if (sigInfoElem.hasAttribute(SL_CONFORM_ATTR_NAME)) {
+ securityLayerConform =
+ BoolUtils.valueOf(sigInfoElem.getAttribute(SL_CONFORM_ATTR_NAME));
+ } else {
+ securityLayerConform = true;
+ }
+
+ return factory.createSingleSignatureInfoCMS(
+ dataObjectInfo,
+ securityLayerConform);
+ }
+
+ /**
+ * Parse the <code>DataObjectInfo</code> DOM elements contained in the given
+ * <code>SingleSignatureInfo</code> DOM element.
+ *
+ * @param sigInfoElem The <code>SingleSignatureInfo</code> DOM element
+ * whose <code>DataObjectInfo</code>s to parse.
+ * @return A <code>List</code> of <code>DataObjectInfo</code> API objects
+ * containing the data from the <code>DataObjectInfo</code> DOM elements.
+ * @throws MOAApplicationException An error occurred parsing one of the
+ * <code>DataObjectInfo</code>s.
+ */
+ private DataObjectInfo parseDataObjectInfo(Element sigInfoElem)
+ throws MOAApplicationException {
+
+ Element dataObjInfoElem = (Element)XPathUtils.selectSingleNode(sigInfoElem, DATA_OBJECT_INFO_XPATH);
+
+ String structure = dataObjInfoElem.getAttribute("Structure");
+ Element dataObjectElem =
+ (Element) XPathUtils.selectSingleNode(dataObjInfoElem, DATA_OBJECT_XPATH);
+
+ CMSDataObject dataObject = parseDataObject(dataObjectElem);
+
+ return factory.createDataObjectInfo(
+ structure,
+ dataObject);
+
+ }
+
+
+
+
+
+ /**
+ * Parse a the <code>DataObject</code> DOM element contained in a given
+ * <code>CreateCMSSignatureRequest</code> DOM element.
+ *
+ * @param requestElem The DataObject DOM element of the <code>VerifyCMSSignatureRequest</code>
+ * to parse.
+ * @return The <code>CMSDataObject</code> API object containing the data
+ * from the <code>DataObject</code> DOM element.
+ */
+ private CMSDataObject parseDataObject(Element dataObjectElem) {
+
+ if (dataObjectElem != null) {
+ Element metaInfoElem = (Element) XPathUtils.selectSingleNode(dataObjectElem, META_INFO_XPATH);
+ MetaInfo metaInfo = null;
+ Element contentElem = (Element) XPathUtils.selectSingleNode(dataObjectElem, CONTENT_XPATH);
+ CMSContent content = parseContent(contentElem);
+
+ if (metaInfoElem != null) {
+ metaInfo = RequestParserUtils.parseMetaInfo(metaInfoElem);
+ }
+
+ String excludeByteRangeFromStr = XPathUtils.getElementValue(dataObjectElem, EXCLUDEBYTERANGE_FROM_XPATH, null);
+ String excludeByteRangeToStr = XPathUtils.getElementValue(dataObjectElem, EXCLUDEBYTERANGE_TO_XPATH, null);
+
+ BigDecimal excludeByteRangeFrom = null;
+ BigDecimal excludeByteRangeTo = null;
+
+ if (excludeByteRangeFromStr != null)
+ excludeByteRangeFrom = new BigDecimal(excludeByteRangeFromStr);
+ if (excludeByteRangeToStr != null)
+ excludeByteRangeTo = new BigDecimal(excludeByteRangeToStr);
+
+ return factory.createCMSDataObject(metaInfo, content, excludeByteRangeFrom, excludeByteRangeTo);
+ }
+ else {
+ return null;
+ }
+ }
+
+
+
+ /**
+ * Parse the content contained in a <code>CMSContentBaseType</code> kind of
+ * DOM element.
+ *
+ * @param contentElem The <code>CMSContentBaseType</code> kind of element to
+ * parse.
+ * @return A <code>CMSDataObject</code> API object containing the data
+ * from the given DOM element.
+ */
+ private CMSContent parseContent(Element contentElem) {
+ Element base64ContentElem =
+ (Element) XPathUtils.selectSingleNode(contentElem, BASE64_CONTENT_XPATH);
+
+ if (base64ContentElem != null) {
+ String base64Str = DOMUtils.getText(base64ContentElem);
+ InputStream binaryContent = Base64Utils.decodeToStream(base64Str, true);
+ return factory.createCMSContent(binaryContent);
+ } else {
+ return factory.createCMSContent(
+ contentElem.getAttribute("Reference"));
+ }
+ }
+
+} \ No newline at end of file