http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarFilter.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarFilter.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarFilter.java new file mode 100755 index 0000000..af88d87 --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarFilter.java @@ -0,0 +1,289 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.filters; + +import java.text.*; +import java.util.*; + +import javax.xml.bind.*; + +import com.ibm.juno.core.*; +import com.ibm.juno.core.filter.*; +import com.ibm.juno.core.parser.ParseException; +import com.ibm.juno.core.utils.*; + +/** + * Transforms {@link Calendar Calendars} to {@link String Strings}. + * + * + * <h6 class='topic'>Behavior-specific subclasses</h6> + * <p> + * The following direct subclasses are provided for convenience: + * <ul> + * <li>{@link ToString} - Transforms to {@link String Strings} using the {@code Date.toString()} method. + * <li>{@link ISO8601DT} - Transforms to ISO8601 date-time strings. + * <li>{@link ISO8601DTZ} - Same as {@link ISO8601DT}, except always serializes in GMT. + * <li>{@link RFC2822DT} - Transforms to RFC2822 date-time strings. + * <li>{@link RFC2822DTZ} - Same as {@link RFC2822DT}, except always serializes in GMT. + * <li>{@link RFC2822D} - Transforms to RFC2822 date strings. + * <li>{@link Simple} - Transforms to simple <js>"yyyy/MM/dd HH:mm:ss"</js> strings. + * <li>{@link Medium} - Transforms to {@link DateFormat#MEDIUM} strings. + * </ul> + * + * + * @author James Bognar ([email protected]) + */ +public class CalendarFilter extends PojoFilter<Calendar,String> { + + private static final TimeZone GMT = TimeZone.getTimeZone("GMT"); + + /** + * Transforms {@link Calendar Calendars} to {@link String Strings} using the {@code Date.toString()} method. + * + * <dl> + * <dt>Example output:</dt> + * <dd> + * <ul> + * <li><js>"Wed Jul 04 15:30:45 EST 2001"</js> + * </ul> + * </dd> + * </dl> + */ + public static class ToString extends CalendarFilter { + /** Constructor */ + public ToString() { + super("EEE MMM dd HH:mm:ss zzz yyyy"); + } + } + + /** + * Transforms {@link Calendar Calendars} to ISO8601 date-time strings. + * + * <dl> + * <dt>Example output:</dt> + * <dd> + * <ul> + * <li><js>"2001-07-04T15:30:45-05:00"</js> + * <li><js>"2001-07-04T15:30:45Z"</js> + * </ul> + * </dd> + * <dt>Example input:</dt> + * <dd> + * <ul> + * <li><js>"2001-07-04T15:30:45-05:00"</js> + * <li><js>"2001-07-04T15:30:45Z"</js> + * <li><js>"2001-07-04T15:30:45.1Z"</js> + * <li><js>"2001-07-04T15:30Z"</js> + * <li><js>"2001-07-04"</js> + * <li><js>"2001-07"</js> + * <li><js>"2001"</js> + * </ul> + * </dd> + * </dl> + */ + public static class ISO8601DT extends CalendarFilter { + + /** Constructor */ + public ISO8601DT() {} + + @Override /* PojoFilter */ + public Calendar unfilter(String o, ClassMeta<?> hint) throws ParseException { + try { + if (StringUtils.isEmpty(o)) + return null; + return convert(DatatypeConverter.parseDateTime(o), hint); + } catch (Exception e) { + throw new ParseException(e); + } + } + + @Override /* PojoFilter */ + public String filter(Calendar o) { + return DatatypeConverter.printDateTime(o); + } + } + + /** + * Same as {@link ISO8601DT}, except always serializes in GMT. + * <p> + * Example output: <js>"2001-07-04T15:30:45Z"</js> + */ + public static class ISO8601DTZ extends CalendarFilter { + + /** Constructor */ + public ISO8601DTZ() {} + + @Override /* PojoFilter */ + public Calendar unfilter(String o, ClassMeta<?> hint) throws ParseException { + try { + if (StringUtils.isEmpty(o)) + return null; + return convert(DatatypeConverter.parseDateTime(o), hint); + } catch (Exception e) { + throw new ParseException(e); + } + } + + @Override /* PojoFilter */ + public String filter(Calendar o) { + if (o.getTimeZone().getRawOffset() != 0) { + Calendar c = Calendar.getInstance(GMT); + c.setTime(o.getTime()); + o = c; + } + return DatatypeConverter.printDateTime(o); + } + } + + /** + * Transforms {@link Calendar Calendars} to RFC2822 date-time strings. + */ + public static class RFC2822DT extends CalendarFilter { + /** Constructor */ + public RFC2822DT() { + super("EEE, dd MMM yyyy HH:mm:ss Z"); + } + } + + /** + * Same as {@link RFC2822DT}, except always serializes in GMT. + * <p> + * Example output: <js>"Wed, 31 Jan 2001 12:34:56 +0000"</js> + */ + public static class RFC2822DTZ extends CalendarFilter { + /** Constructor */ + public RFC2822DTZ() { + super("EEE, dd MMM yyyy HH:mm:ss 'GMT'", GMT); + } + } + + /** + * Transforms {@link Calendar Calendars} to RFC2822 date strings. + */ + public static class RFC2822D extends CalendarFilter { + /** Constructor */ + public RFC2822D() { + super("dd MMM yyyy"); + } + } + + /** + * Transforms {@link Calendar Calendars} to simple <js>"yyyy/MM/dd HH:mm:ss"</js> strings. + */ + public static class Simple extends CalendarFilter { + /** Constructor */ + public Simple() { + super("yyyy/MM/dd HH:mm:ss"); + } + } + + /** + * Transforms {@link Calendar Calendars} to {@link DateFormat#MEDIUM} strings. + */ + public static class Medium extends CalendarFilter { + /** Constructor */ + public Medium() { + super(DateFormat.getDateInstance(DateFormat.MEDIUM)); + } + } + + /** The formatter to convert dates to Strings. */ + private DateFormat format; + + private TimeZone timeZone; + + /** + * Default constructor. + * <p> + * This constructor is used when <code>filter()</code> and <code>unfilter()</code> are overridden by subclasses. + */ + public CalendarFilter() {} + + /** + * Construct a filter using the specified date format string that will be + * used to construct a {@link SimpleDateFormat} that will be used to convert + * dates to strings. + * + * @param simpleDateFormat The {@link SimpleDateFormat} pattern. + */ + public CalendarFilter(String simpleDateFormat) { + this(new SimpleDateFormat(simpleDateFormat)); + } + + /** + * Construct a filter using the specified date format string that will be + * used to construct a {@link SimpleDateFormat} that will be used to convert + * dates to strings. + * + * @param simpleDateFormat The {@link SimpleDateFormat} pattern. + * @param timeZone The time zone to associate with the date pattern. + */ + public CalendarFilter(String simpleDateFormat, TimeZone timeZone) { + this(new SimpleDateFormat(simpleDateFormat)); + format.setTimeZone(timeZone); + this.timeZone = timeZone; + } + + /** + * Construct a filter using the specified {@link DateFormat} that will be used to convert + * dates to strings. + * + * @param format The format to use to convert dates to strings. + */ + public CalendarFilter(DateFormat format) { + super(); + this.format = format; + } + + /** + * Converts the specified {@link Calendar} to a {@link String}. + */ + @Override /* PojoFilter */ + public String filter(Calendar o) { + DateFormat df = format; + TimeZone tz1 = o.getTimeZone(); + TimeZone tz2 = format.getTimeZone(); + if (timeZone == null && ! tz1.equals(tz2)) { + df = (DateFormat)format.clone(); + df.setTimeZone(tz1); + } + return df.format(o.getTime()); + } + + /** + * Converts the specified {@link String} to a {@link Calendar}. + */ + @Override /* PojoFilter */ + public Calendar unfilter(String o, ClassMeta<?> hint) throws ParseException { + try { + if (StringUtils.isEmpty(o)) + return null; + return convert(format.parse(o), hint); + } catch (Exception e) { + throw new ParseException(e); + } + } + + private static Calendar convert(Calendar in, ClassMeta<?> hint) throws Exception { + if (hint.isInstance(in) || ! hint.canCreateNewInstance()) + return in; + Calendar c = (Calendar)hint.newInstance(); + c.setTime(in.getTime()); + c.setTimeZone(in.getTimeZone()); + return c; + } + + private static Calendar convert(Date in, ClassMeta<?> hint) throws Exception { + if (hint == null || ! hint.canCreateNewInstance()) + hint = BeanContext.DEFAULT.getClassMeta(GregorianCalendar.class); + Calendar c = (Calendar)hint.newInstance(); + c.setTime(in); + return c; + } +}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarLongFilter.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarLongFilter.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarLongFilter.class new file mode 100755 index 0000000..98d2415 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarLongFilter.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarLongFilter.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarLongFilter.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarLongFilter.java new file mode 100755 index 0000000..c68b3c9 --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarLongFilter.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.filters; + +import java.util.*; + +import com.ibm.juno.core.*; +import com.ibm.juno.core.filter.*; +import com.ibm.juno.core.parser.*; + +/** + * Transforms {@link Calendar Calendars} to {@link Long Longs} using {@code Calender.getTime().getTime()}. + * <p> + * TODO: This class does not handle timezones correctly when parsing {@code GregorianCalendar} objects. + * + * @author James Bognar ([email protected]) + */ +public class CalendarLongFilter extends PojoFilter<Calendar,Long> { + + /** + * Converts the specified {@link Calendar} to a {@link Long}. + */ + @Override /* PojoFilter */ + public Long filter(Calendar o) { + return o.getTime().getTime(); + } + + /** + * Converts the specified {@link Long} to a {@link Calendar}. + */ + @Override /* PojoFilter */ + @SuppressWarnings("unchecked") + public Calendar unfilter(Long o, ClassMeta<?> hint) throws ParseException { + ClassMeta<? extends Calendar> tt; + try { + if (hint == null || ! hint.canCreateNewInstance()) + hint = getBeanContext().getClassMeta(GregorianCalendar.class); + tt = (ClassMeta<? extends Calendar>)hint; + Calendar c = tt.newInstance(); + c.setTimeInMillis(o); + return c; + } catch (Exception e) { + throw new ParseException(e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarMapFilter.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarMapFilter.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarMapFilter.class new file mode 100755 index 0000000..bf9f7fd Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarMapFilter.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarMapFilter.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarMapFilter.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarMapFilter.java new file mode 100755 index 0000000..9c4ab3f --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/CalendarMapFilter.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.filters; + +import java.util.*; + +import com.ibm.juno.core.*; +import com.ibm.juno.core.filter.*; +import com.ibm.juno.core.parser.*; + +/** + * Transforms {@link Calendar Calendars} to {@link Map Maps} of the format <code>{_class:String,value:long}</code>. + * <p> + * TODO: This class does not handle timezones correctly when parsing {@code GregorianCalendar} objects. + * + * @author James Bognar ([email protected]) + */ +@SuppressWarnings("rawtypes") +public class CalendarMapFilter extends PojoFilter<Calendar,Map> { + + /** + * Converts the specified {@link Calendar} to a {@link Map}. + */ + @Override /* PojoFilter */ + public Map filter(Calendar o) { + ObjectMap m = new ObjectMap(); + m.put("time", o.getTime().getTime()); + m.put("timeZone", o.getTimeZone().getID()); + return m; + } + + /** + * Converts the specified {@link Map} to a {@link Calendar}. + */ + @Override /* PojoFilter */ + @SuppressWarnings("unchecked") + public Calendar unfilter(Map o, ClassMeta<?> hint) throws ParseException { + ClassMeta<? extends Calendar> tt; + try { + if (hint == null || ! hint.canCreateNewInstance()) + hint = getBeanContext().getClassMeta(GregorianCalendar.class); + tt = (ClassMeta<? extends Calendar>)hint; + long time = Long.parseLong(o.get("time").toString()); + String timeZone = o.get("timeZone").toString(); + Date d = new Date(time); + Calendar c = tt.newInstance(); + c.setTime(d); + c.setTimeZone(TimeZone.getTimeZone(timeZone)); + return c; + } catch (Exception e) { + throw new ParseException(e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DT.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DT.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DT.class new file mode 100755 index 0000000..19e7cf5 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DT.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTP.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTP.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTP.class new file mode 100755 index 0000000..5063f59 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTP.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTPNZ.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTPNZ.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTPNZ.class new file mode 100755 index 0000000..3c4fc61 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTPNZ.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTZ.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTZ.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTZ.class new file mode 100755 index 0000000..5e26cba Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTZ.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTZP.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTZP.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTZP.class new file mode 100755 index 0000000..d41205f Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ISO8601DTZP.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$Medium.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$Medium.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$Medium.class new file mode 100755 index 0000000..570a27b Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$Medium.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822D.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822D.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822D.class new file mode 100755 index 0000000..0c8f4f1 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822D.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822DT.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822DT.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822DT.class new file mode 100755 index 0000000..f034235 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822DT.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822DTZ.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822DTZ.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822DTZ.class new file mode 100755 index 0000000..41db26c Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$RFC2822DTZ.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$Simple.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$Simple.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$Simple.class new file mode 100755 index 0000000..e438251 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$Simple.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$SimpleP.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$SimpleP.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$SimpleP.class new file mode 100755 index 0000000..be31fe4 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$SimpleP.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ToString.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ToString.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ToString.class new file mode 100755 index 0000000..7a78e4d Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter$ToString.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter.class new file mode 100755 index 0000000..123a252 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter.java new file mode 100755 index 0000000..1759b41 --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateFilter.java @@ -0,0 +1,345 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.filters; + +import java.text.*; +import java.util.*; + +import javax.xml.bind.*; + +import com.ibm.juno.core.*; +import com.ibm.juno.core.filter.*; +import com.ibm.juno.core.parser.ParseException; +import com.ibm.juno.core.utils.*; + +/** + * Transforms {@link Date Dates} to {@link String Strings}. + * + * + * <h6 class='topic'>Behavior-specific subclasses</h6> + * <p> + * The following direct subclasses are provided for convenience: + * <ul> + * <li>{@link ToString} - Transforms to {@link String Strings} using the {@code Date.toString()} method. + * <li>{@link ISO8601DT} - Transforms to ISO8601 date-time strings. + * <li>{@link ISO8601DTP} - Transforms to ISO8601 date-time strings with millisecond precision. + * <li>{@link ISO8601DTZ} - Same as {@link ISO8601DT}, except always serializes in GMT. + * <li>{@link ISO8601DTZ} - Same as {@link ISO8601DTZ}, except with millisecond precision. + * <li>{@link RFC2822DT} - Transforms to RFC2822 date-time strings. + * <li>{@link RFC2822DTZ} - Same as {@link RFC2822DT}, except always serializes in GMT. + * <li>{@link RFC2822D} - Transforms to RFC2822 date strings. + * <li>{@link Simple} - Transforms to simple <js>"yyyy/MM/dd HH:mm:ss"</js> strings. + * <li>{@link Medium} - Transforms to {@link DateFormat#MEDIUM} strings. + * </ul> + * + * + * @author James Bognar ([email protected]) + */ +public class DateFilter extends PojoFilter<Date,String> { + + /** + * Transforms {@link Date Dates} to {@link String Strings} using the {@code Date.toString()} method. + * <p> + * <dl> + * <dt>Example output:</dt> + * <dd> + * <ul> + * <li><js>"Wed Jul 04 15:30:45 EST 2001"</js> + * </ul> + * </dd> + * </dl> + */ + public static class ToString extends DateFilter { + /** Constructor */ + public ToString() { + super("EEE MMM dd HH:mm:ss zzz yyyy"); + } + } + + /** + * Transforms {@link Date Dates} to ISO8601 date-time strings. + * + * <dl> + * <dt>Example output:</dt> + * <dd> + * <ul> + * <li><js>"2001-07-04T15:30:45-05:00"</js> + * <li><js>"2001-07-04T15:30:45Z"</js> + * </ul> + * </dd> + * <dt>Example input:</dt> + * <dd> + * <ul> + * <li><js>"2001-07-04T15:30:45-05:00"</js> + * <li><js>"2001-07-04T15:30:45Z"</js> + * <li><js>"2001-07-04T15:30:45.1Z"</js> + * <li><js>"2001-07-04T15:30Z"</js> + * <li><js>"2001-07-04"</js> + * <li><js>"2001-07"</js> + * <li><js>"2001"</js> + * </ul> + * </dd> + * </dl> + */ + public static class ISO8601DT extends DateFilter { + private SimpleDateFormat tzFormat = new SimpleDateFormat("Z"); + + /** Constructor */ + public ISO8601DT() { + this("yyyy-MM-dd'T'HH:mm:ss"); + } + + /** + * Constructor with specific pattern. + * + * @param pattern The {@link MessageFormat}-style format string. + */ + protected ISO8601DT(String pattern) { + super(pattern); + } + + @Override /* PojoFilter */ + public Date unfilter(String o, ClassMeta<?> hint) throws ParseException { + try { + if (StringUtils.isEmpty(o)) + return null; + return convert(DatatypeConverter.parseDateTime(o).getTime(), hint); + } catch (ParseException e) { + throw e; + } catch (Exception e) { + throw new ParseException(e); + } + } + + @Override /* PojoFilter */ + public String filter(Date o) { + String s = super.filter(o); + String tz = tzFormat.format(o); + if (tz.equals("+0000")) + return s + "Z"; + return s + tz.substring(0,3) + ':' + tz.substring(3); + } + } + + /** + * Same as {@link ISO8601DT} except serializes to millisecond precision. + * <p> + * Example output: <js>"2001-07-04T15:30:45.123-05:00"</js> + */ + public static class ISO8601DTP extends ISO8601DT { + + /** Constructor */ + public ISO8601DTP() { + super("yyyy-MM-dd'T'HH:mm:ss.SSS"); + } + } + + /** + * Same as {@link ISO8601DT} except serializes to millisecond precision and doesn't include timezone. + * <p> + * Example output: <js>"2001-07-04T15:30:45.123"</js> + */ + public static class ISO8601DTPNZ extends DateFilter { + + /** Constructor */ + public ISO8601DTPNZ() { + super("yyyy-MM-dd'T'HH:mm:ss.SSS"); + } + } + + /** + * Same as {@link ISO8601DT}, except always serializes in GMT. + * <p> + * Example output: <js>"2001-07-04T15:30:45Z"</js> + */ + public static class ISO8601DTZ extends DateFilter { + + /** Constructor */ + public ISO8601DTZ() { + this("yyyy-MM-dd'T'HH:mm:ss'Z'"); + } + + /** + * Constructor with specific pattern. + * + * @param pattern The {@link MessageFormat}-style format string. + */ + protected ISO8601DTZ(String pattern) { + super(pattern, "GMT"); + } + + @Override /* PojoFilter */ + public Date unfilter(String o, ClassMeta<?> hint) throws ParseException { + try { + if (StringUtils.isEmpty(o)) + return null; + return convert(DatatypeConverter.parseDateTime(o).getTime(), hint); + } catch (ParseException e) { + throw e; + } catch (Exception e) { + throw new ParseException(e); + } + } + } + + /** + * Same as {@link ISO8601DTZ} except serializes to millisecond precision. + * <p> + * Example output: <js>"2001-07-04T15:30:45.123Z"</js> + */ + public static class ISO8601DTZP extends ISO8601DT { + + /** Constructor */ + public ISO8601DTZP() { + super("yyyy-MM-dd'T'HH:mm:ss.SSS"); + } + } + + /** + * Transforms {@link Date Dates} to RFC2822 date-time strings. + */ + public static class RFC2822DT extends DateFilter { + /** Constructor */ + public RFC2822DT() { + super("EEE, dd MMM yyyy HH:mm:ss z"); + } + } + + /** + * Same as {@link RFC2822DT}, except always serializes in GMT. + * <p> + * Example output: <js>"2001-07-04T15:30:45Z"</js> + */ + public static class RFC2822DTZ extends DateFilter { + /** Constructor */ + public RFC2822DTZ() { + super("EEE, dd MMM yyyy HH:mm:ss z", "GMT"); + } + } + + /** + * Transforms {@link Date Dates} to RFC2822 date strings. + */ + public static class RFC2822D extends DateFilter { + /** Constructor */ + public RFC2822D() { + super("dd MMM yyyy"); + } + } + + /** + * Transforms {@link Date Dates} to simple <js>"yyyy/MM/dd HH:mm:ss"</js> strings. + */ + public static class Simple extends DateFilter { + /** Constructor */ + public Simple() { + super("yyyy/MM/dd HH:mm:ss"); + } + } + + /** + * Transforms {@link Date Dates} to simple <js>"yyyy/MM/dd HH:mm:ss.SSS"</js> strings. + */ + public static class SimpleP extends DateFilter { + /** Constructor */ + public SimpleP() { + super("yyyy/MM/dd HH:mm:ss.SSS"); + } + } + + /** + * Transforms {@link Date Dates} to {@link DateFormat#MEDIUM} strings. + */ + public static class Medium extends DateFilter { + /** Constructor */ + public Medium() { + super(DateFormat.getDateInstance(DateFormat.MEDIUM)); + } + } + + /** The formatter to convert dates to Strings. */ + private DateFormat format; + + /** + * Construct a filter using the specified date format string that will be + * used to construct a {@link SimpleDateFormat} that will be used to convert + * dates to strings. + * + * @param simpleDateFormat The {@link SimpleDateFormat} pattern. + */ + public DateFilter(String simpleDateFormat) { + this(new SimpleDateFormat(simpleDateFormat)); + } + + /** + * Construct a filter using the specified date format string that will be + * used to construct a {@link SimpleDateFormat} that will be used to convert + * dates to strings. + * + * @param simpleDateFormat The {@link SimpleDateFormat} pattern. + * @param timeZone The time zone to associate with the date pattern. + */ + public DateFilter(String simpleDateFormat, String timeZone) { + this(new SimpleDateFormat(simpleDateFormat)); + format.setTimeZone(TimeZone.getTimeZone(timeZone)); + } + + /** + * Construct a filter using the specified {@link DateFormat} that will be used to convert + * dates to strings. + * + * @param format The format to use to convert dates to strings. + */ + public DateFilter(DateFormat format) { + super(); + this.format = format; + } + + /** + * Converts the specified {@link Date} to a {@link String}. + */ + @Override /* PojoFilter */ + public String filter(Date o) { + return format.format(o); + } + + /** + * Converts the specified {@link String} to a {@link Date}. + */ + @Override /* PojoFilter */ + public Date unfilter(String o, ClassMeta<?> hint) throws ParseException { + try { + if (StringUtils.isEmpty(o)) + return null; + Date d = format.parse(o); + return convert(d, hint); + } catch (ParseException e) { + throw e; + } catch (Exception e) { + throw new ParseException(e); + } + } + + private static Date convert(Date in, ClassMeta<?> hint) throws Exception { + if (in == null) + return null; + if (hint == null || hint.isInstance(in)) + return in; + Class<?> c = hint.getInnerClass(); + if (c == java.util.Date.class) + return in; + if (c == java.sql.Date.class) + return new java.sql.Date(in.getTime()); + if (c == java.sql.Time.class) + return new java.sql.Time(in.getTime()); + if (c == java.sql.Timestamp.class) + return new java.sql.Timestamp(in.getTime()); + throw new ParseException("DateFilter is unable to narrow object of type ''{0}''", c); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateLongFilter.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateLongFilter.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateLongFilter.class new file mode 100755 index 0000000..70b7348 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateLongFilter.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateLongFilter.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateLongFilter.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateLongFilter.java new file mode 100755 index 0000000..c454645 --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateLongFilter.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.filters; + +import java.util.*; + +import com.ibm.juno.core.*; +import com.ibm.juno.core.filter.*; +import com.ibm.juno.core.parser.*; + +/** + * Transforms {@link Date Dates} to {@link Long Longs}. + * + * @author James Bognar ([email protected]) + */ +public class DateLongFilter extends PojoFilter<Date,Long> { + + /** + * Converts the specified {@link Date} to a {@link Long}. + */ + @Override /* PojoFilter */ + public Long filter(Date o) { + return o.getTime(); + } + + /** + * Converts the specified {@link Long} to a {@link Date}. + */ + @Override /* PojoFilter */ + public Date unfilter(Long o, ClassMeta<?> hint) throws ParseException { + Class<?> c = (hint == null ? java.util.Date.class : hint.getInnerClass()); + if (c == java.util.Date.class) + return new java.util.Date(o); + if (c == java.sql.Date.class) + return new java.sql.Date(o); + if (c == java.sql.Time.class) + return new java.sql.Time(o); + if (c == java.sql.Timestamp.class) + return new java.sql.Timestamp(o); + throw new ParseException("DateLongFilter is unable to narrow object of type ''{0}''", c); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateMapFilter.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateMapFilter.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateMapFilter.class new file mode 100755 index 0000000..1a84d40 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateMapFilter.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateMapFilter.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateMapFilter.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateMapFilter.java new file mode 100755 index 0000000..ba5c63f --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/DateMapFilter.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.filters; + +import java.util.*; + +import com.ibm.juno.core.*; +import com.ibm.juno.core.filter.*; +import com.ibm.juno.core.parser.*; + +/** + * Transforms {@link Date Dates} to {@link Map Maps} of the format <tt>{value:long}</tt>. + * + * @author James Bognar ([email protected]) + */ +@SuppressWarnings("rawtypes") +public class DateMapFilter extends PojoFilter<Date,Map> { + + /** + * Converts the specified {@link Date} to a {@link Map}. + */ + @Override /* PojoFilter */ + public Map filter(Date o) { + ObjectMap m = new ObjectMap(); + m.put("time", o.getTime()); + return m; + } + + /** + * Converts the specified {@link Map} to a {@link Date}. + */ + @Override /* PojoFilter */ + public Date unfilter(Map o, ClassMeta<?> hint) throws ParseException { + Class<?> c = (hint == null ? java.util.Date.class : hint.getInnerClass()); + long l = Long.parseLong(((Map<?,?>)o).get("time").toString()); + if (c == java.util.Date.class) + return new java.util.Date(l); + if (c == java.sql.Date.class) + return new java.sql.Date(l); + if (c == java.sql.Time.class) + return new java.sql.Time(l); + if (c == java.sql.Timestamp.class) + return new java.sql.Timestamp(l); + throw new ParseException("DateMapFilter is unable to narrow object of type ''{0}''", c); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/EnumerationFilter.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/EnumerationFilter.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/EnumerationFilter.class new file mode 100755 index 0000000..3aaf8b1 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/EnumerationFilter.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/EnumerationFilter.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/EnumerationFilter.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/EnumerationFilter.java new file mode 100755 index 0000000..549f7da --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/EnumerationFilter.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2014. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.filters; + +import java.util.*; + +import com.ibm.juno.core.filter.*; + +/** + * Transforms {@link Enumeration Enumerations} to {@code List<Object>} objects. + * <p> + * This is a one-way filter, since {@code Enumerations} cannot be reconstituted. + * + * @author James Bognar ([email protected]) + */ +@SuppressWarnings({"unchecked","rawtypes"}) +public class EnumerationFilter extends PojoFilter<Enumeration,List> { + + /** + * Converts the specified {@link Enumeration} to a {@link List}. + */ + @Override /* PojoFilter */ + public List filter(Enumeration o) { + List l = new LinkedList(); + while (o.hasMoreElements()) + l.add(o.nextElement()); + return l; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/IteratorFilter.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/IteratorFilter.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/IteratorFilter.class new file mode 100755 index 0000000..f7ef926 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/IteratorFilter.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/IteratorFilter.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/IteratorFilter.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/IteratorFilter.java new file mode 100755 index 0000000..7e5ded6 --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/IteratorFilter.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2014. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.filters; + +import java.util.*; + +import com.ibm.juno.core.filter.*; + +/** + * Transforms {@link Iterator Iterators} to {@code List<Object>} objects. + * <p> + * This is a one-way filter, since {@code Iterators} cannot be reconstituted. + * + * @author James Bognar ([email protected]) + */ +@SuppressWarnings({"unchecked","rawtypes"}) +public class IteratorFilter extends PojoFilter<Iterator,List> { + + /** + * Converts the specified {@link Iterator} to a {@link List}. + */ + @Override /* PojoFilter */ + public List filter(Iterator o) { + List l = new LinkedList(); + while (o.hasNext()) + l.add(o.next()); + return l; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Html.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Html.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Html.class new file mode 100755 index 0000000..1e70661 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Html.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Json.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Json.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Json.class new file mode 100755 index 0000000..4a97b6b Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Json.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$PlainText.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$PlainText.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$PlainText.class new file mode 100755 index 0000000..8e5c6fd Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$PlainText.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Xml.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Xml.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Xml.class new file mode 100755 index 0000000..21130fc Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter$Xml.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter.class new file mode 100755 index 0000000..c425ae6 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter.java new file mode 100755 index 0000000..e1d4ecc --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/ReaderFilter.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2014. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.filters; + +import java.io.*; + +import com.ibm.juno.core.filter.*; +import com.ibm.juno.core.html.*; +import com.ibm.juno.core.json.*; +import com.ibm.juno.core.parser.*; +import com.ibm.juno.core.serializer.*; +import com.ibm.juno.core.utils.*; +import com.ibm.juno.core.xml.*; + +/** + * Transforms the contents of a {@link Reader} into an {@code Object}. + * + * + * <h6 class='topic'>Description</h6> + * <p> + * The {@code Reader} must contain JSON, Juno-generated XML (output from {@link XmlSerializer}), + * or Juno-generated HTML (output from {@link JsonSerializer}) in order to be parsed correctly. + * <p> + * Useful for serializing models that contain {@code Readers} created by {@code RestCall} instances. + * <p> + * This is a one-way filter, since {@code Readers} cannot be reconstituted. + * + * + * <h6 class='topic'>Behavior-specific subclasses</h6> + * <p> + * The following direct subclasses are provided for convenience: + * <ul> + * <li>{@link Json} - Parses JSON text. + * <li>{@link Xml} - Parses XML text. + * <li>{@link Html} - Parses HTML text. + * <li>{@link PlainText} - Parses plain text. + * </ul> + * + * + * @author James Bognar ([email protected]) + */ +public class ReaderFilter extends PojoFilter<Reader,Object> { + + /** Reader filter for reading JSON text. */ + public static class Json extends ReaderFilter { + /** Constructor */ + public Json() { + super(JsonParser.DEFAULT); + } + } + + /** Reader filter for reading XML text. */ + public static class Xml extends ReaderFilter { + /** Constructor */ + public Xml() { + super(XmlParser.DEFAULT); + } + } + + /** Reader filter for reading HTML text. */ + public static class Html extends ReaderFilter { + /** Constructor */ + public Html() { + super(HtmlParser.DEFAULT); + } + } + + /** Reader filter for reading plain text. */ + public static class PlainText extends ReaderFilter { + /** Constructor */ + public PlainText() { + super(null); + } + } + + /** The parser to use to parse the contents of the Reader. */ + private ReaderParser parser; + + /** + * @param parser The parser to use to convert the contents of the reader to Java objects. + */ + public ReaderFilter(ReaderParser parser) { + this.parser = parser; + } + + /** + * Converts the specified {@link Reader} to an {@link Object} whose type is determined + * by the contents of the reader. + */ + @Override /* PojoFilter */ + public Object filter(Reader o) throws SerializeException { + try { + if (parser == null) + return IOUtils.read(o); + return parser.parse(o, -1, beanContext.object()); + } catch (IOException e) { + return e.getLocalizedMessage(); + } catch (Exception e) { + throw new SerializeException("ReaderFilter could not filter object of type ''{0}''", o == null ? null : o.getClass().getName()).initCause(e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/XMLGregorianCalendarFilter.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/XMLGregorianCalendarFilter.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/XMLGregorianCalendarFilter.class new file mode 100755 index 0000000..51e4b5d Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/XMLGregorianCalendarFilter.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/XMLGregorianCalendarFilter.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/XMLGregorianCalendarFilter.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/XMLGregorianCalendarFilter.java new file mode 100755 index 0000000..f2f111f --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/XMLGregorianCalendarFilter.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2013, 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.filters; + +import javax.xml.datatype.*; + +import com.ibm.juno.core.*; +import com.ibm.juno.core.filter.*; +import com.ibm.juno.core.parser.*; +import com.ibm.juno.core.serializer.*; +import com.ibm.juno.core.utils.*; + +/** + * Transforms {@link XMLGregorianCalendar XMLGregorianCalendars} to ISO8601 date-time {@link String Strings}. + * <p> + * Objects are converted to strings using {@link XMLGregorianCalendar#toXMLFormat()}. + * <p> + * Strings are converted to objects using {@link DatatypeFactory#newXMLGregorianCalendar(String)}. + * + * @author James Bognar ([email protected]) + */ +public class XMLGregorianCalendarFilter extends PojoFilter<XMLGregorianCalendar,String> { + + private DatatypeFactory dtf; + + /** + * Constructor. + */ + public XMLGregorianCalendarFilter() { + try { + this.dtf = DatatypeFactory.newInstance(); + } catch (DatatypeConfigurationException e) { + throw new RuntimeException(e); + } + } + + /** + * Converts the specified <code>XMLGregorianCalendar</code> to a {@link String}. + */ + @Override /* PojoFilter */ + public String filter(XMLGregorianCalendar b) throws SerializeException { + return b.toXMLFormat(); + } + + /** + * Converts the specified {@link String} to an <code>XMLGregorianCalendar</code>. + */ + @Override /* PojoFilter */ + public XMLGregorianCalendar unfilter(String s, ClassMeta<?> hint) throws ParseException { + if (StringUtils.isEmpty(s)) + return null; + return dtf.newXMLGregorianCalendar(s); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/package.html ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/package.html b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/package.html new file mode 100755 index 0000000..27e7a14 --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/filters/package.html @@ -0,0 +1,59 @@ +<!DOCTYPE HTML> +<!-- + Licensed Materials - Property of IBM + (c) Copyright IBM Corporation 2014. All Rights Reserved. + + Note to U.S. Government Users Restricted Rights: + Use, duplication or disclosure restricted by GSA ADP Schedule + Contract with IBM Corp. + --> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> + <style type="text/css"> + /* For viewing in Page Designer */ + @IMPORT url("../../../../../../javadoc.css"); + + /* For viewing in REST interface */ + @IMPORT url("../htdocs/javadoc.css"); + body { + margin: 20px; + } + </style> + <script> + /* Replace all @code and @link tags. */ + window.onload = function() { + document.body.innerHTML = document.body.innerHTML.replace(/\{\@code ([^\}]+)\}/g, '<code>$1</code>'); + document.body.innerHTML = document.body.innerHTML.replace(/\{\@link (([^\}]+)\.)?([^\.\}]+)\}/g, '<code>$3</code>'); + } + </script> +</head> +<body> +<p>Predefined Filter implementations</p> +<script> + function toggle(x) { + var div = x.nextSibling; + while (div != null && div.nodeType != 1) + div = div.nextSibling; + if (div != null) { + var d = div.style.display; + if (d == 'block' || d == '') { + div.style.display = 'none'; + x.className += " closed"; + } else { + div.style.display = 'block'; + x.className = x.className.replace(/(?:^|\s)closed(?!\S)/g , '' ); + } + } + } +</script> + +<!-- ======================================================================================================== --> +<a id="PredefinedFilters"></a><h2 class='topic'>1 - Predefined filter support</h2> +<p> + This package contains various predefined instances of filters for commonly-serialized/parsed class types. +</p> +<p> + See {@link com.ibm.juno.core.filter} for more information about filters. +</p> +</body> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlBeanPropertyMeta.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlBeanPropertyMeta.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlBeanPropertyMeta.class new file mode 100755 index 0000000..bcdcdb8 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlBeanPropertyMeta.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlBeanPropertyMeta.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlBeanPropertyMeta.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlBeanPropertyMeta.java new file mode 100755 index 0000000..4405f91 --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlBeanPropertyMeta.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.html; + +import com.ibm.juno.core.*; +import com.ibm.juno.core.html.annotation.*; + +/** + * Metadata on bean properties specific to the HTML serializers and parsers pulled from the {@link Html @Html} annotation on the bean property. + * + * @author James Bognar ([email protected]) + * @param <T> The bean class. + */ +public class HtmlBeanPropertyMeta<T> { + + private boolean asXml, noTables, noTableHeaders, asPlainText; + + /** + * Constructor. + * + * @param beanPropertyMeta The metadata of the bean property of this additional metadata. + */ + public HtmlBeanPropertyMeta(BeanPropertyMeta<T> beanPropertyMeta) { + if (beanPropertyMeta.getField() != null) + findHtmlInfo(beanPropertyMeta.getField().getAnnotation(Html.class)); + if (beanPropertyMeta.getGetter() != null) + findHtmlInfo(beanPropertyMeta.getGetter().getAnnotation(Html.class)); + if (beanPropertyMeta.getSetter() != null) + findHtmlInfo(beanPropertyMeta.getSetter().getAnnotation(Html.class)); + } + + private void findHtmlInfo(Html html) { + if (html == null) + return; + if (html.asXml()) + asXml = html.asXml(); + if (html.noTables()) + noTables = html.noTables(); + if (html.noTableHeaders()) + noTableHeaders = html.noTableHeaders(); + if (html.asPlainText()) + asPlainText = html.asPlainText(); + } + + /** + * Returns whether this bean property should be serialized as XML instead of HTML. + * + * @return <jk>true</jk> if the the {@link Html} annotation is specified, and {@link Html#asXml()} is <jk>true</jk>. + */ + protected boolean isAsXml() { + return asXml; + } + + /** + * Returns whether this bean property should be serialized as plain text instead of HTML. + * + * @return <jk>true</jk> if the the {@link Html} annotation is specified, and {@link Html#asPlainText()} is <jk>true</jk>. + */ + protected boolean isAsPlainText() { + return asPlainText; + } + + /** + * Returns whether this bean property should not be serialized as an HTML table. + * + * @return <jk>true</jk> if the the {@link Html} annotation is specified, and {@link Html#noTables()} is <jk>true</jk>. + */ + protected boolean isNoTables() { + return noTables; + } + + /** + * Returns whether this bean property should not include table headers when serialized as an HTML table. + * + * @return <jk>true</jk> if the the {@link Html} annotation is specified, and {@link Html#noTableHeaders()} is <jk>true</jk>. + */ + public boolean isNoTableHeaders() { + return noTableHeaders; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlClassMeta.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlClassMeta.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlClassMeta.class new file mode 100755 index 0000000..74294b9 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlClassMeta.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlClassMeta.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlClassMeta.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlClassMeta.java new file mode 100755 index 0000000..b5af7e5 --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlClassMeta.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.html; + +import com.ibm.juno.core.html.annotation.*; +import com.ibm.juno.core.utils.*; + +/** + * Metadata on classes specific to the HTML serializers and parsers pulled from the {@link Html @Html} annotation on the class. + * + * @author James Bognar ([email protected]) + */ +public class HtmlClassMeta { + + private final Html html; + private final boolean asXml, noTables, noTableHeaders, asPlainText; + + /** + * Constructor. + * + * @param c The class that this annotation is defined on. + */ + public HtmlClassMeta(Class<?> c) { + this.html = ReflectionUtils.getAnnotation(Html.class, c); + if (html != null) { + asXml = html.asXml(); + noTables = html.noTables(); + noTableHeaders = html.noTableHeaders(); + asPlainText = html.asPlainText(); + } else { + asXml = false; + noTables = false; + noTableHeaders = false; + asPlainText = false; + } + } + + /** + * Returns the {@link Html} annotation defined on the class. + * + * @return The value of the {@link Html} annotation, or <jk>null</jk> if not specified. + */ + protected Html getAnnotation() { + return html; + } + + /** + * Returns the {@link Html#asXml()} annotation defined on the class. + * + * @return The value of the {@link Html#asXml()} annotation. + */ + protected boolean isAsXml() { + return asXml; + } + + /** + * Returns the {@link Html#asPlainText()} annotation defined on the class. + * + * @return The value of the {@link Html#asPlainText()} annotation. + */ + protected boolean isAsPlainText() { + return asPlainText; + } + + /** + * Returns the {@link Html#noTables()} annotation defined on the class. + * + * @return The value of the {@link Html#noTables()} annotation. + */ + protected boolean isNoTables() { + return noTables; + } + + /** + * Returns the {@link Html#noTableHeaders()} annotation defined on the class. + * + * @return The value of the {@link Html#noTableHeaders()} annotation. + */ + public boolean isNoTableHeaders() { + return noTableHeaders; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializer.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializer.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializer.class new file mode 100755 index 0000000..e0992ad Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializer.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializer.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializer.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializer.java new file mode 100755 index 0000000..a58709d --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializer.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.html; + +import java.io.*; +import java.lang.reflect.*; +import java.util.*; + +import com.ibm.juno.core.*; +import com.ibm.juno.core.annotation.*; +import com.ibm.juno.core.dto.*; +import com.ibm.juno.core.serializer.*; +import com.ibm.juno.core.utils.*; + +/** + * Serializes POJOs to HTTP responses as HTML documents. + * + * + * <h6 class='topic'>Media types</h6> + * <p> + * Handles <code>Accept</code> types: <code>text/html</code> + * <p> + * Produces <code>Content-Type</code> types: <code>text/html</code> + * + * + * <h6 class='topic'>Description</h6> + * <p> + * Same as {@link HtmlSerializer}, except wraps the response in <code><xt><html></code>, <code><xt><head></code>, + * and <code><xt><body></code> tags so that it can be rendered in a browser. + * + * + * <h6 class='topic'>Configurable properties</h6> + * <p> + * This class has the following properties associated with it: + * <ul> + * <li>{@link HtmlDocSerializerProperties} + * <li>{@link HtmlSerializerProperties} + * <li>{@link SerializerProperties} + * <li>{@link BeanContextProperties} + * </ul> + * + * + * @author James Bognar ([email protected]) + */ +@Produces("text/html") +public class HtmlDocSerializer extends HtmlStrippedDocSerializer { + + // Properties defined in RestServletProperties + private static final String + REST_method = "RestServlet.method", + REST_relativeServletURI = "RestServlet.relativeServletURI"; + + + //-------------------------------------------------------------------------------- + // Overridden methods + //-------------------------------------------------------------------------------- + + @Override /* Serializer */ + protected void doSerialize(Object o, Writer out, SerializerContext ctx) throws IOException, SerializeException { + + HtmlSerializerContext hctx = (HtmlSerializerContext)ctx; + HtmlSerializerWriter w = hctx.getWriter(out); + + ObjectMap properties = hctx.getProperties(); + + boolean isOptionsPage = properties.containsKey(REST_method) && properties.getString(REST_method).equalsIgnoreCase("OPTIONS"); + + // Render the header. + w.sTag("html").nl(); + w.sTag("head").nl(); + + String cssUrl = hctx.getCssUrl(); + if (cssUrl == null) + cssUrl = properties.getString(REST_relativeServletURI) + "/style.css"; + + w.oTag(1, "style") + .attr("type", "text/css") + .appendln(">") + .append(2, "@import ").q().append(cssUrl).q().appendln(";"); + if (hctx.isNoWrap()) + w.appendln("\n* {white-space:nowrap;}"); + if (hctx.getCssImports() != null) + for (String cssImport : hctx.getCssImports()) + w.append(2, "@import ").q().append(cssImport).q().appendln(";"); + w.eTag(1, "style").nl(); + w.eTag("head").nl(); + w.sTag("body").nl(); + // Write the title of the page. + String title = hctx.getTitle(); + if (title == null && isOptionsPage) + title = "Options"; + String description = hctx.getDescription(); + if (title != null) + w.oTag(1, "h3").attr("class", "title").append('>').encodeText(title).eTag("h3").nl(); + if (description != null) + w.oTag(1, "h5").attr("class", "description").append('>').encodeText(description).eTag("h5").nl(); + + // Write the action links that render above the results. + List<Link> actions = new LinkedList<Link>(); + + // If this is an OPTIONS request, provide a 'back' link to return to the GET request page. + if (! isOptionsPage) { + ObjectMap htmlLinks = hctx.getLinks(); + if (htmlLinks != null) { + for (Map.Entry<String,Object> e : htmlLinks.entrySet()) { + String uri = e.getValue().toString(); + if (uri.indexOf("://") == -1 && ! StringUtils.startsWith(uri, '/')) { + StringBuilder sb = new StringBuilder(properties.getString(REST_relativeServletURI)); + if (! (uri.isEmpty() || uri.charAt(0) == '?' || uri.charAt(0) == '/')) + sb.append('/'); + sb.append(uri); + uri = sb.toString(); + } + + actions.add(new Link(e.getKey(), uri)); + } + } + } + + if (actions.size() > 0) { + w.oTag(1, "p").attr("class", "links").append('>').nl(); + for (Iterator<Link> i = actions.iterator(); i.hasNext();) { + Link h = i.next(); + w.oTag(2, "a").attr("class", "link").attr("href", h.getHref(), true).append('>').append(h.getName()).eTag("a").nl(); + if (i.hasNext()) + w.append(3, " - ").nl(); + } + w.eTag(1, "p").nl(); + } + + hctx.indent = 3; + + // To allow for page formatting using CSS, we encapsulate the data inside two div tags: + // <div class='outerdata'><div class='data' id='data'>...</div></div> + w.oTag(1, "div").attr("class","outerdata").append('>').nl(); + w.oTag(2, "div").attr("class","data").attr("id", "data").append('>').nl(); + if (isEmptyList(o)) + w.oTag(3, "p").append('>').append("no results").eTag("p"); + else + super.doSerialize(o, w, hctx); + w.eTag(2, "div").nl(); + w.eTag(1, "div").nl(); + + w.eTag("body").nl().eTag("html").nl(); + } + + private boolean isEmptyList(Object o) { + if (o == null) + return false; + if (o instanceof Collection && ((Collection<?>)o).size() == 0) + return true; + if (o.getClass().isArray() && Array.getLength(o) == 0) + return true; + return false; + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializerProperties.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializerProperties.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializerProperties.class new file mode 100755 index 0000000..b9afc9c Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializerProperties.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializerProperties.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializerProperties.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializerProperties.java new file mode 100755 index 0000000..dd565af --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlDocSerializerProperties.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2014, 2015. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.html; + + +/** + * Properties associated with the {@link HtmlDocSerializer} class. + * <p> + * These are typically specified via <ja>@RestResource.properties()</ja> and <ja>@RestMethod.properties()</ja> annotations, + * although they can also be set programmatically via the <code>RestREsponse.setProperty()</code> method. + * + * <h6 class='topic'>Example</h6> + * <p class='bcode'> + * <ja>@RestResource</ja>( + * messages=<js>"nls/AddressBookResource"</js>, + * properties={ + * <ja>@Property</ja>(name=HtmlDocSerializerProperties.<jsf>HTMLDOC_title</jsf>, value=<js>"$L{title}"</js>), + * <ja>@Property</ja>(name=HtmlDocSerializerProperties.<jsf>HTMLDOC_description</jsf>, value=<js>"$L{description}"</js>), + * <ja>@Property</ja>(name=HtmlDocSerializerProperties.<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>) + * } + * ) + * <jk>public class</jk> AddressBookResource <jk>extends</jk> RestServletJenaDefault { + * </p> + * <p> + * The <code>$L{...}</code> variable represent localized strings pulled from the resource bundle identified by the <code>messages</code> annotation. + * These variables are replaced at runtime based on the HTTP request locale. + * Several built-in runtime variable types are defined, and the API can be extended to include user-defined variables. + * </p> + * + * @author James Bognar ([email protected]) + */ +public final class HtmlDocSerializerProperties { + + /** + * Adds a title at the top of a page. + * + * <dl> + * <dt>Example:</dt> + * <dd> + * <p> + * The <code>AddressBookResource</code> sample class uses this property... + * </p> + * <p class='bcode'> + * <ja>@RestResource</ja>( + * messages=<js>"nls/AddressBookResource"</js>, + * properties={ + * <ja>@Property</ja>(name=HtmlDocSerializerProperties.<jsf>HTMLDOC_title</jsf>, value=<js>"$L{title}"</js>) + * } + * ) + * <jk>public class</jk> AddressBookResource <jk>extends</jk> RestServletJenaDefault { + * </p> + * <p> + * ...with this property in <code>AddressBookResource.properties</code>... + * </p> + * <p class='bcode'> + * title = <js>AddressBook sample resource</js> + * </p> + * <p> + * ...to produce this title on the HTML page... + * </p> + * <img class='bordered' src='doc-files/HTML_TITLE.png'> + * </dd> + * </dl> + */ + public static final String HTMLDOC_title = "HtmlSerializer.title"; + + /** + * Adds a description right below the title of a page. + * + * <dl> + * <dt>Example:</dt> + * <dd> + * <p> + * The <code>AddressBookResource</code> sample class uses this property... + * </p> + * <p class='bcode'> + * <ja>@RestResource</ja>( + * messages=<js>"nls/AddressBookResource"</js>, + * properties={ + * <ja>@Property</ja>(name=HtmlDocSerializerProperties.<jsf>HTMLDOC_description</jsf>, value=<js>"description"</js>, type=<jsf>NLS</jsf>) + * } + * ) + * <jk>public class</jk> AddressBookResource <jk>extends</jk> RestServletJenaDefault { + * </p> + * <p> + * ...with this property in <code>AddressBookResource.properties</code>... + * </p> + * <p class='bcode'> + * description = <js>Simple address book POJO sample resource</js> + * </p> + * <p> + * ...to produce this description on the HTML page... + * </p> + * <img class='bordered' src='doc-files/HTML_DESCRIPTION.png'> + * </dd> + * </dl> + */ + public static final String HTMLDOC_description = "HtmlSerializer.description"; + + /** + * Adds a list of hyperlinks immediately under the title and description but above the content of the page. + * <p> + * This can be used to provide convenient hyperlinks when viewing the REST interface from a browser. + * <p> + * The value is a JSON object string where the keys are anchor text and the values are URLs. + * <p> + * Relative URLs are considered relative to the servlet path. + * For example, if the servlet path is <js>"http://localhost/myContext/myServlet"</js>, and the + * URL is <js>"foo"</js>, the link becomes <js>"http://localhost/myContext/myServlet/foo"</js>. + * Absolute (<js>"/myOtherContext/foo"</js>) and fully-qualified (<js>"http://localhost2/foo"</js>) URLs + * can also be used. + * + * <dl> + * <dt>Example:</dt> + * <dd> + * <p> + * The <code>AddressBookResource</code> sample class uses this property... + * </p> + * <p class='bcode'> + * <ja>@RestResource</ja>( + * messages=<js>"nls/AddressBookResource"</js>, + * properties={ + * <ja>@Property</ja>(name=HtmlDocSerializerProperties.<jsf>HTMLDOC_links</jsf>, value=<js>"{options:'?method=OPTIONS',doc:'doc'}"</js>) + * } + * ) + * <jk>public class</jk> AddressBookResource <jk>extends</jk> RestServletJenaDefault { + * </p> + * <p> + * ...to produce this list of links on the HTML page... + * </p> + * <img class='bordered' src='doc-files/HTML_LINKS.png'> + * </dd> + * </dl> + */ + public static final String HTMLDOC_links = "HtmlDocSerializer.links"; + + /** + * Similar to {@link #HTMLDOC_links} except appends on to the existing list of links. + */ + public static final String HTMLDOC_addLinks = "HtmlDocSerializer.addLinks"; + + /** + * Adds a link to the specified stylesheet URL. + * <p> + * If not specified, defaults to the built-in stylesheet located at <js>"/servletPath/style.css"</js>. + * Note that this stylesheet is controlled by the <code><ja>@RestResource</ja>.style()</code> annotation. + */ + public static final String HTMLDOC_cssUrl = "HtmlDocSerializer.cssUrl"; + + /** + * Imports the specified CSS page URLs into the page. + */ + public static final String HTMLDOC_cssImports = "HtmlDocSerializer.cssImports"; + + /** + * Adds <js>"* {white-space:nowrap}"</js> to the style header to prevent word wrapping. + */ + public static final String HTMLDOC_nowrap = "HtmlDocSerializer.nowrap"; +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlLink.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlLink.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlLink.class new file mode 100755 index 0000000..54ac01b Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlLink.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlLink.java ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlLink.java b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlLink.java new file mode 100755 index 0000000..208f1bd --- /dev/null +++ b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlLink.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Licensed Materials - Property of IBM + * (c) Copyright IBM Corporation 2011, 2014. All Rights Reserved. + * + * The source code for this program is not published or otherwise + * divested of its trade secrets, irrespective of what has been + * deposited with the U.S. Copyright Office. + *******************************************************************************/ +package com.ibm.juno.core.html; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; + +import java.lang.annotation.*; + +/** + * Used in conjunction with the {@link HtmlSerializer} class to define hyperlinks. + * <p> + * This annotation is applied to classes. + * <p> + * Annotation that can be used to specify that a class has a URL associated with it. + * <p> + * When rendered using the {@link com.ibm.juno.core.html.HtmlSerializer HtmlSerializer} class, this class will get rendered as a hyperlink like so... + * <p class='code'> + * <xt><a</xt> <xa>href</xa>=<xs>'hrefProperty'</xs><xt>></xt>nameProperty<xt></a></xt> + * </p> + * + * @author James Bognar ([email protected]) + */ +@Documented +@Target(TYPE) +@Retention(RUNTIME) +@Inherited +public @interface HtmlLink { + + /** + * The bean property whose value becomes the name in the hyperlink. + */ + String nameProperty() default ""; + + /** + * The bean property whose value becomes the url in the hyperlink. + */ + String hrefProperty() default ""; +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlParser$Tag.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlParser$Tag.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlParser$Tag.class new file mode 100755 index 0000000..70e31b6 Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlParser$Tag.class differ http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/7e4f63e6/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlParser.class ---------------------------------------------------------------------- diff --git a/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlParser.class b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlParser.class new file mode 100755 index 0000000..9c3206d Binary files /dev/null and b/com.ibm.team.juno.releng/bin/core/com/ibm/juno/core/html/HtmlParser.class differ
