Java Code Examples for com.helger.xml.microdom.IMicroElement#forAllAttributes()
The following examples show how to use
com.helger.xml.microdom.IMicroElement#forAllAttributes() .
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 |
/** * Read a <value-of> 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 2
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 6 votes |
/** * Read a <name> 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 3
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 6 votes |
/** * 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 4
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 6 votes |
/** * Read an <include> 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 5
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 5 votes |
/** * Read a <ns> 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 6
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 5 votes |
/** * Read a <title> element * * @param eTitle * The source micro element. Never <code>null</code>. * @return The created domain object. May not be <code>null</code>. */ @Nonnull public PSTitle readTitleFromXML (@Nonnull final IMicroElement eTitle) { final PSTitle ret = new PSTitle (); eTitle.forAllAttributes ( (sNS, sAttrName, sVal) -> { final String sAttrValue = _getAttributeValue (sVal); _warn (ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'"); }); eTitle.forAllChildren (aTitleChild -> { switch (aTitleChild.getType ()) { case TEXT: ret.addText (((IMicroText) aTitleChild).getNodeValue ()); break; case ELEMENT: final IMicroElement eElement = (IMicroElement) aTitleChild; if (isValidSchematronNS (eElement.getNamespaceURI ())) { final String sLocalName = eElement.getLocalName (); if (sLocalName.equals (CSchematronXML.ELEMENT_DIR)) ret.addDir (readDirFromXML (eElement)); else _warn (ret, "Unsupported Schematron element '" + sLocalName + "'"); } else _warn (ret, "Unsupported namespace URI '" + eElement.getNamespaceURI () + "'"); break; case COMMENT: // Ignore comments break; default: _warn (ret, "Unsupported child node: " + aTitleChild); } }); return ret; }
Example 7
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 5 votes |
/** * Read a <span> element * * @param eSpan * The source micro element. Never <code>null</code>. * @return The created domain object. May not be <code>null</code>. */ @Nonnull public PSSpan readSpanFromXML (@Nonnull final IMicroElement eSpan) { final PSSpan ret = new PSSpan (); eSpan.forAllAttributes ( (sNS, sAttrName, sVal) -> { final String sAttrValue = _getAttributeValue (sVal); if (sAttrName.equals (CSchematronXML.ATTR_CLASS)) ret.setClazz (sAttrValue); else ret.addForeignAttribute (sAttrName, sAttrValue); }); eSpan.forAllChildren (aSpanChild -> { switch (aSpanChild.getType ()) { case TEXT: ret.addText (((IMicroText) aSpanChild).getNodeValue ()); break; case ELEMENT: final IMicroElement eElement = (IMicroElement) aSpanChild; if (isValidSchematronNS (eElement.getNamespaceURI ())) { _warn (ret, "Unsupported Schematron element '" + eElement.getLocalName () + "'"); } else ret.addForeignElement (eElement.getClone ()); break; case COMMENT: // Ignore comments break; default: _warn (ret, "Unsupported child node: " + aSpanChild); } }); return ret; }
Example 8
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 5 votes |
/** * Read a <param> 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 | 5 votes |
/** * Read a <let> 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 10
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 5 votes |
/** * Read an <emph> element * * @param eEmph * The source micro element. Never <code>null</code>. * @return The created domain object. May not be <code>null</code>. */ @Nonnull public PSEmph readEmphFromXML (@Nonnull final IMicroElement eEmph) { final PSEmph ret = new PSEmph (); eEmph.forAllAttributes ( (sNS, sAttrName, sVal) -> { final String sAttrValue = _getAttributeValue (sVal); _warn (ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'"); }); eEmph.forAllChildren (aEmphChild -> { switch (aEmphChild.getType ()) { case TEXT: ret.addText (((IMicroText) aEmphChild).getNodeValue ()); break; case ELEMENT: final IMicroElement eElement = (IMicroElement) aEmphChild; if (isValidSchematronNS (eElement.getNamespaceURI ())) { _warn (ret, "Unsupported Schematron element '" + eElement.getLocalName () + "'"); } else _warn (ret, "Unsupported namespace URI '" + eElement.getNamespaceURI () + "'"); break; case COMMENT: // Ignore comments break; default: _warn (ret, "Unsupported child node: " + aEmphChild); } }); return ret; }
Example 11
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 5 votes |
/** * Read a <dir> element * * @param eDir * The source micro element. Never <code>null</code>. * @return The created domain object. May not be <code>null</code>. */ @Nonnull public PSDir readDirFromXML (@Nonnull final IMicroElement eDir) { final PSDir ret = new PSDir (); eDir.forAllAttributes ( (sNS, sAttrName, sVal) -> { final String sAttrValue = _getAttributeValue (sVal); if (sAttrName.equals (CSchematronXML.ATTR_VALUE)) ret.setValue (EDirValue.getFromIDOrNull (sAttrValue)); else ret.addForeignAttribute (sAttrName, sAttrValue); }); eDir.forAllChildren (aDirChild -> { switch (aDirChild.getType ()) { case TEXT: ret.addText (((IMicroText) aDirChild).getNodeValue ()); break; case ELEMENT: final IMicroElement eElement = (IMicroElement) aDirChild; if (isValidSchematronNS (eElement.getNamespaceURI ())) { _warn (ret, "Unsupported Schematron element '" + eElement.getLocalName () + "'"); } else ret.addForeignElement (eElement.getClone ()); break; case COMMENT: // Ignore comments break; default: _warn (ret, "Unsupported child node: " + aDirChild); } }); return ret; }
Example 12
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 5 votes |
/** * Read a <diagnostics> 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 13
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 4 votes |
/** * Read an <active> element * * @param eActive * The source micro element. Never <code>null</code>. * @return The created domain object. May not be <code>null</code>. */ @Nonnull public PSActive readActiveFromXML (@Nonnull final IMicroElement eActive) { final PSActive ret = new PSActive (); eActive.forAllAttributes ( (sNS, sAttrName, sVal) -> { final String sAttrValue = _getAttributeValue (sVal); if (sAttrName.equals (CSchematronXML.ATTR_PATTERN)) ret.setPattern (sAttrValue); else ret.addForeignAttribute (sAttrName, sAttrValue); }); eActive.forAllChildren (aActiveChild -> { switch (aActiveChild.getType ()) { case TEXT: ret.addText (((IMicroText) aActiveChild).getNodeValue ()); break; case ELEMENT: final IMicroElement eElement = (IMicroElement) aActiveChild; if (isValidSchematronNS (eElement.getNamespaceURI ())) { final String sLocalName = eElement.getLocalName (); if (sLocalName.equals (CSchematronXML.ELEMENT_DIR)) ret.addDir (readDirFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_EMPH)) ret.addEmph (readEmphFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_SPAN)) ret.addSpan (readSpanFromXML (eElement)); else _warn (ret, "Unsupported Schematron element '" + sLocalName + "'"); } else ret.addForeignElement (eElement.getClone ()); break; case COMMENT: // Ignore comments break; default: _warn (ret, "Unsupported child node: " + aActiveChild); } }); return ret; }
Example 14
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 4 votes |
/** * Read a <p> element * * @param eP * The source micro element. Never <code>null</code>. * @return The created domain object. May not be <code>null</code>. */ @Nonnull public PSP readPFromXML (@Nonnull final IMicroElement eP) { final PSP ret = new PSP (); eP.forAllAttributes ( (sNS, sAttrName, sVal) -> { final String sAttrValue = _getAttributeValue (sVal); if (sAttrName.equals (CSchematronXML.ATTR_ID)) ret.setID (sAttrValue); else if (sAttrName.equals (CSchematronXML.ATTR_CLASS)) ret.setClazz (sAttrValue); else if (sAttrName.equals (CSchematronXML.ATTR_ICON)) ret.setIcon (sAttrValue); else ret.addForeignAttribute (sAttrName, sAttrValue); }); eP.forAllChildren (aChild -> { switch (aChild.getType ()) { case TEXT: ret.addText (((IMicroText) aChild).getNodeValue ()); break; case ELEMENT: final IMicroElement eElement = (IMicroElement) aChild; if (isValidSchematronNS (eElement.getNamespaceURI ())) { final String sLocalName = eElement.getLocalName (); if (sLocalName.equals (CSchematronXML.ELEMENT_DIR)) ret.addDir (readDirFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_EMPH)) ret.addEmph (readEmphFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_SPAN)) ret.addSpan (readSpanFromXML (eElement)); else _warn (ret, "Unsupported Schematron element '" + sLocalName + "'"); } else ret.addForeignElement (eElement.getClone ()); break; case COMMENT: // Ignore comments break; default: _warn (ret, "Unsupported child node: " + aChild); } }); return ret; }
Example 15
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 4 votes |
/** * Read a <pattern> 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 16
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 4 votes |
/** * Read a <phase> 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 17
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 4 votes |
/** * Read a <rule> 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 18
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 4 votes |
/** * 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; }
Example 19
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 4 votes |
/** * Read a <diagnostic> element * * @param eDiagnostic * The source micro element. Never <code>null</code>. * @return The created domain object. May not be <code>null</code>. */ @Nonnull public PSDiagnostic readDiagnosticFromXML (@Nonnull final IMicroElement eDiagnostic) { final PSDiagnostic ret = new PSDiagnostic (); final PSRichGroup aRichGroup = new PSRichGroup (); eDiagnostic.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); eDiagnostic.forAllChildren (aDiagnosticChild -> { switch (aDiagnosticChild.getType ()) { case TEXT: ret.addText (((IMicroText) aDiagnosticChild).getNodeValue ()); break; case ELEMENT: final IMicroElement eElement = (IMicroElement) aDiagnosticChild; if (isValidSchematronNS (eElement.getNamespaceURI ())) { final String sLocalName = eElement.getLocalName (); if (sLocalName.equals (CSchematronXML.ELEMENT_VALUE_OF)) ret.addValueOf (readValueOfFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_EMPH)) ret.addEmph (readEmphFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_DIR)) ret.addDir (readDirFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_SPAN)) ret.addSpan (readSpanFromXML (eElement)); else _warn (ret, "Unsupported Schematron element '" + sLocalName + "'"); } else ret.addForeignElement (eElement.getClone ()); break; case COMMENT: // Ignore comments break; default: _warn (ret, "Unsupported child node: " + aDiagnosticChild); } }); return ret; }
Example 20
Source File: PSReader.java From ph-schematron with Apache License 2.0 | 4 votes |
/** * Read an <assert> or a <report> element * * @param eAssertReport * The source micro element. Never <code>null</code>. * @return The created domain object. May not be <code>null</code>. */ @Nonnull public PSAssertReport readAssertReportFromXML (@Nonnull final IMicroElement eAssertReport) { final PSAssertReport ret = new PSAssertReport (eAssertReport.getLocalName () .equals (CSchematronXML.ELEMENT_ASSERT)); final PSRichGroup aRichGroup = new PSRichGroup (); final PSLinkableGroup aLinkableGroup = new PSLinkableGroup (); eAssertReport.forAllAttributes ( (sNS, sAttrName, sVal) -> { final String sAttrValue = _getAttributeValue (sVal); if (sAttrName.equals (CSchematronXML.ATTR_TEST)) ret.setTest (sAttrValue); else if (sAttrName.equals (CSchematronXML.ATTR_FLAG)) ret.setFlag (sAttrValue); else if (sAttrName.equals (CSchematronXML.ATTR_ID)) ret.setID (sAttrValue); else if (sAttrName.equals (CSchematronXML.ATTR_DIAGNOSTICS)) ret.setDiagnostics (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); eAssertReport.forAllChildren (aAssertReportChild -> { switch (aAssertReportChild.getType ()) { case TEXT: ret.addText (((IMicroText) aAssertReportChild).getNodeValue ()); break; case ELEMENT: final IMicroElement eElement = (IMicroElement) aAssertReportChild; if (isValidSchematronNS (eElement.getNamespaceURI ())) { final String sLocalName = eElement.getLocalName (); if (sLocalName.equals (CSchematronXML.ELEMENT_NAME)) ret.addName (readNameFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_VALUE_OF)) ret.addValueOf (readValueOfFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_EMPH)) ret.addEmph (readEmphFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_DIR)) ret.addDir (readDirFromXML (eElement)); else if (sLocalName.equals (CSchematronXML.ELEMENT_SPAN)) ret.addSpan (readSpanFromXML (eElement)); else _warn (ret, "Unsupported Schematron element '" + sLocalName + "'"); } else ret.addForeignElement (eElement.getClone ()); break; case COMMENT: // Ignore comments break; default: _warn (ret, "Unsupported child node: " + aAssertReportChild); } }); return ret; }