Search in sources :

Example 6 with IMicroElement

use of com.helger.xml.microdom.IMicroElement in project ph-schematron by phax.

the class PSReader method readActiveFromXML.

/**
 * 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 (CSchematron.NAMESPACE_SCHEMATRON.equals(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;
}
Also used : IMicroElement(com.helger.xml.microdom.IMicroElement) Nonnull(javax.annotation.Nonnull)

Example 7 with IMicroElement

use of com.helger.xml.microdom.IMicroElement in project ph-schematron by phax.

the class PSReader method readTitleFromXML.

/**
 * Read a &lt;title&gt; 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 (CSchematron.NAMESPACE_SCHEMATRON.equals(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;
}
Also used : IMicroElement(com.helger.xml.microdom.IMicroElement) Nonnull(javax.annotation.Nonnull)

Example 8 with IMicroElement

use of com.helger.xml.microdom.IMicroElement in project ph-schematron by phax.

the class PSReader method readDiagnosticFromXML.

/**
 * Read a &lt;diagnostic&gt; 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 (CSchematron.NAMESPACE_SCHEMATRON.equals(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;
}
Also used : IMicroElement(com.helger.xml.microdom.IMicroElement) Nonnull(javax.annotation.Nonnull)

Example 9 with IMicroElement

use of com.helger.xml.microdom.IMicroElement in project ph-schematron by phax.

the class PSReader method readSpanFromXML.

/**
 * Read a &lt;span&gt; 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 (CSchematron.NAMESPACE_SCHEMATRON.equals(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;
}
Also used : IMicroElement(com.helger.xml.microdom.IMicroElement) Nonnull(javax.annotation.Nonnull)

Example 10 with IMicroElement

use of com.helger.xml.microdom.IMicroElement in project ph-schematron by phax.

the class PSReader method readPFromXML.

/**
 * Read a &lt;p&gt; 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 (CSchematron.NAMESPACE_SCHEMATRON.equals(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;
}
Also used : IMicroElement(com.helger.xml.microdom.IMicroElement) Nonnull(javax.annotation.Nonnull)

Aggregations

IMicroElement (com.helger.xml.microdom.IMicroElement)41 Nonnull (javax.annotation.Nonnull)30 MicroElement (com.helger.xml.microdom.MicroElement)18 IMicroDocument (com.helger.xml.microdom.IMicroDocument)7 OpenAS2Exception (com.helger.as2lib.exception.OpenAS2Exception)3 IReadableResource (com.helger.commons.io.resource.IReadableResource)3 File (java.io.File)3 CommandResult (com.helger.as2.cmd.CommandResult)2 XMLPartnershipFactory (com.helger.as2lib.partner.xml.XMLPartnershipFactory)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 IMicroNode (com.helger.xml.microdom.IMicroNode)2 MicroDocument (com.helger.xml.microdom.MicroDocument)2 Partnership (com.helger.as2lib.partner.Partnership)1 Partner (com.helger.as2lib.partner.xml.Partner)1 IMessageProcessor (com.helger.as2lib.processor.IMessageProcessor)1 ValueEnforcer (com.helger.commons.ValueEnforcer)1 Nonempty (com.helger.commons.annotation.Nonempty)1 ICommonsList (com.helger.commons.collection.impl.ICommonsList)1 DefaultHierarchyVisitorCallback (com.helger.commons.hierarchy.visit.DefaultHierarchyVisitorCallback)1 EHierarchyVisitorReturn (com.helger.commons.hierarchy.visit.EHierarchyVisitorReturn)1