Java Code Examples for com.helger.xml.microdom.IMicroElement#getAllChildElements()
The following examples show how to use
com.helger.xml.microdom.IMicroElement#getAllChildElements() .
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: SettingsMicroDocumentConverter.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull public T convertToNative (final IMicroElement aElement) { // Create new settings object final String sSettingsName = aElement.getAttributeValue (ATTR_NAME); if (StringHelper.hasNoText (sSettingsName)) throw new IllegalStateException ("Settings 'name' is missing or empty"); final T aSettings = m_aSettingFactory.apply (sSettingsName); // settings are only on the top-level for (final IMicroElement eSetting : aElement.getAllChildElements ()) { final String sFieldName = eSetting.getAttributeValue (ATTR_NAME); final String sValue; if (eSetting.hasAttribute (ATTR_IS_NULL)) { // Special case for null sValue = null; } else { // Backwards compatibility final IMicroElement eValue = eSetting.getFirstChildElement ("value"); if (eValue != null) sValue = eValue.getTextContent (); else sValue = eSetting.getTextContent (); } // Use "put" instead of "putIn" to avoid that the callbacks are invoked! // Use "putIn" to ensure that the custom value modifiers are applied and // that it is consistent with the properties implementation aSettings.putIn (sFieldName, sValue); } return aSettings; }
Example 2
Source File: MultilingualTextMicroTypeConverterRegistrar.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull protected static MultilingualText convertToMLT (@Nonnull final IMicroElement aElement) { final MultilingualText aMLT = new MultilingualText (); final LocaleCache aLC = LocaleCache.getInstance (); for (final IMicroElement eText : aElement.getAllChildElements (ELEMENT_TEXT)) { final Locale aLocale = aLC.getLocale (eText.getAttributeValue (ATTR_LOCALE)); aMLT.setText (aLocale, eText.getTextContent ()); } return aMLT; }
Example 3
Source File: XMLMapHandler.java From ph-commons with Apache License 2.0 | 5 votes |
@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 4
Source File: ChildrenProviderElementWithName.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull @ReturnsMutableCopy public ICommonsList <? extends IMicroElement> getAllChildren (@Nullable final IMicroElement aCurrent) { // Not an element? if (aCurrent == null) return new CommonsArrayList <> (); // Namespace URI defined? if (StringHelper.hasText (m_sNamespaceURI)) return aCurrent.getAllChildElements (m_sNamespaceURI, m_sTagName); return aCurrent.getAllChildElements (m_sTagName); }
Example 5
Source File: XMLListHandler.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull public static ESuccess readList (@Nonnull final IMicroElement aParentElement, @Nonnull final Collection <String> aTargetList) { ValueEnforcer.notNull (aParentElement, "ParentElement"); ValueEnforcer.notNull (aTargetList, "TargetList"); try { // and insert all elements for (final IMicroElement eItem : aParentElement.getAllChildElements (ELEMENT_ITEM)) { final String sValue = eItem.getAttributeValue (ATTR_VALUE); if (sValue == null) LOGGER.warn ("Ignoring list item because value is null"); else if (!aTargetList.add (sValue)) { if (LOGGER.isWarnEnabled ()) LOGGER.warn ("Ignoring list item '" + sValue + "' because value is already contained"); } } return ESuccess.SUCCESS; } catch (final Exception ex) { LOGGER.warn ("Failed to read list document", ex); } return ESuccess.FAILURE; }
Example 6
Source File: MainCreateJAXBBinding20.java From ph-ubl with Apache License 2.0 | 4 votes |
private static void _generateExplicitEnumMapping (@Nonnull final IMicroDocument aDoc, @Nonnull @Nonempty final String sFilename, @Nonnull final IMicroElement eBindings) { final ICommonsSet <String> aUsedNames = new CommonsHashSet <> (); final ICommonsNavigableMap <String, String> aValueToConstants = new CommonsTreeMap <> (); final IMicroElement eSimpleType = aDoc.getDocumentElement ().getFirstChildElement (); final IMicroElement eInnerBindings = eBindings.appendElement (JAXB_NS_URI, "bindings") .setAttribute ("node", "xsd:simpleType[@name='" + eSimpleType.getAttributeValue ("name") + "']"); final IMicroElement eTypesafeEnumClass = eInnerBindings.appendElement (JAXB_NS_URI, "typesafeEnumClass"); final IMicroElement eRestriction = eSimpleType.getFirstChildElement (); for (final IMicroElement eEnumeration : eRestriction.getAllChildElements (XMLConstants.W3C_XML_SCHEMA_NS_URI, "enumeration")) { final IMicroElement eAnnotation = eEnumeration.getFirstChildElement (XMLConstants.W3C_XML_SCHEMA_NS_URI, "annotation"); if (eAnnotation == null) throw new IllegalStateException ("annotation is missing"); final IMicroElement eDocumentation = eAnnotation.getFirstChildElement (XMLConstants.W3C_XML_SCHEMA_NS_URI, "documentation"); if (eDocumentation == null) throw new IllegalStateException ("documentation is missing"); final IMicroElement eCodeName = eDocumentation.getFirstChildElement ("urn:un:unece:uncefact:documentation:2", "CodeName"); if (eCodeName == null) throw new IllegalStateException ("CodeName is missing"); final String sValue = eEnumeration.getAttributeValue ("value"); // Create an upper case Java identifier, without duplicate "_" String sCodeName = RegExHelper.getAsIdentifier (eCodeName.getTextContent ().trim ().toUpperCase (Locale.US)) .replaceAll ("_+", "_"); if (!aUsedNames.add (sCodeName)) { // Ensure uniqueness of the enum member name int nSuffix = 1; while (true) { final String sSuffixedCodeName = sCodeName + "_" + nSuffix; if (aUsedNames.add (sSuffixedCodeName)) { sCodeName = sSuffixedCodeName; break; } ++nSuffix; } } eTypesafeEnumClass.appendElement (JAXB_NS_URI, "typesafeEnumMember") .setAttribute ("value", sValue) .setAttribute ("name", sCodeName); aValueToConstants.put (sValue, sCodeName); } // Write out the mapping file for easy later-on resolving XMLMapHandler.writeMap (aValueToConstants, new FileSystemResource ("src/main/resources/schemas/" + sFilename + ".mapping")); }