diff options
author | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2008-09-15 18:01:32 +0000 |
---|---|---|
committer | clemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4> | 2008-09-15 18:01:32 +0000 |
commit | fd1db02bdc9fbd2a5beca0cc2b214c1adbcc1a7a (patch) | |
tree | 0410052f7561b4a56711ec6509850246180f06b5 /bkucommon/src/main/java | |
parent | 677bff2bdb7b2cb327930f0596d5f3133363295c (diff) | |
download | mocca-fd1db02bdc9fbd2a5beca0cc2b214c1adbcc1a7a.tar.gz mocca-fd1db02bdc9fbd2a5beca0cc2b214c1adbcc1a7a.tar.bz2 mocca-fd1db02bdc9fbd2a5beca0cc2b214c1adbcc1a7a.zip |
encoding
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@39 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'bkucommon/src/main/java')
3 files changed, 90 insertions, 74 deletions
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/Id.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/Id.java index 93ab2e8b..fc7c35c3 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/Id.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/Id.java @@ -14,14 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.binding;
-
-/**
- * The unique identifier for a BindingProcessor
- * @author wbauer
- *
- */
-public interface Id {
-
- public String toString();
+package at.gv.egiz.bku.binding; + +/** + * The unique identifier for a BindingProcessor + * @author wbauer + * + */ +public interface Id { + + @Override + public String toString(); + + @Override + public boolean equals(Object id); }
\ No newline at end of file diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/IdImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/IdImpl.java index 5523992a..c8a76823 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/IdImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/IdImpl.java @@ -14,67 +14,70 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.binding;
-
-import iaik.utils.Base64OutputStream;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.security.SecureRandom;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Implementation that uses a Base64 representation for self generated Ids.
- * @author wbauer
- *
- */
-public class IdImpl implements at.gv.egiz.bku.binding.Id {
- private static Log log = LogFactory.getLog(IdImpl.class);
-
- private String idString;
-
- public IdImpl(int bitNumber, SecureRandom random) {
- int byteSize = bitNumber/8;
- if (bitNumber % 8 != 0) {
- byteSize++;
- }
- byte[] randomBytes = new byte[byteSize];
- random.nextBytes(randomBytes);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Base64OutputStream b64 = new Base64OutputStream(baos);
- try {
- b64.write(randomBytes);
- b64.flush();
- b64.close();
- idString = new String(baos.toByteArray());
- } catch (IOException e) {
- log.error("Cannot create secure id: "+e);
- }
- }
-
- public IdImpl(String idString) {
- if (idString == null) {
- throw new NullPointerException("Provided idstring must not be null");
- }
- this.idString = idString;
- }
-
- public String toString() {
- return idString;
- }
-
- public int hashCode() {
- return idString.hashCode();
- }
-
- public boolean equals(Object other) {
- if (other instanceof Id) {
- Id otherId = (Id)other;
- return otherId.toString().equals(idString);
- } else {
- return false;
- }
- }
+package at.gv.egiz.bku.binding; + +import iaik.utils.Base64OutputStream; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.security.SecureRandom; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Implementation that uses a Base64 representation for self generated Ids. + * @author wbauer + * + */ +public class IdImpl implements at.gv.egiz.bku.binding.Id { + private static Log log = LogFactory.getLog(IdImpl.class); + + private String idString; + + public IdImpl(int bitNumber, SecureRandom random) { + int byteSize = bitNumber/8; + if (bitNumber % 8 != 0) { + byteSize++; + } + byte[] randomBytes = new byte[byteSize]; + random.nextBytes(randomBytes); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Base64OutputStream b64 = new Base64OutputStream(baos); + try { + b64.write(randomBytes); + b64.flush(); + b64.close(); + idString = new String(baos.toByteArray()); + } catch (IOException e) { + log.error("Cannot create secure id: "+e); + } + } + + public IdImpl(String idString) { + if (idString == null) { + throw new NullPointerException("Provided idstring must not be null"); + } + this.idString = idString; + } + + @Override + public String toString() { + return idString; + } + + @Override + public int hashCode() { + return idString.hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other instanceof Id) { + Id otherId = (Id)other; + return otherId.toString().equals(idString); + } else { + return false; + } + } }
\ No newline at end of file diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java index 49d3c63f..d6999404 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/HashDataInputImpl.java @@ -4,6 +4,7 @@ */ package at.gv.egiz.bku.slcommands.impl; +import at.gv.egiz.bku.binding.HttpUtil; import at.gv.egiz.bku.slcommands.impl.xsect.DataObject; import at.gv.egiz.stal.HashDataInput; import java.io.InputStream; @@ -16,11 +17,14 @@ public class HashDataInputImpl implements HashDataInput { String refId; String mimeType; + String encoding; InputStream hashDataInput; public HashDataInputImpl(DataObject dataObject) { refId = dataObject.getReference().getId(); - mimeType = dataObject.getMimeType(); + String contentType = dataObject.getMimeType(); + mimeType = contentType.split(";")[0].trim(); + encoding = HttpUtil.getCharset(dataObject.getMimeType(), false); hashDataInput = dataObject.getReference().getDigestInputStream(); } @@ -39,4 +43,9 @@ public class HashDataInputImpl implements HashDataInput { return hashDataInput; } + @Override + public String getEncoding() { + return encoding; + } + } |