Search in sources :

Example 1 with MicroDocument

use of com.helger.xml.microdom.MicroDocument 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 2 with MicroDocument

use of com.helger.xml.microdom.MicroDocument 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)

Example 3 with MicroDocument

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

the class PSWriter method getAsDocument.

@Nonnull
@OverrideOnDemand
protected IMicroNode getAsDocument(@Nonnull final IMicroElement aElement) {
    final IMicroDocument aDoc = new MicroDocument();
    aDoc.appendChild(aElement);
    return aDoc;
}
Also used : IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) IMicroDocument(com.helger.xml.microdom.IMicroDocument) Nonnull(javax.annotation.Nonnull) OverrideOnDemand(com.helger.commons.annotation.OverrideOnDemand)

Aggregations

IMicroDocument (com.helger.xml.microdom.IMicroDocument)3 MicroDocument (com.helger.xml.microdom.MicroDocument)3 CommandResult (com.helger.as2.cmd.CommandResult)2 XMLPartnershipFactory (com.helger.as2lib.partner.xml.XMLPartnershipFactory)2 IMicroElement (com.helger.xml.microdom.IMicroElement)2 Partnership (com.helger.as2lib.partner.Partnership)1 Partner (com.helger.as2lib.partner.xml.Partner)1 OverrideOnDemand (com.helger.commons.annotation.OverrideOnDemand)1 Nonnull (javax.annotation.Nonnull)1