List of usage examples for java.beans PropertyEditor getAsText
String getAsText();
From source file:org.pentaho.reporting.engine.classic.core.modules.parser.bundle.writer.elements.AbstractElementWriteHandler.java
private void writeBulkAttributes(final WriteableDocumentBundle bundle, final BundleWriterState state, final Element element, final XmlWriter writer) throws IOException, BundleWriterException { final ElementMetaData metaData = element.getElementType().getMetaData(); final String[] attributeNamespaces = element.getAttributeNamespaces(); for (int i = 0; i < attributeNamespaces.length; i++) { final String namespace = attributeNamespaces[i]; final String[] attributeNames = element.getAttributeNames(namespace); for (int j = 0; j < attributeNames.length; j++) { final String name = attributeNames[j]; final Object value = element.getAttribute(namespace, name); if (value == null) { continue; }/* www . j ava2s . co m*/ final AttributeMetaData attrMeta = metaData.getAttributeDescription(namespace, name); if (attrMeta == null) { continue; } if (attrMeta.isTransient()) { continue; } if (isFiltered(attrMeta)) { continue; } if (attrMeta.isBulk() == false) { continue; } if ("Resource".equals(attrMeta.getValueRole())) { final AttributeList attList = new AttributeList(); if (attList.isNamespaceUriDefined(namespace) == false && writer.isNamespaceDefined(namespace) == false) { attList.addNamespaceDeclaration("autoGenNS", namespace); } if (value instanceof URL) { attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "url"); writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN); writer.writeTextNormalized(String.valueOf(value), true); writer.writeCloseTag(); } else if (value instanceof ResourceKey) { try { final ResourceKey key = (ResourceKey) value; final ResourceManager resourceManager = bundle.getResourceManager(); final ResourceKey bundleKey = bundle.getBundleKey().getParent(); final String serializedKey = resourceManager.serialize(bundleKey, key); attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "resource-key"); writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN); writer.writeTextNormalized(serializedKey, true); writer.writeCloseTag(); } catch (ResourceException re) { logger.error("Could not serialize the ResourceKey: " + re.getMessage(), re); throw new IOException("Could not serialize the ResourceKey: ", re); } } else if (value instanceof File) { attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "file"); writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN); writer.writeTextNormalized(String.valueOf(value), true); writer.writeCloseTag(); } else if (value instanceof String) { attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "local-ref"); writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN); writer.writeTextNormalized(String.valueOf(value), true); writer.writeCloseTag(); } else { logger.warn("Unknown value-type in resource-attribute " + namespace + ":" + name); } continue; } if ("Expression".equals(attrMeta.getValueRole()) && value instanceof Expression) { // write attribute-expressions. final AttributeList attList = new AttributeList(); attList.setAttribute(BundleNamespaces.LAYOUT, "attribute-namespace", namespace); attList.setAttribute(BundleNamespaces.LAYOUT, "attribute-name", name); ExpressionWriterUtility.writeExpressionCore(bundle, state, (Expression) value, writer, BundleNamespaces.LAYOUT, "expression", attList); continue; } try { final PropertyEditor propertyEditor = attrMeta.getEditor(); if (propertyEditor != null) { propertyEditor.setValue(value); final String text = propertyEditor.getAsText(); final AttributeList attList = new AttributeList(); if (attList.isNamespaceUriDefined(namespace) == false && writer.isNamespaceDefined(namespace) == false) { attList.addNamespaceDeclaration("autoGenNS", namespace); } writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN); writer.writeTextNormalized(text, true); writer.writeCloseTag(); } else { final String attrValue = ConverterRegistry.toAttributeValue(value); final AttributeList attList = new AttributeList(); if (attList.isNamespaceUriDefined(namespace) == false && writer.isNamespaceDefined(namespace) == false) { attList.addNamespaceDeclaration("autoGenNS", namespace); } writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN); writer.writeTextNormalized(attrValue, true); writer.writeCloseTag(); } } catch (BeanException e) { AbstractElementWriteHandler.logger.warn( "Attribute '" + namespace + '|' + name + "' is not convertible with the bean-methods"); } } } }
From source file:org.ppwcode.vernacular.value_III.jsf.AbstractPropertyEditorConverter.java
/** * @pre context != null;/*from w w w. ja v a2 s. c o m*/ * @pre component != null; * @return ; the result of the conversion of <code>value</code> * to a String by {@link #getPropertyEditor(FacesContext, UIComponent)} * @throws ConverterException * getPropertyEditor(context, component); */ public final String getAsString(final FacesContext context, final UIComponent component, final Object value) throws ConverterException { assert context != null; assert component != null; if (LOG.isDebugEnabled()) { LOG.debug("request to convert object \"" + value + "\" to String for " + component + "(id = " + component.getClientId(context) + ")"); } PropertyEditor editor = getPropertyEditor(context, component); // ConverterException LOG.debug("retrieved PropertyEditor: " + editor); editor.setValue(value); String result = editor.getAsText(); LOG.debug("convertion result: " + result); return result; }
From source file:org.springframework.faces.mvc.bind.ReverseDataBinder.java
/** * Utility method to convert a given value into a string using a property editor. * @param value The value to convert (can be <tt>null</tt>) * @param propertyEditor The property editor or <tt>null</tt> if no suitable property editor exists * @return The converted value/* w ww. j a v a 2 s .c o m*/ */ private String convertToStringUsingPropertyEditor(Object value, PropertyEditor propertyEditor) { if (propertyEditor != null) { propertyEditor.setValue(value); return propertyEditor.getAsText(); } if (value instanceof String) { return value == null ? null : value.toString(); } return null; }