public static LinkedHashSet<String> findJars(LogicalPlan dag, Class<?>[] defaultClasses) { List<Class<?>> jarClasses = new ArrayList<Class<?>>(); for (String className : dag.getClassNames()) { try { Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className); jarClasses.add(clazz); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Failed to load class " + className, e); } } for (Class<?> clazz : Lists.newArrayList(jarClasses)) { // process class and super classes (super does not require deploy annotation) for (Class<?> c = clazz; c != Object.class && c != null; c = c.getSuperclass()) { // LOG.debug("checking " + c); jarClasses.add(c); jarClasses.addAll(Arrays.asList(c.getInterfaces())); } } jarClasses.addAll(Arrays.asList(defaultClasses)); if (dag.isDebug()) { LOG.debug("Deploy dependencies: {}", jarClasses); } LinkedHashSet<String> localJarFiles = new LinkedHashSet<String>(); // avoid duplicates HashMap<String, String> sourceToJar = new HashMap<String, String>(); for (Class<?> jarClass : jarClasses) { if (jarClass.getProtectionDomain().getCodeSource() == null) { // system class continue; } String sourceLocation = jarClass.getProtectionDomain().getCodeSource().getLocation().toString(); String jar = sourceToJar.get(sourceLocation); if (jar == null) { // don't create jar file from folders multiple times jar = JarFinder.getJar(jarClass); sourceToJar.put(sourceLocation, jar); LOG.debug("added sourceLocation {} as {}", sourceLocation, jar); } if (jar == null) { throw new AssertionError("Cannot resolve jar file for " + jarClass); } localJarFiles.add(jar); } String libJarsPath = dag.getValue(LogicalPlan.LIBRARY_JARS); if (!StringUtils.isEmpty(libJarsPath)) { String[] libJars = StringUtils.splitByWholeSeparator(libJarsPath, LIB_JARS_SEP); localJarFiles.addAll(Arrays.asList(libJars)); } LOG.info("Local jar file dependencies: " + localJarFiles); return localJarFiles; }
/** * @param filterName 比较属性字符串,含待比较的比较类型、属性值类型及属性列表. eg. LIKES_NAME_OR_LOGIN_NAME * @param value 待比较的值. */ public PropertyFilter(final String filterName, final Object value) { String firstPart = StringUtils.upperCase(StringUtils.substringBefore(filterName, "_")); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException("filter名称" + filterName + "没有按规则编写,无法得到属性比较类型.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException("filter名称" + filterName + "没有按规则编写,无法得到属性值类型.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); // AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter名称" + filterName + // "没有按规则编写,无法得到属性名称."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = value; if (null == value || !String.class.equals(value.getClass())) { return; } if (!String.class.equals(propertyClass)) { this.matchValue = ConvertUtils.convert((String) value, propertyClass); } }
/** * get the IndicatorDefinitionParameter information from the record and build the paraMap, set it * into UDIParameters. * * @param record */ private static Map<String, String> buildIndDefPara(HashMap<String, String> record) { Map<String, String> paraMap = new HashMap<String, String>(); String string = record.get(PatternToExcelEnum.IndicatorDefinitionParameter.getLiteral()); if (StringUtils.isNotBlank(string)) { String[] keyValues = StringUtils.splitByWholeSeparator(string, UDIHelper.PARA_SEPARATE_2); for (String keyValue : keyValues) { if (StringUtils.isNotBlank(keyValue)) { String[] para = StringUtils.splitByWholeSeparator(keyValue, UDIHelper.PARA_SEPARATE_1); // the key should not be blank, the value can be anything if (para.length == 2 && StringUtils.isNotBlank(para[0]) && para[1] != null) { paraMap.put(para[0], para[1]); } } } } return paraMap; }
/* * 공통 정규식 후처리는 아래에서 구현하고 * 사이트별 후처리는 사이트별 filter에서 처리하자 * 정규식이 2가지가 될 수 있기에 if 문으로 나누어서 후처리 한다. * 정규식이 1가지만으로 처리 된다면 filterPostprocessing 에 직접 로직을 구현하자. * @see search.crawl.napoli.filter.Filter#filterPostprocessing() */ public Map<String, String> regexpPostprocessing(Map<String, String> result) { result = super.regexpPostprocessing(result); int retState = 1; result.put("section", "질문과답변"); result.put("quesdate", StringUtils.replace(result.get("quesdate"), ".", "-")); // 답변 나누기 String[] ansList = StringUtils.splitByWholeSeparator(result.get("0,a_answerlist"), "<!-- 답변 1시작 -->"); // selectedAnswerCount=0; this.answerCount = ansList.length; int tmpInx = 0; if (this.answerCount > 0) { String selectedString = "<span class=\"tx14_black2\"[^>]*>(.*)<td class=\"tx11_black\"[^>]*>.*" + "등록일 : </b>([^ ]*) ([^ ]*) <font color=\"#7A8AAC\">\\|</font><b> id : </b>([^<]*).*" + "<td class=\"tx13_black\"[^>]*>(.*)<td style=\"padding-bottom:10px;\">"; InterruptibleCharSequence ics = new InterruptibleCharSequence(ansList[0]); Matcher matcher = Pattern.compile(selectedString, Pattern.MULTILINE | Pattern.DOTALL) .matcher(ics.toString()); if (matcher.find()) { result.put("0,a_title", matcher.group(1)); result.put("0,a_date", matcher.group(2)); result.put("0,a_time", matcher.group(2)); result.put("0,a_id", matcher.group(2)); result.put("0,a_bodyhtml", matcher.group(2)); result.put("0,a_date", StringUtils.replace(result.get("0,a_date"), ".", "-")); this.selectedAnswerCount++; tmpInx++; } else { this.answerCount--; } } String a_regexp = "<td height=\"26\" bgcolor=\"F6F6F6\" class=\"tx14_black3\"[^>]*>(.*)<td width=\"5\" height=\"5\"[^>]*>.*" + "등록일 : </b>([^ ]*) ([^ ]*) <font color=\"#7A8AAC\">\\|</font><b> id : </b>([^<]*).*" + "<td class=\"tx13_black\"[^>]*>(.*)<td style=\"padding-bottom:10px;\">"; InterruptibleCharSequence ics = null; Matcher matcher = null; for (int i = tmpInx; i < this.answerCount; i++) { ics = new InterruptibleCharSequence(ansList[i]); matcher = Pattern.compile(a_regexp, Pattern.MULTILINE | Pattern.DOTALL).matcher(ics.toString()); if (matcher.find()) { result.put(i + ",a_title", matcher.group(1)); result.put(i + ",a_date", StringUtils.replace(matcher.group(2), ".", "-")); result.put(i + ",a_time", matcher.group(3)); result.put(i + ",a_id", matcher.group(4)); result.put(i + ",a_bodyhtml", matcher.group(5)); } } result.put("filterstate", "1"); return result; }
public Line(String separator, String textPart, boolean endsWithNextLine) { this.endsWithNextLine = endsWithNextLine; this.separator = separator; if (separator.equals(" ")) { split = StringUtils.splitByWholeSeparator(textPart, separator); } else { split = StringUtils.splitByWholeSeparatorPreserveAllTokens(textPart, separator); } hasSeparatorBeforeFirstToken = split.length > 0 && split[0].length() == 0; }
/** Value is splitted and trimmed. */ public String[] getStringArrayBySeparator(String key, String separator) { String value = getString(key); if (value != null) { String[] strings = StringUtils.splitByWholeSeparator(value, separator); String[] result = new String[strings.length]; for (int index = 0; index < strings.length; index++) { result[index] = StringUtils.trim(strings[index]); } return result; } return ArrayUtils.EMPTY_STRING_ARRAY; }
protected void parsePage(Document doc, FetchTask task) throws Exception { // TODO Auto-generated method stub PacutoBBSPostBean post = null; PacutoBBSUserBean user = null; Elements postList = doc.select("div.psot_wrap_first"); if (!postList.isEmpty()) { // user对象 user = new PacutoBBSUserBean(); // userId name url Elements userInfoElements = postList.select("td.post_left p.uName>a"); if (!userInfoElements.isEmpty()) { String url = userInfoElements.first().absUrl("href"); user.setUrl(url); String userId = StringUtils.substringBetween(url, "http://my.pcauto.com.cn/", "/forum/"); user.setId(userId); String name = userInfoElements.first().text(); user.setName(name); } // city Elements areaElements = postList.select("td.post_left div.floor-userInfo div.user_info li"); if (!areaElements.isEmpty()) { for (Element liElement : areaElements) { String dataElement = liElement.text(); if (dataElement.startsWith("地区")) { String dataResult = StringUtils.substringAfter(dataElement, ": "); user.setCity(dataResult); } } } // post对象 post = new PacutoBBSPostBean(); // content Elements contentElements = postList.select("td.post_right div.post_main"); if (!contentElements.isEmpty()) { String content = contentElements.first().text(); post.setContent(content); } // postTime Elements postTimeElements = postList.select("td.post_right div.post_time"); if (!postTimeElements.isEmpty()) { String postTime = StringUtils.substringAfter(postTimeElements.first().text(), "发表于"); post.setPostTime(postTime); } // views replys Elements overView = doc.select("td.post_left p.overView"); if (!overView.isEmpty()) { String viewReply = overView.first().text(); String views = StringUtils.substringBetween(viewReply, "查看:", " "); String replys = StringUtils.substringAfter(viewReply, "回复:"); post.setViews(views); post.setReplys(replys); } // title Elements titleElements = doc.select("td.post_right div.post_r_tit>h1"); if (!titleElements.isEmpty()) { String title = titleElements.first().text(); post.setTitle(title); } // id String postUrl = task.getUrl(); String postId = StringUtils.substringBetween(postUrl, "http://bbs.pcauto.com.cn/topic-", ".html"); post.setId(postId); post.setAuthorId(user.getId()); } if (post != null) { String id = StringUtils.substringBetween(task.getUrl(), "-", ".html"); post.setKeyword(task.getName()); post.setId(id); post.setUrl(task.getUrl()); String extra[] = StringUtils.splitByWholeSeparator(task.getExtra(), ","); post.setForumId(extra[0]); post.setType(extra[1]); if (user != null && StringUtils.isNotBlank(user.getId())) { user.persistOnNotExist(); post.setAuthorId(user.getId()); } post.persistOnNotExist(); } log.debug("Parse post:{} ", post); log.debug("Parse user:{} ", user); }
public static Map<String, String> getParams(Order order) { User customer = SpringUtil.getSecurityService().loadUserByUsername(order.getOrderedBy()); BillingInformation bi = order.getBillingInformation(); SalesOrderEntry entry = order.getFiles(SalesOrderEntry.class).get(0); Map<String, String> res = new HashMap<String, String>(); res.put("cname", customer.toString()); res.put("caddress", bi.getAddressLine1() + " " + bi.getAddressLine2()); res.put("cphone", bi.getPhone() + "/" + bi.getMobile()); res.put("email", bi.getEmail()); res.put("fsNumber", order.getCode()); res.put("date", new SimpleDateFormat("dd/MMM/yyyy").format(order.getDateOfTransaction())); Calendar cal = Calendar.getInstance(); cal.setTime(order.getDateOfTransaction()); cal.add(Calendar.MONTH, 6); Date effDate = cal.getTime(); res.put("effDate", new SimpleDateFormat("dd/MMM/yyyy").format(effDate)); res.put("salesman", order.getOwner()); res.put("plan", entry.getTitle()); res.put("jFee", StringUtil.toCurrency("MUR", order.getJoiningFee())); res.put("inst", StringUtil.toCurrency("MUR", order.getInstallment())); res.put("total", StringUtil.toCurrency("MUR", order.getTotal())); res.put("paymentMode", order.getPaymentMethod()); cal.add(Calendar.MONTH, -5); res.put("firstInstallment", new SimpleDateFormat("dd/MMM/yyyy").format(cal.getTime())); Value val = bi.getFile("applicationForm", Value.class); String[] as = StringUtils.splitByWholeSeparator( val.getString(), "-:;:-"); // StringUtil.split(val.getString(), "-:;:-"); Map<String, String> f = new HashMap<String, String>(); for (String s : as) { String[] kv = StringUtil.split(s, ":"); if (kv.length > 1 && !kv[1].equalsIgnoreCase("null")) { f.put(kv[0], kv[1]); } else { if (kv.length > 0) { f.put(kv[0], ""); } } } for (int i = 1; i <= 6; i++) { if (f.containsKey("c" + i + "surname")) { res.put("member" + (i + 1), f.get("c" + i + "surname") + " " + f.get("c" + i + "name")); StringBuilder dob = new StringBuilder(); for (int c = 1; c <= 11; c++) { String key = "c" + i + c; dob.append(f.get(key)); } res.put("dob" + (i + 1), dob.toString()); res.put("sn" + (i + 1), i + ""); } else { res.put("member" + (i + 1), ""); res.put("dob" + (i + 1), ""); res.put("sn" + (i + 1), ""); } } res.put("dob", f.get("pdob")); if (res.containsKey("pidnumber")) { res.put("dob", res.get("pidnumber") + " " + f.get("pdob")); } res.put("cname", f.get("cfullName") + " " + f.get("cSurname")); res.put("address", f.get("presi") + " " + f.get("presi2")); res.put("phone", f.get("ptelhome") + "/" + f.get("pcell")); res.put("email", f.get("email")); res.put("name", f.get("pfullName") + " " + f.get("pSurname")); if (f.containsKey("sSurname") || f.containsKey("sfullName")) { res.put("sname", f.get("sfullName") + " " + f.get("sSurname")); } else { res.put("sname", f.get("")); } if (f.containsKey("sdob")) { res.put("sdob", f.get("sdob")); } else { res.put("sdob", ""); } if (f.containsKey("sidnumber")) { String dob = res.get("sdob"); res.put("sdob", f.get("sidnumber").toString() + " " + dob); } return res; }
@Override protected void handleDrop() { String[] arrayDragSourceData = null; try { arrayDragSourceData = StringUtils.splitByWholeSeparator( ((String) getCurrentEvent().data), PublicTadpoleDefine.DELIMITER); int sourceDBSeq = Integer.parseInt(arrayDragSourceData[0]); if (userDB.getSeq() != sourceDBSeq) { MessageDialog.openError( null, "Error", Messages.TableTransferDropTargetListener_1); // $NON-NLS-1$ return; } } catch (Exception e) { logger.error("dragger error", e); // $NON-NLS-1$ MessageDialog.openError( null, "Error", "Draging exception : " + e.getMessage()); // $NON-NLS-1$ return; } String tableName = arrayDragSourceData[1]; String refTableNames = "'" + tableName + "',"; // $NON-NLS-1$ //$NON-NLS-2$ // 이미 editor 상에 테이블 정보를 가져온다. Map<String, Table> mapDBTables = new HashMap<String, Table>(); for (Table table : db.getTables()) { mapDBTables.put(table.getName(), table); refTableNames += "'" + table.getName() + "',"; // $NON-NLS-1$ //$NON-NLS-2$ } refTableNames = StringUtils.chompLast(refTableNames, ","); // $NON-NLS-1$ // 이미 등록되어 있는 것이 아니라면 if (mapDBTables.get(tableName) == null) { // 테이블 모델 생성 Table tableModel = tadpoleFactory.createTable(); tableModel.setName(tableName); tableModel.setDb(db); if (userDB.getDBDefine() == DBDefine.SQLite_DEFAULT) { tableModel.setComment(""); } else { String tableComment = arrayDragSourceData[2]; tableComment = StringUtils.substring("" + tableComment, 0, 10); tableModel.setComment(tableComment); } tableModel.setConstraints(new Rectangle(getDropLocation().x, getDropLocation().y, -1, -1)); try { // 컬럼 모델 생성 for (TableColumnDAO columnDAO : getColumns(tableName)) { Column column = tadpoleFactory.createColumn(); column.setDefault(columnDAO.getDefault()); column.setExtra(columnDAO.getExtra()); column.setField(columnDAO.getField()); column.setNull(columnDAO.getNull()); column.setKey(columnDAO.getKey()); column.setType(columnDAO.getType()); String strComment = columnDAO.getComment(); if (strComment == null) strComment = ""; else strComment = StringUtils.substring("" + strComment, 0, 10); column.setComment(strComment); column.setTable(tableModel); tableModel.getColumns().add(column); } mapDBTables.put(tableName, tableModel); RelationUtil.calRelation( userDB, mapDBTables, db, refTableNames); // RelationUtil.getReferenceTable(userDB, refTableNames)); } catch (Exception e) { logger.error("GEF Table Drag and Drop Exception", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", Messages.TadpoleModelUtils_2, errStatus); //$NON-NLS-1$ } transferFactory.setTable(tableModel); } else { transferFactory.setTable(mapDBTables.get(tableName)); } super.handleDrop(); }
/** * Retrieve a list of values from delimited String. Used for MultiSelect Object Configurables * * @param values Delimited String * @return List of Strings, never null */ private List<String> getListFromMultiSelectValue(final String values) { final String[] vals = StringUtils.splitByWholeSeparator(values, PORTLET_MULTI_VALUE_SEPARATOR); return vals == null ? Collections.<String>emptyList() : Arrays.asList(vals); }