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

The following examples show how to use com.helger.xml.microdom.IMicroElement#getTextContent() . 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 vote down vote up
@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: StringMicroTypeConverter.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
public String convertToNative (@Nonnull final IMicroElement aElement)
{
  return aElement.getTextContent ();
}
 
Example 3
Source File: MicroHelper.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Helper method to extract the text content of the child element denoted by
 * the parameter sChildElementName of the passed parent element.
 *
 * @param eParentElement
 *        The parent element to use. May not be <code>null</code>.
 * @param sChildElementName
 *        The name of the child element who's text content is to be extracted.
 * @return <code>null</code> if the child element does not exist or the child
 *         element does not contain any text.
 */
@Nullable
public static String getChildTextContent (@Nonnull final IMicroElement eParentElement,
                                          @Nonnull final String sChildElementName)
{
  final IMicroElement eChildElement = eParentElement.getFirstChildElement (sChildElementName);
  return eChildElement != null ? eChildElement.getTextContent () : null;
}
 
Example 4
Source File: MicroHelper.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Helper method to extract the text content of the child element denoted by
 * the parameters sNamespaceURI and sChildElementName of the passed parent
 * element.
 *
 * @param eParentElement
 *        The parent element to use. May not be <code>null</code>.
 * @param sNamespaceURI
 *        The expected namespace URI of the element.
 * @param sChildElementName
 *        The name of the child element who's text content is to be extracted.
 * @return <code>null</code> if the child element does not exist or the child
 *         element does not contain any text.
 */
@Nullable
public static String getChildTextContent (@Nonnull final IMicroElement eParentElement,
                                          @Nonnull final String sNamespaceURI,
                                          @Nonnull final String sChildElementName)
{
  final IMicroElement eChildElement = eParentElement.getFirstChildElement (sNamespaceURI, sChildElementName);
  return eChildElement != null ? eChildElement.getTextContent () : null;
}