All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.metawidget.inspector.xml.XmlInspector Maven / Gradle / Ivy

The newest version!
// Metawidget
//
// This file is dual licensed under both the LGPL
// (http://www.gnu.org/licenses/lgpl-2.1.html) and the EPL
// (http://www.eclipse.org/org/documents/epl-v10.php). As a
// recipient of Metawidget, you may choose to receive it under either
// the LGPL or the EPL.
//
// Commercial licenses are also available. See http://metawidget.org
// for details.

package org.metawidget.inspector.xml;

import static org.metawidget.inspector.InspectionResultConstants.*;

import java.util.Map;

import org.metawidget.inspector.InspectionResultConstants;
import org.metawidget.inspector.iface.InspectorException;
import org.metawidget.inspector.impl.BaseXmlInspector;
import org.metawidget.util.XmlUtils;
import org.w3c.dom.Element;

/**
 * Inspects inspection-result-1.0.xsd-compliant files (such as
 * metawidget-metadata.xml).
 * 

* XmlInspector is a very simple Inspector: it takes as its input XML in the same format that * Inspectors usually output. It can be useful for declaring 'ad hoc' UI entities that do not map to * any Java class, as well as for declaring UI-specific attributes for existing Java classes (ie. if * you prefer not to use annotations, or if you want to introduce additional 'virtual' properties). * Some attributes accept multiple values, such as lookup. These can be * supplied as a comma-separated string. The values will be trimmed for whitespace. If the values * themselves contain commas, they can be escaped with the \ character. *

* Note when using XmlInspector you should still try to avoid duplicating UI metadata * that already exists in other parts of your application. For example, if you are also using * PropertyTypeInspector in your CompositeInspector there is no need to * duplicate the names and types of properties. Also, if you are using * PropertyTypeInspector and XmlInspector together, please read the * JavaDoc for restrictAgainstObject. *

* XmlInspector does add some niceties beyond inspection-result-1.0.xsd. * It supports an extends attribute to allow one entity to inherit from * another. It also supports nested entities, for example: *

* <entity type="Person">
*    <property name="surname"/>
*    <property name="address">
*       <property name="street"/>
*       <property name="postcode"/>
*    </property>
* </entity>
* * @author Richard Kennard */ public class XmlInspector extends BaseXmlInspector { // // Constructors // /** * Constructs an XmlInspector. *

* Note XmlInspector requires a config. It does not have a default constructor, because the * XmlInspectorConfig must be externally configured using setResourceResolver to * support resolving resources from non-standard locations (such as WEB-INF inspectProperty( Element toInspect ) { if ( PROPERTY.equals( toInspect.getNodeName() ) ) { Map attributes = XmlUtils.getAttributesAsMap( toInspect ); // Warn about some common typos if ( attributes.containsKey( "readonly" ) ) { throw InspectorException.newException( "Attribute named 'readonly' should be '" + InspectionResultConstants.READ_ONLY + "'" ); } if ( attributes.containsKey( "dontexpand" ) ) { throw InspectorException.newException( "Attribute named 'dontexpand' should be '" + InspectionResultConstants.DONT_EXPAND + "'" ); } // All good return attributes; } return null; } @Override protected Map inspectAction( Element toInspect ) { if ( ACTION.equals( toInspect.getNodeName() ) ) { return XmlUtils.getAttributesAsMap( toInspect ); } return null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy