Search in sources :

Example 16 with IMicroElement

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

the class PSAssertReport method getAsMicroElement.

@Nonnull
public IMicroElement getAsMicroElement() {
    final IMicroElement ret = new MicroElement(CSchematron.NAMESPACE_SCHEMATRON, m_bIsAssert ? CSchematronXML.ELEMENT_ASSERT : CSchematronXML.ELEMENT_REPORT);
    ret.setAttribute(CSchematronXML.ATTR_ID, m_sID);
    ret.setAttribute(CSchematronXML.ATTR_FLAG, m_sFlag);
    ret.setAttribute(CSchematronXML.ATTR_TEST, m_sTest);
    if (CollectionHelper.isNotEmpty(m_aDiagnostics))
        ret.setAttribute(CSchematronXML.ATTR_DIAGNOSTICS, StringHelper.getImploded(' ', m_aDiagnostics));
    if (m_aRich != null)
        m_aRich.fillMicroElement(ret);
    if (m_aLinkable != null)
        m_aLinkable.fillMicroElement(ret);
    if (m_aForeignElements != null)
        for (final IMicroElement aForeignElement : m_aForeignElements) ret.appendChild(aForeignElement.getClone());
    for (final Object aContent : m_aContent) if (aContent instanceof String)
        ret.appendText((String) aContent);
    else
        ret.appendChild(((IPSElement) aContent).getAsMicroElement());
    if (m_aForeignAttrs != null)
        for (final Map.Entry<String, String> aEntry : m_aForeignAttrs.entrySet()) ret.setAttribute(aEntry.getKey(), aEntry.getValue());
    return ret;
}
Also used : MicroElement(com.helger.xml.microdom.MicroElement) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroElement(com.helger.xml.microdom.IMicroElement) Nonnull(javax.annotation.Nonnull)

Example 17 with IMicroElement

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

the class PSDiagnostic method getAsMicroElement.

@Nonnull
public IMicroElement getAsMicroElement() {
    final IMicroElement ret = new MicroElement(CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_DIAGNOSTIC);
    ret.setAttribute(CSchematronXML.ATTR_ID, m_sID);
    if (m_aRich != null)
        m_aRich.fillMicroElement(ret);
    if (m_aForeignElements != null)
        for (final IMicroElement aForeignElement : m_aForeignElements) ret.appendChild(aForeignElement.getClone());
    for (final Object aContent : m_aContent) if (aContent instanceof String)
        ret.appendText((String) aContent);
    else
        ret.appendChild(((IPSElement) aContent).getAsMicroElement());
    if (m_aForeignAttrs != null)
        for (final Map.Entry<String, String> aEntry : m_aForeignAttrs.entrySet()) ret.setAttribute(aEntry.getKey(), aEntry.getValue());
    return ret;
}
Also used : MicroElement(com.helger.xml.microdom.MicroElement) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroElement(com.helger.xml.microdom.IMicroElement) Nonnull(javax.annotation.Nonnull)

Example 18 with IMicroElement

use of com.helger.xml.microdom.IMicroElement in project as2-server by phax.

the class AS2ServerXMLSession method load.

protected void load(@Nonnull @WillClose final InputStream aIS) throws OpenAS2Exception {
    final IMicroDocument aDoc = MicroReader.readMicroXML(aIS);
    final IMicroElement eRoot = aDoc.getDocumentElement();
    // Special global attributes
    final String sCryptoVerifyUseCertificateInBodyPart = eRoot.getAttributeValue(ATTR_CRYPTO_VERIFY_USE_CERTIFICATE_IN_BODY_PART);
    if (sCryptoVerifyUseCertificateInBodyPart != null)
        setCryptoVerifyUseCertificateInBodyPart(StringParser.parseBool(sCryptoVerifyUseCertificateInBodyPart, DEFAULT_CRYPTO_VERIFY_USE_CERTIFICATE_IN_BODY_PART));
    final String sCryptoSignIncludeCertificateInBodyPart = eRoot.getAttributeValue(ATTR_CRYPTO_SIGN_INCLUDE_CERTIFICATE_IN_BODY_PART);
    if (sCryptoSignIncludeCertificateInBodyPart != null)
        setCryptoSignIncludeCertificateInBodyPart(StringParser.parseBool(sCryptoSignIncludeCertificateInBodyPart, DEFAULT_CRYPTO_SIGN_INCLUDE_CERTIFICATE_IN_BODY_PART));
    for (final IMicroElement eRootChild : eRoot.getAllChildElements()) {
        final String sNodeName = eRootChild.getTagName();
        if (sNodeName.equals(EL_CERTIFICATES))
            loadCertificates(eRootChild);
        else if (sNodeName.equals(EL_PROCESSOR))
            loadMessageProcessor(eRootChild);
        else if (sNodeName.equals(EL_CMDPROCESSOR))
            loadCommandProcessors(eRootChild);
        else if (sNodeName.equals(EL_PARTNERSHIPS))
            loadPartnerships(eRootChild);
        else if (sNodeName.equals(EL_COMMANDS))
            loadCommands(eRootChild);
        else
            throw new OpenAS2Exception("Undefined tag: " + sNodeName);
    }
}
Also used : OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument)

Example 19 with IMicroElement

use of com.helger.xml.microdom.IMicroElement in project as2-server by phax.

the class AddPartnerCommand method execute.

@Override
public CommandResult execute(final IPartnershipFactoryWithPartners partFx, final Object[] params) throws OpenAS2Exception {
    if (params.length < 1) {
        return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
    }
    final IMicroDocument doc = new MicroDocument();
    final IMicroElement root = doc.appendElement("partner");
    for (int i = 0; i < params.length; i++) {
        final String param = (String) params[i];
        final int pos = param.indexOf('=');
        if (i == 0) {
            root.setAttribute("name", param);
        } else if (pos == 0) {
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing name");
        } else if (pos > 0) {
            root.setAttribute(param.substring(0, pos), param.substring(pos + 1));
        } else
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing value");
    }
    final Partner aNewPartner = ((XMLPartnershipFactory) partFx).loadPartner(root);
    partFx.addPartner(aNewPartner);
    return new CommandResult(ECommandResultType.TYPE_OK);
}
Also used : IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument) Partner(com.helger.as2lib.partner.xml.Partner) XMLPartnershipFactory(com.helger.as2lib.partner.xml.XMLPartnershipFactory) CommandResult(com.helger.as2.cmd.CommandResult)

Example 20 with IMicroElement

use of com.helger.xml.microdom.IMicroElement in project as2-server by phax.

the class AddPartnershipCommand method execute.

@Override
public CommandResult execute(final IPartnershipFactoryWithPartners partFx, final Object[] params) throws OpenAS2Exception {
    if (params.length < 3)
        return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
    final IMicroDocument doc = new MicroDocument();
    final IMicroElement root = doc.appendElement("partnership");
    for (int nIndex = 0; nIndex < params.length; nIndex++) {
        final String param = (String) params[nIndex];
        final int pos = param.indexOf('=');
        if (nIndex == 0) {
            root.setAttribute("name", param);
        } else if (nIndex == 1) {
            final IMicroElement elem = root.appendElement("sender");
            elem.setAttribute("name", param);
        } else if (nIndex == 2) {
            final IMicroElement elem = root.appendElement("receiver");
            elem.setAttribute("name", param);
        } else if (pos == 0) {
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing name");
        } else if (pos > 0) {
            final IMicroElement elem = root.appendElement("attribute");
            elem.setAttribute("name", param.substring(0, pos));
            elem.setAttribute("value", param.substring(pos + 1));
        } else
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing value");
    }
    final XMLPartnershipFactory aXMLPartnershipFactory = (XMLPartnershipFactory) partFx;
    final Partnership aPartnership = aXMLPartnershipFactory.loadPartnership(root, aXMLPartnershipFactory.getPartnerMap());
    if (aXMLPartnershipFactory.getPartnershipByName(aPartnership.getName()) != null)
        return new CommandResult(ECommandResultType.TYPE_ERROR, "A partnership with name '" + aPartnership.getName() + "' is already present!");
    // add the partnership to the list of available partnerships
    partFx.addPartnership(aPartnership);
    return new CommandResult(ECommandResultType.TYPE_OK);
}
Also used : IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) Partnership(com.helger.as2lib.partner.Partnership) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument) XMLPartnershipFactory(com.helger.as2lib.partner.xml.XMLPartnershipFactory) CommandResult(com.helger.as2.cmd.CommandResult)

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