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