Java Code Examples for com.helger.xml.microdom.IMicroElement#forAllChildElements()

The following examples show how to use com.helger.xml.microdom.IMicroElement#forAllChildElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PSReader.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
/**
 * Read an <extends> element
 *
 * @param eExtends
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSExtends readExtendsFromXML (@Nonnull final IMicroElement eExtends)
{
  final PSExtends ret = new PSExtends ();

  eExtends.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_RULE))
      ret.setRule (sAttrValue);
    else
      ret.addForeignAttribute (sAttrName, sAttrValue);
  });

  eExtends.forAllChildElements (eChild -> {
    if (isValidSchematronNS (eChild.getNamespaceURI ()))
    {
      _warn (ret, "Unsupported Schematron element '" + eChild.getLocalName () + "'");
    }
    else
      _warn (ret, "Unsupported namespace URI '" + eChild.getNamespaceURI () + "'");
  });
  return ret;
}
 
Example 2
Source File: PSReader.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
/**
 * Read an &lt;include&gt; element
 *
 * @param eInclude
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSInclude readIncludeFromXML (@Nonnull final IMicroElement eInclude)
{
  final PSInclude ret = new PSInclude ();

  eInclude.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_HREF))
      ret.setHref (sAttrValue);
    else
      _warn (ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'");
  });

  eInclude.forAllChildElements (eValueOfChild -> {
    if (isValidSchematronNS (eValueOfChild.getNamespaceURI ()))
    {
      _warn (ret, "Unsupported Schematron element '" + eValueOfChild.getLocalName () + "'");
    }
    else
      _warn (ret, "Unsupported namespace URI '" + eValueOfChild.getNamespaceURI () + "'");
  });
  return ret;
}
 
Example 3
Source File: PSReader.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
/**
 * Read a &lt;name&gt; element
 *
 * @param eName
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSName readNameFromXML (@Nonnull final IMicroElement eName)
{
  final PSName ret = new PSName ();

  eName.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_PATH))
      ret.setPath (sAttrValue);
    else
      ret.addForeignAttribute (sAttrName, sAttrValue);
  });

  eName.forAllChildElements (eNameChild -> {
    if (isValidSchematronNS (eNameChild.getNamespaceURI ()))
    {
      _warn (ret, "Unsupported Schematron element '" + eNameChild.getLocalName () + "'");
    }
    else
      _warn (ret, "Unsupported namespace URI '" + eNameChild.getNamespaceURI () + "'");
  });
  return ret;
}
 
Example 4
Source File: PSReader.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
/**
 * Read a &lt;value-of&gt; element
 *
 * @param eValueOf
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSValueOf readValueOfFromXML (@Nonnull final IMicroElement eValueOf)
{
  final PSValueOf ret = new PSValueOf ();

  eValueOf.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_SELECT))
      ret.setSelect (sAttrValue);
    else
      ret.addForeignAttribute (sAttrName, sAttrValue);
  });

  eValueOf.forAllChildElements (eValueOfChild -> {
    if (isValidSchematronNS (eValueOfChild.getNamespaceURI ()))
    {
      _warn (ret, "Unsupported Schematron element '" + eValueOfChild.getLocalName () + "'");
    }
    else
      _warn (ret, "Unsupported namespace URI '" + eValueOfChild.getNamespaceURI () + "'");
  });
  return ret;
}
 
Example 5
Source File: PSReader.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Read a &lt;diagnostics&gt; element
 *
 * @param eDiagnostics
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSDiagnostics readDiagnosticsFromXML (@Nonnull final IMicroElement eDiagnostics)
{
  final PSDiagnostics ret = new PSDiagnostics ();

  eDiagnostics.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    ret.addForeignAttribute (sAttrName, sAttrValue);
  });

  eDiagnostics.forAllChildElements (eDiagnosticsChild -> {
    if (isValidSchematronNS (eDiagnosticsChild.getNamespaceURI ()))
    {
      if (eDiagnosticsChild.getLocalName ().equals (CSchematronXML.ELEMENT_INCLUDE))
        ret.addInclude (readIncludeFromXML (eDiagnosticsChild));
      else
        if (eDiagnosticsChild.getLocalName ().equals (CSchematronXML.ELEMENT_DIAGNOSTIC))
          ret.addDiagnostic (readDiagnosticFromXML (eDiagnosticsChild));
        else
          _warn (ret, "Unsupported Schematron element '" + eDiagnosticsChild.getLocalName () + "'");
    }
    else
      ret.addForeignElement (eDiagnosticsChild.getClone ());
  });
  return ret;
}
 
Example 6
Source File: PSReader.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Read a &lt;let&gt; element
 *
 * @param eLet
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSLet readLetFromXML (@Nonnull final IMicroElement eLet)
{
  final PSLet ret = new PSLet ();

  eLet.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_NAME))
      ret.setName (sAttrValue);
    else
      if (sAttrName.equals (CSchematronXML.ATTR_VALUE))
        ret.setValue (sAttrValue);
      else
        _warn (ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'");
  });

  eLet.forAllChildElements (eLetChild -> {
    if (isValidSchematronNS (eLetChild.getNamespaceURI ()))
    {
      _warn (ret, "Unsupported Schematron element '" + eLetChild.getLocalName () + "'");
    }
    else
      _warn (ret, "Unsupported namespace URI '" + eLetChild.getNamespaceURI () + "'");
  });
  return ret;
}
 
Example 7
Source File: PSReader.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Read a &lt;ns&gt; element
 *
 * @param eNS
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSNS readNSFromXML (@Nonnull final IMicroElement eNS)
{
  final PSNS ret = new PSNS ();

  eNS.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_URI))
      ret.setUri (sAttrValue);
    else
      if (sAttrName.equals (CSchematronXML.ATTR_PREFIX))
        ret.setPrefix (sAttrValue);
      else
        ret.addForeignAttribute (sAttrName, sAttrValue);
  });

  eNS.forAllChildElements (eLetChild -> {
    if (isValidSchematronNS (eLetChild.getNamespaceURI ()))
    {
      _warn (ret, "Unsupported Schematron element '" + eLetChild.getLocalName () + "'");
    }
    else
      _warn (ret, "Unsupported namespace URI '" + eLetChild.getNamespaceURI () + "'");
  });
  return ret;
}
 
Example 8
Source File: PSReader.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Read a &lt;param&gt; element
 *
 * @param eParam
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSParam readParamFromXML (@Nonnull final IMicroElement eParam)
{
  final PSParam ret = new PSParam ();

  eParam.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_NAME))
      ret.setName (sAttrValue);
    else
      if (sAttrName.equals (CSchematronXML.ATTR_VALUE))
        ret.setValue (sAttrValue);
      else
        _warn (ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'");
  });

  eParam.forAllChildElements (eParamChild -> {
    if (isValidSchematronNS (eParamChild.getNamespaceURI ()))
    {
      _warn (ret, "Unsupported Schematron element '" + eParamChild.getLocalName () + "'");
    }
    else
      _warn (ret, "Unsupported namespace URI '" + eParamChild.getNamespaceURI () + "'");
  });
  return ret;
}
 
Example 9
Source File: PSReader.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
/**
 * Read a &lt;pattern&gt; element
 *
 * @param ePattern
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSPattern readPatternFromXML (@Nonnull final IMicroElement ePattern)
{
  final PSPattern ret = new PSPattern ();

  final PSRichGroup aRichGroup = new PSRichGroup ();
  ePattern.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_ABSTRACT))
      ret.setAbstract (StringParser.parseBool (sAttrValue));
    else
      if (sAttrName.equals (CSchematronXML.ATTR_ID))
        ret.setID (sAttrValue);
      else
        if (sAttrName.equals (CSchematronXML.ATTR_IS_A))
          ret.setIsA (sAttrValue);
        else
          if (PSRichGroup.isRichAttribute (sAttrName))
            _handleRichGroup (sAttrName, sAttrValue, aRichGroup);
          else
            ret.addForeignAttribute (sAttrName, sAttrValue);
  });
  ret.setRich (aRichGroup);

  ePattern.forAllChildElements (ePatternChild -> {
    if (isValidSchematronNS (ePatternChild.getNamespaceURI ()))
    {
      if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_INCLUDE))
        ret.addInclude (readIncludeFromXML (ePatternChild));
      else
        if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_TITLE))
          ret.setTitle (readTitleFromXML (ePatternChild));
        else
          if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_P))
            ret.addP (readPFromXML (ePatternChild));
          else
            if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_LET))
              ret.addLet (readLetFromXML (ePatternChild));
            else
              if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_RULE))
                ret.addRule (readRuleFromXML (ePatternChild));
              else
                if (ePatternChild.getLocalName ().equals (CSchematronXML.ELEMENT_PARAM))
                  ret.addParam (readParamFromXML (ePatternChild));
                else
                  _warn (ret,
                         "Unsupported Schematron element '" +
                              ePatternChild.getLocalName () +
                              "' in " +
                              ret.toString ());
    }
    else
      ret.addForeignElement (ePatternChild.getClone ());
  });
  return ret;
}
 
Example 10
Source File: PSReader.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
/**
 * Read a &lt;phase&gt; element
 *
 * @param ePhase
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSPhase readPhaseFromXML (@Nonnull final IMicroElement ePhase)
{
  final PSPhase ret = new PSPhase ();

  final PSRichGroup aRichGroup = new PSRichGroup ();
  ePhase.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_ID))
      ret.setID (sAttrValue);
    else
      if (PSRichGroup.isRichAttribute (sAttrName))
        _handleRichGroup (sAttrName, sAttrValue, aRichGroup);
      else
        ret.addForeignAttribute (sAttrName, sAttrValue);
  });
  ret.setRich (aRichGroup);

  ePhase.forAllChildElements (ePhaseChild -> {
    if (isValidSchematronNS (ePhaseChild.getNamespaceURI ()))
    {
      if (ePhaseChild.getLocalName ().equals (CSchematronXML.ELEMENT_INCLUDE))
        ret.addInclude (readIncludeFromXML (ePhaseChild));
      else
        if (ePhaseChild.getLocalName ().equals (CSchematronXML.ELEMENT_P))
          ret.addP (readPFromXML (ePhaseChild));
        else
          if (ePhaseChild.getLocalName ().equals (CSchematronXML.ELEMENT_LET))
            ret.addLet (readLetFromXML (ePhaseChild));
          else
            if (ePhaseChild.getLocalName ().equals (CSchematronXML.ELEMENT_ACTIVE))
              ret.addActive (readActiveFromXML (ePhaseChild));
            else
              _warn (ret, "Unsupported Schematron element '" + ePhaseChild.getLocalName () + "'");
    }
    else
      ret.addForeignElement (ePhaseChild.getClone ());
  });
  return ret;
}
 
Example 11
Source File: PSReader.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
/**
 * Read a &lt;rule&gt; element
 *
 * @param eRule
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSRule readRuleFromXML (@Nonnull final IMicroElement eRule)
{
  final PSRule ret = new PSRule ();

  final PSRichGroup aRichGroup = new PSRichGroup ();
  final PSLinkableGroup aLinkableGroup = new PSLinkableGroup ();
  eRule.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_FLAG))
      ret.setFlag (sAttrValue);
    else
      if (sAttrName.equals (CSchematronXML.ATTR_ABSTRACT))
        ret.setAbstract (StringParser.parseBool (sAttrValue));
      else
        if (sAttrName.equals (CSchematronXML.ATTR_CONTEXT))
          ret.setContext (sAttrValue);
        else
          if (sAttrName.equals (CSchematronXML.ATTR_ID))
            ret.setID (sAttrValue);
          else
            if (PSRichGroup.isRichAttribute (sAttrName))
              _handleRichGroup (sAttrName, sAttrValue, aRichGroup);
            else
              if (PSLinkableGroup.isLinkableAttribute (sAttrName))
                _handleLinkableGroup (sAttrName, sAttrValue, aLinkableGroup);
              else
                ret.addForeignAttribute (sAttrName, sAttrValue);
  });
  ret.setRich (aRichGroup);
  ret.setLinkable (aLinkableGroup);

  eRule.forAllChildElements (eRuleChild -> {
    if (isValidSchematronNS (eRuleChild.getNamespaceURI ()))
    {
      final String sLocalName = eRuleChild.getLocalName ();
      if (sLocalName.equals (CSchematronXML.ELEMENT_INCLUDE))
        ret.addInclude (readIncludeFromXML (eRuleChild));
      else
        if (sLocalName.equals (CSchematronXML.ELEMENT_LET))
          ret.addLet (readLetFromXML (eRuleChild));
        else
          if (sLocalName.equals (CSchematronXML.ELEMENT_ASSERT) || sLocalName.equals (CSchematronXML.ELEMENT_REPORT))
            ret.addAssertReport (readAssertReportFromXML (eRuleChild));
          else
            if (sLocalName.equals (CSchematronXML.ELEMENT_EXTENDS))
              ret.addExtends (readExtendsFromXML (eRuleChild));
            else
              _warn (ret, "Unsupported Schematron element '" + sLocalName + "'");
    }
    else
      ret.addForeignElement (eRuleChild.getClone ());
  });
  return ret;
}
 
Example 12
Source File: PSReader.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the Schematron into a pure Java object. This method makes no
 * assumptions on the validity of the document!
 *
 * @param eSchema
 *        The XML element to use. May not be <code>null</code>.
 * @return The created {@link PSSchema} object or <code>null</code> in case of
 *         <code>null</code> document or a fatal error.
 * @throws SchematronReadException
 *         If reading fails
 */
@Nonnull
public PSSchema readSchemaFromXML (@Nonnull final IMicroElement eSchema) throws SchematronReadException
{
  ValueEnforcer.notNull (eSchema, "Schema");

  if (!isLenient () && SchematronHelper.isDeprecatedSchematronNS (eSchema.getNamespaceURI ()))
    LOGGER.warn ("OLD Schematron NS '" +
                 eSchema.getNamespaceURI () +
                 "' is deprecated, use '" +
                 CSchematron.NAMESPACE_SCHEMATRON +
                 "' instead");

  if (!isValidSchematronNS (eSchema.getNamespaceURI ()))
    throw new SchematronReadException (m_aResource, "The passed element is not an ISO Schematron element!");

  final PSSchema ret = new PSSchema (m_aResource);
  final PSRichGroup aRichGroup = new PSRichGroup ();
  eSchema.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_ID))
      ret.setID (sAttrValue);
    else
      if (sAttrName.equals (CSchematronXML.ATTR_SCHEMA_VERSION))
        ret.setSchemaVersion (sAttrValue);
      else
        if (sAttrName.equals (CSchematronXML.ATTR_DEFAULT_PHASE))
          ret.setDefaultPhase (sAttrValue);
        else
          if (sAttrName.equals (CSchematronXML.ATTR_QUERY_BINDING))
            ret.setQueryBinding (sAttrValue);
          else
            if (PSRichGroup.isRichAttribute (sAttrName))
              _handleRichGroup (sAttrName, sAttrValue, aRichGroup);
            else
              ret.addForeignAttribute (sAttrName, sAttrValue);
  });
  ret.setRich (aRichGroup);

  eSchema.forAllChildElements (eSchemaChild -> {
    if (isValidSchematronNS (eSchemaChild.getNamespaceURI ()))
    {
      if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_INCLUDE))
        ret.addInclude (readIncludeFromXML (eSchemaChild));
      else
        if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_TITLE))
          ret.setTitle (readTitleFromXML (eSchemaChild));
        else
          if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_NS))
            ret.addNS (readNSFromXML (eSchemaChild));
          else
            if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_P))
            {
              final PSP aP = readPFromXML (eSchemaChild);
              if (ret.hasNoPatterns ())
                ret.addStartP (aP);
              else
                ret.addEndP (aP);
            }
            else
              if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_LET))
                ret.addLet (readLetFromXML (eSchemaChild));
              else
                if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_PHASE))
                  ret.addPhase (readPhaseFromXML (eSchemaChild));
                else
                  if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_PATTERN))
                    ret.addPattern (readPatternFromXML (eSchemaChild));
                  else
                    if (eSchemaChild.getLocalName ().equals (CSchematronXML.ELEMENT_DIAGNOSTICS))
                      ret.setDiagnostics (readDiagnosticsFromXML (eSchemaChild));
                    else
                      _warn (ret, "Unsupported Schematron element '" + eSchemaChild.getLocalName () + "'");
    }
    else
      ret.addForeignElement (eSchemaChild.getClone ());
  });
  return ret;
}