Subversion Repositories XServices

Compare Revisions

No changes between revisions

Ignore whitespace Rev 82 → Rev 83

/xservices/trunk/src/java/net/brutex/xservices/types/DateTimeUnits.java
53,8 → 53,11
* days
*/
@XmlEnumValue("days")
DAYS("days");
DAYS("days"),
@XmlEnumValue("years")
YEARS("years");
private String value;
DateTimeUnits(String value) {
/xservices/trunk/src/java/net/brutex/xservices/types/DateFormatType.java
15,34 → 15,54
*/
package net.brutex.xservices.types;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
 
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlType;
 
import net.brutex.xservices.util.BrutexNamespaces;
 
/**
* Different pre-defined date formats.
*
* @author Brian Rosenberger, bru@brutex.de
*/
@XmlEnum(value = String.class)
@XmlEnum()
public enum DateFormatType {
 
/**
* ISO 8601 format (2011-05-24T14:39Z)
* ISO 8601 format (2011-05-24T14:39+01:00)
*/
@XmlEnumValue("ISO 8601")
ISO8601("ISO 8601", "yyyy-MM-dd'T'HH:mm:ssZ"),
@XmlEnumValue("ISO 8601")
ISO8601("ISO 8601", "yyyy-MM-dd'T'HH:mm:ss.SSSZ"),
/**
* RFC822 format (2011-05-24T14:39+0100)
*/
@XmlEnumValue("RFC 822")
RFC822("RFC 822", "yyyy-MM-dd'T'HH:mm:ss.SSSZ"),
/**
* yyyy/mm/dd
*/
@XmlEnumValue("yyyy/mm/dd")
YYYYMMDD("yyyy/mm/dd", "yyyy/MM/dd"),
@XmlEnumValue("DateOnly-slashed")
YYYYMMDD("DateOnly-slashed", "yyyy/MM/dd"),
/**
* dd.mm.yyyy
*/
@XmlEnumValue("dd.mm.yyyy")
DDMMYY("dd.mm.yyyy", "dd.MM.yyyy");
@XmlEnumValue("DateOnly-dotted")
DDMMYYYY("DateOnly-dotted", "dd.MM.yyyy"),
/**
* dd.mm.yyyy
*/
@XmlEnumValue("DateOnly-dashed")
DDMMYYYYdashed("DateOnly-dashed", "dd-MM-yyyy");
private String value;
private String format;
59,7 → 79,33
return value;
}
public String format() {
return format;
public String format(Date date, Locale locale, TimeZone timezone) {
if(date==null) return "";
if(locale==null) locale = Locale.getDefault();
if(timezone==null) timezone = TimeZone.getDefault();
String result = "";
SimpleDateFormat f;
if(this.equals(ISO8601)) {
//apply ISO8061 hack
f = new SimpleDateFormat(RFC822.format, locale);
f.setTimeZone(timezone);
result = f.format(date);
result = result.substring(0, 26) + ":" + result.substring(26);
} else {
f = new SimpleDateFormat(this.format, locale);
f.setTimeZone(timezone);
result = f.format(date);
}
return result;
}
public Date parse(String s, Locale locale, TimeZone timezone)
throws ParseException {
if(locale==null) locale = Locale.getDefault();
if(timezone==null) timezone = TimeZone.getDefault();
SimpleDateFormat fin = new SimpleDateFormat(this.format, locale);
fin.setTimeZone(timezone);
Date date = fin.parse(s);
return date;
}
}
/xservices/trunk/src/java/net/brutex/xservices/types/DateInfoType.java
0,0 → 1,96
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.types;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
 
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
 
import net.brutex.xservices.util.BrutexNamespaces;
 
 
 
 
/**
* Date object representation with different formats
*
* @author Brian Rosenberger, bru@brutex.de
*/
@XmlType(name=DateInfoType.XML_NAME, namespace=BrutexNamespaces.WS_XSERVICES,
propOrder={"isoDate","rfcDate", "millis"})
public class DateInfoType {
 
public static final String XML_NAME="DateInfoType";
private final GregorianCalendar date;
private final TimeZone zone;
/**
* Create a new DateInfoType
* @param date date/time
*/
public DateInfoType(GregorianCalendar date, TimeZone zone) {
this.date = date;
this.zone = zone;
}
/**
* Create a new DateInfoType with current date/time
*/
public DateInfoType() {
this.zone = TimeZone.getDefault();
this.date = new GregorianCalendar(zone);
}
/**
* @return milliseconds since 01.01.1970
*/
@XmlElement(name="timestamp")
public long getMillis() {
return date.getTimeInMillis();
}
/**
* Get date formated according to ISO8601 (done by jaxb->xsd:datetime conversion)
* @return date
*/
@XmlElement(name="iso8601date")
public Date getIsoDate() {
//String format = DateFormatType.ISO8601.format();
//SimpleDateFormat f = new SimpleDateFormat(format);
//String text = f.format(date.getTime());
//Fix missing colon in java timezone
//return text.substring(0, 22) + ":" + text.substring(22);
return date.getTime();
}
/**
* Get date formated according to RFC822 (also java standard)
* @return date string
*/
@XmlElement(name="rfc822date")
public String getRfcDate() {
return DateFormatType.RFC822.format(date.getTime(), null, null);
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/types/DateInfoExtendedType.java
0,0 → 1,69
/*
* Copyright 2011 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.types;
 
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.TimeZone;
 
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
 
import net.brutex.xservices.util.BrutexNamespaces;
 
/**
* @author Brian Rosenberger
*
*/
@XmlType(namespace=BrutexNamespaces.WS_XSERVICES)
public class DateInfoExtendedType extends DateInfoType {
 
private GregorianCalendar date = null;
private TimeZone zone = null;
 
@SuppressWarnings("unused")
public DateInfoExtendedType() {
super();
}
 
public DateInfoExtendedType(GregorianCalendar date, TimeZone zone) {
this.date = date;
this.zone = zone;
}
 
@XmlElement(name = "format1")
public String getFormat1() {
return DateFormatType.DDMMYYYY.format(date.getTime(), null, null);
}
 
/**
* @return
*/
@XmlElement(name = "format2")
public String getFormat2() {
return DateFormatType.YYYYMMDD.format(date.getTime(), null, null);
}
 
@XmlElement(name = "format3")
public String getFormat3() {
String format = "HH:mm:ss";
SimpleDateFormat f = new SimpleDateFormat(format);
return f.format(date.getTime());
}
 
// yyyy-MM-dd'T'HH:mm:ssZ
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/xservices/trunk/src/java/net/brutex/xservices/types/TimeZoneType.java
0,0 → 1,81
/*
* Copyright 2012 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.xservices.types;
 
import java.util.TimeZone;
 
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
 
import net.brutex.xservices.util.BrutexNamespaces;
 
/**
* Different pre-defined date formats.
*
* @author Brian Rosenberger, bru@brutex.de
*/
@XmlType(name=TimeZoneType.XML_NAME, namespace=BrutexNamespaces.WS_XSERVICES)
public class TimeZoneType {
public static final String XML_NAME = "timezone";
private String id;
private String displayname;
private TimeZone timezone;
private long offset;
public TimeZoneType(TimeZone timezone) {
this.timezone = timezone;
this.id = timezone.getID();
this.displayname = timezone.getDisplayName();
this.offset = timezone.getRawOffset()/1000;
}
public TimeZoneType() {
this(TimeZone.getDefault());
}
 
/**
* @return the id
*/
@XmlElement
public String getId() {
return id;
}
 
/**
* @return the displayname
*/
@XmlElement
public String getDisplayname() {
return displayname;
}
 
/**
* @return the timezone
*/
public TimeZone getTimezone() {
return timezone;
}
 
/**
* @return the offset
*/
@XmlElement
public long getOffset() {
return offset;
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property