Search in sources :

Example 1 with IMicroDocument

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

the class PSXPathBoundSchemaTest method testSchematronValidation.

@Test
public void testSchematronValidation() throws SAXException, SchematronException {
    for (int i = 0; i < SCH.length; ++i) {
        final IReadableResource aSchRes = new ClassPathResource("test-sch/" + SCH[i]);
        final IReadableResource aXmlRes = new ClassPathResource("test-xml/" + XML[i]);
        // Resolve all includes
        final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aSchRes);
        assertNotNull(aDoc);
        // Read to domain object
        final PSReader aReader = new PSReader(aSchRes);
        final PSSchema aSchema = aReader.readSchemaFromXML(aDoc.getDocumentElement());
        assertNotNull(aSchema);
        // Create a compiled schema
        final String sPhaseID = null;
        final IPSErrorHandler aErrorHandler = null;
        final IPSBoundSchema aBoundSchema = PSXPathQueryBinding.getInstance().bind(aSchema, sPhaseID, aErrorHandler);
        // Validate completely
        final SchematronOutputType aSVRL = aBoundSchema.validateComplete(DOMReader.readXMLDOM(aXmlRes), aXmlRes.getAsURL().toExternalForm());
        assertNotNull(aSVRL);
        if (false)
            System.out.println(new SVRLMarshaller().getAsString(aSVRL));
    }
}
Also used : IPSErrorHandler(com.helger.schematron.pure.errorhandler.IPSErrorHandler) SchematronOutputType(org.oclc.purl.dsdl.svrl.SchematronOutputType) IPSBoundSchema(com.helger.schematron.pure.bound.IPSBoundSchema) IReadableResource(com.helger.commons.io.resource.IReadableResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) IMicroDocument(com.helger.xml.microdom.IMicroDocument) PSReader(com.helger.schematron.pure.exchange.PSReader) PSSchema(com.helger.schematron.pure.model.PSSchema) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 2 with IMicroDocument

use of com.helger.xml.microdom.IMicroDocument in project ph-css by phax.

the class MainFetchW3C_CSSTests method _fetch.

private static void _fetch(final String sURL, final String sDestDir) throws MalformedURLException {
    final ICommonsList<String> aCSSFilenames = new CommonsArrayList<>();
    System.out.println("Fetching from " + sURL);
    final ICommonsList<String> aIndex = StreamHelper.readStreamLines(new URLResource(sURL + "index.html"), StandardCharsets.UTF_8);
    {
        // Remove doctype
        aIndex.remove(0);
        // Fix HTML to be XML
        for (int i = 0; i < aIndex.size(); ++i) {
            final String sLine = aIndex.get(i);
            if (sLine.contains("<link"))
                aIndex.set(i, sLine + "</link>");
        }
    }
    final IMicroDocument aDoc = MicroReader.readMicroXML(StringHelper.getImploded('\n', aIndex));
    MicroVisitor.visit(aDoc, new DefaultHierarchyVisitorCallback<IMicroNode>() {

        @Override
        public EHierarchyVisitorReturn onItemBeforeChildren(final IMicroNode aItem) {
            if (aItem.isElement()) {
                final IMicroElement e = (IMicroElement) aItem;
                if (e.getTagName().equals("a")) {
                    final String sHref = e.getAttributeValue("href");
                    if (sHref.endsWith(".xml"))
                        aCSSFilenames.add(StringHelper.replaceAll(sHref, ".xml", ".css"));
                }
            }
            return EHierarchyVisitorReturn.CONTINUE;
        }
    });
    System.out.println("Fetching a total of " + aCSSFilenames.size() + " files");
    int i = 0;
    for (final String sCSSFilename : aCSSFilenames) {
        System.out.println("  " + (++i) + ".: " + sCSSFilename);
        final String sContent = StreamHelper.getAllBytesAsString(new URLResource(sURL + sCSSFilename), StandardCharsets.UTF_8);
        SimpleFileIO.writeFile(new File(sDestDir, sCSSFilename), sContent, StandardCharsets.UTF_8);
    }
}
Also used : URLResource(com.helger.commons.io.resource.URLResource) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroNode(com.helger.xml.microdom.IMicroNode) EHierarchyVisitorReturn(com.helger.commons.hierarchy.visit.EHierarchyVisitorReturn) IMicroDocument(com.helger.xml.microdom.IMicroDocument) File(java.io.File) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Example 3 with IMicroDocument

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

the class SchematronValidatorTest method testSchematron.

@Test
public void testSchematron() {
    // Check all documents
    for (final IReadableResource aRes : SchematronTestHelper.getAllValidSchematronFiles()) {
        final IMicroDocument aDoc = SchematronHelper.getWithResolvedSchematronIncludes(aRes);
        final boolean bIsValid = SchematronValidator.isValidSchematron(aDoc);
        assertTrue(aRes.getPath(), bIsValid);
    }
}
Also used : IReadableResource(com.helger.commons.io.resource.IReadableResource) IMicroDocument(com.helger.xml.microdom.IMicroDocument) Test(org.junit.Test)

Example 4 with IMicroDocument

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

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

Aggregations

IMicroDocument (com.helger.xml.microdom.IMicroDocument)14 IMicroElement (com.helger.xml.microdom.IMicroElement)7 IReadableResource (com.helger.commons.io.resource.IReadableResource)6 Nonnull (javax.annotation.Nonnull)4 Test (org.junit.Test)4 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)3 PSReader (com.helger.schematron.pure.exchange.PSReader)3 PSSchema (com.helger.schematron.pure.model.PSSchema)3 MicroDocument (com.helger.xml.microdom.MicroDocument)3 File (java.io.File)3 CommandResult (com.helger.as2.cmd.CommandResult)2 OpenAS2Exception (com.helger.as2lib.exception.OpenAS2Exception)2 XMLPartnershipFactory (com.helger.as2lib.partner.xml.XMLPartnershipFactory)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 IMicroNode (com.helger.xml.microdom.IMicroNode)2 Partnership (com.helger.as2lib.partner.Partnership)1 Partner (com.helger.as2lib.partner.xml.Partner)1 ValueEnforcer (com.helger.commons.ValueEnforcer)1 Nonempty (com.helger.commons.annotation.Nonempty)1 OverrideOnDemand (com.helger.commons.annotation.OverrideOnDemand)1