/* $$ Clover has instrumented this file $$ */// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.tapestry.form;
import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Resource;
import org.apache.tapestry.IAsset;
import org.apache.tapestry.IEngine;
import org.apache.tapestry.IForm;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.IScript;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.engine.IScriptSource;
import org.apache.tapestry.html.Body;
/**
* Provides a Form <tt>java.util.Date</tt> field component for selecting dates.
*
* [<a href="../../../../../ComponentReference/DatePicker.html">Component Reference</a>]
*
* @author Paul Geerts
* @author Malcolm Edgar
* @since 2.2
*
*/
public abstract class DatePicker extends AbstractFormComponent
{public static com.cortexeb.tools.clover.d __CLOVER_128_0 = com.cortexeb.tools.clover.aq.getRecorder(new char[] {67,58,92,119,111,114,107,115,112,97,99,101,92,106,97,107,97,114,116,97,45,116,97,112,101,115,116,114,121,92,102,114,97,109,101,119,111,114,107,92,116,97,114,103,101,116,92,99,108,111,118,101,114,45,100,98},1096998272901L);
public abstract String getFormat();
public abstract Date getValue();
public abstract void setValue(Date value);
public abstract boolean isDisabled();
public abstract boolean getIncludeWeek();
public abstract IAsset getIcon();
private IScript _script;
private static final String SYM_NAME = "name";
private static final String SYM_FORMNAME = "formName";
private static final String SYM_MONTHNAMES = "monthNames";
private static final String SYM_SHORT_MONTHNAMES = "shortMonthNames";
private static final String SYM_WEEKDAYNAMES = "weekDayNames";
private static final String SYM_SHORT_WEEKDAYNAMES = "shortWeekDayNames";
private static final String SYM_FIRSTDAYINWEEK = "firstDayInWeek";
private static final String SYM_MINDAYSINFIRSTWEEK = "minimalDaysInFirstWeek";
private static final String SYM_FORMAT = "format";
private static final String SYM_INCL_WEEK = "includeWeek";
private static final String SYM_VALUE = "value";
private static final String SYM_BUTTONONCLICKHANDLER = "buttonOnclickHandler";
// Output symbol
private static final String SYM_BUTTONNAME = "buttonName";
protected void finishLoad()
{try { __CLOVER_128_0.M[675]++;
__CLOVER_128_0.S[2938]++;IEngine engine = getPage().getEngine();
__CLOVER_128_0.S[2939]++;IScriptSource source = engine.getScriptSource();
__CLOVER_128_0.S[2940]++;Resource location =
getSpecification().getSpecificationLocation().getRelativeResource("DatePicker.script");
__CLOVER_128_0.S[2941]++;_script = source.getScript(location);
} finally { }}
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{try { __CLOVER_128_0.M[676]++;
__CLOVER_128_0.S[2942]++;IForm form = getForm(cycle);
__CLOVER_128_0.S[2943]++;String name = form.getElementId(this);
__CLOVER_128_0.S[2944]++;String format = getFormat();
__CLOVER_128_0.S[2945]++;if ((((format == null) && (++__CLOVER_128_0.CT[533] != 0)) || (++__CLOVER_128_0.CF[533] == 0))){
__CLOVER_128_0.S[2946]++;format = "dd MMM yyyy";}
__CLOVER_128_0.S[2947]++;SimpleDateFormat formatter = new SimpleDateFormat(format, getPage().getLocale());
__CLOVER_128_0.S[2948]++;boolean disabled = isDisabled();
__CLOVER_128_0.S[2949]++;if ((((!cycle.isRewinding()) && (++__CLOVER_128_0.CT[534] != 0)) || (++__CLOVER_128_0.CF[534] == 0))){
{
__CLOVER_128_0.S[2950]++;Body body = Body.get(cycle);
__CLOVER_128_0.S[2951]++;if ((((body == null) && (++__CLOVER_128_0.CT[535] != 0)) || (++__CLOVER_128_0.CF[535] == 0))){
__CLOVER_128_0.S[2952]++;throw new ApplicationRuntimeException(
Tapestry.format("must-be-contained-by-body", "DatePicker"),
this,
null,
null);}
__CLOVER_128_0.S[2953]++;Locale locale = getPage().getLocale();
__CLOVER_128_0.S[2954]++;DateFormatSymbols dfs = new DateFormatSymbols(locale);
__CLOVER_128_0.S[2955]++;Calendar cal = Calendar.getInstance(locale);
__CLOVER_128_0.S[2956]++;Date value = getValue();
__CLOVER_128_0.S[2957]++;Map symbols = new HashMap();
__CLOVER_128_0.S[2958]++;symbols.put(SYM_NAME, name);
__CLOVER_128_0.S[2959]++;symbols.put(SYM_FORMAT, format);
__CLOVER_128_0.S[2960]++;symbols.put(SYM_INCL_WEEK, (((getIncludeWeek() ) && (++__CLOVER_128_0.CT[536] != 0)) || (++__CLOVER_128_0.CF[536] == 0))? Boolean.TRUE : Boolean.FALSE);
__CLOVER_128_0.S[2961]++;symbols.put(SYM_MONTHNAMES, makeStringList(dfs.getMonths(), 0, 12));
__CLOVER_128_0.S[2962]++;symbols.put(SYM_SHORT_MONTHNAMES, makeStringList(dfs.getShortMonths(), 0, 12));
__CLOVER_128_0.S[2963]++;symbols.put(SYM_WEEKDAYNAMES, makeStringList(dfs.getWeekdays(), 1, 8));
__CLOVER_128_0.S[2964]++;symbols.put(SYM_SHORT_WEEKDAYNAMES, makeStringList(dfs.getShortWeekdays(), 1, 8));
__CLOVER_128_0.S[2965]++;symbols.put(SYM_FIRSTDAYINWEEK, new Integer(cal.getFirstDayOfWeek() - 1));
__CLOVER_128_0.S[2966]++;symbols.put(SYM_MINDAYSINFIRSTWEEK, new Integer(cal.getMinimalDaysInFirstWeek()));
__CLOVER_128_0.S[2967]++;symbols.put(SYM_FORMNAME, form.getName());
__CLOVER_128_0.S[2968]++;symbols.put(SYM_VALUE, value);
__CLOVER_128_0.S[2969]++;_script.execute(cycle, body, symbols);
__CLOVER_128_0.S[2970]++;writer.beginEmpty("input");
__CLOVER_128_0.S[2971]++;writer.attribute("type", "text");
__CLOVER_128_0.S[2972]++;writer.attribute("name", name);
__CLOVER_128_0.S[2973]++;writer.attribute("title", formatter.toLocalizedPattern());
__CLOVER_128_0.S[2974]++;if ((((value != null) && (++__CLOVER_128_0.CT[537] != 0)) || (++__CLOVER_128_0.CF[537] == 0))){
__CLOVER_128_0.S[2975]++;writer.attribute("value", formatter.format(value));}
__CLOVER_128_0.S[2976]++;if ((((disabled) && (++__CLOVER_128_0.CT[538] != 0)) || (++__CLOVER_128_0.CF[538] == 0))){
__CLOVER_128_0.S[2977]++;writer.attribute("disabled", "disabled");}
__CLOVER_128_0.S[2978]++;renderInformalParameters(writer, cycle);
__CLOVER_128_0.S[2979]++;writer.printRaw(" ");
__CLOVER_128_0.S[2980]++;if ((((!disabled) && (++__CLOVER_128_0.CT[539] != 0)) || (++__CLOVER_128_0.CF[539] == 0))){
{
__CLOVER_128_0.S[2981]++;writer.begin("a");
__CLOVER_128_0.S[2982]++;writer.attribute("href", (String) symbols.get(SYM_BUTTONONCLICKHANDLER));
}}
__CLOVER_128_0.S[2983]++;IAsset icon = getIcon();
__CLOVER_128_0.S[2984]++;writer.beginEmpty("img");
__CLOVER_128_0.S[2985]++;writer.attribute("src", icon.buildURL(cycle));
__CLOVER_128_0.S[2986]++;writer.attribute("border", 0);
__CLOVER_128_0.S[2987]++;if ((((!disabled) && (++__CLOVER_128_0.CT[540] != 0)) || (++__CLOVER_128_0.CF[540] == 0))){
__CLOVER_128_0.S[2988]++;writer.end();} // <a>
}}
__CLOVER_128_0.S[2989]++;if ((((form.isRewinding()) && (++__CLOVER_128_0.CT[541] != 0)) || (++__CLOVER_128_0.CF[541] == 0))){
{
__CLOVER_128_0.S[2990]++;if ((((disabled) && (++__CLOVER_128_0.CT[542] != 0)) || (++__CLOVER_128_0.CF[542] == 0))){
__CLOVER_128_0.S[2991]++;return;}
__CLOVER_128_0.S[2992]++;String textValue = cycle.getRequestContext().getParameter(name);
__CLOVER_128_0.S[2993]++;if ((((Tapestry.isBlank(textValue)) && (++__CLOVER_128_0.CT[543] != 0)) || (++__CLOVER_128_0.CF[543] == 0))){
__CLOVER_128_0.S[2994]++;return;}
__CLOVER_128_0.S[2995]++;try
{
__CLOVER_128_0.S[2996]++;Date value = formatter.parse(textValue);
__CLOVER_128_0.S[2997]++;setValue(value);
}
catch (ParseException ex)
{
}
}}
} finally { }}
/**
* Create a list of quoted strings. The list is suitable for
* initializing a JavaScript array.
*/
private String makeStringList(String[] a, int offset, int length)
{try { __CLOVER_128_0.M[677]++;
__CLOVER_128_0.S[2998]++;StringBuffer b = new StringBuffer();
__CLOVER_128_0.S[2999]++;for (int i = offset; (((i < length) && (++__CLOVER_128_0.CT[544] != 0)) || (++__CLOVER_128_0.CF[544] == 0)); i++){
{
// JavaScript is sensitive to some UNICODE characters. So for
// the sake of simplicity, we just escape everything
__CLOVER_128_0.S[3000]++;b.append('"');
__CLOVER_128_0.S[3001]++;char[] ch = a[i].toCharArray();
__CLOVER_128_0.S[3002]++;for (int j = 0; (((j < ch.length) && (++__CLOVER_128_0.CT[545] != 0)) || (++__CLOVER_128_0.CF[545] == 0)); j++){
{
__CLOVER_128_0.S[3003]++;if ((((ch[j] < 128) && (++__CLOVER_128_0.CT[546] != 0)) || (++__CLOVER_128_0.CF[546] == 0))){
{
__CLOVER_128_0.S[3004]++;b.append(ch[j]);
}}
else{
{
__CLOVER_128_0.S[3005]++;b.append(escape(ch[j]));
}}
}}
__CLOVER_128_0.S[3006]++;b.append('"');
__CLOVER_128_0.S[3007]++;if ((((i < length - 1) && (++__CLOVER_128_0.CT[547] != 0)) || (++__CLOVER_128_0.CF[547] == 0))){
{
__CLOVER_128_0.S[3008]++;b.append(", ");
}}
}}
__CLOVER_128_0.S[3009]++;return b.toString();
} finally { }}
/**
* Create an escaped Unicode character
* @param c
* @return The unicode character in escaped string form
*/
private static String escape(char c)
{try { __CLOVER_128_0.M[678]++;
__CLOVER_128_0.S[3010]++;StringBuffer b = new StringBuffer();
__CLOVER_128_0.S[3011]++;for (int i = 0; (((i < 4) && (++__CLOVER_128_0.CT[548] != 0)) || (++__CLOVER_128_0.CF[548] == 0)); i++){
{
__CLOVER_128_0.S[3012]++;b.append(Integer.toHexString(c & 0x000F).toUpperCase());
__CLOVER_128_0.S[3013]++;c >>>= 4;
}}
__CLOVER_128_0.S[3014]++;b.append("u\\");
__CLOVER_128_0.S[3015]++;return b.reverse().toString();
} finally { }}
}