Example usage for java.beans PropertyEditor getAsText

List of usage examples for java.beans PropertyEditor getAsText

Introduction

In this page you can find the example usage for java.beans PropertyEditor getAsText.

Prototype

String getAsText();

Source Link

Document

Gets the property value as text.

Usage

From source file:org.dspace.app.cris.model.ACrisObject.java

@Override
public DCValue[] getMetadata(String schema, String element, String qualifier, String lang) {
    List values = new ArrayList();
    String authority = null;//from w ww.j a  v a2  s.  c om
    if ("crisdo".equals(schema) && "name".equals(element)) {
        values.add(getName());
    } else if (!schema.equalsIgnoreCase("cris" + this.getPublicPath())) {
        return new DCValue[0];
    } else {
        element = getCompatibleJDynAShortName(this, element);

        List<P> proprieties = this.getAnagrafica4view().get(element);

        if (proprieties != null) {
            for (P prop : proprieties) {
                Object val = prop.getObject();
                if (StringUtils.isNotEmpty(qualifier) && val instanceof ACrisObject) {
                    authority = ResearcherPageUtils.getPersistentIdentifier((ACrisObject) val);
                    qualifier = getCompatibleJDynAShortName((ACrisObject) val, qualifier);
                    List pointProps = (List) ((ACrisObject) val).getAnagrafica4view().get(qualifier);
                    if (pointProps != null && pointProps.size() > 0) {
                        for (Object pprop : pointProps) {
                            values.add(((Property) pprop).getObject());
                        }
                    }
                } else if (val instanceof ACrisObject) {
                    authority = ResearcherPageUtils.getPersistentIdentifier((ACrisObject) val);
                    values.add(((ACrisObject) val).getName());
                } else {
                    PropertyEditor propertyEditor = prop.getTypo().getRendering().getPropertyEditor(null);
                    propertyEditor.setValue(val);
                    values.add(propertyEditor.getAsText());
                }
            }
        }
    }
    DCValue[] result = new DCValue[values.size()];
    for (int idx = 0; idx < values.size(); idx++) {
        result[idx] = new DCValue();
        result[idx].schema = schema;
        result[idx].element = element;
        result[idx].qualifier = qualifier;
        result[idx].authority = authority;
        result[idx].confidence = StringUtils.isNotEmpty(authority) ? Choices.CF_ACCEPTED : Choices.CF_UNSET;
        result[idx].value = values.get(idx).toString();
    }
    return result;
}

From source file:org.dspace.app.cris.util.UtilsXLS.java

private static int createSimpleElement(ApplicationService applicationService, int y, int i, String shortName,
        List<RPProperty> proprietaDellaTipologia, WritableSheet sheet)
        throws RowsExceededException, WriteException {
    String field_value = "";
    String field_visibility = "";
    boolean first = true;
    for (RPProperty rr : proprietaDellaTipologia) {

        PropertyEditor pe = rr.getTypo().getRendering().getPropertyEditor(applicationService);
        pe.setValue(rr.getObject());//  w w w .j  a va  2 s.  c o  m
        if (!first) {
            field_value += STOPFIELDS_EXCEL;
        }
        field_value += pe.getAsText();
        if (!first) {
            field_visibility += STOPFIELDS_EXCEL;
        }
        field_visibility += VisibilityConstants.getDescription(rr.getVisibility());
        first = false;

    }
    y = y + 1;
    Label label_v = new Label(y, i, field_value);
    sheet.addCell(label_v);
    Label labelCaption = new Label(y, 0, shortName);
    sheet.addCell(labelCaption);
    y = y + 1;
    Label label_vv = new Label(y, i, field_visibility);
    sheet.addCell(label_vv);
    labelCaption = new Label(y, 0, shortName + ImportExportUtils.LABELCAPTION_VISIBILITY_SUFFIX);
    sheet.addCell(labelCaption);

    return y;
}

From source file:org.easyrec.plugin.configuration.ConfigurationHelper.java

/**
 * Converts the parameter value to a string. If a custom {@link PropertyEditor} is configured for the parameter (via
 * the {@link PluginParameterPropertyEditor} Annotation), it is used for conversion, otherwise the value's
 * <code>toString()</code> method is called. If the value is <code>null</code>, <code>null</code> is returned.
 *
 * @param parameterName/* w ww  . j  a v a2  s.co  m*/
 *
 * @throws IllegalArgumentException if no parameter of given name exists.
 */
public String getParameterStringValue(String parameterName) {
    Field field = getParameterField(parameterName);
    PropertyEditor editor = this.configurationWrapper.findCustomEditor(field.getType(), field.getName());
    Object value = getParameterValue(parameterName);
    if (editor != null) {
        editor.setValue(value);
        return editor.getAsText();
    } else {
        if (value == null) {
            return null;
        }
        return value.toString();
    }
}

From source file:org.jsecurity.web.attr.AbstractWebAttribute.java

protected String toStringValue(T value) {
    Class clazz = getEditorClass();
    if (clazz == null) {

        if (log.isDebugEnabled()) {
            log.debug("No 'editorClass' property set - returning value.toString() as the string value for "
                    + "method argument.");
        }//  w w w  .  j  ava 2 s .c o  m
        return value.toString();
    } else {
        PropertyEditor editor = (PropertyEditor) ClassUtils.newInstance(getEditorClass());
        editor.setValue(value);
        return editor.getAsText();
    }
}

From source file:org.kuali.rice.krad.uif.util.ObjectPropertyUtils.java

/**
 * Looks up a property value, then convert to text using a registered property editor.
 *
 * @param bean bean instance to look up a property value for
 * @param path property path relative to the bean
 * @return The property value, converted to text using a registered property editor.
 *//*from   w  w  w. j a  v a 2 s.  c o  m*/
public static String getPropertyValueAsText(Object bean, String path) {
    Object propertyValue = getPropertyValue(bean, path);
    PropertyEditor editor = getPropertyEditor(bean, path);

    if (editor == null) {
        return propertyValue == null ? null : propertyValue.toString();
    } else {
        editor.setValue(propertyValue);
        return editor.getAsText();
    }
}

From source file:org.lnicholls.galleon.gui.HMEConfigurationPanel.java

public HMEConfigurationPanel(Object bean) {

    setLayout(new GridLayout(0, 1));

    target = bean;//from w  w w .  jav  a2s.c o  m

    try {

        BeanInfo bi = Introspector.getBeanInfo(target.getClass());

        properties = bi.getPropertyDescriptors();

    } catch (IntrospectionException ex) {

        Tools.logException(HMEConfigurationPanel.class, ex, "PropertySheet: Couldn't introspect");

        return;

    }

    editors = new PropertyEditor[properties.length];

    values = new Object[properties.length];

    views = new Component[properties.length];

    labels = new JLabel[properties.length];

    for (int i = 0; i < properties.length; i++) {

        // Don't display hidden or expert properties.

        if (properties[i].isHidden() || properties[i].isExpert()) {

            continue;

        }

        String name = properties[i].getDisplayName();

        Class type = properties[i].getPropertyType();

        Method getter = properties[i].getReadMethod();

        Method setter = properties[i].getWriteMethod();

        // Only display read/write properties.

        if (getter == null || setter == null) {

            continue;

        }

        Component view = null;

        try {

            Object args[] = {};

            Object value = getter.invoke(target, args);

            values[i] = value;

            PropertyEditor editor = null;

            Class pec = properties[i].getPropertyEditorClass();

            if (pec != null) {

                try {

                    editor = (PropertyEditor) pec.newInstance();

                } catch (Exception ex) {

                    // Drop through.

                }

            }

            if (editor == null) {

                editor = PropertyEditorManager.findEditor(type);

            }

            editors[i] = editor;

            // If we can't edit this component, skip it.

            if (editor == null) {

                // If it's a user-defined property we give a warning.

                String getterClass = properties[i].getReadMethod().getDeclaringClass().getName();

                if (getterClass.indexOf("java.") != 0) {

                    log.error("Warning: Can't find public property editor for property \"" + name

                            + "\".  Skipping.");

                }

                continue;

            }

            // Don't try to set null values:

            if (value == null) {

                // If it's a user-defined property we give a warning.

                String getterClass = properties[i].getReadMethod().getDeclaringClass().getName();

                if (getterClass.indexOf("java.") != 0) {

                    log.error("Warning: Property \"" + name + "\" has null initial value.  Skipping.");

                }

                continue;

            }

            editor.setValue(value);

            // editor.addPropertyChangeListener(adaptor);

            // Now figure out how to display it...

            if (editor.isPaintable() && editor.supportsCustomEditor()) {

                view = new PropertyCanvas(frame, editor);

            } else if (editor.getTags() != null) {

                view = new PropertySelector(editor);

            } else if (editor.getAsText() != null) {

                String init = editor.getAsText();

                view = new PropertyText(editor);

            } else {

                log.error("Warning: Property \"" + name + "\" has non-displayabale editor.  Skipping.");

                continue;

            }

        } catch (InvocationTargetException ex) {

            Tools.logException(HMEConfigurationPanel.class, ex.getTargetException(),
                    "Skipping property " + name);

            continue;

        } catch (Exception ex) {

            Tools.logException(HMEConfigurationPanel.class, ex, "Skipping property " + name);

            continue;

        }

        labels[i] = new JLabel(WordUtils.capitalize(name), JLabel.RIGHT);

        // add(labels[i]);

        views[i] = view;

        // add(views[i]);

    }

    int validCounter = 0;

    for (int i = 0; i < labels.length; i++) {

        if (labels[i] != null)

            validCounter++;

    }

    String rowStrings = ""; // general

    if (validCounter > 0)

        rowStrings = "pref, ";

    else

        rowStrings = "pref";

    int counter = 0;

    for (int i = 0; i < labels.length; i++) {

        if (labels[i] != null) {

            if (++counter == (validCounter))

                rowStrings = rowStrings + "9dlu, " + "pref";

            else

                rowStrings = rowStrings + "9dlu, " + "pref, ";

        }

    }

    FormLayout layout = new FormLayout("right:pref, 3dlu, 50dlu:g, right:pref:grow", rowStrings);

    PanelBuilder builder = new PanelBuilder(layout);

    //DefaultFormBuilder builder = new DefaultFormBuilder(new FormDebugPanel(), layout);

    builder.setDefaultDialogBorder();

    CellConstraints cc = new CellConstraints();

    builder.addSeparator("General", cc.xyw(1, 1, 4));

    counter = 0;

    for (int i = 0; i < labels.length; i++) {

        if (labels[i] != null) {

            counter++;

            builder.add(labels[i], cc.xy(1, counter * 2 + 1));

            builder.add(views[i], cc.xy(3, counter * 2 + 1));

        }

    }

    JPanel panel = builder.getPanel();

    //FormDebugUtils.dumpAll(panel);

    add(panel);

}

From source file:org.lnicholls.galleon.gui.HMEConfigurationPanel.java

PropertyText(PropertyEditor pe) {

    super(pe.getAsText());

    editor = pe;

    addKeyListener(this);

    addFocusListener(this);

}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.xml.internal.XmlDocumentWriter.java

private void writeElementAttributes(final RenderNode element) throws IOException {
    final ReportAttributeMap attributes = element.getAttributes();
    final ElementType type = element.getElementType();

    final Set<AttributeMap.DualKey> collection = attributes.keySet();
    final AttributeMap.DualKey[] attributeNames = collection
            .toArray(new AttributeMap.DualKey[collection.size()]);
    Arrays.sort(attributeNames, new DualKeySorter());

    for (int j = 0; j < attributeNames.length; j++) {
        final String namespace = attributeNames[j].namespace;
        if (AttributeNames.Designtime.NAMESPACE.equals(namespace)) {
            continue;
        }//from  ww w .  j  a va2  s . c  o m
        final String name = attributeNames[j].name;
        final Object value = attributes.getAttribute(namespace, name);
        if (value == null) {
            continue;
        }

        if (metaData.isFeatureSupported(XmlPageOutputProcessorMetaData.WRITE_RESOURCEKEYS) == false
                && value instanceof ResourceKey) {
            continue;
        }

        final AttributeMetaData attrMeta = type.getMetaData().getAttributeDescription(namespace, name);
        if (attrMeta == null) {
            // if you want to use attributes in this output target, declare the attribute's metadata first.
            continue;
        }

        final AttributeList attList = new AttributeList();
        if (value instanceof String) {
            final String s = (String) value;
            if (StringUtils.isEmpty(s)) {
                continue;
            }

            if (xmlWriter.isNamespaceDefined(namespace) == false
                    && attList.isNamespaceUriDefined(namespace) == false) {
                attList.addNamespaceDeclaration("autoGenNs", namespace);
            }

            // preserve strings, but discard anything else. Until a attribute has a definition, we cannot
            // hope to understand the attribute's value. String-attributes can be expressed in XML easily,
            // and string is also how all unknown attributes are stored by the parser.
            attList.setAttribute(namespace, name, String.valueOf(value));
            this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList,
                    XmlWriter.CLOSE);
            continue;
        }

        if (xmlWriter.isNamespaceDefined(namespace) == false
                && attList.isNamespaceUriDefined(namespace) == false) {
            attList.addNamespaceDeclaration("autoGenNs", namespace);
        }

        try {
            final PropertyEditor propertyEditor = attrMeta.getEditor();
            final String textValue;
            if (propertyEditor != null) {
                propertyEditor.setValue(value);
                textValue = propertyEditor.getAsText();
            } else {
                textValue = ConverterRegistry.toAttributeValue(value);
            }

            if (textValue != null) {
                if ("".equals(textValue) == false) {
                    attList.setAttribute(namespace, name, textValue);
                    this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList,
                            XmlWriter.CLOSE);
                }
            } else {
                if (value instanceof ResourceKey) {
                    final ResourceKey reskey = (ResourceKey) value;
                    final String identifierAsString = reskey.getIdentifierAsString();
                    attList.setAttribute(namespace, name,
                            "resource-key:" + reskey.getSchema() + ":" + identifierAsString);
                    this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList,
                            XmlWriter.CLOSE);
                } else {
                    XmlDocumentWriter.logger.debug("Attribute '" + namespace + '|' + name
                            + "' is not convertible to a text - returned null: " + value);
                }
            }
        } catch (BeanException e) {
            if (attrMeta.isTransient() == false) {
                XmlDocumentWriter.logger.warn(
                        "Attribute '" + namespace + '|' + name + "' is not convertible with the bean-methods");
            } else {
                XmlDocumentWriter.logger.debug(
                        "Attribute '" + namespace + '|' + name + "' is not convertible with the bean-methods");
            }
        }
    }

}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xml.internal.XmlDocumentWriter.java

private void writeAttributes(final ReportAttributeMap attributes, ElementType type) throws IOException {
    if (type == null) {
        type = AutoLayoutBoxType.INSTANCE;
    }// ww  w  .  jav a 2 s  .com

    final Set<AttributeMap.DualKey> collection = attributes.keySet();
    final AttributeMap.DualKey[] attributeNames = collection
            .toArray(new AttributeMap.DualKey[collection.size()]);
    Arrays.sort(attributeNames, new DualKeySorter());
    for (int j = 0; j < attributeNames.length; j++) {

        final String namespace = attributeNames[j].namespace;
        if (AttributeNames.Designtime.NAMESPACE.equals(namespace)) {
            continue;
        }

        final String name = attributeNames[j].name;
        final Object value = attributes.getAttribute(namespace, name);
        if (value == null) {
            continue;
        }

        if (metaData.isFeatureSupported(XmlTableOutputProcessorMetaData.WRITE_RESOURCEKEYS) == false
                && value instanceof ResourceKey) {
            continue;
        }

        final AttributeMetaData attrMeta = type.getMetaData().getAttributeDescription(namespace, name);
        if (attrMeta == null) {
            // if you want to use attributes in this output target, declare the attribute's metadata first.
            continue;
        }

        final AttributeList attList = new AttributeList();
        if (value instanceof String) {
            final String s = (String) value;
            if (StringUtils.isEmpty(s)) {
                continue;
            }

            if (xmlWriter.isNamespaceDefined(namespace) == false
                    && attList.isNamespaceUriDefined(namespace) == false) {
                attList.addNamespaceDeclaration("autoGenNs", namespace);
            }

            // preserve strings, but discard anything else. Until a attribute has a definition, we cannot
            // hope to understand the attribute's value. String-attributes can be expressed in XML easily,
            // and string is also how all unknown attributes are stored by the parser.
            attList.setAttribute(namespace, name, s);
            this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList,
                    XmlWriter.CLOSE);
            continue;
        }

        if (xmlWriter.isNamespaceDefined(namespace) == false
                && attList.isNamespaceUriDefined(namespace) == false) {
            attList.addNamespaceDeclaration("autoGenNs", namespace);
        }

        try {
            final PropertyEditor propertyEditor = attrMeta.getEditor();
            final String textValue;
            if (propertyEditor != null) {
                propertyEditor.setValue(value);
                textValue = propertyEditor.getAsText();
            } else {
                textValue = ConverterRegistry.toAttributeValue(value);
            }

            if (textValue != null) {
                if ("".equals(textValue) == false) {
                    attList.setAttribute(namespace, name, textValue);
                    this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList,
                            XmlWriter.CLOSE);
                }
            } else {
                if (value instanceof ResourceKey) {
                    final ResourceKey reskey = (ResourceKey) value;
                    final String identifierAsString = reskey.getIdentifierAsString();
                    attList.setAttribute(namespace, name,
                            "resource-key:" + reskey.getSchema() + ":" + identifierAsString);
                    this.xmlWriter.writeTag(XmlDocumentWriter.LAYOUT_OUTPUT_NAMESPACE, "attribute", attList,
                            XmlWriter.CLOSE);
                } else {
                    XmlDocumentWriter.logger.debug("Attribute '" + namespace + '|' + name
                            + "' is not convertible to a text - returned null: " + value);
                }
            }
        } catch (BeanException e) {
            if (attrMeta.isTransient() == false) {
                XmlDocumentWriter.logger.warn(
                        "Attribute '" + namespace + '|' + name + "' is not convertible with the bean-methods");
            } else {
                XmlDocumentWriter.logger.debug(
                        "Attribute '" + namespace + '|' + name + "' is not convertible with the bean-methods");
            }
        }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.bundle.writer.elements.AbstractElementWriteHandler.java

protected AttributeList createMainAttributes(final Element element, final XmlWriter writer,
        final AttributeList attList) {
    if (element == null) {
        throw new NullPointerException();
    }//  w  ww  .j  a  v  a 2s .  co m
    if (writer == null) {
        throw new NullPointerException();
    }
    if (attList == null) {
        throw new NullPointerException();
    }

    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;
            }

            final AttributeMetaData attrMeta = metaData.getAttributeDescription(namespace, name);
            if (attrMeta == null) {
                if (value instanceof String) {
                    ensureNamespaceDefined(writer, attList, namespace);

                    // preserve strings, but discard anything else. Until a attribute has a definition, we cannot
                    // hope to understand the attribute's value. String-attributes can be expressed in XML easily,
                    // and string is also how all unknown attributes are stored by the parser.
                    attList.setAttribute(namespace, name, String.valueOf(value));
                }
                continue;
            }

            if (attrMeta.isTransient()) {
                continue;
            }
            if (isFiltered(attrMeta)) {
                continue;
            }
            if (attrMeta.isBulk()) {
                continue;
            }

            ensureNamespaceDefined(writer, attList, namespace);
            try {
                final PropertyEditor propertyEditor = attrMeta.getEditor();
                if (propertyEditor != null) {
                    propertyEditor.setValue(value);
                    attList.setAttribute(namespace, name, propertyEditor.getAsText());
                } else {
                    final String attrValue = ConverterRegistry.toAttributeValue(value);
                    attList.setAttribute(namespace, name, attrValue);
                }

            } catch (BeanException e) {
                AbstractElementWriteHandler.logger.warn(
                        "Attribute '" + namespace + '|' + name + "' is not convertible with the bean-methods");
            }
        }
    }
    return attList;
}