summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/uic/barcode/dynamicContent
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/uic/barcode/dynamicContent')
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java51
-rw-r--r--src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java20
2 files changed, 45 insertions, 26 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
index 34406e0..b49bcb9 100644
--- a/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java
+++ b/src/main/java/org/uic/barcode/dynamicContent/api/DynamicContentCoder.java
@@ -57,21 +57,25 @@ public class DynamicContentCoder {
private static SequenceOfExtension getAsnContentExtensions(UicDynamicContentDataFDC1 asn, List<IExtension> dynamicContentResponseList) throws EncodingFormatException {
- if (dynamicContentResponseList != null && !dynamicContentResponseList.isEmpty()){
+ if (dynamicContentResponseList == null || dynamicContentResponseList.isEmpty()){
+ return null;
+ }
- 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;
+ 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;
}
@@ -92,8 +96,12 @@ public class DynamicContentCoder {
GeoCoordinateType asnPoint = new GeoCoordinateType();
- asnPoint.setLatitude(point.getLatitude());
- asnPoint.setLongitude(point.getLongitude());
+ if (point.getLatitude() != null) {
+ asnPoint.setLatitude(point.getLatitude());
+ }
+ if (point.getLongitude() != null) {
+ asnPoint.setLongitude(point.getLongitude());
+ }
if (point.getUnit() != IGeoUnitType.milliDegree && point.getUnit() != null){
asnPoint.setGeoUnit(GeoUnitType.valueOf(point.getUnit().name()));
@@ -158,8 +166,9 @@ public class DynamicContentCoder {
content.setGeoCoordinate(getGeoCoordinate(asn.getGeoCoordinate()));
- content.setTimeStamp(asn.getTimeStamp().getTimeAsDate());
-
+ if (asn.getTimeStamp() != null) {
+ content.setTimeStamp(asn.getTimeStamp().getTimeAsDate());
+ }
return content;
@@ -167,10 +176,16 @@ public class DynamicContentCoder {
private static IGeoCoordinate getGeoCoordinate(GeoCoordinateType asnCoordinate) {
+ if (asnCoordinate == null) return null;
+
IGeoCoordinate g = new SimpleGeoCoordinate();
- g.setLatitude(asnCoordinate.getLatitude());
- g.setLongitude(asnCoordinate.getLongitude());
+ if (asnCoordinate.getLatitude() != null) {
+ g.setLatitude(asnCoordinate.getLatitude());
+ }
+ if (asnCoordinate.getLongitude() != null) {
+ g.setLongitude(asnCoordinate.getLongitude());
+ }
if (asnCoordinate.getCoordinateSystem() != null) {
g.setSystem(IGeoCoordinateSystemType.valueOf(asnCoordinate.getCoordinateSystem().name()));
diff --git a/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java b/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java
index c2cd8fa..2f54da3 100644
--- a/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java
+++ b/src/main/java/org/uic/barcode/dynamicContent/fdc1/TimeStamp.java
@@ -1,11 +1,11 @@
package org.uic.barcode.dynamicContent.fdc1;
import java.time.Instant;
-import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
-import java.time.temporal.ChronoField;
+import java.util.Calendar;
import java.util.Date;
+import java.util.TimeZone;
import org.uic.barcode.asn1.datatypes.FieldOrder;
import org.uic.barcode.asn1.datatypes.IntRange;
@@ -41,18 +41,22 @@ public class TimeStamp {
* Instantiates a new time stamp and sets the time-stamp to now.
*/
public TimeStamp() {
- ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
- day = new Long(now.get(ChronoField.DAY_OF_YEAR));
- secondOfDay = new Long(now.get(ChronoField.SECOND_OF_DAY));
+ setNow();
}
/**
* Sets the the time-stamp to now.
*/
public void setNow() {
- ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
- day = new Long(now.get(ChronoField.DAY_OF_YEAR));
- secondOfDay = new Long(now.get(ChronoField.SECOND_OF_DAY));
+ Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ day = (long) c.get(Calendar.DAY_OF_YEAR);
+ long now = c.getTimeInMillis();
+ c.set(Calendar.HOUR_OF_DAY, 0);
+ c.set(Calendar.MINUTE, 0);
+ c.set(Calendar.SECOND, 0);
+ c.set(Calendar.MILLISECOND, 0);
+ long passed = now - c.getTimeInMillis();
+ secondOfDay = passed / 1000;
}
/**