com.helger.xml.microdom.IMicroElement Java Examples

The following examples show how to use com.helger.xml.microdom.IMicroElement. 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: PSRule.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_RULE);
  ret.setAttribute (CSchematronXML.ATTR_FLAG, m_sFlag);
  if (m_bAbstract)
    ret.setAttribute (CSchematronXML.ATTR_ABSTRACT, "true");
  ret.setAttribute (CSchematronXML.ATTR_CONTEXT, m_sContext);
  ret.setAttribute (CSchematronXML.ATTR_ID, m_sID);
  if (m_aRich != null)
    m_aRich.fillMicroElement (ret);
  if (m_aLinkable != null)
    m_aLinkable.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 #2
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 #3
Source File: MultilingualTextMicroTypeConverterRegistrarTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiLingualText ()
{
  final MultilingualText aMLT = new MultilingualText ();
  aMLT.setText (Locale.GERMAN, "Cumberlandstraße");
  aMLT.setText (Locale.CHINA, "Whatsoever");

  final IMicroElement aElement = MicroTypeConverter.convertToMicroElement (aMLT, "mtext");
  assertNotNull (aElement);
  assertNull (MicroTypeConverter.convertToMicroElement (null, "mtext"));

  final MultilingualText aMLT2 = MicroTypeConverter.convertToNative (aElement, MultilingualText.class);
  assertEquals (aMLT, aMLT2);
  assertNull (MicroTypeConverter.convertToNative (null, MultilingualText.class));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aMLT, aMLT2);
}
 
Example #4
Source File: MultilingualTextMicroTypeConverterRegistrarTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadonlyMultiLingualText ()
{
  final ReadOnlyMultilingualText aMLT = new ReadOnlyMultilingualText (CollectionHelper.newMap (new Locale [] { Locale.GERMAN,
                                                                                                               Locale.CHINA },
                                                                                               new String [] { "Cumberlandstraße",
                                                                                                               "Whatspever" }));

  final IMicroElement aElement = MicroTypeConverter.convertToMicroElement (aMLT, "mtext");
  assertNotNull (aElement);

  final ReadOnlyMultilingualText aMLT2 = MicroTypeConverter.convertToNative (aElement,
                                                                             ReadOnlyMultilingualText.class);
  assertEquals (aMLT, aMLT2);
  assertNull (MicroTypeConverter.convertToNative (null, ReadOnlyMultilingualText.class));

  CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aMLT, aMLT2);
}
 
Example #5
Source File: MicroHelperTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetPath ()
{
  final IMicroDocument aDoc = new MicroDocument ();
  assertEquals ("#document", MicroHelper.getPath (aDoc, "/"));
  final IMicroElement eRoot = aDoc.appendElement ("root");
  assertEquals ("#document/root", MicroHelper.getPath (eRoot, "/"));
  final IMicroElement eChild = eRoot.appendElement ("child");
  assertEquals ("#document/root/child", MicroHelper.getPath (eChild, "/"));
  assertEquals ("", MicroHelper.getPath (null, "/"));
  try
  {
    MicroHelper.getPath (eChild, null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
Example #6
Source File: PSP.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_P);
  ret.setAttribute (CSchematronXML.ATTR_ID, m_sID);
  ret.setAttribute (CSchematronXML.ATTR_CLASS, m_sClass);
  ret.setAttribute (CSchematronXML.ATTR_ICON, m_sIcon);
  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 #7
Source File: StatisticsVisitorCallbackToXML.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Override
public void onKeyedCounter (final String sName, final IStatisticsHandlerKeyedCounter aHandler)
{
  if (aHandler.getInvocationCount () > 0)
  {
    final IMicroElement eKeyedCounter = m_eRoot.appendElement (StatisticsExporter.ELEMENT_KEYEDCOUNTER)
                                               .setAttribute (StatisticsExporter.ATTR_NAME, sName)
                                               .setAttribute (StatisticsExporter.ATTR_INVOCATIONCOUNT,
                                                              aHandler.getInvocationCount ());
    for (final String sKey : aHandler.getAllKeys ().getSorted (Comparator.naturalOrder ()))
    {
      eKeyedCounter.appendElement (StatisticsExporter.ELEMENT_KEY)
                   .setAttribute (StatisticsExporter.ATTR_NAME, sKey)
                   .setAttribute (StatisticsExporter.ATTR_INVOCATIONCOUNT, aHandler.getInvocationCount (sKey))
                   .setAttribute (StatisticsExporter.ATTR_COUNT, aHandler.getCount (sKey));
    }
  }
}
 
Example #8
Source File: StatisticsVisitorCallbackToXML.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Override
public void onKeyedSize (final String sName, final IStatisticsHandlerKeyedSize aHandler)
{
  if (aHandler.getInvocationCount () > 0)
  {
    final IMicroElement eKeyedSize = m_eRoot.appendElement (StatisticsExporter.ELEMENT_KEYEDSIZE)
                                            .setAttribute (StatisticsExporter.ATTR_NAME, sName)
                                            .setAttribute (StatisticsExporter.ATTR_INVOCATIONCOUNT,
                                                           aHandler.getInvocationCount ());
    for (final String sKey : aHandler.getAllKeys ().getSorted (Comparator.naturalOrder ()))
    {
      eKeyedSize.appendElement (StatisticsExporter.ELEMENT_KEY)
                .setAttribute (StatisticsExporter.ATTR_NAME, sKey)
                .setAttribute (StatisticsExporter.ATTR_INVOCATIONCOUNT, aHandler.getInvocationCount (sKey))
                .setAttribute (StatisticsExporter.ATTR_MIN, aHandler.getMin (sKey))
                .setAttribute (StatisticsExporter.ATTR_AVERAGE, aHandler.getAverage (sKey))
                .setAttribute (StatisticsExporter.ATTR_MAX, aHandler.getMax (sKey))
                .setAttributeWithConversion (StatisticsExporter.ATTR_SUM, aHandler.getSum (sKey));
    }
  }
}
 
Example #9
Source File: MicroHelperTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetChildTextContentWithConversionAndNS ()
{
  final String sNSURI = "my-namespace-uri";
  final IMicroElement e = new MicroElement (sNSURI, "x");
  assertNull (MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
  final IMicroElement y = e.appendElement (sNSURI, "y");
  assertNull (MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
  y.appendText ("100");
  assertEquals (CGlobal.BIGINT_100, MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
  y.appendElement ("a");
  assertEquals (CGlobal.BIGINT_100, MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
  y.appendCDATA ("234");
  assertEquals (BigInteger.valueOf (100234),
                MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
}
 
Example #10
Source File: PSReader.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
/**
 * Read an &lt;include&gt; element
 *
 * @param eInclude
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSInclude readIncludeFromXML (@Nonnull final IMicroElement eInclude)
{
  final PSInclude ret = new PSInclude ();

  eInclude.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_HREF))
      ret.setHref (sAttrValue);
    else
      _warn (ret, "Unsupported attribute '" + sAttrName + "'='" + sAttrValue + "'");
  });

  eInclude.forAllChildElements (eValueOfChild -> {
    if (isValidSchematronNS (eValueOfChild.getNamespaceURI ()))
    {
      _warn (ret, "Unsupported Schematron element '" + eValueOfChild.getLocalName () + "'");
    }
    else
      _warn (ret, "Unsupported namespace URI '" + eValueOfChild.getNamespaceURI () + "'");
  });
  return ret;
}
 
Example #11
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 #12
Source File: ChildrenProviderElementWithNameTest.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic ()
{
  final IMicroDocument aDoc = _buildTestDoc ();
  final IMicroElement aDocElement = aDoc.getDocumentElement ();

  ChildrenProviderElementWithName x = new ChildrenProviderElementWithName ("any");

  assertTrue (x.hasChildren (aDocElement));
  assertEquals (2, x.getChildCount (aDocElement));
  assertEquals (2, x.getAllChildren (aDocElement).size ());

  x = new ChildrenProviderElementWithName ("namespace", "any");

  assertTrue (x.hasChildren (aDocElement));
  assertEquals (1, x.getChildCount (aDocElement));
  assertEquals (1, x.getAllChildren (aDocElement).size ());
}
 
Example #13
Source File: PSReader.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
/**
 * Read a &lt;value-of&gt; element
 *
 * @param eValueOf
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSValueOf readValueOfFromXML (@Nonnull final IMicroElement eValueOf)
{
  final PSValueOf ret = new PSValueOf ();

  eValueOf.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_SELECT))
      ret.setSelect (sAttrValue);
    else
      ret.addForeignAttribute (sAttrName, sAttrValue);
  });

  eValueOf.forAllChildElements (eValueOfChild -> {
    if (isValidSchematronNS (eValueOfChild.getNamespaceURI ()))
    {
      _warn (ret, "Unsupported Schematron element '" + eValueOfChild.getLocalName () + "'");
    }
    else
      _warn (ret, "Unsupported namespace URI '" + eValueOfChild.getNamespaceURI () + "'");
  });
  return ret;
}
 
Example #14
Source File: MicroTypeConverter.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
public static <T> IMicroElement convertToMicroElement (@Nullable final T aObject,
                                                       @Nullable final String sNamespaceURI,
                                                       @Nonnull @Nonempty final String sTagName)
{
  ValueEnforcer.notEmpty (sTagName, "TagName");

  if (aObject == null)
    return null;

  // Lookup converter
  final Class <T> aSrcClass = GenericReflection.uncheckedCast (aObject.getClass ());
  final IMicroTypeConverter <T> aConverter = MicroTypeConverterRegistry.getInstance ()
                                                                       .getConverterToMicroElement (aSrcClass);
  if (aConverter == null)
    throw new TypeConverterException (aSrcClass, IMicroElement.class, EReason.NO_CONVERTER_FOUND);

  // Perform conversion
  final IMicroElement ret = aConverter.convertToMicroElement (aObject, sNamespaceURI, sTagName);
  if (ret == null)
    throw new TypeConverterException (aSrcClass, IMicroElement.class, EReason.CONVERSION_FAILED);
  return ret;
}
 
Example #15
Source File: PSReader.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
/**
 * Read an &lt;extends&gt; element
 *
 * @param eExtends
 *        The source micro element. Never <code>null</code>.
 * @return The created domain object. May not be <code>null</code>.
 */
@Nonnull
public PSExtends readExtendsFromXML (@Nonnull final IMicroElement eExtends)
{
  final PSExtends ret = new PSExtends ();

  eExtends.forAllAttributes ( (sNS, sAttrName, sVal) -> {
    final String sAttrValue = _getAttributeValue (sVal);
    if (sAttrName.equals (CSchematronXML.ATTR_RULE))
      ret.setRule (sAttrValue);
    else
      ret.addForeignAttribute (sAttrName, sAttrValue);
  });

  eExtends.forAllChildElements (eChild -> {
    if (isValidSchematronNS (eChild.getNamespaceURI ()))
    {
      _warn (ret, "Unsupported Schematron element '" + eChild.getLocalName () + "'");
    }
    else
      _warn (ret, "Unsupported namespace URI '" + eChild.getNamespaceURI () + "'");
  });
  return ret;
}
 
Example #16
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 #17
Source File: ChildrenProviderElementWithName.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnegative
public int getChildCount (@Nullable final IMicroElement aCurrent)
{
  if (aCurrent == null)
    return 0;
  return getAllChildren (aCurrent).size ();
}
 
Example #18
Source File: XMLMapHandler.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static IMicroDocument createMapDocument (@Nonnull final Map <String, String> aMap)
{
  ValueEnforcer.notNull (aMap, "Map");

  final IMicroDocument aDoc = new MicroDocument ();
  final IMicroElement eRoot = aDoc.appendElement (ELEMENT_MAPPING);
  for (final Map.Entry <String, String> aEntry : aMap.entrySet ())
  {
    final IMicroElement eMap = eRoot.appendElement (ELEMENT_MAP);
    eMap.setAttribute (ATTR_KEY, aEntry.getKey ());
    eMap.setAttribute (ATTR_VALUE, aEntry.getValue ());
  }
  return aDoc;
}
 
Example #19
Source File: ReadWriteXML11FuncTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
private static void _generateXmlFile (final String sFilename, @Nonnegative final int nElementCount)
{
  final IMicroDocument aDoc = new MicroDocument ();
  final IMicroElement eMain = aDoc.appendElement ("main_tag");
  for (int i = 0; i < nElementCount; ++i)
    eMain.appendElement ("test").appendText (StringHelper.getLeadingZero (i, 4));

  assertTrue (MicroWriter.writeToFile (aDoc, new File (sFilename), XWS_11).isSuccess ());
}
 
Example #20
Source File: PSAssertReport.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,
                                              m_bIsAssert ? CSchematronXML.ELEMENT_ASSERT
                                                          : CSchematronXML.ELEMENT_REPORT);
  ret.setAttribute (CSchematronXML.ATTR_ID, m_sID);
  ret.setAttribute (CSchematronXML.ATTR_FLAG, m_sFlag);
  ret.setAttribute (CSchematronXML.ATTR_TEST, m_sTest);
  if (CollectionHelper.isNotEmpty (m_aDiagnostics))
    ret.setAttribute (CSchematronXML.ATTR_DIAGNOSTICS, StringHelper.getImploded (' ', m_aDiagnostics));
  if (m_aRich != null)
    m_aRich.fillMicroElement (ret);
  if (m_aLinkable != null)
    m_aLinkable.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 #21
Source File: PSP.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public void addForeignElement (@Nonnull final IMicroElement aForeignElement)
{
  ValueEnforcer.notNull (aForeignElement, "ForeignElement");
  if (aForeignElement.hasParent ())
    throw new IllegalArgumentException ("ForeignElement already has a parent!");
  m_aContent.add (aForeignElement);
}
 
Example #22
Source File: XMLMapHandler.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ESuccess readMap (@Nonnull final IMicroElement aParentElement,
                                @Nonnull final Map <String, String> aTargetMap)
{
  ValueEnforcer.notNull (aParentElement, "ParentElement");
  ValueEnforcer.notNull (aTargetMap, "TargetMap");

  try
  {
    // and insert all elements
    for (final IMicroElement eMap : aParentElement.getAllChildElements (ELEMENT_MAP))
    {
      final String sName = eMap.getAttributeValue (ATTR_KEY);
      if (sName == null)
        LOGGER.warn ("Ignoring mapping element because key is null");
      else
      {
        final String sValue = eMap.getAttributeValue (ATTR_VALUE);
        if (sValue == null)
          LOGGER.warn ("Ignoring mapping element because value is null");
        else
        {
          if (aTargetMap.containsKey (sName))
            if (LOGGER.isWarnEnabled ())
              LOGGER.warn ("Key '" + sName + "' is already contained - overwriting!");
          aTargetMap.put (sName, sValue);
        }
      }
    }
    return ESuccess.SUCCESS;
  }
  catch (final Exception ex)
  {
    if (LOGGER.isWarnEnabled ())
      LOGGER.warn ("Failed to read mapping document", ex);
  }
  return ESuccess.FAILURE;
}
 
Example #23
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 #24
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 #25
Source File: TreeXMLConverter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <KEYTYPE, DATATYPE, ITEMTYPE extends ITreeItemWithID <KEYTYPE, DATATYPE, ITEMTYPE>> IMicroElement getTreeWithIDAsXML (@Nonnull final IBasicTree <DATATYPE, ITEMTYPE> aTree,
                                                                                                                                    @Nonnull final Comparator <? super ITEMTYPE> aItemComparator,
                                                                                                                                    @Nonnull final Function <? super KEYTYPE, ? extends String> aIDConverter,
                                                                                                                                    @Nonnull final IConverterTreeItemToMicroNode <? super DATATYPE> aDataConverter)
{
  final String sNamespaceURI = aDataConverter.getNamespaceURI ();
  final IMicroElement eRoot = new MicroElement (sNamespaceURI, ELEMENT_ROOT);
  fillTreeWithIDAsXML (aTree, aItemComparator, aIDConverter, aDataConverter, eRoot);
  return eRoot;
}
 
Example #26
Source File: TreeXMLConverter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <KEYTYPE, DATATYPE> DefaultTreeWithID <KEYTYPE, DATATYPE> getXMLAsTreeWithID (@Nonnull final IMicroElement aElement,
                                                                                            @Nonnull final Function <? super String, ? extends KEYTYPE> aIDConverter,
                                                                                            @Nonnull final IConverterMicroNodeToTreeItem <? extends DATATYPE> aDataConverter)
{
  final DefaultTreeWithID <KEYTYPE, DATATYPE> aTree = new DefaultTreeWithID <> ();
  fillXMLAsTreeWithID (aElement, aIDConverter, aDataConverter, aTree);
  return aTree;
}
 
Example #27
Source File: AbstractWALDAO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@OverrideOnDemand
protected String convertNativeToWALString (@Nonnull final DATATYPE aModifiedElement)
{
  final IMicroElement aElement = MicroTypeConverter.convertToMicroElement (aModifiedElement, "item");
  if (aElement == null)
    throw new IllegalStateException ("Failed to convert " +
                                     aModifiedElement +
                                     " of class " +
                                     aModifiedElement.getClass ().getName () +
                                     " to XML!");
  return MicroWriter.getNodeAsString (aElement, getWALXMLWriterSettings ());
}
 
Example #28
Source File: TreeXMLConverter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public static <KEYTYPE, DATATYPE, ITEMTYPE extends ITreeItemWithID <KEYTYPE, DATATYPE, ITEMTYPE>> void fillXMLAsTreeWithID (@Nonnull final IMicroElement aElement,
                                                                                                                            @Nonnull final Function <? super String, ? extends KEYTYPE> aIDConverter,
                                                                                                                            @Nonnull final IConverterMicroNodeToTreeItem <? extends DATATYPE> aDataConverter,
                                                                                                                            @Nonnull final BasicTreeWithID <KEYTYPE, DATATYPE, ITEMTYPE> aTree)
{
  final String sNamespaceURI = aDataConverter.getNamespaceURI ();
  final NonBlockingStack <ITEMTYPE> aParents = new NonBlockingStack <> ();
  aParents.push (aTree.getRootItem ());
  MicroVisitor.visit (aElement,
                      new ChildrenProviderElementWithName (sNamespaceURI, ELEMENT_ITEM),
                      new DefaultHierarchyVisitorCallback <IMicroElement> ()
                      {
                        @Override
                        @Nonnull
                        public EHierarchyVisitorReturn onItemBeforeChildren (@Nullable final IMicroElement eItem)
                        {
                          if (eItem != null)
                          {
                            final KEYTYPE aTreeItemID = aIDConverter.apply (eItem.getAttributeValue (ATTR_ID));

                            final IMicroElement eData = eItem.getFirstChildElement (sNamespaceURI, ELEMENT_DATA);
                            final DATATYPE aTreeItemValue = aDataConverter.getAsDataValue (eData);

                            final ITEMTYPE aTreeItem = aParents.peek ().createChildItem (aTreeItemID, aTreeItemValue);
                            aParents.push (aTreeItem);
                          }
                          return EHierarchyVisitorReturn.CONTINUE;
                        }

                        @Override
                        @Nonnull
                        public EHierarchyVisitorReturn onItemAfterChildren (@Nullable final IMicroElement aItem)
                        {
                          if (aItem != null)
                            aParents.pop ();
                          return EHierarchyVisitorReturn.CONTINUE;
                        }
                      });
}
 
Example #29
Source File: TreeXMLConverter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <DATATYPE, ITEMTYPE extends ITreeItem <DATATYPE, ITEMTYPE>> IMicroElement getTreeAsXML (@Nonnull final IBasicTree <DATATYPE, ITEMTYPE> aTree,
                                                                                                      @Nonnull final Comparator <? super ITEMTYPE> aItemComparator,
                                                                                                      @Nonnull final IConverterTreeItemToMicroNode <? super DATATYPE> aDataConverter)
{
  final String sNamespaceURI = aDataConverter.getNamespaceURI ();
  final IMicroElement eRoot = new MicroElement (sNamespaceURI, ELEMENT_ROOT);
  fillTreeAsXML (aTree, aItemComparator, aDataConverter, eRoot);
  return eRoot;
}
 
Example #30
Source File: MainCreateJAXBBinding21.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;
}