Java Code Examples for org.apache.commons.lang.StringUtils#replaceEachRepeatedly()

The following examples show how to use org.apache.commons.lang.StringUtils#replaceEachRepeatedly() . 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: SingleSignOnServiceImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String signinWithSAML2POST(SAMLToken samlToken) throws TechnicalConnectorException {
   FileWriter fw = null;

   try {
      String template = ConnectorIOUtils.getResourceAsString("/sso/SSORequestSTSSAML2POST.xml");
      template = StringUtils.replaceEach(template, new String[]{"${reqId}", "${endpoint.idp.saml2.post}"}, new String[]{this.idGenerator.generateId(), this.getSAML2Post()});
      NodeList assertions = this.invokeSecureTokenService(ConnectorXmlUtils.flatten(template), samlToken).getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Assertion");
      Validate.notNull(assertions);
      Validate.isTrue(assertions.getLength() == 1);
      Element assertion = (Element)assertions.item(0);
      String samlResponse = ConnectorIOUtils.getResourceAsString("/sso/bindingTemplate-SAMLResponse.xml");
      samlResponse = StringUtils.replaceEachRepeatedly(samlResponse, new String[]{"${SAMLResponseID}", "${SAMLResponseIssueInstant}", "${SAMLAssertion}"}, new String[]{IdGeneratorFactory.getIdGenerator("xsid").generateId(), (new DateTime()).toString(), this.toXMLString(assertion)});
      return new String(Base64.encode(ConnectorIOUtils.toBytes(ConnectorXmlUtils.flatten(samlResponse), Charset.UTF_8)));
   } finally {
      ConnectorIOUtils.closeQuietly(fw);
   }

}
 
Example 2
Source File: AbstractMqttMessagePubSub.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Split the given string into a string array using ':' as the separator. If
 * the separator is escaped like '\:', the separator is ignored.
 * 
 * @param configString
 * @return configString split into array.
 */
protected String[] splitConfigurationString(String configString) {

    if (StringUtils.isEmpty(configString)) {
        return new String[0];
    }

    String[] result = StringUtils
            .replaceEachRepeatedly(configString, new String[] { "\\:" }, new String[] { TEMP_COLON_REPLACEMENT })
            .split(":");
    for (int i = 0; i < result.length; i++) {
        result[i] = StringUtils.replaceEachRepeatedly(result[i], new String[] { TEMP_COLON_REPLACEMENT },
                new String[] { ":" });
    }
    return result;
}
 
Example 3
Source File: MafOutputRenderer.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Transforms a given {@code value} to the equivalent MAF-valid value based on the given {@code key}.
 * @param key The {@code key} off of which to base the transformation.  This key is the final (transformed) key for output (i.e. the column name in the MAF file).
 * @param value The {@code value} to transform into a MAF-valid value.
 * @param referenceVersion The version of the reference used to create these annotations.
 * @return The MAF-valid equivalent of the given {@code value}.
 */
public static String mafTransform(final String key, final String value, final String referenceVersion) {

    switch (key) {
        case MafOutputRendererConstants.FieldName_Variant_Classification:
            if ( MafOutputRendererConstants.VariantClassificationMap.containsKey(value)) {
                return MafOutputRendererConstants.VariantClassificationMap.get(value);
            }
            break;
            
        case MafOutputRendererConstants.FieldName_Chromosome:
            if ( value.equals(MafOutputRendererConstants.FieldValue_Gencode_Chromosome_Mito) ) {
                return MafOutputRendererConstants.FieldValue_Chromosome_Mito;
            }
            else if ( value.toLowerCase().startsWith("chr") && (referenceVersion.toLowerCase().equals("hg19") || referenceVersion.toLowerCase().equals("b37"))) {
                final String trimVal = value.substring(3);
                if ( HG_19_CHR_SET.contains(trimVal)) {
                    return trimVal;
                }
            }
            break;
        case MafOutputRendererConstants.FieldName_Other_Transcripts:
            // Use apache commons string utils because it's much, much faster to do this replacement:
            return StringUtils.replaceEachRepeatedly(value, ORDERED_GENCODE_VARIANT_CLASSIFICATIONS.toArray(new String[]{}), ORDERED_MAF_VARIANT_CLASSIFICATIONS.toArray(new String[]{}));
    }

    return value;
 }
 
Example 4
Source File: MafOutputRenderer.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Transforms a given {@code value} from a MAF-valid value to a general-purpose value based on the given {@code key}.
 * @param key The {@code key} off of which to base the transformation.  This key is the transformed key for output (i.e. the column name in the MAF file).
 * @param value The {@code value} to transform from a MAF-valid value into a general-purpose value.
 * @param referenceVersion The version of the reference used to create these annotations.
 * @return The general-purpose equivalent of the given MAF-valid {@code value}.
 */
public static String mafTransformInvert(final String key, final String value, final String referenceVersion ) {
    switch (key) {
        case MafOutputRendererConstants.FieldName_Variant_Classification:
            if ( MafOutputRendererConstants.VariantClassificationMapInverse.containsKey(value)) {
                return MafOutputRendererConstants.VariantClassificationMapInverse.get(value);
            }
            break;

        case MafOutputRendererConstants.FieldName_Chromosome:
            if ( value.equals(MafOutputRendererConstants.FieldValue_Chromosome_Mito) ) {
                return MafOutputRendererConstants.FieldValue_Gencode_Chromosome_Mito;
            }
            else if (referenceVersion.toLowerCase().equals("hg19") || referenceVersion.toLowerCase().equals("b37")) {
                if ( value.length() <= 2 ) {
                    if ( HG_19_CHR_SET.contains(value) ) {
                        return "chr" + value;
                    }
                }
            }
            break;
        case MafOutputRendererConstants.FieldName_Other_Transcripts:

            // Use apache commons string utils because it's much, much faster to do this replacement:
            // But we have to do the LINCRNA -> RNA conversion separately, so exclude those indices:
            String replacement = StringUtils.replaceEachRepeatedly(
                    value,
                    ORDERED_MAF_VARIANT_CLASSIFICATIONS.subList(0, ORDERED_MAF_VARIANT_CLASSIFICATIONS.size()-1).toArray(new String[]{}),
                    ORDERED_GENCODE_VARIANT_CLASSIFICATIONS.subList(0, ORDERED_MAF_VARIANT_CLASSIFICATIONS.size()-1).toArray(new String[]{})
            );

            // Handle the RNA/LINCRNA case specially:
            final String needle = MafOutputRendererConstants.VariantClassificationMap.get(GencodeFuncotation.VariantClassification.LINCRNA.toString());
            int indx = replacement.indexOf(needle);
            while ( indx != -1 ) {
                // make sure the previous letters are not LINC:
                if ( (indx <= 3 ) || ((indx > 3) && (!replacement.substring(indx - 4, indx).equals("LINC")))) {
                    replacement = replacement.substring(0, indx) + GencodeFuncotation.VariantClassification.LINCRNA.toString() + replacement.substring(indx + needle.length());
                    indx += needle.length();
                }
                else {
                    ++indx;
                }

                indx = replacement.indexOf(needle, indx);
            }

            return replacement;
    }

    return value;
}