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));
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
Aggregations