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

The following examples show how to use org.apache.commons.lang.StringUtils#replaceEach() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
private void signinWithSAML2Artifact(String targetLocation) throws TechnicalConnectorException {
   try {
      String template = ConnectorIOUtils.getResourceAsString("/sso/SSORequestSTSSAML2Artifact.xml");
      template = StringUtils.replaceEach(template, new String[]{"${reqId}", "${endpoint.idp.saml2.artifact}"}, new String[]{this.idGenerator.generateId(), this.getSAML2Artifact()});
      NodeList references = this.invokeSecureTokenService(ConnectorXmlUtils.flatten(template)).getElementsByTagNameNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Reference");
      Validate.notNull(references);
      Validate.isTrue(references.getLength() == 1);
      Element reference = (Element)references.item(0);
      String uri = reference.getAttribute("URI");
      if (StringUtils.isNotBlank(targetLocation)) {
         uri = uri + "&RelayState=" + targetLocation;
      }

      LOG.debug("Launching browser with url [" + uri + "]");
      this.launchBrowser(new URI(uri));
   } catch (IOException var6) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var6, new Object[]{var6.getMessage()});
   } catch (URISyntaxException var7) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var7, new Object[]{var7.getMessage()});
   }
}
 
Example 2
private void signinWithSAML2Artifact(String targetLocation) throws TechnicalConnectorException {
   try {
      String template = ConnectorIOUtils.getResourceAsString("/sso/SSORequestSTSSAML2Artifact.xml");
      template = StringUtils.replaceEach(template, new String[]{"${reqId}", "${endpoint.idp.saml2.artifact}"}, new String[]{this.idGenerator.generateId(), this.getSAML2Artifact()});
      NodeList references = this.invokeSecureTokenService(ConnectorXmlUtils.flatten(template)).getElementsByTagNameNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Reference");
      Validate.notNull(references);
      Validate.isTrue(references.getLength() == 1);
      Element reference = (Element)references.item(0);
      String uri = reference.getAttribute("URI");
      if (StringUtils.isNotBlank(targetLocation)) {
         uri = uri + "&RelayState=" + targetLocation;
      }

      LOG.debug("Launching browser with url [" + uri + "]");
      this.browserHandler.browse(new URI(uri));
   } catch (URISyntaxException var6) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var6, new Object[]{var6.getMessage()});
   }
}
 
Example 3
private void signinWithSAML2Artifact(String targetLocation) throws TechnicalConnectorException {
   try {
      String template = ConnectorIOUtils.getResourceAsString("/sso/SSORequestSTSSAML2Artifact.xml");
      template = StringUtils.replaceEach(template, new String[]{"${reqId}", "${endpoint.idp.saml2.artifact}"}, new String[]{this.idGenerator.generateId(), this.getSAML2Artifact()});
      NodeList references = this.invokeSecureTokenService(ConnectorXmlUtils.flatten(template)).getElementsByTagNameNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Reference");
      Validate.notNull(references);
      Validate.isTrue(references.getLength() == 1);
      Element reference = (Element)references.item(0);
      String uri = reference.getAttribute("URI");
      if (StringUtils.isNotBlank(targetLocation)) {
         uri = uri + "&RelayState=" + targetLocation;
      }

      LOG.debug("Launching browser with url [" + uri + "]");
      this.launchBrowser(new URI(uri));
   } catch (IOException var6) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var6, new Object[]{var6.getMessage()});
   } catch (URISyntaxException var7) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var7, new Object[]{var7.getMessage()});
   }
}
 
Example 4
private void signinWithSAML2Artifact(String targetLocation) throws TechnicalConnectorException {
   try {
      String template = ConnectorIOUtils.getResourceAsString("/sso/SSORequestSTSSAML2Artifact.xml");
      template = StringUtils.replaceEach(template, new String[]{"${reqId}", "${endpoint.idp.saml2.artifact}"}, new String[]{this.idGenerator.generateId(), this.getSAML2Artifact()});
      NodeList references = this.invokeSecureTokenService(ConnectorXmlUtils.flatten(template)).getElementsByTagNameNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Reference");
      Validate.notNull(references);
      Validate.isTrue(references.getLength() == 1);
      Element reference = (Element)references.item(0);
      String uri = reference.getAttribute("URI");
      if (StringUtils.isNotBlank(targetLocation)) {
         uri = uri + "&RelayState=" + targetLocation;
      }

      LOG.debug("Launching browser with url [" + uri + "]");
      this.launchBrowser(new URI(uri));
   } catch (IOException var6) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var6, new Object[]{var6.getMessage()});
   } catch (URISyntaxException var7) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var7, new Object[]{var7.getMessage()});
   }
}
 
Example 5
private String signinWithSAML2Artifact(SAMLToken samlToken) throws TechnicalConnectorException {
   try {
      String template = ConnectorIOUtils.getResourceAsString("/sso/SSORequestSTSSAML2Artifact.xml");
      template = StringUtils.replaceEach(template, new String[]{"${reqId}", "${endpoint.idp.saml2.artifact}"}, new String[]{this.idGenerator.generateId(), this.getSAML2Artifact()});
      NodeList references = this.invokeSecureTokenService(ConnectorXmlUtils.flatten(template), samlToken).getElementsByTagNameNS("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Reference");
      Validate.notNull(references);
      Validate.isTrue(references.getLength() == 1);
      Element reference = (Element)references.item(0);
      String uri = reference.getAttribute("URI");

      LOG.debug("Launching browser with url [" + uri + "]");
      return new URI(uri).toASCIIString();
   } catch (URISyntaxException var6) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.CORE_TECHNICAL, var6, new Object[]{var6.getMessage()});
   }
}
 
Example 6
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 7
protected Resource writeRecordPolicy(Resource user, Resource recordId, Resource masterBranchId) {
    try {
        // Record Policy
        InputStream recordPolicyStream = AbstractMappingRecordService.class
                .getResourceAsStream("/mappingRecordPolicy.xml");
        String encodedRecordIRI = ResourceUtils.encode(recordId);

        String[] search = {USER_IRI_BINDING, RECORD_IRI_BINDING, ENCODED_RECORD_IRI_BINDING,
                MASTER_BRANCH_IRI_BINDING};
        String[] replace = {user.stringValue(), recordId.stringValue(), encodedRecordIRI,
                masterBranchId.stringValue()};
        String recordPolicy = StringUtils.replaceEach(IOUtils.toString(recordPolicyStream, "UTF-8"),
                search, replace);

        return addPolicy(recordPolicy);
    } catch (IOException e) {
        throw new MobiException("Error writing record policy.", e);
    }
}
 
Example 8
/**
 * Creates a policy file based on default templates that controls who can view and modify the Record.
 *
 * @param user The Resource of the user who created the Record and associated Policy files
 * @param recordId The Resource of the Record to write out
 * @param masterBranchId The Resource of the Master Branch associated with the recordId
 */
protected Resource writeRecordPolicy(Resource user, Resource recordId, Resource masterBranchId) {
    try {
        InputStream recordPolicyStream = AbstractVersionedRDFRecordService.class
                .getResourceAsStream("/recordPolicy.xml");
        String encodedRecordIRI = ResourceUtils.encode(recordId);

        String[] search = {USER_IRI_BINDING, RECORD_IRI_BINDING, ENCODED_RECORD_IRI_BINDING,
                MASTER_BRANCH_IRI_BINDING};
        String[] replace = {user.stringValue(), recordId.stringValue(), encodedRecordIRI,
                masterBranchId.stringValue()};
        String recordPolicy = StringUtils.replaceEach(IOUtils.toString(recordPolicyStream, "UTF-8"),
                search, replace);

        return addPolicy(recordPolicy);
    } catch (IOException e) {
        throw new MobiException("Error writing record policy.", e);
    }
}
 
Example 9
public Row addColumn(String content) {
    boolean _csv = StringUtils.equals(builder.__format, "csv");
    boolean _markdown = StringUtils.equals(builder.__format, "markdown");
    if (!_csv && builder.__escape) {
        if (_markdown) {
            content = StringUtils.replaceEach(content, new String[]{"_", "|", "\r\n", "\r", "\n", "\t"}, new String[]{"\\_", "\\|", "<br>", "", "<br>", ""});
        } else {
            content = StringUtils.replaceEach(content, new String[]{"\r\n", "\r", "\n", "\t"}, new String[]{"[\\r][\\n]", "[\\r]", "[\\n]", "[\\t]"});
        }
    }
    if (_csv) {
        if (StringUtils.contains(content, '"')) {
            content = StringUtils.replace(content, "\"", "\"\"");
        }
        if (StringUtils.contains(content, ',')) {
            content = "\"" + content + "\"";
        }
    }
    this.columns.add(new Column(content));
    return this;
}
 
Example 10
Source Project: ymate-platform-v2   File: ColumnInfo.java    License: Apache License 2.0 6 votes vote down vote up
public ColumnInfo(IEntityNamedFilter namedFilter, String columnName, String columnType, boolean autoIncrement, boolean primaryKey, boolean signed, int precision, int scale, int nullable, String defaultValue, String remarks) {
    this.columnName = columnName;
    this.columnType = columnType;
    this.autoIncrement = autoIncrement;
    this.primaryKey = primaryKey;
    this.signed = signed;
    this.precision = precision;
    this.scale = scale;
    this.nullable = nullable > 0;
    this.defaultValue = defaultValue;
    this.remarks = StringUtils.replaceEach(remarks, new String[]{"\"", "\r\n", "\r", "\n", "\t"}, new String[]{"\\\"", "[\\r][\\n]", "[\\r]", "[\\n]", "[\\t]"});
    //
    if (namedFilter != null) {
        this.name = StringUtils.defaultIfBlank(namedFilter.doFilter(columnName), columnName);
    } else {
        this.name = columnName;
    }
    this.name = StringUtils.uncapitalize(EntityMeta.propertyNameToFieldName(this.name.toLowerCase()));
}
 
Example 11
Source Project: DataSphereStudio   File: CodeParser.java    License: Apache License 2.0 5 votes vote down vote up
private  String replaceCodeResourceNames(String code, ArrayList<String> resourceNameList, ArrayList<BMLResource> resourceList){
    if(resourceList.size() != resourceNameList.size()){
        throw new RuntimeException("Failed to parsed resource file");
    }

    String[] names = resourceNameList.toArray(new String[]{});

    String[] afterNames = new String[resourceList.size()];
    for (int i=0 ; i < afterNames.length ; i++){
        afterNames[i] = resourceList.get(i).getFileName();
    }
    return StringUtils.replaceEach(code, names, afterNames);
}
 
Example 12
/**
 * Creates a policy file based on default templates that controls who can modify the policy for the Record.
 *
 * @param user The Resource of the user who created the Record and associated Policy files
 * @param recordId The Resource of the Record to write out
 * @param recordPolicyResource The Resource of the Record policy
 */
protected void writeRecordPolicyPolicy(Resource user, Resource recordId,  Resource recordPolicyResource) {
    try {
        String encodedRecordIRI = ResourceUtils.encode(recordId);
        String[] search = {USER_IRI_BINDING, POLICY_IRI_BINDING, ENCODED_POLICY_IRI_BINDING};
        String[] replace = {user.stringValue(), recordPolicyResource.stringValue(), encodedRecordIRI};
        InputStream policyPolicyStream = AbstractVersionedRDFRecordService.class
                .getResourceAsStream("/policyPolicy.xml");
        String policyPolicy = StringUtils.replaceEach(IOUtils.toString(policyPolicyStream, "UTF-8"),
                search, replace);
        addPolicy(policyPolicy);
    } catch (IOException e) {
        throw new MobiException("Error writing record policy.", e);
    }
}
 
Example 13
Source Project: framework   File: PropertyHolder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Description: <br>
 * 
 * @author 王伟<br>
 * @taskId <br>
 * @return <br>
 */
public static String getProjectName() {
    String name = getProperty("project.name");
    if (StringUtils.isEmpty(name)) {
        String realPath = StringUtils.replaceEach(
            PropertyHolder.class.getClassLoader().getResource(GlobalConstants.BLANK).getPath(), new String[] {
                "/target/classes/", "/WEB-INF/classes/"
            }, new String[] {
                GlobalConstants.BLANK, GlobalConstants.BLANK
            });

        name = realPath.substring(realPath.lastIndexOf(GlobalConstants.PATH_SPLITOR));
    }
    return name;
}
 
Example 14
Source Project: Halyard   File: HttpSparqlHandler.java    License: Apache License 2.0 4 votes vote down vote up
public String getQuery() {
    //replace all tokens matchig {{parameterName}} inside the SPARQL query with corresponding parameterValues
    return StringUtils.replaceEach(query, parameterNames.toArray(new String[parameterNames.size()]), parameterValues.toArray(new String[parameterValues.size()]));
}
 
Example 15
Source Project: tddl5   File: IOSEmojiUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static String transToIOS4emoji(String src) {
    return StringUtils.replaceEach(src, ios5emoji, ios4emoji);
}
 
Example 16
Source Project: tddl5   File: IOSEmojiUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static String transToIOS5emoji(String src) {
    return StringUtils.replaceEach(src, ios4emoji, ios5emoji);
}
 
Example 17
Source Project: tddl5   File: IOSEmojiUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static String transToAndroidemojiNull(String src) {
    return StringUtils.replaceEach(src, ios5emoji, androidnullemoji);
}
 
Example 18
Source Project: tddl5   File: IOSEmojiUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static String transToAndroidemojiSB(String src) {
    return StringUtils.replaceEach(src, ios5emoji, adsbuniemoji);
}
 
Example 19
Source Project: tddl5   File: IOSEmojiUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static String transSBToIOS5emoji(String src) {
    return StringUtils.replaceEach(src, adsbuniemoji, ios5emoji);
}
 
Example 20
Source Project: yes-cart   File: HttpUtil.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Escape raw text to be safe for rendering HTML.
 *
 * @param raw raw value
 *
 * @return XSS safe value
 */
public static String escapeForHTMLAttribute(final String raw) {
    if (StringUtils.isNotBlank(raw)) {
        return StringUtils.replaceEach(escapeForHTML(raw), NO_QUOTES[0], NO_QUOTES[1]);
    }
    return raw;
}