Java Code Examples for com.helger.xml.microdom.IMicroElement#setAttribute()

The following examples show how to use com.helger.xml.microdom.IMicroElement#setAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PSDiagnostic.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroElement ()
{
  final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_DIAGNOSTIC);
  ret.setAttribute (CSchematronXML.ATTR_ID, m_sID);
  if (m_aRich != null)
    m_aRich.fillMicroElement (ret);
  for (final Object aContent : m_aContent)
    if (aContent instanceof IMicroElement)
      ret.appendChild (((IMicroElement) aContent).getClone ());
    else
      if (aContent instanceof String)
        ret.appendText ((String) aContent);
      else
        ret.appendChild (((IPSElement) aContent).getAsMicroElement ());
  if (m_aForeignAttrs != null)
    for (final Map.Entry <String, String> aEntry : m_aForeignAttrs.entrySet ())
      ret.setAttribute (aEntry.getKey (), aEntry.getValue ());
  return ret;
}
 
Example 2
Source File: PSPattern.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroElement ()
{
  final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_PATTERN);
  if (m_bAbstract)
    ret.setAttribute (CSchematronXML.ATTR_ABSTRACT, "true");
  ret.setAttribute (CSchematronXML.ATTR_ID, m_sID);
  ret.setAttribute (CSchematronXML.ATTR_IS_A, m_sIsA);
  if (m_aRich != null)
    m_aRich.fillMicroElement (ret);
  for (final Object aContent : m_aContent)
    if (aContent instanceof IMicroElement)
      ret.appendChild (((IMicroElement) aContent).getClone ());
    else
      ret.appendChild (((IPSElement) aContent).getAsMicroElement ());
  if (m_aForeignAttrs != null)
    for (final Map.Entry <String, String> aEntry : m_aForeignAttrs.entrySet ())
      ret.setAttribute (aEntry.getKey (), aEntry.getValue ());
  return ret;
}
 
Example 3
Source File: PSActive.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroElement ()
{
  final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_ACTIVE);
  ret.setAttribute (CSchematronXML.ATTR_PATTERN, m_sPattern);
  for (final Object aContent : m_aContent)
    if (aContent instanceof IMicroElement)
      ret.appendChild (((IMicroElement) aContent).getClone ());
    else
      if (aContent instanceof String)
        ret.appendText ((String) aContent);
      else
        ret.appendChild (((IPSElement) aContent).getAsMicroElement ());
  if (m_aForeignAttrs != null)
    for (final Map.Entry <String, String> aEntry : m_aForeignAttrs.entrySet ())
      ret.setAttribute (aEntry.getKey (), aEntry.getValue ());
  return ret;
}
 
Example 4
Source File: PSDir.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroElement ()
{
  final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_DIR);
  if (m_eValue != null)
    ret.setAttribute (CSchematronXML.ATTR_VALUE, m_eValue.getID ());
  for (final Object aContent : m_aContent)
    if (aContent instanceof IMicroElement)
      ret.appendChild (((IMicroElement) aContent).getClone ());
    else
      ret.appendText ((String) aContent);
  if (m_aForeignAttrs != null)
    for (final Map.Entry <String, String> aEntry : m_aForeignAttrs.entrySet ())
      ret.setAttribute (aEntry.getKey (), aEntry.getValue ());
  return ret;
}
 
Example 5
Source File: MainCreateJAXBBinding23.java    From ph-ubl with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static IMicroDocument _createBaseDoc ()
{
  final IMicroDocument eDoc = new MicroDocument ();
  final IMicroElement eRoot = eDoc.appendElement (JAXB_NS_URI, "bindings");
  eRoot.setAttribute (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,
                      "schemaLocation",
                      JAXB_NS_URI + " http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd");
  // This is the JAXB version, not the UBL version :)
  eRoot.setAttribute ("version", "2.1");

  final IMicroElement eGlobal = eRoot.appendElement (JAXB_NS_URI, "globalBindings");
  eGlobal.setAttribute ("typesafeEnumMaxMembers", "2000");
  eGlobal.setAttribute ("typesafeEnumMemberName", "generateError");
  return eDoc;
}
 
Example 6
Source File: PSPhase.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroElement ()
{
  final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_PHASE);
  ret.setAttribute (CSchematronXML.ATTR_ID, m_sID);
  if (m_aRich != null)
    m_aRich.fillMicroElement (ret);
  for (final Object aContent : m_aContent)
    if (aContent instanceof IMicroElement)
      ret.appendChild (((IMicroElement) aContent).getClone ());
    else
      ret.appendChild (((IPSElement) aContent).getAsMicroElement ());
  if (m_aForeignAttrs != null)
    for (final Map.Entry <String, String> aEntry : m_aForeignAttrs.entrySet ())
      ret.setAttribute (aEntry.getKey (), aEntry.getValue ());
  return ret;
}
 
Example 7
Source File: MicroWriterTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrderNamespaces ()
{
  XMLWriterSettings aSettings = new XMLWriterSettings ().setIndent (EXMLSerializeIndent.NONE)
                                                        .setUseDoubleQuotesForAttributes (false);

  // default order
  final IMicroElement e = new MicroElement ("urn:stringdefault", "a");
  e.setAttribute ("urn:string3", "c", "1");
  e.setAttribute ("urn:string2", "b", "2");
  e.setAttribute ("urn:string1", "a", "3");
  // Attributes are ordered automatically in DOM!
  assertEquals ("<a xmlns='urn:stringdefault' xmlns:ns0='urn:string3' ns0:c='1' xmlns:ns1='urn:string2' ns1:b='2' xmlns:ns2='urn:string1' ns2:a='3' />",
                MicroWriter.getNodeAsString (e, aSettings));

  aSettings = aSettings.setOrderAttributesAndNamespaces (true);
  assertEquals ("<a xmlns='urn:stringdefault' xmlns:ns0='urn:string3' xmlns:ns1='urn:string2' xmlns:ns2='urn:string1' ns2:a='3' ns1:b='2' ns0:c='1' />",
                MicroWriter.getNodeAsString (e, aSettings));
}
 
Example 8
Source File: PSValueOf.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: PSInclude.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroElement ()
{
  final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_INCLUDE);
  ret.setAttribute (CSchematronXML.ATTR_HREF, m_sHref);
  return ret;
}
 
Example 10
Source File: PSSpan.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroElement ()
{
  final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_SPAN);
  ret.setAttribute (CSchematronXML.ATTR_CLASS, m_sClass);
  for (final Object aContent : m_aContent)
    if (aContent instanceof IMicroElement)
      ret.appendChild (((IMicroElement) aContent).getClone ());
    else
      ret.appendText ((String) aContent);
  if (m_aForeignAttrs != null)
    for (final Map.Entry <String, String> aEntry : m_aForeignAttrs.entrySet ())
      ret.setAttribute (aEntry.getKey (), aEntry.getValue ());
  return ret;
}
 
Example 11
Source File: PSNS.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroElement ()
{
  final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_NS);
  ret.setAttribute (CSchematronXML.ATTR_PREFIX, m_sPrefix);
  ret.setAttribute (CSchematronXML.ATTR_URI, m_sUri);
  if (m_aForeignAttrs != null)
    for (final Map.Entry <String, String> aEntry : m_aForeignAttrs.entrySet ())
      ret.setAttribute (aEntry.getKey (), aEntry.getValue ());
  return ret;
}
 
Example 12
Source File: MicroSerializerTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
private IMicroDocument _createLargeDoc (@Nonnull final IMicroDocument doc,
                                        final boolean bWithText,
                                        final boolean bWithAttrs)
{
  final IMicroElement aDocElement = doc.appendElement ("root");
  for (int i = 1; i <= 10; ++i)
  {
    final IMicroElement e1 = aDocElement.appendElement ("level1");
    if (bWithAttrs)
    {
      e1.setAttribute ("a1", "Supsi1");
      e1.setAttribute ("a1a", "Supsi1a");
    }
    for (int j = 1; j <= 20; ++j)
    {
      final IMicroElement e2 = e1.appendElement ("level2");
      if (bWithAttrs)
        e2.setAttribute ("a2", "Supsi");
      for (int k = 1; k <= 100; ++k)
      {
        final IMicroElement e3 = e2.appendElement ("level3");
        if (bWithAttrs)
          e3.setAttribute ("a3", "Supsi");
        if (bWithText)
          e3.appendText ("Level 3 text <> " + Double.toString (Math.random ()));
      }
      if (bWithText)
        e2.appendText ("Level 2 text " + Double.toString (Math.random ()));
    }
    if (bWithText)
      e1.appendText ("Level 1 text " + Double.toString (Math.random ()));
  }
  return doc;
}
 
Example 13
Source File: MainCreateSupportedCSSPropertiesFile.java    From ph-css with Apache License 2.0 5 votes vote down vote up
private static void _boolean (@Nonnull final IMicroElement td, final boolean bSet, @Nullable final String sTitle)
{
  if (bSet)
  {
    td.setAttribute ("class", "center").appendText ("X");
    if (StringHelper.hasText (sTitle))
      td.setAttribute ("title", sTitle);
  }
  else
    td.appendText ("");
}
 
Example 14
Source File: XMLListHandler.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static IMicroDocument createListDocument (@Nonnull final Collection <String> aCollection)
{
  ValueEnforcer.notNull (aCollection, "Collection");

  final IMicroDocument aDoc = new MicroDocument ();
  final IMicroElement eRoot = aDoc.appendElement (ELEMENT_LIST);
  for (final String sItem : aCollection)
  {
    final IMicroElement eItem = eRoot.appendElement (ELEMENT_ITEM);
    eItem.setAttribute (ATTR_VALUE, sItem);
  }
  return aDoc;
}
 
Example 15
Source File: ColorMicroTypeConverter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public IMicroElement convertToMicroElement (@Nonnull final Color aObject,
                                            @Nullable final String sNamespaceURI,
                                            @Nonnull final String sTagName)
{
  final IMicroElement aElement = new MicroElement (sNamespaceURI, sTagName);

  aElement.setAttribute (ATTR_RED, aObject.getRed ());
  aElement.setAttribute (ATTR_GREEN, aObject.getGreen ());
  aElement.setAttribute (ATTR_BLUE, aObject.getBlue ());
  aElement.setAttribute (ATTR_ALPHA, aObject.getAlpha ());

  return aElement;
}
 
Example 16
Source File: PSDiagnostics.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroElement ()
{
  final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_DIAGNOSTICS);
  for (final Object aContent : m_aContent)
    if (aContent instanceof IMicroElement)
      ret.appendChild (((IMicroElement) aContent).getClone ());
    else
      ret.appendChild (((IPSElement) aContent).getAsMicroElement ());
  if (m_aForeignAttrs != null)
    for (final Map.Entry <String, String> aEntry : m_aForeignAttrs.entrySet ())
      ret.setAttribute (aEntry.getKey (), aEntry.getValue ());
  return ret;
}
 
Example 17
Source File: PSLet.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroElement ()
{
  final IMicroElement ret = new MicroElement (CSchematron.NAMESPACE_SCHEMATRON, CSchematronXML.ELEMENT_LET);
  ret.setAttribute (CSchematronXML.ATTR_NAME, m_sName);
  ret.setAttribute (CSchematronXML.ATTR_VALUE, m_sValue);
  return ret;
}
 
Example 18
Source File: MainCreateJAXBBinding20.java    From ph-ubl with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static IMicroDocument _createBaseDoc ()
{
  final IMicroDocument eDoc = new MicroDocument ();
  final IMicroElement eRoot = eDoc.appendElement (JAXB_NS_URI, "bindings");
  eRoot.setAttribute ("xsi:schemaLocation", JAXB_NS_URI + " http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd");
  eRoot.setAttribute ("version", "2.1");

  final IMicroElement eGlobal = eRoot.appendElement (JAXB_NS_URI, "globalBindings");
  eGlobal.setAttribute ("typesafeEnumMaxMembers", "2000");
  eGlobal.setAttribute ("typesafeEnumMemberName", "generateError");
  return eDoc;
}
 
Example 19
Source File: PSLinkableGroup.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
public void fillMicroElement (@Nonnull final IMicroElement aElement)
{
  aElement.setAttribute (CSchematronXML.ATTR_ROLE, m_sRole);
  aElement.setAttribute (CSchematronXML.ATTR_SUBJECT, m_sSubject);
}
 
Example 20
Source File: ThreadDescriptor.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroNode ()
{
  final IMicroElement eRet = new MicroElement ("thread");
  eRet.setAttribute ("id", m_nID);
  eRet.setAttribute ("name", m_sName);
  if (m_eState != null)
    eRet.setAttribute ("state", m_eState.toString ());
  eRet.setAttribute ("priority", m_nPriority);
  eRet.setAttribute ("threadgroup", m_sThreadGroup);
  eRet.appendElement ("stacktrace").appendText (getStackTraceNotNull ());
  if (m_aThreadInfo != null)
  {
    final IMicroElement eThreadInfo = eRet.appendElement ("threadinfo");
    try
    {
      final MonitorInfo [] aMonitorInfos = m_aThreadInfo.getLockedMonitors ();
      if (ArrayHelper.isNotEmpty (aMonitorInfos))
      {
        final IMicroElement eMonitorInfos = eThreadInfo.appendElement ("monitorinfos");
        eMonitorInfos.setAttribute ("count", aMonitorInfos.length);
        for (final MonitorInfo aMonitorInfo : aMonitorInfos)
        {
          final IMicroElement eMonitor = eMonitorInfos.appendElement ("monitor");
          eMonitor.setAttribute ("classname", aMonitorInfo.getClassName ());
          eMonitor.setAttribute ("identity", Integer.toHexString (aMonitorInfo.getIdentityHashCode ()));
          if (aMonitorInfo.getLockedStackFrame () != null)
            eMonitor.setAttribute ("stackframe", aMonitorInfo.getLockedStackFrame ().toString ());
          if (aMonitorInfo.getLockedStackDepth () >= 0)
            eMonitor.setAttribute ("stackdepth", aMonitorInfo.getLockedStackDepth ());
        }
      }

      final LockInfo [] aSynchronizers = m_aThreadInfo.getLockedSynchronizers ();
      if (ArrayHelper.isNotEmpty (aSynchronizers))
      {
        final IMicroElement eSynchronizers = eThreadInfo.appendElement ("synchronizers");
        eSynchronizers.setAttribute ("count", aSynchronizers.length);
        for (final LockInfo aSynchronizer : aSynchronizers)
        {
          final IMicroElement eSynchronizer = eSynchronizers.appendElement ("synchronizer");
          eSynchronizer.setAttribute ("classname", aSynchronizer.getClassName ());
          eSynchronizer.setAttribute ("identity", Integer.toHexString (aSynchronizer.getIdentityHashCode ()));
        }
      }
    }
    catch (final Exception ex)
    {
      eThreadInfo.setAttribute ("error", ex.getMessage ()).appendText (StackTraceHelper.getStackAsString (ex));
    }
  }
  return eRet;
}