summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/uic
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/uic')
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java211
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/api/IUicDynamicContent.java130
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/api/SimpleUicDynamicContent.java150
3 files changed, 491 insertions, 0 deletions
diff --git a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java
new file mode 100644
index 0000000..d8bf3b4
--- /dev/null
+++ b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java
@@ -0,0 +1,211 @@
+package org.uic.barcode.dynamicContent.api;
+
+import java.util.Date;
+import java.util.List;
+
+import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateType;
+import org.uic.barcode.dynamicContent.fdc1.SequenceOfExtension;
+import org.uic.barcode.dynamicContent.fdc1.TimeStamp;
+import org.uic.barcode.dynamicContent.fdc1.UicDynamicContentDataFDC1;
+import org.uic.barcode.ticket.EncodingFormatException;
+import org.uic.barcode.asn1.uper.UperEncoder;
+import org.uic.barcode.dynamicContent.fdc1.ExtensionData;
+import org.uic.barcode.dynamicContent.fdc1.GeoCoordinateSystemType;
+import org.uic.barcode.dynamicContent.fdc1.GeoUnitType;
+import org.uic.barcode.dynamicContent.fdc1.HemisphereLatitudeType;
+import org.uic.barcode.dynamicContent.fdc1.HemisphereLongitudeType;
+import org.uic.barcode.ticket.api.impl.SimpleExtension;
+import org.uic.barcode.ticket.api.impl.SimpleGeoCoordinate;
+import org.uic.barcode.ticket.api.spec.IExtension;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinate;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinateSystemType;
+import org.uic.barcode.ticket.api.spec.IGeoUnitType;
+import org.uic.barcode.ticket.api.spec.IHemisphereLatitudeType;
+import org.uic.barcode.ticket.api.spec.IHemisphereLongitudeType;
+import org.uic.barcode.ticket.api.utils.UicEncoderUtils;
+
+public class DynamicContentCoder {
+
+ public static byte[] encode(IUicDynamicContent content, String format) throws EncodingFormatException {
+
+ if (format != null && !format.equals("FDC1")) {
+ throw new EncodingFormatException("Format of dynamic content not supported!");
+ }
+
+ UicDynamicContentDataFDC1 asn = new UicDynamicContentDataFDC1();
+
+ asn.setAppId(content.getAppId());
+
+ if (content.getChallengeString() != null && content.getChallengeString().length() > 0) {
+ asn.setChallengeString(content.getChallengeString());
+ }
+
+ asn.setDynamicContentExtension(getAsnExtension(content.getExtension()));
+
+ asn.setGeoCoordinate(getAsnGeoCoordinate(content.getGeoCoordinate()));
+
+ asn.setTimeStamp(getAsnTimeStamp(content.getTimeStamp()));
+
+ asn.setExtensions(getAsnContentExtensions(asn, content.getDynamicContentResponseList()));
+
+ return UperEncoder.encode(asn);
+
+ }
+
+
+
+ private static SequenceOfExtension getAsnContentExtensions(UicDynamicContentDataFDC1 asn, List<IExtension> dynamicContentResponseList) throws EncodingFormatException {
+ if (dynamicContentResponseList != null && !dynamicContentResponseList.isEmpty()){
+
+ SequenceOfExtension asnList = asn.getExtensions();
+ if (asnList == null) asnList = new SequenceOfExtension();
+ for (IExtension extension : dynamicContentResponseList){
+ ExtensionData asnExtension = getAsnExtension(extension);
+ if (asnExtension!= null) {
+ asnList.add(asnExtension);
+ }
+ }
+ if (!asnList.isEmpty()){
+ return asnList;
+ }
+ }
+
+ return null;
+ }
+
+ private static TimeStamp getAsnTimeStamp(Date date) {
+
+ if (date == null) return null;
+
+ TimeStamp asnTimeStamp = new TimeStamp();
+ asnTimeStamp.setDateTime(date);
+
+ return asnTimeStamp;
+
+ }
+
+ private static GeoCoordinateType getAsnGeoCoordinate(IGeoCoordinate point) {
+
+ if (point == null) return null;
+
+ GeoCoordinateType asnPoint = new GeoCoordinateType();
+
+ asnPoint.setLatitude(point.getLatitude());
+ asnPoint.setLongitude(point.getLongitude());
+
+ if (point.getUnit() != IGeoUnitType.milliDegree && point.getUnit() != null){
+ asnPoint.setGeoUnit(GeoUnitType.valueOf(point.getUnit().name()));
+ }
+
+ if (point.getAccuracy() != null) {
+ asnPoint.setAccuracy(GeoUnitType.valueOf(point.getAccuracy().name()));
+ }
+
+ if (point.getHemisphereLatitude() != IHemisphereLatitudeType.east && point.getHemisphereLatitude() != null) {
+ asnPoint.setHemisphereLatitude(HemisphereLatitudeType.valueOf(point.getHemisphereLatitude().name()));
+ }
+
+ if (point.getHemisphereLongitude() != IHemisphereLongitudeType.north && point.getHemisphereLongitude() != null) {
+ asnPoint.setHemisphereLongitude(HemisphereLongitudeType.valueOf(point.getHemisphereLongitude().name()));
+ }
+
+ if (point.getSystem() != IGeoCoordinateSystemType.wgs84 && point.getSystem() != null){
+ asnPoint.setCoordinateSystem(GeoCoordinateSystemType.valueOf(point.getSystem().name()));
+ }
+
+
+ return asnPoint;
+ }
+
+ private static ExtensionData getAsnExtension(IExtension extension) throws EncodingFormatException {
+ if (extension==null) return null;
+
+ if (extension.getBinarydata() == null || extension.getBinarydata().length == 0) {
+ throw new EncodingFormatException("Extension does not include data");
+ }
+
+ if (extension.getId() == null || extension.getId().length() == 0) {
+ throw new EncodingFormatException("Extension does not include id");
+ }
+
+ ExtensionData asnExtension = new ExtensionData();
+
+ asnExtension.setExtensionData(extension.getBinarydata());
+ asnExtension.setExtensionId(UicEncoderUtils.getIA5(extension.getId()));
+
+ return asnExtension;
+ }
+
+ public static IUicDynamicContent decode(byte[] bytes) {
+
+ UicDynamicContentDataFDC1 asn = UperEncoder.decode(bytes, UicDynamicContentDataFDC1.class);
+
+ IUicDynamicContent content = new SimpleUicDynamicContent();
+
+ content.setAppId(asn.getAppId());
+
+ content.setChallengeString(asn.getChallengeString());
+
+ content.setExtension(getExtension(asn.getDynamicContentExtension()));
+
+ if (asn.getExtensions() != null && !asn.getExtensions().isEmpty()) {
+ for (ExtensionData e : asn.getExtensions()) {
+ content.addDynamicContentResponse(getExtension(e));
+ }
+ }
+
+ content.setGeoCoordinate(getGeoCoordinate(asn.getGeoCoordinate()));
+
+ content.setTimeStamp(asn.getTimeStamp().getTimeAsDate());
+
+
+ return content;
+
+ }
+
+ private static IGeoCoordinate getGeoCoordinate(GeoCoordinateType asnCoordinate) {
+
+ IGeoCoordinate g = new SimpleGeoCoordinate();
+
+ g.setLatitude(asnCoordinate.getLatitude());
+ g.setLongitude(asnCoordinate.getLongitude());
+
+ if (asnCoordinate.getCoordinateSystem() != null) {
+ g.setSystem(IGeoCoordinateSystemType.valueOf(asnCoordinate.getCoordinateSystem().name()));
+ }
+
+ if (asnCoordinate.getAccuracy() != null) {
+ g.setAccuracy(IGeoUnitType.valueOf(asnCoordinate.getAccuracy().name()));
+ }
+
+ if (asnCoordinate.getGeoUnit() != null) {
+ g.setUnit(IGeoUnitType.valueOf(asnCoordinate.getGeoUnit().name()));
+ }
+
+ if (asnCoordinate.getHemisphereLatitude() != null) {
+ g.setHemisphereLatitude(IHemisphereLatitudeType.valueOf(asnCoordinate.getHemisphereLatitude().name()));
+ }
+
+ if (asnCoordinate.getHemisphereLongitude() != null) {
+ g.setHemisphereLongitude(IHemisphereLongitudeType.valueOf(asnCoordinate.getHemisphereLongitude().name()));
+ }
+
+
+ return g;
+ }
+
+
+
+ private static IExtension getExtension(ExtensionData asnExtension) {
+
+ if (asnExtension == null) return null;
+
+ SimpleExtension e = new SimpleExtension();
+ e.setBinarydata(asnExtension.getExtensionData());
+ e.setId(asnExtension.getExtensionId());
+
+ return e;
+ }
+
+
+}
diff --git a/src/main/java/org/uic/barcode/dynamicContent/api/IUicDynamicContent.java b/src/main/java/org/uic/barcode/dynamicContent/api/IUicDynamicContent.java
new file mode 100644
index 0000000..718d013
--- /dev/null
+++ b/src/main/java/org/uic/barcode/dynamicContent/api/IUicDynamicContent.java
@@ -0,0 +1,130 @@
+package org.uic.barcode.dynamicContent.api;
+
+import java.util.Date;
+import java.util.List;
+
+import org.uic.barcode.ticket.api.spec.IExtension;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinate;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Interface IUicDynamicContent.
+ */
+public interface IUicDynamicContent {
+
+ /**
+ * Gets the app id.
+ *
+ * @return the app id
+ */
+ public String getAppId();
+
+ /**
+ * Sets the app id.
+ * @param string
+ *
+ * @return the string
+ */
+ public void setAppId(String string);
+
+ /**
+ * Gets the time stamp.
+ *
+ * @return the time stamp
+ */
+ public Date getTimeStamp();
+
+ /**
+ * Sets the time stamp.
+ *
+ * @param date the new time stamp
+ */
+ public void setTimeStamp(Date date);
+
+ /**
+ * Gets the geo coordinate.
+ *
+ * @return the geo coordinate
+ */
+ public IGeoCoordinate getGeoCoordinate();
+
+ /**
+ * Sets the geo coordinate.
+ *
+ * @param geoCoordinate the new geo coordinate
+ */
+ public void setGeoCoordinate(IGeoCoordinate geoCoordinate);
+
+
+ /**
+ * Gets the extension.
+ *
+ * @return the extension
+ */
+ public IExtension getExtension();
+
+ /**
+ * Sets the extension.
+ *
+ * @param extension the new extension
+ */
+ public void setExtension(IExtension extension);
+
+ /**
+ * Gets the challenge string.
+ *
+ * @return the challenge string
+ */
+ public String getChallengeString();
+
+ /**
+ * Sets the challenge string.
+ *
+ * @param challenge the new challenge string
+ */
+ public void setChallengeString(String challenge);
+
+ /**
+ * Gets the phone id hash.
+ *
+ * @return the phone id hash
+ */
+ public byte[] getPhoneIdHash();
+
+ /**
+ * Sets the phone id hash.
+ *
+ * @param phoneIdHash the new phone id hash
+ */
+ public void setPhoneIdHash(byte[] phoneIdHash);
+
+ /**
+ * Gets the pass id hash.
+ *
+ * @return the pass id hash
+ */
+ public byte[] getPassIdHash();
+
+ /**
+ * Sets the pass id hash.
+ *
+ * @param passIdHash the new pass id hash
+ */
+ public void setPassIdHash(byte[] passIdHash);
+
+ /**
+ * Gets the dynamic content response list.
+ *
+ * @return the dynamic content response list
+ */
+ public List<IExtension> getDynamicContentResponseList();
+
+ /**
+ * Adds the dynamic content response.
+ *
+ * @param challenge the challenge
+ */
+ public void addDynamicContentResponse(IExtension challenge);
+
+
+}
diff --git a/src/main/java/org/uic/barcode/dynamicContent/api/SimpleUicDynamicContent.java b/src/main/java/org/uic/barcode/dynamicContent/api/SimpleUicDynamicContent.java
new file mode 100644
index 0000000..ca5880d
--- /dev/null
+++ b/src/main/java/org/uic/barcode/dynamicContent/api/SimpleUicDynamicContent.java
@@ -0,0 +1,150 @@
+package org.uic.barcode.dynamicContent.api;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.uic.barcode.ticket.api.impl.SimpleExtension;
+import org.uic.barcode.ticket.api.spec.IExtension;
+import org.uic.barcode.ticket.api.spec.IGeoCoordinate;
+
+public class SimpleUicDynamicContent implements IUicDynamicContent {
+
+
+ protected String appId;
+
+ protected Date timeStamp;
+
+ protected String challenge;
+
+ protected IGeoCoordinate geoCoordinate;
+
+ protected IExtension dynamicContentExtension;
+
+ protected List<IExtension> dynamicContentResponseList;
+
+
+
+ public String getAppId() {
+ return appId;
+ }
+
+ public void setAppId(String appId) {
+ this.appId = appId;
+ }
+
+
+ public IGeoCoordinate getGeoCoordinate() {
+ return geoCoordinate;
+ }
+
+ public void setGeoCoordinate(IGeoCoordinate geoCoordinate) {
+ this.geoCoordinate = geoCoordinate;
+ }
+
+ public IExtension getDynamicContentExtension() {
+ return dynamicContentExtension;
+ }
+
+ public void setDynamicContentExtension(IExtension dynamicContentExtension) {
+ this.dynamicContentExtension = dynamicContentExtension;
+ }
+
+
+ @Override
+ public Date getTimeStamp() {
+ return timeStamp;
+ }
+
+ @Override
+ public void setTimeStamp(Date date) {
+ timeStamp = date;
+
+ }
+
+ @Override
+ public IExtension getExtension() {
+ return dynamicContentExtension;
+ }
+
+ @Override
+ public void setExtension(IExtension extension) {
+ dynamicContentExtension = extension;
+ }
+
+ @Override
+ public String getChallengeString() {
+ return challenge;
+ }
+
+ @Override
+ public void setChallengeString(String challenge) {
+ this.challenge = challenge;
+ }
+
+ @Override
+ public byte[] getPhoneIdHash() {
+ return getExtensionData("phone");
+ }
+
+ @Override
+ public void setPhoneIdHash(byte[] phoneIdHash) {
+ if (dynamicContentResponseList == null) {
+ dynamicContentResponseList = new ArrayList<IExtension>();
+ }
+
+ IExtension e = new SimpleExtension();
+ e.setBinarydata(phoneIdHash);
+ e.setId("phone");
+ getDynamicContentResponseList().add(e);
+ }
+
+ @Override
+ public byte[] getPassIdHash() {
+ return getExtensionData("pass");
+ }
+
+ private byte[] getExtensionData(String name) {
+ if (dynamicContentResponseList == null) return null;
+ for (IExtension e : dynamicContentResponseList) {
+ if (e.getId().equals(name)){
+ return e.getBinarydata();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void setPassIdHash(byte[] passIdHash) {
+ if (dynamicContentResponseList == null) {
+ dynamicContentResponseList = new ArrayList<IExtension>();
+ }
+
+ IExtension e = new SimpleExtension();
+ e.setBinarydata(passIdHash);
+ e.setId("pass");
+ getDynamicContentResponseList().add(e);
+ }
+
+ @Override
+ public List<IExtension> getDynamicContentResponseList() {
+ if (dynamicContentResponseList == null) {
+ dynamicContentResponseList = new ArrayList<IExtension>();
+ }
+
+ return dynamicContentResponseList;
+ }
+
+ @Override
+ public void addDynamicContentResponse(IExtension challenge) {
+
+ if (this.dynamicContentResponseList == null) {
+ this.dynamicContentResponseList = new ArrayList<IExtension>();
+ }
+
+ this.dynamicContentResponseList.add(challenge);
+
+ }
+
+
+}