Java Code Examples for com.helger.commons.string.StringHelper#hasText()

The following examples show how to use com.helger.commons.string.StringHelper#hasText() . 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: PDTFromString.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
public static ZonedDateTime getZonedDateTimeFromString (@Nullable final String sValue,
                                                        @Nonnull final DateTimeFormatter aDF)
{
  ValueEnforcer.notNull (aDF, "DateTimeFormatter");

  if (StringHelper.hasText (sValue))
    try
    {
      return aDF.parse (sValue, ZonedDateTime::from);
    }
    catch (final DateTimeParseException ex)
    {
      _onParseException ("ZonedDateTime", sValue, aDF, ex);
    }
  return null;
}
 
Example 2
Source File: ILocation.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * @return The display text of the resource location.
 */
@Nonnull
default String getAsString ()
{
  String ret = "";

  final String sResourceID = getResourceID ();
  if (StringHelper.hasText (sResourceID))
    ret += sResourceID;

  if (hasLineNumber ())
  {
    if (hasColumnNumber ())
      ret += "(" + getLineNumber () + ":" + getColumnNumber () + ")";
    else
      ret += "(" + getLineNumber () + ":?)";
  }
  else
  {
    if (hasColumnNumber ())
      ret += "(?:" + getColumnNumber () + ")";
    // else: neither nor
  }
  return ret;
}
 
Example 3
Source File: PSRule.java    From ph-schematron with Apache License 2.0 6 votes vote down vote up
public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
{
  // abstract rules need an ID
  if (m_bAbstract && StringHelper.hasNoText (m_sID))
    aErrorHandler.error (this, "abstract <rule> has no 'id'");
  // abstract rules may not have a context
  if (m_bAbstract && StringHelper.hasText (m_sContext))
    aErrorHandler.error (this, "abstract <rule> may not have a 'context'");
  // Non-abstract rules need a context
  if (!m_bAbstract && StringHelper.hasNoText (m_sContext))
    aErrorHandler.error (this, "<rule> must have a 'context'");
  // At least one assert, report or extends must be present
  if (m_aContent.isEmpty ())
    aErrorHandler.error (this, "<rule> has no content");
  for (final Object aContent : m_aContent)
    if (aContent instanceof IPSElement)
      ((IPSElement) aContent).validateCompletely (aErrorHandler);
}
 
Example 4
Source File: MimeTypeInfo.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public boolean containsMimeType (@Nullable final String sMimeType)
{
  if (StringHelper.hasText (sMimeType))
    for (final MimeTypeWithSource aItem : m_aMimeTypes)
      if (aItem.getMimeTypeAsString ().equals (sMimeType))
        return true;
  return false;
}
 
Example 5
Source File: PSDiagnostics.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
@Nullable
public PSDiagnostic getDiagnosticOfID (@Nullable final String sID)
{
  if (StringHelper.hasText (sID))
    for (final Object aContent : m_aContent)
      if (aContent instanceof PSDiagnostic)
      {
        final PSDiagnostic aDiagnostic = (PSDiagnostic) aContent;
        if (sID.equals (aDiagnostic.getID ()))
          return aDiagnostic;
      }
  return null;
}
 
Example 6
Source File: CSSColorHelper.java    From ph-css with Apache License 2.0 5 votes vote down vote up
/**
 * Extract the CSS RGB color value from the passed String. Example value:
 * <code>rgb(255,0,0)</code>
 *
 * @param sValue
 *        The value to extract the value from. May be <code>null</code>.
 * @return <code>null</code> if the passed value is not a valid CSS RGB color
 *         value.
 */
@Nullable
public static CSSRGB getParsedRGBColorValue (@Nullable final String sValue)
{
  final String sRealValue = StringHelper.trim (sValue);
  if (StringHelper.hasText (sRealValue) && sRealValue.startsWith (CCSSValue.PREFIX_RGB))
  {
    final String [] aValues = RegExHelper.getAllMatchingGroupValues (PATTERN_RGB, sRealValue);
    if (aValues != null)
      return new CSSRGB (aValues[0], aValues[1], aValues[2]);
  }
  return null;
}
 
Example 7
Source File: PSRule.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public boolean isValid (@Nonnull final IPSErrorHandler aErrorHandler)
{
  // abstract rules need an ID
  if (m_bAbstract && StringHelper.hasNoText (m_sID))
  {
    aErrorHandler.error (this, "abstract <rule> has no 'id'");
    return false;
  }
  // abstract rules may not have a context
  if (m_bAbstract && StringHelper.hasText (m_sContext))
  {
    aErrorHandler.error (this, "abstract <rule> may not have a 'context'");
    return false;
  }
  // Non-abstract rules need a context
  if (!m_bAbstract && StringHelper.hasNoText (m_sContext))
  {
    aErrorHandler.error (this, "<rule> must have a 'context'");
    return false;
  }
  // At least one assert, report or extends must be present
  if (m_aContent.isEmpty ())
  {
    aErrorHandler.error (this, "<rule> has no content");
    return false;
  }
  for (final Object aContent : m_aContent)
    if (aContent instanceof IPSElement)
      if (!((IPSElement) aContent).isValid (aErrorHandler))
        return false;
  return true;
}
 
Example 8
Source File: XMLEmitter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * CDATA node.
 *
 * @param sText
 *        The contained text
 */
public void onCDATA (@Nullable final String sText)
{
  if (StringHelper.hasText (sText))
  {
    if (sText.indexOf (CDATA_END) >= 0)
    {
      // Split CDATA sections if they contain the illegal "]]>" marker
      final ICommonsList <String> aParts = StringHelper.getExploded (CDATA_END, sText);
      final int nParts = aParts.size ();
      for (int i = 0; i < nParts; ++i)
      {
        _append (CDATA_START);
        if (i > 0)
          _append ('>');
        _appendMasked (EXMLCharMode.CDATA, aParts.get (i));
        if (i < nParts - 1)
          _append ("]]");
        _append (CDATA_END);
      }
    }
    else
    {
      // No special handling required
      _append (CDATA_START)._appendMasked (EXMLCharMode.CDATA, sText)._append (CDATA_END);
    }
  }
}
 
Example 9
Source File: MicroSAXHandler.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public void startElement (@Nullable final String sNamespaceURI,
                          @Nonnull final String sLocalName,
                          @Nullable final String sQName,
                          @Nullable final Attributes aAttributes)
{
  _updatePosition ("startElement");
  _createParentDocument ();

  IMicroElement aElement;
  if (StringHelper.hasText (sNamespaceURI))
    aElement = m_aParent.appendElement (sNamespaceURI, sLocalName);
  else
    aElement = m_aParent.appendElement (sLocalName);

  // copy attributes
  if (aAttributes != null)
  {
    final int nAttrCount = aAttributes.getLength ();
    for (int i = 0; i < nAttrCount; ++i)
    {
      final String sAttrNamespaceURI = aAttributes.getURI (i);
      final String sAttrName = aAttributes.getLocalName (i);
      final String sAttrValue = aAttributes.getValue (i);

      // Ignore the "xmlns" attributes, as the SAX handler passes the correct
      // namespace URIs
      if (!sAttrName.startsWith (XMLConstants.XMLNS_ATTRIBUTE))
        aElement.setAttribute (sAttrNamespaceURI, sAttrName, sAttrValue);
    }
  }

  m_aParent = aElement;
}
 
Example 10
Source File: ConfigFileBuilder.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public ConfigFileBuilder addPath (@Nullable final String sConfigPath)
{
  if (StringHelper.hasText (sConfigPath))
    m_aPaths.add (sConfigPath);
  return this;
}
 
Example 11
Source File: CSSColorHelper.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nullable
public static CSSRGBA getParsedRGBAColorValue (@Nullable final String sValue)
{
  final String sRealValue = StringHelper.trim (sValue);
  if (StringHelper.hasText (sRealValue) && sRealValue.startsWith (CCSSValue.PREFIX_RGBA))
  {
    final String [] aValues = RegExHelper.getAllMatchingGroupValues (PATTERN_RGBA, sRealValue);
    if (aValues != null)
      return new CSSRGBA (aValues[0], aValues[1], aValues[2], aValues[3]);
  }
  return null;
}
 
Example 12
Source File: Schematron.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
void addToMap (@Nonnull final Map <String, String> aMap)
{
  // Only add parameters that have a name
  // If the value is null it becomes ""
  if (StringHelper.hasText (m_sName))
    aMap.put (m_sName, StringHelper.getNotNull (m_sValue));
}
 
Example 13
Source File: ReadableResourceByteArray.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public ReadableResourceByteArray (@Nullable final String sResourceID,
                                  @Nonnull final byte [] aBytes,
                                  @Nonnegative final int nOfs,
                                  @Nonnegative final int nLen,
                                  final boolean bCopyNeeded)
{
  super (StringHelper.hasText (sResourceID) ? sResourceID : "byte[]");
  ValueEnforcer.isArrayOfsLen (aBytes, nOfs, nLen);
  // Create a copy to avoid outside modifications
  m_aBytes = new ByteArrayWrapper (aBytes, nOfs, nLen, bCopyNeeded);
}
 
Example 14
Source File: WSClientConfig.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * @return <code>true</code> if a HTTP Basic Auth user name is defined,
 *         <code>false</code> otherwise.
 */
public boolean hasUserName ()
{
  return StringHelper.hasText (m_sUserName);
}
 
Example 15
Source File: WSClientConfig.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * @return <code>true</code> if a HTTP Basic Auth password is defined,
 *         <code>false</code> otherwise.
 */
public boolean hasPassword ()
{
  return StringHelper.hasText (m_sPassword);
}
 
Example 16
Source File: XMLHelper.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static IPredicate <? super Element> filterElementWithNamespace ()
{
  return x -> x != null && StringHelper.hasText (x.getNamespaceURI ());
}
 
Example 17
Source File: MimeTypeInfo.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public boolean hasComment ()
{
  return StringHelper.hasText (m_sComment);
}
 
Example 18
Source File: ReadableResourceInputStream.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public ReadableResourceInputStream (@Nullable final String sResourceID, @Nonnull @WillNotClose final InputStream aIS)
{
  super (StringHelper.hasText (sResourceID) ? sResourceID : "input-stream");
  m_aIS = ValueEnforcer.notNull (aIS, "InputStream");
}
 
Example 19
Source File: FilenameHelper.java    From ph-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Check if the passed filename is a Unix hidden filename.
 *
 * @param sFilename
 *        The filename to check. May be <code>null</code>.
 * @return <code>true</code> if the filename is neither <code>null</code> nor
 *         empty and starts with a dot.
 * @see #isHiddenFilename(File)
 */
public static boolean isHiddenFilename (@Nullable final String sFilename)
{
  return StringHelper.hasText (sFilename) && sFilename.charAt (0) == HIDDEN_FILE_PREFIX;
}
 
Example 20
Source File: XMLEmitter.java    From ph-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Ignorable whitespace characters.
 *
 * @param aWhitespaces
 *        The whitespace character sequence
 */
public void onContentElementWhitespace (@Nullable final CharSequence aWhitespaces)
{
  if (StringHelper.hasText (aWhitespaces))
    _append (aWhitespaces.toString ());
}