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

The following examples show how to use com.helger.commons.string.StringHelper#trimEnd() . 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: CertificateHelper.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
public static PrivateKey convertStringToPrivateKey (@Nullable final String sPrivateKey) throws GeneralSecurityException
{
  if (StringHelper.hasNoText (sPrivateKey))
    return null;

  String sRealPrivateKey = StringHelper.trimStart (sPrivateKey, BEGIN_PRIVATE_KEY);
  sRealPrivateKey = StringHelper.trimEnd (sRealPrivateKey, END_PRIVATE_KEY);
  sRealPrivateKey = StringHelper.getWithoutAnySpaces (sRealPrivateKey);
  final byte [] aPrivateKeyBytes = Base64.safeDecode (sRealPrivateKey);
  if (aPrivateKeyBytes == null)
    return null;

  final KeyFactory aKeyFactory = KeyFactory.getInstance ("RSA");
  final PKCS8EncodedKeySpec aKeySpec = new PKCS8EncodedKeySpec (aPrivateKeyBytes);
  return aKeyFactory.generatePrivate (aKeySpec);
}
 
Example 2
Source File: FormatterStringSkipPrefixAndSuffix.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Override
public String apply (@Nullable final Object aValue)
{
  String sValue = getValueAsString (aValue);
  // strip prefix and suffix
  if (m_sPrefix.length () > 0)
    sValue = StringHelper.trimStart (sValue, m_sPrefix);
  if (m_sSuffix.length () > 0)
    sValue = StringHelper.trimEnd (sValue, m_sSuffix);
  return sValue;
}
 
Example 3
Source File: CertificateHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Remove any eventually preceding {@value #BEGIN_CERTIFICATE} and succeeding
 * {@value #END_CERTIFICATE} values from the passed certificate string.
 * Additionally all whitespaces of the string are removed.
 *
 * @param sCertificate
 *        The source certificate string. May be <code>null</code>.
 * @return <code>null</code> if the input string is <code>null</code> or
 *         empty, the stripped down string otherwise.
 */
@Nullable
public static String getWithoutPEMHeader (@Nullable final String sCertificate)
{
  if (StringHelper.hasNoText (sCertificate))
    return null;

  // Remove special begin and end stuff
  String sRealCertificate = sCertificate.trim ();

  /**
   * Handle certain misconfiguration issues. E.g. for 9906:testconsip on
   *
   * <pre>
   * http://b-c073e04afb234f70e74d3444ba3f8eaa.iso6523-actorid-upis.acc.edelivery.tech.ec.europa.eu/iso6523-actorid-upis%3A%3A9906%3Atestconsip/services/busdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3AOrder-2%3A%3AOrder%23%23urn%3Awww.cenbii.eu%3Atransaction%3Abiitrns001%3Aver2.0%3Aextended%3Aurn%3Awww.peppol.eu%3Abis%3Apeppol3a%3Aver2.0%3A%3A2.1
   * </pre>
   */
  sRealCertificate = StringHelper.trimStart (sRealCertificate, BEGIN_CERTIFICATE_INVALID);
  sRealCertificate = StringHelper.trimEnd (sRealCertificate, END_CERTIFICATE_INVALID);

  // Remove regular PEM headers also
  sRealCertificate = StringHelper.trimStart (sRealCertificate, BEGIN_CERTIFICATE);
  sRealCertificate = StringHelper.trimEnd (sRealCertificate, END_CERTIFICATE);

  // Remove all existing whitespace characters
  return StringHelper.getWithoutAnySpaces (sRealCertificate);
}
 
Example 4
Source File: CSSFilenameHelper.java    From ph-css with Apache License 2.0 5 votes vote down vote up
/**
 * Get the minified CSS filename from the passed filename. If the passed
 * filename is already minified, it is returned as is.
 *
 * @param sCSSFilename
 *        The filename to get minified. May not be <code>null</code>.
 * @return The minified filename
 */
@Nonnull
public static String getMinifiedCSSFilename (@Nonnull final String sCSSFilename)
{
  ValueEnforcer.isTrue (isCSSFilename (sCSSFilename),
                        "Passed file name '" + sCSSFilename + "' is not a CSS file name!");
  if (isMinifiedCSSFilename (sCSSFilename))
    return sCSSFilename;
  return StringHelper.trimEnd (sCSSFilename, CCSS.FILE_EXTENSION_CSS) + CCSS.FILE_EXTENSION_MIN_CSS;
}
 
Example 5
Source File: AbstractCreateUBLActionCode.java    From ph-ubl with Apache License 2.0 4 votes vote down vote up
protected static void append (@Nonnull final IJAXBDocumentType e,
                              @Nonnull final EPhase ePhase,
                              @Nonnull final StringBuilder aSB,
                              @Nonnull final String sBuilderClass)
{
  final String sType = ClassHelper.getClassLocalName (e.getImplementationClass ());
  final String sName = StringHelper.trimEnd (sType, "Type");
  final String sBuilderMethodName = Character.toLowerCase (sName.charAt (0)) + sName.substring (1);

  switch (ePhase)
  {
    case READ:
      // Builder<T> read ()
      aSB.append ("/** Create a reader builder for " +
                  sName +
                  ".\n" +
                  "@return The builder and never <code>null</code> */\n");
      aSB.append ("@Nonnull public static ")
         .append (sBuilderClass)
         .append ('<')
         .append (sType)
         .append ("> ")
         .append (sBuilderMethodName)
         .append ("(){return ")
         .append (sBuilderClass)
         .append (".create(")
         .append (sType)
         .append (".class);}\n");
      break;
    case WRITE:
      // Builder<T> write ()
      aSB.append ("/** Create a writer builder for " +
                  sName +
                  ".\n" +
                  "@return The builder and never <code>null</code> */\n");
      aSB.append ("@Nonnull public static ")
         .append (sBuilderClass)
         .append ('<')
         .append (sType)
         .append ("> ")
         .append (sBuilderMethodName)
         .append ("(){return ")
         .append (sBuilderClass)
         .append (".create(")
         .append (sType)
         .append (".class);}\n");
      break;
    case VALIDATE:
      // Builder<T> validate ()
      aSB.append ("/** Create a validation builder for " +
                  sName +
                  ".\n" +
                  "@return The builder and never <code>null</code> */\n");
      aSB.append ("@Nonnull public static ")
         .append (sBuilderClass)
         .append ('<')
         .append (sType)
         .append ("> ")
         .append (sBuilderMethodName)
         .append ("(){return ")
         .append (sBuilderClass)
         .append (".create(")
         .append (sType)
         .append (".class);}\n");
      break;
  }
}