Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.regex.Pattern;

public class Main {
    /**
     * Replace all occurrences of oldVarName in xpathExpr with newVarName
     * 
     * @param xpathExpr The {@link XPath} expression String
     * @param oldVarName The old variable name
     * @param newVarName The new variable name
     * @return {@link XPath} expression String with replaced {@link Variable}
     *         names
     */
    public static String replaceVariableName(String xpathExpr, String oldVarName, String newVarName) {
        // First replace normal Variable occurrence
        String newExpr = xpathExpr.replaceAll(Pattern.quote("$" + oldVarName) + "(?!\\w{1})\\W??",
                "\\$" + newVarName);
        // Now replace all occurrences in bpel:getVariableProperty
        newExpr = newExpr.replaceAll("bpel:getVariableProperty\\(\"" + oldVarName + "\"",
                "bpel:getVariableProperty(\"" + newVarName + "\"");
        newExpr = newExpr.replaceAll("bpel:getVariableProperty\\('" + oldVarName + "'",
                "bpel:getVariableProperty('" + newVarName + "'");
        return newExpr;
    }
}