Search in sources :

Example 1 with IMicroElement

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

the class PSSpan method getAsMicroElement.

@Nonnull
public IMicroElement getAsMicroElement() {
    final IMicroElement ret = new MicroElement(CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_SPAN);
    ret.setAttribute(CSchematronXML.ATTR_CLASS, m_sClass);
    if (m_aForeignElements != null)
        for (final IMicroElement aForeignElement : m_aForeignElements) ret.appendChild(aForeignElement.getClone());
    for (final String sContent : m_aContent) ret.appendText(sContent);
    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 2 with IMicroElement

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

the class PSValueOf method getAsMicroElement.

@Nonnull
public IMicroElement getAsMicroElement() {
    final IMicroElement ret = new MicroElement(CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_VALUE_OF);
    ret.setAttribute(CSchematronXML.ATTR_SELECT, m_sSelect);
    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 3 with IMicroElement

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

the class MainCreateSupportedCSSPropertiesFile method main.

public static void main(final String[] args) {
    final Locale aLocale = Locale.US;
    final IMicroElement html = new MicroElement("html");
    final IMicroElement head = html.appendElement("head");
    head.appendElement("title").appendText("Supported CSS properties in ph-css");
    head.appendElement("style").appendText("* {font-family:Arial,Helvetica;}" + " table{border-collapse:collapse;}" + " td,th {border:solid 1px black;padding:3px;vertical-align:top; }" + " .odd{background-color:#ddd;}" + " .center{text-align:center;}" + " .nowrap{white-space:nowrap;}" + " a, a:link, a:visited, a:hover, a:active{color:blue;}");
    final IMicroElement body = html.appendElement("body");
    body.appendElement("div").appendText("Automatically generated by " + ClassHelper.getClassLocalName(MainCreateSupportedCSSPropertiesFile.class) + " on " + new Date().toString());
    body.appendElement("div").appendElement("a").setAttribute("href", "#generic").appendText("Generic properties");
    body.appendElement("div").appendElement("a").setAttribute("href", "#vendor").appendText("Vendor specific properties");
    body.appendElement("a").setAttribute("name", "generic").appendText("");
    body.appendElement("h1").appendText("Generic properties");
    IMicroElement table = body.appendElement("table");
    IMicroElement thead = table.appendElement("thead");
    IMicroElement tr = thead.appendElement("tr");
    tr.appendElement("th").appendText("Name");
    tr.appendElement("th").appendText("CSS 1.0");
    tr.appendElement("th").appendText("CSS 2.1");
    tr.appendElement("th").appendText("CSS 3.0");
    tr.appendElement("th").appendText("Links");
    IMicroElement tbody = table.appendElement("tbody");
    int nIndex = 0;
    for (final ECSSProperty eProperty : CollectionHelper.getSorted(ECSSProperty.values(), IHasName.getComparatorName())) if (!eProperty.isVendorSpecific()) {
        final Version eMinVersion = eProperty.getMinimumCSSVersion().getVersion();
        final boolean bCSS10 = eMinVersion.isLE(ECSSVersion.CSS10.getVersion());
        final boolean bCSS21 = eMinVersion.isLE(ECSSVersion.CSS21.getVersion());
        final boolean bCSS30 = eMinVersion.isLE(ECSSVersion.CSS30.getVersion());
        tr = tbody.appendElement("tr");
        if ((nIndex & 1) == 1)
            tr.setAttribute("class", "odd");
        tr.appendElement("td").setAttribute("class", "nowrap").appendText(eProperty.getName());
        _boolean(tr.appendElement("td"), bCSS10, null);
        _boolean(tr.appendElement("td"), bCSS21, null);
        _boolean(tr.appendElement("td"), bCSS30, null);
        final IMicroElement td = tr.appendElement("td");
        for (final ECSSSpecification eSpecs : eProperty.getAllSpecifications()) if (eSpecs.hasHandledURL())
            td.appendElement("div").appendElement("a").setAttribute("href", eSpecs.getHandledURL()).setAttribute("target", "_blank").appendText(eSpecs.getID());
        else
            td.appendElement("div").appendText(eSpecs.getID());
        ++nIndex;
    }
    // Determine all used vendor prefixes
    final EnumSet<ECSSVendorPrefix> aRequiredPrefixes = EnumSet.noneOf(ECSSVendorPrefix.class);
    for (final ECSSVendorPrefix eVendorPrefix : ECSSVendorPrefix.values()) {
        for (final ECSSProperty eProperty : ECSSProperty.values()) if (eProperty.isVendorSpecific(eVendorPrefix)) {
            aRequiredPrefixes.add(eVendorPrefix);
            break;
        }
    }
    body.appendElement("a").setAttribute("name", "vendor").appendText("");
    body.appendElement("h1").appendText("Vendor specific properties");
    table = body.appendElement("table");
    thead = table.appendElement("thead");
    tr = thead.appendElement("tr");
    tr.appendElement("th").appendText("Name");
    for (final ECSSVendorPrefix e : aRequiredPrefixes) {
        final IMicroElement th = tr.appendElement("th");
        th.appendText(e.getDisplayName());
        th.appendElement("span").setAttribute("class", "nowrap").appendText(" (" + e.getPrefix() + ")");
    }
    tbody = table.appendElement("tbody");
    nIndex = 0;
    for (final ECSSProperty eProperty : CollectionHelper.getSorted(ECSSProperty.values(), IComparator.getComparatorCollating(ECSSProperty::getVendorIndependentName, aLocale))) if (eProperty.isVendorSpecific()) {
        tr = tbody.appendElement("tr");
        if ((nIndex & 1) == 1)
            tr.setAttribute("class", "odd");
        tr.appendElement("td").setAttribute("class", "nowrap").appendText(eProperty.getVendorIndependentName());
        for (final ECSSVendorPrefix e : aRequiredPrefixes) _boolean(tr.appendElement("td"), eProperty.isVendorSpecific(e), eProperty.getName());
        ++nIndex;
    }
    body.appendElement("div").setAttribute("style", "margin:2em 0").appendText("That's it.");
    String sHTML = "<!--\r\n" + "\r\n" + "    Copyright (C) 2014 Philip Helger (www.helger.com)\r\n" + "    philip[at]helger[dot]com\r\n" + "\r\n" + "    Licensed under the Apache License, Version 2.0 (the \"License\");\r\n" + "    you may not use this file except in compliance with the License.\r\n" + "    You may obtain a copy of the License at\r\n" + "\r\n" + "            http://www.apache.org/licenses/LICENSE-2.0\r\n" + "\r\n" + "    Unless required by applicable law or agreed to in writing, software\r\n" + "    distributed under the License is distributed on an \"AS IS\" BASIS,\r\n" + "    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n" + "    See the License for the specific language governing permissions and\r\n" + "    limitations under the License.\r\n" + "\r\n" + "-->\r\n";
    sHTML += MicroWriter.getNodeAsString(html, new XMLWriterSettings().setIndent(EXMLSerializeIndent.ALIGN_ONLY).setSerializeVersion(EXMLSerializeVersion.HTML));
    SimpleFileIO.writeFile(new File("src/main/resources/supported-css-properties.html"), sHTML, StandardCharsets.UTF_8);
    System.out.println("Done");
}
Also used : Locale(java.util.Locale) MicroElement(com.helger.xml.microdom.MicroElement) IMicroElement(com.helger.xml.microdom.IMicroElement) XMLWriterSettings(com.helger.xml.serialize.write.XMLWriterSettings) ECSSVendorPrefix(com.helger.css.ECSSVendorPrefix) Date(java.util.Date) ECSSSpecification(com.helger.css.ECSSSpecification) ECSSVersion(com.helger.css.ECSSVersion) EXMLSerializeVersion(com.helger.xml.serialize.write.EXMLSerializeVersion) Version(com.helger.commons.version.Version) IMicroElement(com.helger.xml.microdom.IMicroElement) ECSSProperty(com.helger.css.property.ECSSProperty) File(java.io.File)

Example 4 with IMicroElement

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

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

the class PSWriter method writeToStream.

/**
 * Write the passed Schematron element to the passed output stream.
 *
 * @param aPSElement
 *        The schematron element to write. May not be <code>null</code>.
 * @param aOS
 *        The output stream to write things to. May not be <code>null</code>.
 *        The stream is automatically closed.
 * @return {@link ESuccess}.
 */
@Nonnull
public ESuccess writeToStream(@Nonnull final IPSElement aPSElement, @Nonnull @WillClose final OutputStream aOS) {
    ValueEnforcer.notNull(aPSElement, "PSElement");
    final IMicroElement eXML = aPSElement.getAsMicroElement();
    return MicroWriter.writeToStream(getAsDocument(eXML), aOS, m_aWriterSettings.getXMLWriterSettings());
}
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