Weitere Anpassungen für CT Image
* Datum läßt sich jetzt auch nur teilweise ausfüllen * Traversal-Adapter für search-context geschrieben. Wird der CT jetzt in den Suchindex aufgenommen? git-svn-id: https://svn.libreccm.org/ccm/trunk@786 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
0bd2770fe1
commit
6a9658125a
|
|
@ -15,6 +15,8 @@ object type Image extends ContentPage {
|
||||||
String [0..1] description = ct_images.description VARCHAR(500);
|
String [0..1] description = ct_images.description VARCHAR(500);
|
||||||
String [0..1] artist = ct_images.artist VARCHAR(200);
|
String [0..1] artist = ct_images.artist VARCHAR(200);
|
||||||
Date [0..1] publishDate = ct_images.publish_date DATE;
|
Date [0..1] publishDate = ct_images.publish_date DATE;
|
||||||
|
Boolean[0..1] skipDay = ct_images.skip_day;
|
||||||
|
Boolean[0..1] skipMonth = ct_images.skip_month;
|
||||||
String [0..1] source = ct_images.source VARCHAR(600);
|
String [0..1] source = ct_images.source VARCHAR(600);
|
||||||
String [0..1] media = ct_images.media VARCHAR(300);
|
String [0..1] media = ct_images.media VARCHAR(300);
|
||||||
String [0..1] copyright = ct_images.copyright VARCHAR(400);
|
String [0..1] copyright = ct_images.copyright VARCHAR(400);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
<!-- First off the adapters for ContentItemPanel -->
|
<!-- First off the adapters for ContentItemPanel -->
|
||||||
<xrd:context name="com.arsdigita.cms.dispatcher.SimpleXMLGenerator">
|
<xrd:context name="com.arsdigita.cms.dispatcher.SimpleXMLGenerator">
|
||||||
<xrd:adapter objectType="com.arsdigita.cms.contenttypes.Image" extends="com.arsdigita.cms.contenttypes.ContentPage">
|
<xrd:adapter objectType="com.arsdigita.cms.contenttypes.Image" extends="com.arsdigita.cms.ContentPage">
|
||||||
<xrd:formatter property="/object/publishDate"
|
<xrd:formatter property="/object/publishDate"
|
||||||
class="com.arsdigita.xml.formatters.DateFormatter"/>
|
class="com.arsdigita.xml.formatters.DateFormatter"/>
|
||||||
<xrd:associations rule="include">
|
<xrd:associations rule="include">
|
||||||
|
|
@ -14,4 +14,24 @@
|
||||||
</xrd:adapter>
|
</xrd:adapter>
|
||||||
</xrd:context>
|
</xrd:context>
|
||||||
|
|
||||||
|
<!-- Next the metadata for search -->
|
||||||
|
<xrd:context name="com.arsdigita.cms.search.ContentPageMetadataProvider">
|
||||||
|
<!-- Content item is the simplest type -->
|
||||||
|
<xrd:adapter objectType="com.arsdigita.cms.contenttypes.Image" extends="com.arsdigita.cms.ContentItem" traversalClass="com.arsdigita.cms.contenttypes.ContentItemTraversalAdapter">
|
||||||
|
<xrd:attributes rule="exclude">
|
||||||
|
<xrd:property name="/object/textAsset/id"/>
|
||||||
|
<xrd:property name="/object/textAsset/defaultDomainClass"/>
|
||||||
|
<xrd:property name="/object/textAsset/objectType"/>
|
||||||
|
<xrd:property name="/object/textAsset/displayName"/>
|
||||||
|
<xrd:property name="/object/textAsset/ancestors"/>
|
||||||
|
<xrd:property name="/object/textAsset/version"/>
|
||||||
|
<xrd:property name="/object/textAsset/name"/>
|
||||||
|
<xrd:property name="/object/textAsset/language"/>
|
||||||
|
<xrd:property name="/object/textAsset/isDeleted"/>
|
||||||
|
</xrd:attributes>
|
||||||
|
<xrd:associations rule="include">
|
||||||
|
<xrd:property name="/object/textAsset"/>
|
||||||
|
</xrd:associations>
|
||||||
|
</xrd:adapter>
|
||||||
|
</xrd:context>
|
||||||
</xrd:adapters>
|
</xrd:adapters>
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,8 @@ public class Image extends ContentPage {
|
||||||
public static final String CAPTION = "caption";
|
public static final String CAPTION = "caption";
|
||||||
public static final String DESCRIPTION = "description";
|
public static final String DESCRIPTION = "description";
|
||||||
public static final String ARTIST = "artist";
|
public static final String ARTIST = "artist";
|
||||||
|
public static final String SKIPDAY= "skipDay";
|
||||||
|
public static final String SKIPMONTH= "skipMonth";
|
||||||
public static final String PUBLISHDATE = "publishDate";
|
public static final String PUBLISHDATE = "publishDate";
|
||||||
public static final String SOURCE = "source";
|
public static final String SOURCE = "source";
|
||||||
public static final String MEDIA = "media";
|
public static final String MEDIA = "media";
|
||||||
|
|
@ -207,6 +209,30 @@ public class Image extends ContentPage {
|
||||||
set(ARTIST, artist);
|
set(ARTIST, artist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getSkipDay() {
|
||||||
|
try {
|
||||||
|
return ((Boolean) get(SKIPDAY)).booleanValue();
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSkipDay(Boolean skipDay) {
|
||||||
|
set(SKIPDAY, skipDay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getSkipMonth() {
|
||||||
|
try {
|
||||||
|
return ((Boolean) get(SKIPMONTH)).booleanValue();
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSkipMonth(Boolean skipMonth) {
|
||||||
|
set(SKIPMONTH, skipMonth);
|
||||||
|
}
|
||||||
|
|
||||||
public Date getPublishDate() {
|
public Date getPublishDate() {
|
||||||
return (Date) get(PUBLISHDATE);
|
return (Date) get(PUBLISHDATE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,10 +48,13 @@ import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
|
||||||
import com.arsdigita.cms.ui.authoring.BasicPageForm;
|
import com.arsdigita.cms.ui.authoring.BasicPageForm;
|
||||||
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
|
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
|
||||||
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
|
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
|
||||||
|
import com.arsdigita.dispatcher.DispatcherHelper;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
import java.text.DateFormatSymbols;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -152,7 +155,23 @@ public class ImagePropertiesStep extends SimpleEditStep {
|
||||||
public String format(DomainObject item, String attribute, PageState state) {
|
public String format(DomainObject item, String attribute, PageState state) {
|
||||||
Image image = (Image) item;
|
Image image = (Image) item;
|
||||||
if ((image.getPublishDate()) != null) {
|
if ((image.getPublishDate()) != null) {
|
||||||
|
if (image.getSkipDay().booleanValue() == true || image.getSkipMonth().booleanValue() == true) {
|
||||||
|
String month = "";
|
||||||
|
if (image.getSkipMonth().booleanValue() == false) {
|
||||||
|
Locale locale = DispatcherHelper.getNegotiatedLocale();
|
||||||
|
|
||||||
|
if (locale != null) {
|
||||||
|
|
||||||
|
DateFormatSymbols dfs = new DateFormatSymbols(locale);
|
||||||
|
String[] months = dfs.getMonths();
|
||||||
|
month = months[image.getPublishDate().getMonth()] + " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String year = Integer.toString(image.getPublishDate().getYear() + 1900);
|
||||||
|
return month + year;
|
||||||
|
} else {
|
||||||
return DateFormat.getDateInstance(DateFormat.LONG).format(image.getPublishDate());
|
return DateFormat.getDateInstance(DateFormat.LONG).format(image.getPublishDate());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return (String) ImageGlobalizationUtil.globalize("cms.ui.unknown").localize();
|
return (String) ImageGlobalizationUtil.globalize("cms.ui.unknown").localize();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,13 @@ import com.arsdigita.bebop.event.FormProcessListener;
|
||||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
import com.arsdigita.bebop.form.Date;
|
import com.arsdigita.bebop.form.Date;
|
||||||
|
import com.arsdigita.bebop.form.Hidden;
|
||||||
|
import com.arsdigita.bebop.form.Option;
|
||||||
|
import com.arsdigita.bebop.form.RadioGroup;
|
||||||
import com.arsdigita.bebop.form.TextArea;
|
import com.arsdigita.bebop.form.TextArea;
|
||||||
import com.arsdigita.bebop.form.TextField;
|
import com.arsdigita.bebop.form.TextField;
|
||||||
import com.arsdigita.bebop.parameters.DateParameter;
|
import com.arsdigita.bebop.parameters.BooleanParameter;
|
||||||
|
import com.arsdigita.bebop.parameters.IncompleteDateParameter;
|
||||||
import com.arsdigita.bebop.parameters.ParameterModel;
|
import com.arsdigita.bebop.parameters.ParameterModel;
|
||||||
import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
|
import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
|
@ -102,8 +106,18 @@ public class ImagePropertyForm
|
||||||
TextField artist = new TextField(artistParam);
|
TextField artist = new TextField(artistParam);
|
||||||
add(artist);
|
add(artist);
|
||||||
|
|
||||||
|
ParameterModel skipDayParam = new BooleanParameter(Image.SKIPDAY);
|
||||||
|
Hidden skipDay = new Hidden(skipDayParam);
|
||||||
|
add(skipDay);
|
||||||
|
|
||||||
|
ParameterModel skipMonthParam = new BooleanParameter(Image.SKIPMONTH);
|
||||||
|
Hidden skipMonth = new Hidden(skipMonthParam);
|
||||||
|
add(skipMonth);
|
||||||
|
|
||||||
add(new Label(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.publishDate")));
|
add(new Label(ImageGlobalizationUtil.globalize("cms.contenttypes.ui.image.publishDate")));
|
||||||
ParameterModel publishDateParam = new DateParameter(Image.PUBLISHDATE);
|
IncompleteDateParameter publishDateParam = new IncompleteDateParameter(Image.PUBLISHDATE);
|
||||||
|
publishDateParam.allowSkipDay(true);
|
||||||
|
publishDateParam.allowSkipMonth(true);
|
||||||
Date publishDate = new Date(publishDateParam);
|
Date publishDate = new Date(publishDateParam);
|
||||||
publishDate.setYearRange(Image.getConfig().getStartYear(),
|
publishDate.setYearRange(Image.getConfig().getStartYear(),
|
||||||
GregorianCalendar.getInstance().get(Calendar.YEAR) + Image.getConfig().getEndYearDelta());
|
GregorianCalendar.getInstance().get(Calendar.YEAR) + Image.getConfig().getEndYearDelta());
|
||||||
|
|
@ -176,6 +190,8 @@ public class ImagePropertyForm
|
||||||
data.put(Image.CAPTION, image.getCaption());
|
data.put(Image.CAPTION, image.getCaption());
|
||||||
data.put(Image.DESCRIPTION, image.getDescription());
|
data.put(Image.DESCRIPTION, image.getDescription());
|
||||||
data.put(Image.ARTIST, image.getArtist());
|
data.put(Image.ARTIST, image.getArtist());
|
||||||
|
data.put(Image.SKIPDAY, image.getSkipDay());
|
||||||
|
data.put(Image.SKIPMONTH, image.getSkipMonth());
|
||||||
data.put(Image.PUBLISHDATE, image.getPublishDate());
|
data.put(Image.PUBLISHDATE, image.getPublishDate());
|
||||||
data.put(Image.SOURCE, image.getSource());
|
data.put(Image.SOURCE, image.getSource());
|
||||||
data.put(Image.MEDIA, image.getMedia());
|
data.put(Image.MEDIA, image.getMedia());
|
||||||
|
|
@ -215,6 +231,8 @@ public class ImagePropertyForm
|
||||||
image.setCaption((String) data.get(Image.CAPTION));
|
image.setCaption((String) data.get(Image.CAPTION));
|
||||||
image.setDescription((String) data.get(Image.DESCRIPTION));
|
image.setDescription((String) data.get(Image.DESCRIPTION));
|
||||||
image.setArtist((String) data.get(Image.ARTIST));
|
image.setArtist((String) data.get(Image.ARTIST));
|
||||||
|
image.setSkipDay(((IncompleteDateParameter) data.getParameter(Image.PUBLISHDATE).getModel()).isDaySkipped());
|
||||||
|
image.setSkipMonth(((IncompleteDateParameter) data.getParameter(Image.PUBLISHDATE).getModel()).isMonthSkipped());
|
||||||
image.setPublishDate((java.util.Date) data.get(Image.PUBLISHDATE));
|
image.setPublishDate((java.util.Date) data.get(Image.PUBLISHDATE));
|
||||||
image.setSource((String) data.get(Image.SOURCE));
|
image.setSource((String) data.get(Image.SOURCE));
|
||||||
image.setMedia((String) data.get(Image.MEDIA));
|
image.setMedia((String) data.get(Image.MEDIA));
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,8 @@
|
||||||
</xrd:adapter>
|
</xrd:adapter>
|
||||||
|
|
||||||
<!-- Adds several image assets -->
|
<!-- Adds several image assets -->
|
||||||
|
<!-- Quasimodo: Ich denke, das ist jetzt unnötig -->
|
||||||
|
<!--
|
||||||
<xrd:adapter objectType="com.arsdigita.cms.contenttypes.GenericArticle" extends="com.arsdigita.cms.contenttypes.GenericArticle" traversalClass="com.arsdigita.cms.contenttypes.ContentItemTraversalAdapter">
|
<xrd:adapter objectType="com.arsdigita.cms.contenttypes.GenericArticle" extends="com.arsdigita.cms.contenttypes.GenericArticle" traversalClass="com.arsdigita.cms.contenttypes.ContentItemTraversalAdapter">
|
||||||
<xrd:attributes rule="exclude">
|
<xrd:attributes rule="exclude">
|
||||||
<xrd:property name="/object/imageCaptions/id"/>
|
<xrd:property name="/object/imageCaptions/id"/>
|
||||||
|
|
@ -179,8 +181,10 @@
|
||||||
<xrd:property name="/object/imageCaptions/language"/>
|
<xrd:property name="/object/imageCaptions/language"/>
|
||||||
<xrd:property name="/object/imageCaptions/imageId"/>
|
<xrd:property name="/object/imageCaptions/imageId"/>
|
||||||
<xrd:property name="/object/imageCaptions/articleId"/>
|
<xrd:property name="/object/imageCaptions/articleId"/>
|
||||||
|
-->
|
||||||
<!-- XXX change /cms-service to take OID -->
|
<!-- XXX change /cms-service to take OID -->
|
||||||
<!--<xrd:property name="/object/imageCaptions/imageAsset/id"/>-->
|
<!--<xrd:property name="/object/imageCaptions/imageAsset/id"/>-->
|
||||||
|
<!--
|
||||||
<xrd:property name="/object/imageCaptions/imageAsset/defaultDomainClass"/>
|
<xrd:property name="/object/imageCaptions/imageAsset/defaultDomainClass"/>
|
||||||
<xrd:property name="/object/imageCaptions/imageAsset/objectType"/>
|
<xrd:property name="/object/imageCaptions/imageAsset/objectType"/>
|
||||||
<xrd:property name="/object/imageCaptions/imageAsset/displayName"/>
|
<xrd:property name="/object/imageCaptions/imageAsset/displayName"/>
|
||||||
|
|
@ -199,7 +203,7 @@
|
||||||
<xrd:property name="/object/imageCaptions/imageAsset/mimeType"/>
|
<xrd:property name="/object/imageCaptions/imageAsset/mimeType"/>
|
||||||
</xrd:associations>
|
</xrd:associations>
|
||||||
</xrd:adapter>
|
</xrd:adapter>
|
||||||
|
-->
|
||||||
<!-- Article in several sections -->
|
<!-- Article in several sections -->
|
||||||
</xrd:context>
|
</xrd:context>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ com.arsdigita.cms.allow_content_create_in_section_listing.purpose=Allows you to
|
||||||
com.arsdigita.cms.allow_content_create_in_section_listing.example=true
|
com.arsdigita.cms.allow_content_create_in_section_listing.example=true
|
||||||
com.arsdigita.cms.allow_content_create_in_section_listing.format=[boolean]
|
com.arsdigita.cms.allow_content_create_in_section_listing.format=[boolean]
|
||||||
|
|
||||||
com.arsdigita.cms.item_search.default_tab.title=Set the default tabe for ItemSearchWidget
|
com.arsdigita.cms.item_search.default_tab.title=Set the default table for ItemSearchWidget
|
||||||
com.arsdigita.cms.item_search.default_tab.purpose=Select either "browse" or "search" for default tab
|
com.arsdigita.cms.item_search.default_tab.purpose=Select either "browse" or "search" for default tab
|
||||||
com.arsdigita.cms.item_search.default_tab.example=browse
|
com.arsdigita.cms.item_search.default_tab.example=browse
|
||||||
com.arsdigita.cms.item_search.default_tab.format=[string]
|
com.arsdigita.cms.item_search.default_tab.format=[string]
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import com.arsdigita.bebop.parameters.ParameterData;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.Form;
|
import com.arsdigita.bebop.Form;
|
||||||
import com.arsdigita.bebop.FormData;
|
import com.arsdigita.bebop.FormData;
|
||||||
|
import com.arsdigita.bebop.parameters.IncompleteDateParameter;
|
||||||
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
||||||
// This interface contains the XML element name of this class
|
// This interface contains the XML element name of this class
|
||||||
// in a constant which is used when generating XML
|
// in a constant which is used when generating XML
|
||||||
|
|
@ -80,6 +81,12 @@ public class Date extends Widget implements BebopConstants {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(PageState ps) {
|
public Object getValue(PageState ps) {
|
||||||
|
ParameterModel model = parent.getParameterModel();
|
||||||
|
if (model instanceof IncompleteDateParameter) {
|
||||||
|
if (((IncompleteDateParameter) model).isYearSkipped()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Object value = parent.getFragmentValue(ps, Calendar.YEAR);
|
Object value = parent.getFragmentValue(ps, Calendar.YEAR);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
Calendar currentTime = GregorianCalendar.getInstance();
|
Calendar currentTime = GregorianCalendar.getInstance();
|
||||||
|
|
@ -110,6 +117,12 @@ public class Date extends Widget implements BebopConstants {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(PageState ps) {
|
public Object getValue(PageState ps) {
|
||||||
|
ParameterModel model = parent.getParameterModel();
|
||||||
|
if (model instanceof IncompleteDateParameter) {
|
||||||
|
if (((IncompleteDateParameter) model).isMonthSkipped()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
return parent.getFragmentValue(ps, Calendar.MONTH);
|
return parent.getFragmentValue(ps, Calendar.MONTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,6 +147,12 @@ public class Date extends Widget implements BebopConstants {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(PageState ps) {
|
public Object getValue(PageState ps) {
|
||||||
|
ParameterModel model = parent.getParameterModel();
|
||||||
|
if (model instanceof IncompleteDateParameter) {
|
||||||
|
if (((IncompleteDateParameter) model).isDaySkipped()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
return parent.getFragmentValue(ps, Calendar.DATE);
|
return parent.getFragmentValue(ps, Calendar.DATE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -182,6 +201,11 @@ public class Date extends Widget implements BebopConstants {
|
||||||
m_year_end = yearEnd;
|
m_year_end = yearEnd;
|
||||||
|
|
||||||
m_year.clearOptions();
|
m_year.clearOptions();
|
||||||
|
if (this.getParameterModel() instanceof IncompleteDateParameter) {
|
||||||
|
if (((IncompleteDateParameter) this.getParameterModel()).isSkipYearAllowed()) {
|
||||||
|
m_year.addOption(new Option("", ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
for (int year = m_year_begin; year <= m_year_end; year += 1) {
|
for (int year = m_year_begin; year <= m_year_end; year += 1) {
|
||||||
m_year.addOption(new Option(String.valueOf(year)));
|
m_year.addOption(new Option(String.valueOf(year)));
|
||||||
}
|
}
|
||||||
|
|
@ -356,6 +380,11 @@ public class Date extends Widget implements BebopConstants {
|
||||||
|
|
||||||
m_month.clearOptions();
|
m_month.clearOptions();
|
||||||
|
|
||||||
|
if (this.getParameterModel() instanceof IncompleteDateParameter) {
|
||||||
|
if (((IncompleteDateParameter) this.getParameterModel()).isSkipMonthAllowed()) {
|
||||||
|
m_month.addOption(new Option("", ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
for (int i = 0; i < months.length; i += 1) {
|
for (int i = 0; i < months.length; i += 1) {
|
||||||
// This check is necessary because
|
// This check is necessary because
|
||||||
// java.text.DateFormatSymbols.getMonths() returns an array
|
// java.text.DateFormatSymbols.getMonths() returns an array
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ public class DateParameter extends ParameterModel {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns a new Calendar object that is manipulated
|
* This method returns a new Calendar object that is manipulated
|
||||||
* within transformValue to create a Date Object. This method should
|
* within transformValue to create a Date Object. This method should
|
||||||
|
|
@ -62,6 +61,7 @@ public class DateParameter extends ParameterModel {
|
||||||
* <code>SECOND</code> to 0, since they are by default the current
|
* <code>SECOND</code> to 0, since they are by default the current
|
||||||
* time.
|
* time.
|
||||||
* */
|
* */
|
||||||
|
@Override
|
||||||
public Object transformValue(HttpServletRequest request)
|
public Object transformValue(HttpServletRequest request)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
Calendar c = null;
|
Calendar c = null;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,145 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2.1 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.bebop.parameters;
|
||||||
|
|
||||||
|
import com.arsdigita.globalization.Globalization;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class that represents the model for date form parameters.
|
||||||
|
* This one will allow incomplete entry on date. Should be used in
|
||||||
|
* combination with an additional Boolean DB field to keep track
|
||||||
|
* of the incomplete entry.
|
||||||
|
*
|
||||||
|
* @author Sören Bernstein
|
||||||
|
*/
|
||||||
|
public class IncompleteDateParameter extends DateParameter {
|
||||||
|
|
||||||
|
private boolean allowSkipYear = false;
|
||||||
|
private boolean allowSkipMonth = false;
|
||||||
|
private boolean allowSkipDay = false;
|
||||||
|
private boolean skippedYear = false;
|
||||||
|
private boolean skippedMonth = false;
|
||||||
|
private boolean skippedDay = false;
|
||||||
|
|
||||||
|
public IncompleteDateParameter(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void allowSkipYear(boolean bool) {
|
||||||
|
this.allowSkipYear = bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSkipYearAllowed() {
|
||||||
|
return this.allowSkipYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void allowSkipMonth(boolean bool) {
|
||||||
|
this.allowSkipMonth = bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSkipMonthAllowed() {
|
||||||
|
return this.allowSkipMonth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void allowSkipDay(boolean bool) {
|
||||||
|
this.allowSkipDay = bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSkipDayAllowed() {
|
||||||
|
return this.allowSkipDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDaySkipped() {
|
||||||
|
return this.skippedDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMonthSkipped() {
|
||||||
|
return this.skippedMonth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isYearSkipped() {
|
||||||
|
return this.skippedYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSkipped() {
|
||||||
|
return this.skippedDay || this.skippedMonth || this.skippedYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes a date object from multiple parameters in the
|
||||||
|
* request. This method searches for parameters named
|
||||||
|
* <code>getName() + ".year"<code>, <code>getName() +
|
||||||
|
* ".month"<code> and <code>getName() + ".day"<code>. It sets the
|
||||||
|
* fields <code>HOUR</code>, <code>MINUTE</code> and
|
||||||
|
* <code>SECOND</code> to 0, since they are by default the current
|
||||||
|
* time.
|
||||||
|
* */
|
||||||
|
@Override
|
||||||
|
public Object transformValue(HttpServletRequest request)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
Calendar c = null;
|
||||||
|
Object outVal = null;
|
||||||
|
try {
|
||||||
|
|
||||||
|
c = getCalendar(request);
|
||||||
|
c.clear();
|
||||||
|
//don't accept lenient dates like June 44
|
||||||
|
c.setLenient(false);
|
||||||
|
|
||||||
|
String year = Globalization.decodeParameter(request, getName() + ".year");
|
||||||
|
String month = Globalization.decodeParameter(request, getName() + ".month");
|
||||||
|
String day = Globalization.decodeParameter(request, getName() + ".day");
|
||||||
|
|
||||||
|
// If non-skippable field missing return null
|
||||||
|
if ((this.allowSkipYear == false && (year == null || year.length() == 0))
|
||||||
|
|| (this.allowSkipMonth == false && (month == null || month.length() == 0))
|
||||||
|
|| (this.allowSkipDay == false && (day == null || day.length() == 0))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (year != null && year.length() > 0) {
|
||||||
|
this.skippedYear = false;
|
||||||
|
c.set(Calendar.YEAR, Integer.parseInt(year));
|
||||||
|
} else {
|
||||||
|
this.skippedYear = true;
|
||||||
|
c.set(Calendar.YEAR, 0);
|
||||||
|
}
|
||||||
|
if (month != null && month.length() > 0) {
|
||||||
|
this.skippedMonth = false;
|
||||||
|
c.set(Calendar.MONTH, Integer.parseInt(month));
|
||||||
|
} else {
|
||||||
|
this.skippedMonth = true;
|
||||||
|
c.set(Calendar.MONTH, 1);
|
||||||
|
}
|
||||||
|
if (day != null && day.length() > 0) {
|
||||||
|
this.skippedDay = false;
|
||||||
|
c.set(Calendar.DATE, Integer.parseInt(day));
|
||||||
|
} else {
|
||||||
|
this.skippedDay = true;
|
||||||
|
c.set(Calendar.DATE, 1);
|
||||||
|
}
|
||||||
|
outVal = c.getTime();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new IllegalArgumentException("Invalid Day of Month");
|
||||||
|
}
|
||||||
|
return outVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue