diff options
Diffstat (limited to 'bkucommon/src/main')
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; + } + } |