Java Code Examples for com.xnx3.Lang#subString()

The following examples show how to use com.xnx3.Lang#subString() . 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: Sql.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 传入组合的列名,如 >create_date  或 =id
 * @param groupColumn 
 */
public SqlColumn(String groupColumn){
	for (int i = 0; i < Sql.COLUMN_GROUP.length; i++) {
		if(groupColumn.indexOf(Sql.COLUMN_GROUP[i])>0){
			this.operators = Sql.COLUMN_GROUP[i];
			this.columnName = groupColumn.replace(this.operators, "");
			break;
		}
	}
	
	if(this.operators==null){
		this.columnName = groupColumn;
	}
	
	/**
	 * 时间判断筛选
	 */
	boolean isDateToInt = this.columnName.indexOf("date")>0;	//判断是否需要进行时间戳转换
	if(isDateToInt){
		this.dateFormat = Lang.subString(columnName, "(date:", ")",2);
		this.columnName = this.columnName.replace("(date:"+this.dateFormat+")", "");
	}
}
 
Example 2
Source File: IpUtil.java    From xnx3 with Apache License 2.0 6 votes vote down vote up
/**
 * 获取IP地址,只会返回一个IP
 * @param request
 * @return <li>成功:返回一个ip
 * 			<li>失败:返回null
 */
public static String getIpAddress(HttpServletRequest request) {  
    String ip = request.getHeader("x-forwarded-for");  
    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        ip = request.getHeader("Proxy-Client-IP");  
    }  
    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        ip = request.getHeader("WL-Proxy-Client-IP");  
    }  
    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
        ip = request.getRemoteAddr();  
    }  
    
    //如果有多个ip,拿最前面的
    if(ip.indexOf(",")>0){
    	ip=Lang.subString(ip, null, ",", 2);
    }
    
    if(ip.equals("0:0:0:0:0:0:0:1")){
    	ip = "127.0.0.1";
    }
    return ip;  
}
 
Example 3
Source File: Resource.java    From templatespider with Apache License 2.0 5 votes vote down vote up
/**
	 * @param refererPagePath 来源页面的路径所在。如 www.baidu.com/a/b/c.html 那么这里便是 www.baidu.com/a/b/ 此项的作用,是当 originalUrl 是相对路径时,进行自动补齐其路径
	 */
	public Resource(String baseUri, String originalUrl) {
		this.originalUrl = originalUrl;
		if(baseUri.lastIndexOf("/") < baseUri.length() - 1){
			this.baseUri = Lang.subString(baseUri, "/", null, 3);
		}else{
			this.baseUri = baseUri;
		}
		
		//原始url
		if(originalUrl == null || originalUrl.length() < 2){
			return;
		}
		
		//资源在网络的绝对地址
		if(originalUrl.indexOf("http://") == 0 || originalUrl.indexOf("https://") == 0 || originalUrl.indexOf("//") == 0){
			//传入的是绝对url
			this.netUrl = originalUrl;
		}else{
			//传入的是相对路径,计算出绝对路径。
			if(originalUrl.indexOf("./") == 0){
				//是资源文件饮用
				this.netUrl = this.baseUri + originalUrl.substring(2, originalUrl.length());
			}else if (originalUrl.indexOf("../") == 0) {
				//上级文件,针对此项目,那应该就是html文件了
//				this.netUrl = Lang.subString(this.baseUri.substring(0, this.baseUri.length() - 1), "/", null, 3) + originalUrl.substring(3, originalUrl.length());
				//需要找baseUri的上一级目录
				this.netUrl = this.baseUri.substring(0, this.baseUri.substring(0, this.baseUri.length()-1).lastIndexOf("/")+1) + originalUrl.substring(3, originalUrl.length());
			}else if (originalUrl.indexOf("/") == 0) {
				//是根目录
				System.out.println("根目录");
			}else{
				//什么也没有,直接跟在后面即可
				this.netUrl = this.baseUri + originalUrl;
			}
		}
		
		jisuanLocalFile();
	}
 
Example 4
Source File: Template.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * 获取HTML注释中的指定配置名的文本内容,若没发现这个配置,返回""
 * @param sourceText 指定的HTML内容
 * @param configName 参数名
 * @return 值
 */
public static String getConfigValue(String sourceText,String configName){
	if(sourceText.indexOf("<!--"+configName+"=") > -1){
		return Lang.subString(sourceText, "<!--"+configName+"=", "-->",2);
	}else{
		return "";
	}
}
 
Example 5
Source File: Resource.java    From templatespider with Apache License 2.0 4 votes vote down vote up
/**
	 * 根据this.netUrl 网上的绝对路径,来计算存到本地的路径
	 */
	public void jisuanLocalFile(){
		
//		String originalUrl = null;
		if(this.netUrl.lastIndexOf("/") < 5){
			Global.log("debug netUrl.lastIndexOf < 5, netUrl:"+this.netUrl);
			return;
		}else{
			//保存到本地的文件
			this.localFile = UrlUtil.getFileName(this.netUrl);
//					StringUtil.getFileNameByUrl(this.netUrl);
		}

		//判断资源类型,是html、css、js、image
		//获取资源的后缀名+后面?的一堆
		String suffix = Lang.subString(this.localFile, ".", null, 4);
		//图片文件后缀
		String[] imgs = {"jpg","jpeg","gif","png","bmp","ico","svg"};
		String type = null;
		for (int i = 0; i < imgs.length; i++) {
			if(suffix.equalsIgnoreCase(imgs[i])){
				type = "image";
				break;
			}
		}
		if(type == null){
			//判断是否是js后缀
			if(suffix.equalsIgnoreCase("js")){
				type = "js";
			}
		}
		if(type == null){
			//判断是否是css后缀
			String[] csss = {"css","woff2","woff","eot","ttf","otf"};
			for (int i = 0; i < csss.length; i++) {
				if(suffix.equalsIgnoreCase(csss[i])){
					type = "css";
					break;
				}
			}
		}
		if(type == null){
			//判断是否是html文件
			String[] htmls = {"htm","html","shtml","jsp","action","do","asp","aspx","php"};
			for (int i = 0; i < htmls.length; i++) {
				if(suffix.equalsIgnoreCase(htmls[i])){
					type = "html";
					suffix = "html";	//后缀名变为html
					this.localFile.replace("."+htmls[i], "html");	//将缓存的后缀改为html
					break;
				}
			}
		}
		if(type == null){
			System.out.println("未发现什么类型。type:"+type+",--"+originalUrl);
			this.localUrl = Global.getLocalTemplatePath();
			this.localRelativePath = "/";
		}else{
			switch (type) {
			case "image":
				this.localUrl = Global.getLocalTemplatePath()+"images/";
				this.localRelativePath = "images/";
				break;
			case "js":
				this.localUrl = Global.getLocalTemplatePath()+"js/";
				this.localRelativePath = "js/";
				break;
			case "css":
				this.localUrl = Global.getLocalTemplatePath()+"css/";
				this.localRelativePath = "css/";
				break;
			case "html":
				this.localUrl = Global.getLocalTemplatePath();
				this.localRelativePath = "/";
				break;
			default:
				this.localUrl = Global.getLocalTemplatePath();
				this.localRelativePath = "/";
				break;
			}
		}

		
		//判断磁盘上这个文件是否存在
		if(FileUtil.exists(this.localUrl + localFile)){
			//已经存在了,那么要重新命名,不能覆盖
			this.localFile = Lang.subString(this.localFile, null, ".")+"_"+Lang.uuid()+"."+suffix;
		}
		
		//赋值,当前存储再磁盘的绝对路径
		this.localUrl = this.localUrl + this.localFile;
	}
 
Example 6
Source File: Template.java    From wangmarket with Apache License 2.0 2 votes vote down vote up
/**
 * 获取指定HTML注释中间的文字内容。 如 <pre>首页<!--aboutUs_Start-->12<!--aboutUs_End-->新闻 ,获取其内的 12</pre>
 * @param sourceText 原始字符串,要提取的原始字符
 * @param htmlTag 替换的标签,如 aboutUs
 * @return
 */
public static String getAnnoCenterString(String sourceText,String htmlTag){
	return Lang.subString(sourceText, "<!--"+htmlTag+"_Start-->", "<!--"+htmlTag+"_End-->",2);
}
 
Example 7
Source File: Template.java    From wangmarket with Apache License 2.0 2 votes vote down vote up
/**
 * 获取指定HTML注释中间的文字内容,通过start+id来获取。 如 <pre>首页<!--aboutUs_Start--><!--id=12-->这是内容啊啊啊<!--aboutUs_End-->新闻 ,获取其内的 12</pre>
 * @param sourceText 原始字符串,要提取的原始字符
 * @param htmlTag 替换的标签,如 aboutUs
 * @return
 */
public static String getAnnoCenterStringById(String sourceText,String htmlTag, String id){
	return Lang.subString(sourceText, "<!--"+htmlTag+"_Start--><!--id="+id+"-->", "<!--"+htmlTag+"_End-->",2);
}
 
Example 8
Source File: OSSUtils.java    From xnx3 with Apache License 2.0 2 votes vote down vote up
/**
 * 上传文件。上传后的文件名固定
 * @param path 上传到哪里,包含上传后的文件名,如"image/head/123.jpg"
 * @param inputStream 文件
 * @return {@link PutResult}
 */
public PutResult put(String path,InputStream inputStream){
	PutObjectResult pr = getOSSClient().putObject(bucketName, path, inputStream);
	String name = Lang.subString(path, "/", null, 3);
	return new PutResult(name, path,url+path);
}
 
Example 9
Source File: OSSUtil.java    From xnx3 with Apache License 2.0 2 votes vote down vote up
/**
 * 上传文件。上传后的文件名固定
 * @param path 上传到哪里,包含上传后的文件名,如"image/head/123.jpg"
 * @param inputStream 文件
 * @return {@link PutResult}
 */
public static PutResult put(String path,InputStream inputStream){
	PutObjectResult pr = getOSSClient().putObject(bucketName, path, inputStream);
	String name = Lang.subString(path, "/", null, 3);
	return new PutResult(name, path,url+path);
}