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

The following are Jave code examples for showing how to use replace() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: matrix-appservice-email   File: EmailFormatterOutboud.java   View Source Code Vote up 6 votes
private String processToken(TokenData data, String template) {
    template = StringUtils.replace(template, EmailTemplateToken.ManageUrl.getToken(), data.getManageUrl());
    template = StringUtils.replace(template, EmailTemplateToken.MsgTimeHour.getToken(), data.getTimeHour());
    template = StringUtils.replace(template, EmailTemplateToken.MsgTimeMin.getToken(), data.getTimeMin());
    template = StringUtils.replace(template, EmailTemplateToken.MsgTimeSec.getToken(), data.getTimeSec());
    template = StringUtils.replace(template, EmailTemplateToken.ReceiverAddress.getToken(), data.getReceiverAddress());
    template = StringUtils.replace(template, EmailTemplateToken.SenderAddress.getToken(), data.getSenderAddress());
    template = StringUtils.replace(template, EmailTemplateToken.SenderName.getToken(), data.getSenderName());
    template = StringUtils.replace(template, EmailTemplateToken.SenderAvatar.getToken(), senderAvatarId);
    template = StringUtils.replace(template, EmailTemplateToken.Sender.getToken(), data.getSender());
    template = StringUtils.replace(template, EmailTemplateToken.RoomAddress.getToken(), data.getRoomAddress());
    template = StringUtils.replace(template, EmailTemplateToken.RoomName.getToken(), data.getRoomName());
    template = StringUtils.replace(template, EmailTemplateToken.Room.getToken(), data.getRoom());

    return template;
}
 
Example 2
Project: Hydrograph   File: ExternalSchemaUpdaterHandler.java   View Source Code Vote up 6 votes
private boolean closeEditorIfAlreadyOpen(IPath jobFilePath, String fileName) {

		String jobPathRelative = StringUtils.removeStart(jobFilePath.toString(), "..");
		jobPathRelative = StringUtils.removeStart(jobPathRelative, "/");
		String jobPathAbsolute = StringUtils.replace(jobPathRelative, "/", "\\");
		IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (activeWorkbenchWindow != null) {
			IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
			for (IEditorReference editorRefrence : activePage.getEditorReferences()) {
				if (StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathRelative)
						|| StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathAbsolute)
						|| fileName.equals(editorRefrence.getTitleToolTip())) {
					IEditorPart editor = editorRefrence.getEditor(true);
					if (!activePage.closeEditor(editor, true)) {
						LOGGER.debug("Editor not closed");
					}
					LOGGER.debug("Editor closed");
					return true;
				}
			}
		}
		return false;
	}
 
Example 3
Project: lams   File: RemoveToolContextClasspathTask.java   View Source Code Vote up 6 votes
/** Remove the jar file to the classpath in the MANIFEST.MF file */
   @Override
   protected void updateClasspath(Manifest manifest) throws DeployException {
Attributes mainAttributes = manifest.getMainAttributes();
String classpath = null;
if (mainAttributes != null) {
    classpath = mainAttributes.getValue(Attributes.Name.CLASS_PATH);
}

String newJar = getJarFileNameWithDotSlash();
String newClasspath = null;
if (classpath != null) {
    newClasspath = StringUtils.replace(classpath, newJar, "");
    mainAttributes.put(Attributes.Name.CLASS_PATH, newClasspath);
    if (classpath.length() < newClasspath.length()) {
	System.out.println("Removed " + newJar + " from classpath");
    }
}
   }
 
Example 4
Project: my-spring-boot-project   File: SQLFilter.java   View Source Code Vote up 6 votes
/**
 * SQL注入过滤
 *
 * @param str 待验证的字符串
 */
public static String sqlInject(String str) {
    if (StringUtils.isBlank(str)) {
        return null;
    }
    //去掉'|"|;|\字符
    str = StringUtils.replace(str, "'", "");
    str = StringUtils.replace(str, "\"", "");
    str = StringUtils.replace(str, ";", "");
    str = StringUtils.replace(str, "\\", "");

    //转换成小写
    str = str.toLowerCase();

    //非法字符
    String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alert", "drop"};
    String finalStr = str;
    //判断是否包含非法字符
    return Arrays.stream(keywords).filter(finalStr::contains).findFirst().orElseThrow(() -> new RRException("包含非法字符"));
}
 
Example 5
Project: pds   File: SQLFilter.java   View Source Code Vote up 6 votes
/**
 * SQL注入过滤
 * @param str  待验证的字符串
 */
public static String sqlInject(String str){
    if(StringUtils.isBlank(str)){
        return null;
    }
    //去掉'|"|;|\字符
    str = StringUtils.replace(str, "'", "");
    str = StringUtils.replace(str, "\"", "");
    str = StringUtils.replace(str, ";", "");
    str = StringUtils.replace(str, "\\", "");

    //转换成小写
    str = str.toLowerCase();

    //非法字符
    String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alert", "drop"};

    //判断是否包含非法字符
    for(String keyword : keywords){
        if(str.indexOf(keyword) != -1){
            throw new RRException("包含非法字符");
        }
    }

    return str;
}
 
Example 6
Project: renren-msg   File: SQLFilter.java   View Source Code Vote up 6 votes
/**
 * SQL注入过滤
 * @param str  待验证的字符串
 */
public static String sqlInject(String str){
    if(StringUtils.isBlank(str)){
        return null;
    }
    //去掉'|"|;|\字符
    str = StringUtils.replace(str, "'", "");
    str = StringUtils.replace(str, "\"", "");
    str = StringUtils.replace(str, ";", "");
    str = StringUtils.replace(str, "\\", "");

    //转换成小写
    str = str.toLowerCase();

    //非法字符
    String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alert", "drop"};

    //判断是否包含非法字符
    for(String keyword : keywords){
        if(str.indexOf(keyword) != -1){
            throw new RRException("包含非法字符");
        }
    }

    return str;
}
 
Example 7
Project: Hydrograph   File: SubJobOpenAction.java   View Source Code Vote up 5 votes
private boolean isJobAlreadyOpen(IPath jobFilePath) {
	
	String jobPathRelative = StringUtils.removeStart(jobFilePath.toString(), "..");
	jobPathRelative=StringUtils.removeStart(jobPathRelative, "/");
	String jobPathAbsolute = StringUtils.replace(jobPathRelative, "/", "\\");
	for (IEditorReference editorRefrence : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
			.getEditorReferences()) {
		if (StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathRelative)) {
			return true;
		}else if (StringUtils.equals(editorRefrence.getTitleToolTip(), jobPathAbsolute)) {
			return true;
		}
	}
	return false;
}
 
Example 8
Project: EscapeLag   File: AntiRedstone.java   View Source Code Vote up 5 votes
@EventHandler
public void CheckRedstone(BlockRedstoneEvent event){
	if(ConfigOptimize.AntiRedstoneenable){
		if(event.getOldCurrent() > event.getNewCurrent()){
            return;
        }
        final Block block = event.getBlock();
        Location loc = block.getLocation();
        if(CheckedTimes.get(loc) == null){
            CheckedTimes.put(loc, 0);
        }
        CheckedTimes.put(loc, CheckedTimes.get(loc) + 1);

        if(CheckedTimes.get(loc) > ConfigOptimize.AntiRedstoneTimes){
            if(ConfigOptimize.AntiRedstoneRemoveBlockList.contains(block.getType().name())){
	Bukkit.getScheduler().runTaskLater(EscapeLag.MainThis,new Runnable(){
		public void run(){
			block.setType(Material.AIR);
		}
	},1);
                String message = ConfigOptimize.AntiRedstoneMessage;
                message = StringUtils.replace(message, "%location%", loc.toString());
                AzureAPI.bc(message);
            }
        }
	}
}
 
Example 9
Project: Hydrograph   File: FilterUiConverter.java   View Source Code Vote up 5 votes
/**
 * initialize ui object from external file data.
 * 
 * @param filterLogicDataStructure
 * @param typeTransformOpertaionList
 */
public void populateUIDataFromExternalData(FilterLogicDataStructure filterLogicDataStructure,
		List<JAXBElement<?>> typeTransformOpertaionList) {
	TypeExternalSchema typeExternalSchema=(TypeExternalSchema) filter
			.getOperationOrExpressionOrIncludeExternalOperation().get(0).getValue();
	String filePath = typeExternalSchema.getUri();
	filePath = StringUtils.replace(filePath, "../","");
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	 IPath relativePath=null;
		 relativePath=workspace.getRoot().getFile(new Path(filePath)).getLocation();
	 if(StringUtils.equals("includeExternalExpression", ((JAXBElement<?>) typeTransformOpertaionList.get(0)).getName().getLocalPart()))
	 {
		 	ExpressionData expressionData=FilterLogicExternalOperationExpressionUtil.INSTANCE
			 .importExpression(new File(relativePath.toString()), null, false, uiComponent.getComponentName());
			expressionData.getExternalExpressionData().setExternal(true);
			expressionData.getExternalExpressionData().setFilePath(filePath);
			filterLogicDataStructure.setExpressionEditorData(expressionData);
	 }
	 else {
			OperationClassData operationClassData=FilterLogicExternalOperationExpressionUtil.INSTANCE
		    		 .importOperation(new File(relativePath.toString()), null, false, uiComponent.getComponentName());
		    operationClassData.getExternalOperationClassData().setExternal(true);
		    operationClassData.getExternalOperationClassData().setFilePath(filePath);
		    filterLogicDataStructure.setOperationClassData(operationClassData);
			 
	 }
}
 
Example 10
Project: ICEWall   File: MongoInjection.java   View Source Code Vote up 5 votes
/**
 * @param value 待处理内容
 * @return
 * @Description MongoDB防注入
 */
@Override
public String strip(String value) {


    for (int i=0;i<blackList.length;i++){
        value=StringUtils.replace(value,blackList[i],"");
    }
    return value;
}
 
Example 11
Project: ymate-payment-v2   File: AliPayBaseResponseParser.java   View Source Code Vote up 5 votes
public AliPayBaseResponseParser(Class<? extends RESPONSE> clazz, String methodName) {
    if (clazz == null) {
        throw new NullArgumentException("clazz");
    }
    if (StringUtils.isBlank(methodName)) {
        throw new NullArgumentException("methodName");
    }
    __class = clazz;
    __methodName = StringUtils.replace(methodName, ".", "_") + IAliPay.Const.RESPONSE_SUFFIX;
}
 
Example 12
Project: otter-G   File: NumberFormatUtil.java   View Source Code Vote up 5 votes
public String getHtmlOriginalContent(String originalContent) {
    originalContent = StringUtils.replace(originalContent, "\n", "<br>");
    originalContent = StringUtils.replace(originalContent, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
    return StringEscapeUtils.escapeJavaScript(originalContent);
}
 
Example 13
Project: otter-G   File: AutoKeeperStat.java   View Source Code Vote up 5 votes
public String getHtmlOriginalContent() {
    return StringUtils.replace(originalContent, "\n", "<br>");
}
 
Example 14
Project: media_information_service   File: APIOperations.java   View Source Code Vote up 4 votes
public static LinkedList<MusicInfo> musicGetInfoItunes(String name, String max_result, String orderBy, String artist, String year) throws UnirestException
    {
        String name_request = name.replace(" ", "%20");
        String artist_request = artist.trim().replace(" ", "%20");
        LinkedList<MusicInfo> lis = new LinkedList<MusicInfo>();
        String urlRequest = "";
        if (!artist_request.equals("")) urlRequest="https://itunes.apple.com/search" + "?term=" + name_request+"%20"+artist_request+"&media=music";
        else urlRequest="https://itunes.apple.com/search" + "?term=" + name_request+"&media=music";
        String year_request=year;
        if (year_request.trim().equals("") || year.length()<4) year_request="";
        HttpResponse<JsonNode> jsonResponse = Unirest.get(urlRequest).asJson();
        //System.out.println(jsonResponse.getBody());
        JSONObject jsonObject = new JSONObject(jsonResponse.getBody());
        JSONArray jArray = jsonObject.getJSONArray("array");

        int iteration = 0;
        //Generate list of results
        for (int i = 0; i < jArray.length(); i++) {
            JSONArray resultInfo = jArray.getJSONObject(i).getJSONArray("results");
            for (int k = 0; k < resultInfo.length(); k++) {
                JSONObject result = resultInfo.getJSONObject(k);
                MusicInfo b = new MusicInfo();
                b.setTitle(result.getString("trackName"));
                if (result.has("artistName")) b.setArtist(result.getString("artistName"));
                if (result.has("primaryGenreName")) b.setGenre(result.getString("primaryGenreName"));
                if (result.has("releaseDate")) {
                    String y=result.getString("releaseDate");
                    b.setReleaseDate(y.substring(0,y.indexOf("T")));
                }
                if(result.has("artworkUrl100")) {
                    String link_reverse=StringUtils.reverse(result.getString("artworkUrl100"));
                    link_reverse=StringUtils.replace(link_reverse,"001","215",2);
                    b.setLinkImage(StringUtils.reverse(link_reverse));
                    //iTunes cover link doesn't support HTTPS
                }
                if (result.has("collectionName")) b.setCollection(result.getString("collectionName"));
                if (result.has("description")) b.setOverview(result.getString("description"));
                if (result.has("previewUrl")) b.setLinkpreview(result.getString("previewUrl"));
                if(b.getReleaseDate().substring(0,4).equals(year) || year_request.equals("")) lis.add(b);
                //System.out.println(b);
                if (!max_result.equals("all") && iteration == Integer.parseInt(max_result) - 1) break;
                iteration++;
            }
        }

    if (lis.size() > 0 && (!orderBy.equals("relevance") && !orderBy.equals(""))) {
        Collections.sort(lis, new Comparator<MusicInfo>() {
            @Override
            public int compare(final MusicInfo object1, final MusicInfo object2) {
                if (orderBy.equals("newest")) return object2.getReleaseDate().compareTo(object1.getReleaseDate());
                else return object1.getReleaseDate().compareTo(object2.getReleaseDate());
            }
        });
    }
    return lis;
}
 
Example 15
Project: otter-G   File: NodeCommmunicationClient.java   View Source Code Vote up 4 votes
public void setManagerAddress(String managerAddress) {
    String server = StringUtils.replace(managerAddress, ";", ",");
    String[] servers = StringUtils.split(server, ',');
    this.managerAddress = Arrays.asList(servers);
    this.index = RandomUtils.nextInt(this.managerAddress.size()); // 随机选择一台机器
}
 
Example 16
Project: otter-G   File: CanalCommmunicationClient.java   View Source Code Vote up 4 votes
public void setManagerAddress(String managerAddress) {
    String server = StringUtils.replace(managerAddress, ";", ",");
    String[] servers = StringUtils.split(server, ',');
    this.managerAddress = Arrays.asList(servers);
    this.index = RandomUtils.nextInt(this.managerAddress.size()); // 随机选择一台机器
}
 
Example 17
Project: atlas   File: AwbBundle.java   View Source Code Vote up 4 votes
public String getAwbSoName() {
    if (org.apache.commons.lang3.StringUtils.isEmpty(soFileName)) {
        String packageName = getPackageName();
        if (packageName == null) {
            return null;
        }

        soFileName = "lib" + StringUtils.replace(packageName, ".", "_") + ".so";
    }
    return soFileName;
}
 
Example 18
Project: Hydrograph   File: PreStartActivity.java   View Source Code Vote up 4 votes
private void updateData(byte[] text, String javaHome, String end,RandomAccessFile file) throws IOException {
	String data=new String(text);
	data=StringUtils.replace(data, end, javaHome);
	file.setLength(data.length());
	file.writeBytes(data);
}
 
Example 19
Project: athena   File: DefaultInfluxMetric.java   View Source Code Vote up 4 votes
private DateTime parseTime(String time) {
    String reformatTime = StringUtils.replace(StringUtils.replace(time, "T", " "), "Z", "");
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    return formatter.parseDateTime(reformatTime);
}
 
Example 20
Project: Equella   File: ExtendedPropertiesLayout.java   View Source Code Vote up 4 votes
@SuppressWarnings("nls")
private String escapeValue(Object value)
{
	String escapedValue = StringEscapeUtils.escapeJava(String.valueOf(value));
	return StringUtils.replace(escapedValue, "\\/", "/");
}