gpt4 book ai didi

org.metawidget.util.XmlUtils类的使用及代码示例

转载 作者:知者 更新时间:2024-03-26 22:07:05 28 4
gpt4 key购买 nike

本文整理了Java中org.metawidget.util.XmlUtils类的一些代码示例,展示了XmlUtils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlUtils类的具体详情如下:
包路径:org.metawidget.util.XmlUtils
类名称:XmlUtils

XmlUtils介绍

[英]Utilities for working with XML.
[中]用于处理XML的实用程序。

代码示例

代码示例来源:origin: org.metawidget.modules/metawidget-core

@Override
protected Element stringToElement( String xml ) {
  Document document = XmlUtils.documentFromString( xml );
  return document.getDocumentElement();
}

代码示例来源:origin: org.jboss.forge.addon/scaffold-spi

/**
* Inspects a {@link JavaClass} instance and provides inspection results in return.
*
* @param klass The {@link JavaClass} to inspect.
* @return A list representing inspection results for the {@link JavaClass}. Each list item corresponds to the
*         inspection result for every property of the provided {@link JavaClass}.
*/
public List<Map<String, String>> inspect(JavaClassSource klass)
{
 setupCompositeInspector();
 Element inspectionResult = compositeInspector.inspectAsDom(null, klass.getQualifiedName(), (String[]) null);
 Element inspectedEntity = XmlUtils.getFirstChildElement(inspectionResult);
 Element inspectedProperty = XmlUtils.getFirstChildElement(inspectedEntity);
 List<Map<String, String>> viewPropertyAttributes = new ArrayList<Map<String, String>>();
 while (inspectedProperty != null)
 {
   Map<String, String> propertyAttributes = XmlUtils.getAttributesAsMap(inspectedProperty);
   viewPropertyAttributes.add(propertyAttributes);
   inspectedProperty = XmlUtils.getNextSiblingElement(inspectedProperty);
 }
 return viewPropertyAttributes;
}

代码示例来源:origin: org.metawidget.modules/metawidget-all

@Override
protected Element getDocumentElement( ResourceResolver resolver, InputStream... files )
  throws Exception {
  Document document = XmlUtils.newDocument();
  Element root = document.createElement( FORM_BEANS_ELEMENT );
  document.appendChild( root );
  for ( InputStream file : files ) {
    Document documentParsed = XmlUtils.parse( file );
    Element formBeans = XmlUtils.getChildNamed( documentParsed.getDocumentElement(), FORM_BEANS_ELEMENT );
    if ( formBeans == null ) {
      continue;
    }
    XmlUtils.combineElements( root, formBeans, getTopLevelTypeAttribute(), getNameAttribute() );
  }
  return root;
}

代码示例来源:origin: org.metawidget.modules/metawidget-core

/**
 * Convert the given Element to a JSON Schema (v3) String.
 * <p>
 * If converting <code>inspection-result</code> DOMs into JSON Schemas, consider using this
 * method in conjunction with <code>JsonSchemaMappingProcessor</code> and
 * <code>JsonTypeMappingProcessor</code>. The result is directly compatible with the JavaScript
 * versions of Metawidget. It can therefore be returned by REST services (see
 * http://blog.kennardconsulting.com/2013/02/metawidget-and-rest.html).
 */
public static String inspectionResultToJsonSchema( Element inspectionResult ) {
  return inspectionResultToJsonSchema( XmlUtils.getFirstChildElement( inspectionResult ), false );
}

代码示例来源:origin: org.metawidget.modules/metawidget-core

/**
 * Process the given inspection result in context of the given Metawidget.
 * <p>
 * This method is marked <code>final</code> because most Metawidget implementations will call
 * <code>processInspectionResultAsDom</code> directly instead. So subclasses need to override
 * <code>processInspectionResultAsDom</code>, not <code>processInspectionResult</code>.
 */
public final String processInspectionResult( String inspectionResult, M metawidget, Object toInspect, String type, String... names ) {
  Document document = XmlUtils.documentFromString( inspectionResult );
  Element inspectionResultRoot = document.getDocumentElement();
  Element newInspectionResultRoot = processInspectionResultAsDom( inspectionResultRoot, metawidget, toInspect, type, names );
  return XmlUtils.documentToString( newInspectionResultRoot.getOwnerDocument(), false );
}

代码示例来源:origin: org.metawidget.modules/metawidget-core

Element entity = XmlUtils.getFirstChildElement( inspectionResult );
Element trait = XmlUtils.getFirstChildElement( entity );
  trait = XmlUtils.getNextSiblingElement( trait );
Document newDocument = XmlUtils.newDocument();
Element newInspectionResult = newDocument.createElementNS( NAMESPACE, ROOT );
XmlUtils.setMapAsAttributes( newInspectionResult, XmlUtils.getAttributesAsMap( inspectionResult ) );
newDocument.appendChild( newInspectionResult );
XmlUtils.setMapAsAttributes( newEntity, XmlUtils.getAttributesAsMap( entity ) );
newInspectionResult.appendChild( newEntity );
  newEntity.appendChild( XmlUtils.importElement( newDocument, sortedTrait ) );

代码示例来源:origin: org.metawidget.modules/metawidget-all

Element trait = XmlUtils.getFirstChildElement( entity );
  Map<String, String> attributes = XmlUtils.getAttributesAsMap( trait );
  processTrait( attributes, metawidget );
  XmlUtils.setMapAsAttributes( trait, attributes );
  trait = XmlUtils.getNextSiblingElement( trait );

代码示例来源:origin: org.metawidget.modules/metawidget-all

@Override
  protected Map<String, String> getAttributesAsMap( Element element ) {

    return XmlUtils.getAttributesAsMap( element );
  }
}

代码示例来源:origin: org.metawidget.modules/metawidget-all

if ( SIMPLE_TYPE.equals( XmlUtils.getLocalName( topLevel ) ) ) {
  return topLevel;
if ( COMPLEX_TYPE.equals( XmlUtils.getLocalName( topLevel ) ) ) {
  complexType = XmlUtils.getFirstChildElement( topLevel );
    complexType = XmlUtils.getChildWithAttributeValue( topLevel.getOwnerDocument().getDocumentElement(), NAME, topLevel.getAttribute( TYPE ) );
  if ( SIMPLE_TYPE.equals( XmlUtils.getLocalName( complexType ) ) ) {
    return topLevel;
  if ( !COMPLEX_TYPE.equals( XmlUtils.getLocalName( complexType ) ) ) {
    throw InspectorException.newException( "Unexpected child node '" + XmlUtils.getLocalName( complexType ) + "'" );
Element sequence = XmlUtils.getFirstChildElement( complexType );
String sequenceLocalName = XmlUtils.getLocalName( sequence );
  sequence = XmlUtils.getNextSiblingElement( sequence );
  sequenceLocalName = XmlUtils.getLocalName( sequence );
  Element extension = XmlUtils.getChildNamed( sequence, EXTENSION );
  Element choice = XmlUtils.getChildNamed( sequence, CHOICE );
  throw InspectorException.newException( "Unexpected child node '" + sequenceLocalName + "' inside " + XmlUtils.nodeToString( complexType, true ) );

代码示例来源:origin: org.metawidget.modules/metawidget-core

Element trait = XmlUtils.getFirstChildElement( element );
    String traitSchema = inspectionResultToJsonSchema( trait, true );
  trait = XmlUtils.getNextSiblingElement( trait );
String attributes = attributesToJsonSchema( element.getAttributes(), excludeName );
if ( ACTION.equals( getLocalName( element ) ) && !element.hasAttribute( "type" ) ) {
  if ( jsonBuilder.length() > 0 ) {
    jsonBuilder.insert( 0, "," );

代码示例来源:origin: org.metawidget.modules/metawidget-core

public Element processInspectionResultAsDom( Element inspectionResult, M metawidget, Object toInspect, String type, String... names ) {
  Element entity = XmlUtils.getFirstChildElement( inspectionResult );
  // Sanity check
  String elementName = entity.getNodeName();
  if ( !ENTITY.equals( elementName ) ) {
    throw InspectionResultProcessorException.newException( "Top-level element name should be " + ENTITY + ", not " + elementName );
  }
  Map<String, String> attributes = XmlUtils.getAttributesAsMap( entity );
  processEntity( attributes, metawidget, toInspect, type, names );
  XmlUtils.setMapAsAttributes( entity, attributes );
  processTraits( entity, metawidget, toInspect, type, names );
  return inspectionResult;
}

代码示例来源:origin: org.metawidget.modules.swing/metawidget-swing

Element root = XmlUtils.documentFromString( inspectedType ).getDocumentElement();
NodeList elements = root.getFirstChild().getChildNodes();
  Map<String, String> columnAttributes = XmlUtils.getAttributesAsMap( element );

代码示例来源:origin: org.metawidget.modules/metawidget-all

/**
 * If your architecture is strongly separated, some metadata may only be available in one tier
 * (eg. JPA annotations in the backend) and some only available in another tier (eg.
 * struts-config.xml in the front-end).
 * <p>
 * For this, <code>CompositeInspector</code> supplies this overloaded method outside the normal
 * <code>Inspector</code> interface. It takes an additional XML string of inspection results,
 * and merges forthcoming inspection results with it.
 * <p>
 * This method is marked <code>final</code> because most Metawidget implementations will call
 * <code>inspectAsDom</code> directly instead. So subclasses need to override
 * <code>inspectAsDom</code>, not <code>inspect</code>.
 */
public final String inspect( String master, Object toInspect, String type, String... names ) {
  Element element = inspectAsDom( XmlUtils.documentFromString( master ), toInspect, type, names );
  if ( element == null ) {
    return null;
  }
  return XmlUtils.nodeToString( element, false );
}

代码示例来源:origin: org.metawidget.modules/metawidget-all

if ( SIMPLE_TYPE.equals( XmlUtils.getLocalName( toInspectToUse ) ) ) {
  XmlUtils.setMapAsAttributes( toAddTo, attributes );
  return;
if ( SIMPLE_CONTENT.equals( XmlUtils.getLocalName( toInspectToUse ) ) ) {
  XmlUtils.setMapAsAttributes( toAddTo, attributes );
  return;
if ( COMPLEX_CONTENT.equals( XmlUtils.getLocalName( toInspectToUse ) ) ) {
  toInspectToUse = XmlUtils.getChildNamed( toInspectToUse, EXTENSION );
  Element baseElement = XmlUtils.getChildWithAttributeValue( toInspectToUse.getOwnerDocument().getDocumentElement(), getTopLevelTypeAttribute(), base );
  Element baseSequence = XmlUtils.getFirstChildElement( baseElement );
  if ( COMPLEX_CONTENT.equals( XmlUtils.getLocalName( baseSequence ) ) ) {
    inspectTraits( baseSequence, toAddTo );
    return;
  if ( "anyAttribute".equals( XmlUtils.getLocalName( baseSequence ) ) ) {
    return;
  if ( !SEQUENCE.equals( XmlUtils.getLocalName( baseSequence ) ) ) {
    throw InspectorException.newException( "Unexpected child node '" + XmlUtils.getLocalName( baseSequence ) + "'" );
  toInspectToUse = XmlUtils.getFirstChildElement( toInspectToUse );

代码示例来源:origin: org.metawidget.modules/metawidget-all

public static Element importElement( Document document, Element element ) {
  try {
    return (Element) document.importNode( element, true );
  } catch ( DOMException e ) {
    // Note: importNode returns 'DOMException' under Android 1.1_r1
    Element imported = document.createElementNS( element.getNamespaceURI(), element.getNodeName() );
    setMapAsAttributes( imported, getAttributesAsMap( element ) );
    NodeList nodeList = imported.getChildNodes();
    for ( int loop = 0; loop < nodeList.getLength(); loop++ ) {
      Node node = nodeList.item( loop );
      if ( !( node instanceof Element ) ) {
        continue;
      }
      imported.appendChild( importElement( document, (Element) node ) );
    }
    return imported;
  }
}

代码示例来源:origin: org.metawidget.modules/metawidget-all

/**
 * Prepend 'package' attribute to class 'name' and 'extends' attributes, and to 'class'
 * attributes of children.
 */
@Override
protected void preprocessDocument( Document document ) {
  Element root = document.getDocumentElement();
  String packagePrefix = root.getAttribute( "package" );
  if ( packagePrefix != null && !"".equals( packagePrefix ) ) {
    packagePrefix += StringUtils.SEPARATOR_DOT_CHAR;
    String topLevelAttribute = getTopLevelTypeAttribute();
    String extendsAttribute = getExtendsAttribute();
    Element child = XmlUtils.getFirstChildElement( root );
    while ( child != null ) {
      // 'name' attribute of 'class'/'subclass' element
      String name = child.getAttribute( topLevelAttribute );
      if ( name != null && !"".equals( name ) && name.indexOf( StringUtils.SEPARATOR_DOT_CHAR ) == -1 ) {
        child.setAttribute( topLevelAttribute, packagePrefix + name );
      }
      // 'extends' attribute of 'subclass' element
      String extendsClass = child.getAttribute( extendsAttribute );
      if ( extendsClass != null && !"".equals( extendsClass ) && extendsClass.indexOf( StringUtils.SEPARATOR_DOT_CHAR ) == -1 ) {
        child.setAttribute( extendsAttribute, packagePrefix + extendsClass );
      }
      // 'class' attributes of children
      prependPackageToClassAttribute( child, packagePrefix );
      child = XmlUtils.getNextSiblingElement( child );
    }
  }
}

代码示例来源:origin: org.metawidget.modules/metawidget-core

/**
 * Inspect the <code>toInspect</code> for properties and actions.
 * <p>
 * This method can be overridden by clients wishing to modify the inspection process. Most
 * clients will find it easier to override one of the sub-methods, such as
 * <code>inspectTrait</code> or <code>inspectProperty</code>.
 */
protected void inspectTraits( Element toInspect, Element toAddTo ) {
  if ( toInspect == null ) {
    return;
  }
  Document document = toAddTo.getOwnerDocument();
  // Do 'extends' attribute first
  String extendsAttribute = getExtendsAttribute();
  if ( extendsAttribute != null ) {
    if ( toInspect.hasAttribute( extendsAttribute ) ) {
      inspectTraits( (Element) traverse( null, toInspect.getAttribute( extendsAttribute ), false ).getValue(), toAddTo );
    }
  }
  // Next, inspect each child...
  Element element = document.createElementNS( NAMESPACE, ENTITY );
  inspectTraitSiblings( element, XmlUtils.getFirstChildElement( toInspect ) );
  // ...and combine them all. Note the element may already exist from the superclass,
  // and its attributes will get overridden by the subclass
  XmlUtils.combineElements( toAddTo, element, NAME, NAME );
}

代码示例来源:origin: org.metawidget.modules/metawidget-core

mLog.trace( XmlUtils.documentToString( mRoot.getOwnerDocument(), false ) );
Element entity = XmlUtils.getChildWithAttribute( mRoot, topLevelTypeAttribute );
    Element property = XmlUtils.getChildWithAttribute( entity, nameAttribute );
      property = XmlUtils.getSiblingWithAttribute( property, nameAttribute );
  entity = XmlUtils.getSiblingWithAttribute( entity, topLevelTypeAttribute );

代码示例来源:origin: org.metawidget.modules/metawidget-all

throw new RuntimeException( "Child node #" + ( addLoop + 1 ) + " has no @" + topLevelAttributeToCombineOn + ": " + nodeToString( childToAdd, false ) );
  combineElements( masterChild, childToAdd, childAttributeToCombineOn, childAttributeToCombineOn );
  continue outerLoop;
  Element imported = XmlUtils.importElement( master.getOwnerDocument(), childToAdd );
  master.insertBefore( imported, nodeLastMasterCombinePoint.getNextSibling() );
  nodeLastMasterCombinePoint = imported;
master.appendChild( XmlUtils.importElement( master.getOwnerDocument(), childToAdd ) );

代码示例来源:origin: org.metawidget.modules/metawidget-all

return escapeForXml( value.trim() );
indent( builder, indent );
String nodeName = escapeForXml( node.getNodeName() );
builder.append( "<" );
builder.append( nodeName );
  builder.append( escapeForXml( name.getNodeValue() ) );
  builder.append( "\"" );
  builder.append( escapeForXml( attributeName ) );
  builder.append( "=\"" );
  builder.append( escapeForXml( attribute.getNodeValue() ) );
  builder.append( "\"" );
    builder.append( nodeToString( childNode, nextIndent ) );
    indent( builder, indent );

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com