本文整理汇总了Java中com.ibm.xsp.convert.DateTimeConverter类的典型用法代码示例。如果您正苦于以下问题:Java DateTimeConverter类的具体用法?Java DateTimeConverter怎么用?Java DateTimeConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeConverter类属于com.ibm.xsp.convert包,在下文中一共展示了DateTimeConverter类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeDateTimeAttributes
import com.ibm.xsp.convert.DateTimeConverter; //导入依赖的package包/类
@Override
protected void writeDateTimeAttributes(final FacesContext context, final UIComponent component, final ResponseWriter w, final String paramString) throws IOException {
DateTimeConverter converter = (DateTimeConverter)((UIInput)component).getConverter();
switch(PickerType.valueFor(context, component)) {
case DATE:
w.writeAttribute("data-date-format", convertDojoPatternForJQuery(converter.getDatePattern(context)), null);
break;
case TIME:
w.writeAttribute("data-time-format", convertDojoPatternForJQuery(converter.getTimePattern(context)), null);
break;
case DATETIME:
w.writeAttribute("data-date-format", convertDojoPatternForJQuery(converter.getBothDatePattern(context)), null);
w.writeAttribute("data-time-format", convertDojoPatternForJQuery(converter.getBothTimePattern(context)), null);
break;
}
super.writeDateTimeAttributes(context, component, w, paramString);
}
示例2: valueFor
import com.ibm.xsp.convert.DateTimeConverter; //导入依赖的package包/类
public static PickerType valueFor(final FacesContext context, final UIComponent component) {
DateTimeConverter converter = (DateTimeConverter)((UIInput)component).getConverter();
String type = converter.getType();
if("date".equals(type)) {
return DATE;
} else if("time".equals(type)) {
return TIME;
} else {
return DATETIME;
}
}
示例3: computeValueAsISOString
import com.ibm.xsp.convert.DateTimeConverter; //导入依赖的package包/类
private String computeValueAsISOString(FacesContext context, UIInput input) {
DateTimeConverter converter = (DateTimeConverter) input.getConverter();
// the submitted value takes precedence
// As it is a string, no conversion should happen
Object submittedValue = input.getSubmittedValue();
if (submittedValue != null) {
return (String)submittedValue;
}
Object value = input.getValue();
if( null == value ){
return "";
}
return getAsString(context, input, converter, value);
}
示例4: getAsString
import com.ibm.xsp.convert.DateTimeConverter; //导入依赖的package包/类
private String getAsString(FacesContext context, UIInput input, DateTimeConverter converter, Object value){
if(value instanceof Date) {
Date dateValue = (Date)value;
// Adjust the date to the desired timezone
// Dojo expect the the date already formatted within the desired time zone
// As the SimpleFormat uses the default timezone, we offset the difference so it is
// correctly formatted for dojo.
long offset = 0;
TimeZone clientTimeZone = converter.getTimeZone();
TimeZone serverTimeZone = TimeZone.getDefault();
if( !serverTimeZone.equals(clientTimeZone) ){
// SPR#MKEE9HYGXB cannot use timeZone.getRawOffset()
// because client timezone is-summerTime-ness and the
// server timezone is-summerTime-ness may be different,
// so using the raw offset leads to problems during the
// period where one timezone has changed to summer time
// but the other timezone has not.
Date serverNow = new Date();
Date clientNow = java.util.Calendar.getInstance(clientTimeZone).getTime();
offset = serverTimeZone.getOffset(serverNow.getTime()) - clientTimeZone.getOffset(clientNow.getTime());
}
dateValue = new Date(dateValue.getTime()-offset);
int type = getValueType(input);
return formatValueAsType(dateValue, type);
}
// TODO should probably not fall through to the non-ISO date converter.
if(null == value || "".equals(value)) {
return "";
}
return value.toString();
}
示例5: getConvertedValue
import com.ibm.xsp.convert.DateTimeConverter; //导入依赖的package包/类
@Override
public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)
throws ConverterException {
UIInput uiInput = (UIInput)component;
DateTimeConverter converter = (DateTimeConverter) uiInput.getConverter();
String value = (String)submittedValue;
return getAsObject(context, uiInput, converter, value);
}
示例6: getValueType
import com.ibm.xsp.convert.DateTimeConverter; //导入依赖的package包/类
private int getValueType(UIInput uiInput) {
DateTimeConverter converter = (DateTimeConverter) uiInput.getConverter();
// Find what should be used: date, time or both
// Default is both...
String dateType = converter.getType();
int type = TYPE_TIMESTAMP;
if(StringUtil.isNotEmpty(dateType)) {
if(dateType.equals(DateTimeConverter.TYPE_DATE)) {
type = TYPE_DATE;
} else if(dateType.equals(DateTimeConverter.TYPE_TIME)) {
type = TYPE_TIME;
}
}
return type;
}
示例7: getDefaultValueAsString
import com.ibm.xsp.convert.DateTimeConverter; //导入依赖的package包/类
private String getDefaultValueAsString(FacesContext context,
UIInputEx uiInput, Object defaultValue) {
DateTimeConverter converter = (DateTimeConverter) uiInput.getConverter();
return getAsString(context, uiInput, converter, defaultValue);
}
示例8: getAsObject
import com.ibm.xsp.convert.DateTimeConverter; //导入依赖的package包/类
private Object getAsObject(FacesContext context, UIInput input, DateTimeConverter converter, String value){
if( StringUtil.isEmpty(value) ){
return null;
}
TimeZone tz = converter.getTimeZone();
// If the date is sent as time, then assume today's date in the browser TZ
// So we'll have the proper conversion done. If we don't do that, then java
// uses 1/1/70 and it has an issue when rendering it back in summer, as it leads to
// one hour difference. This is also in sync with what the Notes backend API does
int expectedType = getValueType(input);
value = mutateSubmittedToExpectedFormat(context, input, converter, value, expectedType);
if(value.startsWith("T")) {
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
fmt.setTimeZone(tz);
value = fmt.format(new Date())+value;
}
// assume this is a string in ISO format
// In this case, dojo returns the right date but with a timezone specification computed
// using the browser information. Unfortunately, it doesn't support the daylight savings
// So that lead to a wrong time zone (http://trac.dojotoolkit.org/ticket/588)
// A solution is to ignore the timezone provided by dojo.
// But the date should be converted to the user TimeZone
long dt;
try{
dt = XMIConverter.readXMIDateStrict(value,false,true);
} catch(XMLException ex){
// TODO in 9.0.2, should update this to handle message changes for SPR#MKEE7TXMLG
String message;
int type = expectedType;
if(type==TYPE_DATE) {
message = getMessageDate();
} else if(type==TYPE_TIME) {
message = getMessageTime();
} else {
message = getMessageBoth();
}
throw new ConverterException(new FacesMessage(message),ex);
}
long offset = 0;
TimeZone clientTimeZone = tz;
TimeZone serverTimeZone = TimeZone.getDefault();
if( !serverTimeZone.equals(clientTimeZone) ){
// SPR#MKEE9HYGXB cannot use timeZone.getRawOffset()
// because client timezone is-summerTime-ness and the
// server timezone is-summerTime-ness may be different,
// so using the raw offset leads to problems during the
// period where one timezone has changed to summer time
// but the other timezone has not.
Date serverNow = new Date();
Date clientNow = java.util.Calendar.getInstance(clientTimeZone).getTime();
offset = serverTimeZone.getOffset(serverNow.getTime()) - clientTimeZone.getOffset(clientNow.getTime());
}
dt += offset;
Date date = new Date(dt);
return date;
}
示例9: mutateSubmittedToExpectedFormat
import com.ibm.xsp.convert.DateTimeConverter; //导入依赖的package包/类
/**
* @param value
* @param expectedType
* @return
*/
protected String mutateSubmittedToExpectedFormat(FacesContext context, UIInput input, DateTimeConverter converter, String value, int expectedType) {
boolean hasColon = -1 != value.indexOf(':');
if( TYPE_TIME == expectedType && value.length() == 5 && hasColon && 'T' != value.charAt(0) ){
// in iPhone
// from http://tools.ietf.org/html/rfc3339
// partial-time = time-hour ":" time-minute ":" time-second [time-secfrac]
// We have something like
// 09:30
// we need something like:
// T09:30:00
value = "T"+value+":00"; //$NON-NLS-1$ //$NON-NLS-2$
}
if( TYPE_TIMESTAMP == expectedType && (-1 != value.indexOf('T')) ){
int tee = value.indexOf('T');
int endTimeIndex = Math.max(value.indexOf('Z', tee), Math.max(value.indexOf('+', tee), value.indexOf('-', tee)));
if( -1 == endTimeIndex ){
endTimeIndex = value.length();
}
if( 6 == endTimeIndex - tee ){
// in iPhone
// We have something like
// 2013-12-03T09:30
// we need
// 2013-12-03T09:30:00
// in Android
// We have something like:
// 2013-12-21T09:30Z
// we need
// 2013-12-21T09:30:00Z
value = value.substring(0, endTimeIndex)+":00"+value.substring(endTimeIndex); //$NON-NLS-1$
}
}
if( TYPE_TIMESTAMP == expectedType || TYPE_DATE == expectedType ){
int endDateIndex = (TYPE_TIMESTAMP == expectedType) ? value.indexOf('T') : value.length();
if( endDateIndex - value.indexOf('-') < 6 ){
// in Android
// We have something like
// 2013-5-5T09:30
// 2013-5-5
// we need
// 2013-05-05T09:30
// 2013-05-05
int firstDash = value.indexOf('-');
int secondDash = (-1 == firstDash)? -1 : value.indexOf('-', firstDash+1);
if( -1 != firstDash && -1 != secondDash && 2 == (secondDash - firstDash) ){
// insert 0 after 1st '-'
value = value.substring(0,firstDash+1)+'0'+value.substring(firstDash+1);
// recompute since the string changed:
secondDash = (-1 == firstDash)? -1 : value.indexOf('-', firstDash+1);
endDateIndex = (TYPE_TIMESTAMP == expectedType) ? value.indexOf('T') : value.length();
}
if( -1 != secondDash && -1 != endDateIndex && 2 == (endDateIndex - secondDash) ){
// insert 0 after 2nd '-'
value = value.substring(0,secondDash+1)+'0'+value.substring(secondDash+1);
}
}
}
return value;
}
示例10: generateClientSideConverter
import com.ibm.xsp.convert.DateTimeConverter; //导入依赖的package包/类
/**
* Implements {@link ClientSideConverter#generateClientSideConverter(FacesContext, UIComponent)}
*/
public String generateClientSideConverter(FacesContext context, UIComponent component) {
UIInput input = (UIInput) component;
DateTimeConverter converter = (DateTimeConverter) input.getConverter();
String dateType = converter.getType();
int valueType = TYPE_TIMESTAMP;
if(StringUtil.isNotEmpty(dateType)) {
if(dateType.equals(DateTimeConverter.TYPE_DATE)) {
valueType = TYPE_DATE;
} else if(dateType.equals(DateTimeConverter.TYPE_TIME)) {
valueType = TYPE_TIME;
}
}
// TODO in 9.0.2, should update this to handle message changes for SPR#MKEE7TXMLG
String message;
if( TYPE_DATE == valueType ){
message = getMessageDate();
}else if( TYPE_TIME == valueType ){
message = getMessageTime();
}else{
message = getMessageBoth();
}
DojoModuleResource module;
StringBuilder builder = new StringBuilder();
switch(valueType){
case TYPE_DATE:{
module = ISO_DATE_CONVERTER_MODULE;
builder.append("new extlib.date.IsoDateConverter({message:"); //$NON-NLS-1$
JavaScriptUtil.addMessage(builder, message);
builder.append("})"); //$NON-NLS-1$
break;
}
case TYPE_TIME:{
module = ISO_TIME_CONVERTER_MODULE;
builder.append("new extlib.date.IsoTimeConverter({message:"); //$NON-NLS-1$
JavaScriptUtil.addMessage(builder, message);
builder.append("})"); //$NON-NLS-1$
break;
}
default:{// TYPE_TIMESTAMP
module = ISO_DATE_TIME_CONVERTER_MODULE;
builder.append("new extlib.date.IsoDateTimeConverter({message:"); //$NON-NLS-1$
JavaScriptUtil.addMessage(builder, message);
builder.append("})"); //$NON-NLS-1$
break;
}
}
if( null != module ){
UIViewRootEx rootEx = (UIViewRootEx) context.getViewRoot();
rootEx.addEncodeResource(context,module);
}
return builder.toString();
}