Java Code Examples for org.apache.commons.lang3.StringUtils.substringBeforeLast()

The following are Jave code examples for showing how to use substringBeforeLast() of the org.apache.commons.lang3.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: aceql-http   File: ResultSetWriter.java   View Source Code Vote up 8 votes
/**
    * Format the column as an java.sqlArray
    * 
    * @param resultSet
    * @param columnIndex
    * @return
    * @throws SQLException
    * @throws IOException
    */
   private String formatArrayColumn(ResultSet resultSet, int columnIndex)
    throws SQLException, IOException {
Array array = resultSet.getArray(columnIndex);

Object[] objects = (Object[]) array.getArray();
String arrayStr = "{";
for (int i = 0; i < objects.length; i++) {
    arrayStr += objects[i] + ",";
}

if (arrayStr.contains(",")) {
    arrayStr = StringUtils.substringBeforeLast(arrayStr, ",");
}

arrayStr += "}";
return arrayStr;

/*
 * ArrayHttp arrayHttp = new ArrayHttp(array); ArrayTransporter
 * arrayTransporter = new ArrayTransporter(); String base64 =
 * arrayTransporter.toBase64(arrayHttp); return base64;
 */
   }
 
Example 2
Project: patternlab-for-sling   File: PatternLabUtils.java   View Source Code Vote up 6 votes
public static String constructPatternId(String patternResourcePath, String patternsPath, String templateName, String jsonDataFileName) {
    final String patternPath = StringUtils.substringAfter(patternResourcePath, patternsPath + SLASH);
    final StringBuilder patternIdBuilder = new StringBuilder();
    if (StringUtils.endsWith(patternPath, HTML_EXT)) {
        patternIdBuilder.append(StringUtils.substringBeforeLast(patternPath, HTML_EXT));
    } else {
        patternIdBuilder.append(patternPath);
    }
    if (StringUtils.isNotBlank(templateName)) {
        patternIdBuilder.append(SLASH).append(templateName);
    }
    if (StringUtils.isNotBlank(jsonDataFileName)) {
        final String patternFileName = StringUtils.substringAfterLast(patternPath, SLASH);
        final String fileNameWithoutExt = StringUtils.substringBeforeLast(patternFileName, HTML_EXT);
        final String dataFileSuffix = StringUtils.substringBetween(jsonDataFileName, fileNameWithoutExt
                + SELECTOR, DATA_EXT);
        patternIdBuilder.append(SLASH).append(StringUtils.defaultString(dataFileSuffix, fileNameWithoutExt));
    }
    return StringUtils.replace(patternIdBuilder.toString(), SLASH, PATTERN_ID_REPLACEMENT);
}
 
Example 3
Project: DYB   File: MsgView.java   View Source Code Vote up 5 votes
/**
 * 解析弹幕服务器接收到的协议数据
 * @param data
 * @return
 */
public Map<String, Object> parseRespond(String data){
	Map<String, Object> rtnMsg = new HashMap<String, Object>();
	
	//处理数据字符串末尾的'/0字符'
	data = StringUtils.substringBeforeLast(data, "/");
	
	//对数据字符串进行拆分
	String[] buff = data.split("/");
	
	//分析协议字段中的key和value值
	for(String tmp : buff){
		//获取key值
		String key = StringUtils.substringBefore(tmp, "@=");
		//获取对应的value值
		Object value = StringUtils.substringAfter(tmp, "@=");
		
		//如果value值中包含子序列化值,则进行递归分析
		if(StringUtils.contains((String)value, "@A")){
			value = ((String)value).replaceAll("@S", "/").replaceAll("@A", "@");
			value = this.parseRespond((String)value);
		}
		
		//将分析后的键值对添加到信息列表中
		rtnMsg.put(key, value);
	}
	
	return rtnMsg;
	
}
 
Example 4
Project: YiDu-Novel   File: SingleBookFilter.java   View Source Code Vote up 5 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
        ServletException {
    YiDuConstants.singleBookFlag.set(false);
    HttpServletRequest req = (HttpServletRequest) request;
    String uri = req.getRequestURI();
    if (StringUtils.endsWithAny(uri, "css", "js", "jpg", "png", "gif")) {
        // 静态资源直接跳过
        logger.debug("ignore static resource." + uri);
        chain.doFilter(request, response);
    } else {
        // 非静态资源时,根据具体的信息去做判别,时候需要标识单本
        String rootDomian = YiDuConstants.yiduConf.getString(YiDuConfig.ROOT_DOMAIN);
        String aname = StringUtils.substringBeforeLast(req.getServerName(), "." + rootDomian);
        logger.debug("aname : " + aname);
        if (StringUtils.isNotBlank(aname)) {
            int articleno = SingleBookManager.getArticleno(aname);
            if (articleno != 0) {
                // TODO 即便找到对应的小说,也只做首页和阅读页,其他全部404吧
                Pattern p = Pattern.compile(regex);
                Matcher m = p.matcher(uri);
                boolean matchFlag = false;
                String newURI = "";
                if (m.find()) {
                    // 阅读页
                    newURI = ReaderAction.URL + "?chapterno="
                            + StringUtils.substringBeforeLast(m.group(1), ".html");
                    matchFlag = true;
                } else if (StringUtils.equals(uri, "/") || StringUtils.isEmpty(uri)) {
                    // 首页
                    newURI = InfoAction.URL + "?articleno=" + articleno;
                    matchFlag = true;
                } else {
                    // 返回404
                    YiDuConstants.singleBookFlag.set(true);
                    ((HttpServletResponse) response).sendError(HttpServletResponse.SC_NOT_FOUND);
                }
                logger.debug("newURI str: " + newURI);
                if (matchFlag) {
                    YiDuConstants.singleBookFlag.set(true);
                    YiDuConstants.singleBookServerName.set(req.getServerName());
                    req.getRequestDispatcher(newURI).forward(request, response);
                }
            } else {
                chain.doFilter(request, response);
            }
        } else {
            chain.doFilter(request, response);
        }
    }
}
 
Example 5
Project: GameResourceBot   File: Preprocessor.java   View Source Code Vote up 5 votes
public static File[] extract(File frame, Device userDevice) throws IOException {
    Mat colorFilterTextLow = new Mat(new double[] { 0, 2, 0 });
    Mat colorFilterNumberLow = new Mat(new double[] { 255, 255, 255 });
    final double threshText = 0.04d;
    final int threshTextSrcLow = 200;
    final int threshTextSrcUp = 255;

    final double threshNum = 0.06d;

    // iphone 7
    Mat colorFilterNumLow;
    Device device = userDevice != null ? userDevice : Device.ANDROID;
    switch (device) {
    case IPHONE:
        colorFilterNumLow = new Mat(new double[] { 25, 175, 50 });
        break;
    default:
        colorFilterNumLow = new Mat(new double[] { 25, 255, 50 });
        break;
    }

    Mat colorFilterNumUp = new Mat(new double[] { 50, 255, 255 });
    final int threshNumSrcLow = 180;
    final int threshNumSrcUp = 255;

    String prefix = StringUtils.substringBeforeLast(frame.getName(), "_");

    File text = process(frame, colorFilterTextLow, colorFilterNumberLow, threshText, threshTextSrcLow,
            threshTextSrcUp, CV_THRESH_BINARY, prefix + "_text");
    File number = process(frame, colorFilterNumLow, colorFilterNumUp, threshNum, threshNumSrcLow, threshNumSrcUp,
            CV_THRESH_BINARY_INV, prefix + "_num");

    colorFilterTextLow.close();
    colorFilterNumberLow.close();
    colorFilterNumLow.close();
    colorFilterNumUp.close();

    return new File[] { text, number };
}
 
Example 6
Project: patternlab-for-sling   File: PatternModel.java   View Source Code Vote up 5 votes
public PatternModel(Resource resource, String patternsPath, String patternId, ResourceResolver resourceResolver) throws IOException {
    this.id = PatternLabUtils.constructPatternId(resource.getPath(), patternsPath);
    this.name = StringUtils.lowerCase(PatternLabUtils.getResourceTitleOrName(resource));
    this.template = StringUtils.EMPTY;
    this.path = resource.getPath();
    this.dataPath = StringUtils.EMPTY;
    this.displayed = StringUtils.isBlank(patternId) || StringUtils.startsWith(getId(), patternId);
    this.breadcrumb = Lists.newArrayList(new BreadcrumbItemModel(id, name));
    this.code = PatternLabUtils.getDataFromFile(path, resourceResolver);
    this.data = null;
    final String descriptionPath = StringUtils.substringBeforeLast(path, PatternLabConstants.SELECTOR) + PatternLabConstants.DESCRIPTION_EXT;
    this.description = PatternLabUtils.getDataFromFile(descriptionPath, resourceResolver);
    this.embeddedPatterns = Sets.newHashSet();
    this.includingPatterns = Sets.newHashSet();
}
 
Example 7
Project: redirector   File: ZookeeperConnector.java   View Source Code Vote up 5 votes
private CuratorTransaction saveInTransaction(CuratorTransaction transaction, byte[] data, String path) throws Exception {
    CuratorTransaction resultingTransaction = (transaction == null) ? getConnectedClientOrFailFast().inTransaction() : transaction;
    if (isNodeExistsInternal(path)) {
        resultingTransaction = resultingTransaction.setData().forPath(path, data).and();
    } else {
        String parentPath = StringUtils.substringBeforeLast(path, "/");
        if (!isNodeExistsInternal(parentPath)) {
            resultingTransaction = resultingTransaction.create().forPath(parentPath).and();
        }
        resultingTransaction = resultingTransaction.create().forPath(path, data).and();
    }
    return resultingTransaction;
}
 
Example 8
Project: redirector   File: CustomServiceCache.java   View Source Code Vote up 5 votes
private void writeBackup(String path, final String addressIPV6, Action action, String weight) {
    int nameIndex = path.lastIndexOf(RedirectorConstants.DELIMETER);
    String stack = path.substring(basePath.length(), nameIndex);
    final String address = StringUtils.substringBeforeLast(StringUtils.substring(path, nameIndex + 1), IP_PORT_SEPARATOR);
    StackSnapshot currentSnapshot = createStackSnapshot(stack, address, addressIPV6, weight);
    if (action.getId().equals(Action.REGISTERED.getId())) {
        discoveryStacksBackupManager.addStackSnapshot(currentSnapshot);
    } else {
        discoveryStacksBackupManager.deleteStackSnapshot(currentSnapshot);
    }
}
 
Example 9
Project: gitplex-mit   File: AssetServlet.java   View Source Code Vote up 5 votes
@Override
public final Resource getResource(String pathInContext) {
	ServletContextHandler.Context context = (ServletContextHandler.Context) getServletContext();
	ServletContextHandler contextHandler = (ServletContextHandler) context.getContextHandler();
	
	for (ServletMapping mapping: contextHandler.getServletHandler().getServletMappings()) {
		if (mapping.getServletName().equals(getServletName())) {
			for (String pathSpec: mapping.getPathSpecs()) {
				String relativePath = null;
				if (pathSpec.endsWith("/*")) {
					pathSpec = StringUtils.substringBeforeLast(pathSpec, "/*");
					if (pathInContext.startsWith(pathSpec + "/")) 
						relativePath = pathInContext.substring(pathSpec.length());
				} else if (pathSpec.startsWith("*.")) {
					pathSpec = StringUtils.stripStart(pathSpec, "*");
					if (pathInContext.endsWith(pathSpec))
						relativePath = pathInContext;
				} else if (pathSpec.equals(pathInContext)) {
					relativePath = pathInContext;
				}
				if (relativePath != null) {
					relativePath = StringUtils.stripStart(relativePath, "/");
					Resource resource = Resource.newResource(loadResource(relativePath));
					if (resource != null && resource.exists())
						return resource;
				}
			}
		}
	}
	
	return null;
}
 
Example 10
Project: redirector   File: CustomServiceCache.java   View Source Code Vote up 4 votes
private String getIPv4(String path) {
    int nameIndex = path.lastIndexOf(RedirectorConstants.DELIMETER);
    return StringUtils.substringBeforeLast(StringUtils.substring(path, nameIndex + 1), IP_PORT_SEPARATOR);
}
 
Example 11
Project: wx-idk   File: ShowQrcodeRequest.java   View Source Code Vote up 4 votes
/**
    * 构造函数
    * @param ticket 获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码
    * @param fullDownPath  下载文件路径+文件名
    */
   public ShowQrcodeRequest(String ticket, String fullDownPath) {
	this.ticket = ticket;
	this.fileName = StringUtils.substringAfterLast(fullDownPath, File.separator);
       this.filePath = StringUtils.substringBeforeLast(fullDownPath, File.separator) + File.separator;
}
 
Example 12
Project: wx-idk   File: PerpetualMediaGetRequest.java   View Source Code Vote up 4 votes
/**
 * 构造器
 * @param mediaId  		媒体文件ID
 * @param fullDownPath  下载文件路径+文件名
 */
public PerpetualMediaGetRequest(String mediaId, String fullDownPath) {
    this.media_id = mediaId;
    this.fileName = StringUtils.substringAfterLast(fullDownPath, File.separator);
    this.filePath = StringUtils.substringBeforeLast(fullDownPath, File.separator) + File.separator;
}
 
Example 13
Project: wx-idk   File: NewsInnerImgAddRequest.java   View Source Code Vote up 4 votes
/**
 * 构造器
 * @param fullFilePath  媒体文件路径+文件名
 */
public NewsInnerImgAddRequest(String fullFilePath) {
    this.fileName = StringUtils.substringAfterLast(fullFilePath, File.separator);
    this.filePath = StringUtils.substringBeforeLast(fullFilePath, File.separator) + File.separator;
}
 
Example 14
Project: wx-idk   File: TempMaterialGetRequest.java   View Source Code Vote up 4 votes
/**
 * 构造器
 * @param mediaId  		媒体文件ID
 * @param fullDownPath  下载文件路径+文件名
 */
public TempMaterialGetRequest(String mediaId, String fullDownPath) {
    this.media_id = mediaId;
    this.fileName = StringUtils.substringAfterLast(fullDownPath, File.separator);
    this.filePath = StringUtils.substringBeforeLast(fullDownPath, File.separator) + File.separator;
}
 
Example 15
Project: wx-idk   File: TempMaterialAddRequest.java   View Source Code Vote up 4 votes
/**
 * 构造器
 * @param type          媒体文件类型,分别有图片image、语音voice、视频video和缩略图thumb
 * @param fullFilePath  媒体文件路径+文件名
 */
public TempMaterialAddRequest(String type, String fullFilePath) {
    this.type = type;
    this.fileName = StringUtils.substringAfterLast(fullFilePath, File.separator);
    this.filePath = StringUtils.substringBeforeLast(fullFilePath, File.separator) + File.separator;
}
 
Example 16
Project: wx-idk   File: UploadPoiImgRequest.java   View Source Code Vote up 4 votes
/**
 * 构造器
 * @param fullFilePath  媒体文件路径+文件名
 */
public UploadPoiImgRequest(String fullFilePath) {
    this.fileName = StringUtils.substringAfterLast(fullFilePath, File.separator);
    this.filePath = StringUtils.substringBeforeLast(fullFilePath, File.separator) + File.separator;
}
 
Example 17
Project: Yidu   File: SingleBookFilter.java   View Source Code Vote up 4 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
        ServletException {
    YiDuConstants.singleBookFlag.set(false);
    HttpServletRequest req = (HttpServletRequest) request;
    String uri = req.getRequestURI();
    if (StringUtils.endsWithAny(uri, "css", "js", "jpg", "png", "gif")) {
        // 静态资源直接跳过
        logger.debug("ignore static resource." + uri);
        chain.doFilter(request, response);
    } else {
        // 非静态资源时,根据具体的信息去做判别,时候需要标识单本
        String rootDomian = YiDuConstants.yiduConf.getString(YiDuConfig.ROOT_DOMAIN);
        String aname = StringUtils.substringBeforeLast(req.getServerName(), "." + rootDomian);
        logger.debug("aname : " + aname);
        if (StringUtils.isNotBlank(aname)) {
            int articleno = SingleBookManager.getArticleno(aname);
            if (articleno != 0) {
                // TODO 即便找到对应的小说,也只做首页和阅读页,其他全部404吧
                Pattern p = Pattern.compile(regex);
                Matcher m = p.matcher(uri);
                boolean matchFlag = false;
                String newURI = "";
                if (m.find()) {
                    // 阅读页
                    newURI = ReaderAction.URL + "?chapterno="
                            + StringUtils.substringBeforeLast(m.group(1), ".html");
                    matchFlag = true;
                } else if (StringUtils.equals(uri, "/") || StringUtils.isEmpty(uri)) {
                    // 首页
                    newURI = InfoAction.URL + "?articleno=" + articleno;
                    matchFlag = true;
                } else {
                    // 返回404
                    YiDuConstants.singleBookFlag.set(true);
                    ((HttpServletResponse) response).sendError(HttpServletResponse.SC_NOT_FOUND);
                }
                logger.debug("newURI str: " + newURI);
                if (matchFlag) {
                    YiDuConstants.singleBookFlag.set(true);
                    YiDuConstants.singleBookServerName.set(req.getServerName());
                    req.getRequestDispatcher(newURI).forward(request, response);
                }
            } else {
                chain.doFilter(request, response);
            }
        } else {
            chain.doFilter(request, response);
        }
    }
}
 
Example 18
Project: sling-org-apache-sling-testing-clients   File: SlingClient.java   View Source Code Vote up 2 votes
/**
 * Extracts the parent path from the given String
 *
 * @param path string containing the path
 * @return the parent path if exists or empty string otherwise
 */
protected String getParentPath(final String path) {
    // TODO define more precisely what is the parent of a folder and of a file
    final String normalizedPath = StringUtils.removeEnd(path, "/");  // remove trailing slash in case of folders
    return StringUtils.substringBeforeLast(normalizedPath, "/");
}
 
Example 19
Project: redirector   File: StacksHelper.java   View Source Code Vote up 2 votes
/**
 * @param fullPath of full path e.g. /PO/POC5/1.40/xreGuide
 * @return stack path without serviceName e.g. /PO/POC5/1.40
 */
public static String getStackPathWithoutServiceName(String fullPath) {
    return  StringUtils.substringBeforeLast(fullPath, RedirectorConstants.DELIMETER);
}
 
Example 20
Project: redirector   File: StacksHelper.java   View Source Code Vote up 2 votes
/**
 * @param stackPathWithoutServiceName of stack path without serviceName e.g. /PO/POC5/1.40
 * @return stack e.g. /PO/POC5/1.40
 */
public static String getStackPath(String stackPathWithoutServiceName) {
    return StringUtils.substringBeforeLast(stackPathWithoutServiceName, RedirectorConstants.DELIMETER);
}