/** * Returns the provided number or zero if the value is empty. * * @see #isEmpty(java.lang.Object) */ public static int zeroIfEmpty(Integer value) throws IOException { return isEmpty(value) ? 0 : value; }
/** * @see TextInXhtmlAttributeEncoder * * @param value the value to be encoded */ public ChainWriter encodeXmlAttribute(Object value) throws IOException { Coercion.write(value, textInXhtmlAttributeEncoder, out); return this; }
/** * @see TextInXhtmlEncoder * * @param value the value to be encoded */ public ChainWriter encodeXhtml(Object value) throws IOException { if(value!=null) { if( value instanceof Writable && !((Writable)value).isFastToString() ) { // Avoid unnecessary toString calls Coercion.write(value, textInXhtmlEncoder, out); } else { String str = Coercion.toString(value); BundleLookupMarkup lookupMarkup; BundleLookupThreadContext threadContext = BundleLookupThreadContext.getThreadContext(false); if(threadContext!=null) { lookupMarkup = threadContext.getLookupMarkup(str); } else { lookupMarkup = null; } if(lookupMarkup!=null) lookupMarkup.appendPrefixTo(MarkupType.XHTML, out); textInXhtmlEncoder.write(str, out); if(lookupMarkup!=null) lookupMarkup.appendSuffixTo(MarkupType.XHTML, out); } } return this; }
public static interface LinkImplBody<E extends Throwable> { void doBody(boolean discard) throws E, IOException, SkipPageException; }
@Override protected void doTag(BufferResult capturedBody, Writer out) throws JspTagException, IOException { if(name == null) throw new AttributeRequiredException("name"); Node resolvedTarget; if(target != null) { resolvedTarget = target; } else { resolvedTarget = CurrentNode.getCurrentNode(((PageContext)getJspContext()).getRequest()); if(resolvedTarget == null) throw new JspTagException("Unable to find parent node for property target"); } String propertyName = Coercion.toString(name); boolean propertySet = resolvedTarget.setProperty( propertyName, valueSet ? value : capturedBody.trim() ); if(!propertySet && !allowExisting) { throw new LocalizedJspTagException( ApplicationResources.accessor, "error.duplicateDynamicElementProperty", propertyName ); } } }
@Override protected void evaluateAttributes(Dia dia, ELContext elContext) throws JspTagException, IOException { super.evaluateAttributes(dia, elContext); dia.setLabel(resolveValue(label, String.class, elContext)); dia.setBook(resolveValue(book, String.class, elContext)); dia.setPath(resolveValue(path, String.class, elContext)); dia.setWidth(zeroIfEmpty(resolveValue(width, Integer.class, elContext))); dia.setHeight(zeroIfEmpty(resolveValue(height, Integer.class, elContext))); }
Coercion.write(value, textInJavaScriptEncoder, javaScriptInXhtmlWriter); textInJavaScriptEncoder.writeSuffixTo(javaScriptInXhtmlWriter); } else { String str = Coercion.toString(value); BundleLookupMarkup lookupMarkup; BundleLookupThreadContext threadContext = BundleLookupThreadContext.getThreadContext(false);
Coercion.write(value, textInJavaScriptEncoder, javaScriptInXhtmlAttributeWriter); textInJavaScriptEncoder.writeSuffixTo(javaScriptInXhtmlAttributeWriter); } else { String str = Coercion.toString(value); BundleLookupMarkup lookupMarkup; BundleLookupThreadContext threadContext = BundleLookupThreadContext.getThreadContext(false);
/** * Returns the provided value or null if the value is empty. * * @see #isEmpty(java.lang.Object) */ public static <T> T nullIfEmpty(T value) throws IOException { return isEmpty(value) ? null : value; }
public static ReadableDateTime toDateTime(Object o) throws IOException { if(o instanceof ReadableDateTime) { return (ReadableDateTime)o; } if(o instanceof Long) { long l = (Long)o; return l==-1 || l==0 ? null : new DateTime(l); } if(Coercion.isEmpty(o)) { return null; } return new DateTime(o); }