summaryrefslogtreecommitdiff
path: root/bkucommon/src/main/java/at/gv
diff options
context:
space:
mode:
authorclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-11-24 18:48:00 +0000
committerclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-11-24 18:48:00 +0000
commit5af9b75dccc1b52d1382fe0f2df30affd509f5b9 (patch)
tree8640f3e4f0446e85cbe34f2d87916e187f5b40ad /bkucommon/src/main/java/at/gv
parent650732adaff82503b19a41b6c53d4299be9a1533 (diff)
downloadmocca-5af9b75dccc1b52d1382fe0f2df30affd509f5b9.tar.gz
mocca-5af9b75dccc1b52d1382fe0f2df30affd509f5b9.tar.bz2
mocca-5af9b75dccc1b52d1382fe0f2df30affd509f5b9.zip
Filenames derived from reference URI
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@553 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'bkucommon/src/main/java/at/gv')
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java1
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java6
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java88
3 files changed, 87 insertions, 8 deletions
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
index b1906666..e39addb5 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java
@@ -339,6 +339,7 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements
// process headers and request
setHTTPHeaders(dataUrlResponse.getResponseHeaders());
consumeRequestStream(dataUrlResponse.getStream());
+ //TODO check for bindingProcessorError
closeDataUrlConnection();
srcContex.setSourceCertificate(conn.getServerCertificate());
srcContex.setSourceIsDataURL(true);
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
index 1a9b56fb..57358ba0 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/DataObjectHashDataInput.java
@@ -50,4 +50,10 @@ public class DataObjectHashDataInput implements HashDataInput {
return HttpUtil.getCharset(dataObject.getMimeType(), false);
}
+ @Override
+ public String getFilename() {
+ //TODO obtain filename from dataObject, if not set return null or get filename (extension!) from mimetype
+ return dataObject.getFilename();
+ }
+
}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java
index 89124d16..6e84081e 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/xsect/DataObject.java
@@ -49,8 +49,6 @@ import javax.xml.crypto.dsig.spec.XPathType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.w3._2000._09.xmldsig_.TransformType;
-import org.w3._2000._09.xmldsig_.TransformsType;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
@@ -71,6 +69,7 @@ import at.buergerkarte.namespaces.securitylayer._1.DataObjectInfoType;
import at.buergerkarte.namespaces.securitylayer._1.MetaInfoType;
import at.buergerkarte.namespaces.securitylayer._1.TransformsInfoType;
import at.gv.egiz.bku.binding.HttpUtil;
+import at.gv.egiz.bku.gui.viewer.MimeTypes;
import at.gv.egiz.bku.slexceptions.SLCommandException;
import at.gv.egiz.bku.slexceptions.SLRequestException;
import at.gv.egiz.bku.slexceptions.SLRuntimeException;
@@ -81,11 +80,11 @@ import at.gv.egiz.bku.viewer.ValidationException;
import at.gv.egiz.bku.viewer.Validator;
import at.gv.egiz.bku.viewer.ValidatorFactory;
import at.gv.egiz.dom.DOMUtils;
-import at.gv.egiz.marshal.NamespacePrefixMapperImpl;
import at.gv.egiz.slbinding.impl.XMLContentType;
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
/**
* This class represents a <code>DataObject</code> of an XML-Signature
@@ -184,7 +183,9 @@ public class DataObject {
* An optional description of the digest input.
*/
private String description;
-
+
+ private String filename;
+
/**
* Creates a new instance.
*
@@ -230,6 +231,10 @@ public class DataObject {
return mimeType;
}
+ public String getFilename() {
+ return filename;
+ }
+
/**
* @return the description
*/
@@ -336,7 +341,74 @@ public class DataObject {
}
// other values are not allowed by the schema and are therefore ignored
-
+
+ this.filename = deriveFilename();
+ }
+
+ /**
+ * Extract filename from reference URI
+ * or propose reference Id with an apropriate (mime-type) file extension
+ *
+ * @return if neither reference nor id can be extracted return null (or data.extension?)
+ */
+ private String deriveFilename() {
+
+ String filename = null;
+
+ if (reference != null) {
+ if (reference.getURI() != null && !"".equals(reference.getURI())) {
+ try {
+ log.info("deriving filename from reference URI " + reference.getURI());
+ URI refURI = new URI(reference.getURI());
+
+ if (refURI.isOpaque()) {
+ // could check scheme component, but also allow other schemes (e.g. testlocal)
+ log.trace("opaque reference URI, use scheme-specific part as filename");
+ filename = refURI.getSchemeSpecificPart();
+ if (!hasExtension(filename)) {
+ filename += MimeTypes.getExtension(mimeType);
+ }
+ // else hierarchical URI:
+ // for shorthand xpointer use fragment as filename,
+ // for any other xpointer use reference Id and
+ // for any other hierarchical (absolute or relative) use filename (ignore fragment, see xmldsig section 4.3.3.2: fragments not recommendet)
+ } else if ("".equals(refURI.getPath()) &&
+ refURI.getFragment() != null &&
+ refURI.getFragment().indexOf('(') < 0) { // exclude (schemebased) xpointer expressions
+ log.trace("fragment (shorthand xpointer) URI, use fragment as filename");
+ filename = refURI.getFragment();
+ if(!hasExtension(filename)) {
+ filename += MimeTypes.getExtension(mimeType);
+ }
+ } else if (!"".equals(refURI.getPath())) {
+ log.trace("hierarchical URI with path component, use path as filename");
+ File refFile = new File(refURI.getPath());
+ filename = refFile.getName();
+ if(!hasExtension(filename)) {
+ filename += MimeTypes.getExtension(mimeType);
+ }
+ } else {
+ log.info("failed to derive filename from URI '" + refURI + "', derive filename from reference ID");
+ filename = reference.getId() + MimeTypes.getExtension(mimeType);
+ }
+ } catch (URISyntaxException ex) {
+ log.error("failed to derive filename from invalid URI " + ex.getMessage());
+ filename = reference.getId() + MimeTypes.getExtension(mimeType);
+ }
+ } else {
+ log.info("same-document URI, derive filename from reference ID");
+ filename = reference.getId() + MimeTypes.getExtension(mimeType);
+ }
+ } else {
+ log.error("failed to derive filename, no reference created");
+ }
+ log.debug("derived filename for reference " + reference.getId() + ": " + filename);
+ return filename;
+ }
+
+ private static boolean hasExtension(String filename) {
+ int extDelimiterInd = filename.lastIndexOf('.');
+ return extDelimiterInd >= 0 && extDelimiterInd >= filename.length() - 4;
}
private byte[] getTransformsBytes(at.gv.egiz.slbinding.impl.TransformsInfoType ti) {