List of usage examples for org.apache.commons.lang StringUtils substringBefore
public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator.
From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java
public static ByteArrayOutputStream createTollUploadErrorResponse(InputStream is, List<String> errors) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(is); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFFont font = wb.createFont();//from w ww . j av a2s . c o m font.setColor(Font.COLOR_RED); font.setBoldweight(Font.BOLDWEIGHT_BOLD); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setFont(font); HSSFSheet sheet = wb.getSheetAt(0); Row row = sheet.getRow(0); int lastCell = row.getLastCellNum(); Cell cell = createExcelCell(sheet, row, lastCell, 256 * 100); cell.setCellStyle(cellStyle); cell.setCellValue("ERRORS"); for (String anError : errors) { String lineNoStr = StringUtils.substringBefore(anError, ":"); lineNoStr = StringUtils.substringAfter(lineNoStr, "Line "); Integer lineNo = new Integer(lineNoStr) - 1; row = sheet.getRow(lineNo); cell = createExcelCell(sheet, row, lastCell, 256 * 100); cell.setCellStyle(cellStyle); cell.setCellValue(anError); } return createOutputStream(wb); }
From source file:com.liferay.portal.util.PortalUtilExt.java
public static String getPortletTitle(Portlet portlet, ServletContext servletContext, Locale locale) { String portletName = StringUtils.substringBefore(portlet.getRootPortletId(), PortletConstants.WAR_SEPARATOR); String portletKey = JavaConstants.JAVAX_PORTLET_TITLE.concat(StringPool.PERIOD).concat(portletName); String value = StringUtils.EMPTY; try {//w ww . jav a 2 s. c om value = ResourceBundleUtil.getString(locale, portletKey); } catch (Exception ignored) { } if (StringUtils.isNotBlank(value)) { return value; } return getPortal().getPortletTitle(portlet, servletContext, locale); }
From source file:br.com.bropenmaps.util.Util.java
/** * Extrai os parmetros de uma requisio HTTP * @param query - query string/*from w w w. ja v a 2 s .c o m*/ * @return Objeto {@link HashMap} contendo os parmetros */ public static HashMap<String, String> extraiParametros(String query) { if (query == null) { return null; } final HashMap<String, String> param = new HashMap<String, String>(); String[] tk = StringUtils.split(query, "&"); for (String p : tk) { param.put(StringUtils.substringBefore(p, "="), StringUtils.substringAfter(p, "=")); } return param; }
From source file:br.com.bropenmaps.util.Util.java
/** * Extrai os parmetros de uma requisio HTTP. A string da requisio, neste caso, est criptografada. * @param query - query string//from ww w . j av a2 s . c o m * @return Objeto {@link HashMap} contendo os parmetros */ public static HashMap<String, String> extraiParametrosCript(String query) { if (query == null) { return null; } CriptUtils cript = new CriptUtils(ResourceBundle.getBundle("cript").getString("chave")); query = cript.decrypt(query); final HashMap<String, String> param = new HashMap<String, String>(); String[] tk = StringUtils.split(query, "&"); for (String p : tk) { param.put(StringUtils.substringBefore(p, "="), StringUtils.substringAfter(p, "=")); } return param; }
From source file:edu.cornell.kfs.coa.document.validation.impl.AccountReversionGlobalRule.java
/** * Validates that the fund group code on the sub fund group on the reversion account is valid as defined by the allowed * values in SELECTION_1 system parameter. * // ww w . ja v a 2 s . co m * @param acctRev * @return true if valid, false otherwise */ protected boolean validateAccountFundGroup(AccountReversionGlobalAccount acctRev) { boolean valid = true; String fundGroups = SpringContext.getBean(ParameterService.class).getParameterValueAsString(Reversion.class, CUKFSConstants.Reversion.SELECTION_1); String propertyName = StringUtils.substringBefore(fundGroups, "="); List<String> ruleValues = Arrays.asList(StringUtils.substringAfter(fundGroups, "=").split(";")); if (ObjectUtils.isNotNull(ruleValues) && ruleValues.size() > 0) { if (ObjectUtils.isNotNull(acctRev.getAccount()) && ObjectUtils.isNotNull(acctRev.getAccount().getSubFundGroup())) { String accountFundGroupCode = acctRev.getAccount().getSubFundGroup().getFundGroupCode(); if (!ruleValues.contains(accountFundGroupCode)) { valid = false; GlobalVariables.getMessageMap().putError(CUKFSPropertyConstants.ACCT_REVERSION_ACCT_NUMBER, RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_ALLOWED_VALUES_PARAMETER, new String[] { getDataDictionaryService().getAttributeLabel(FundGroup.class, KFSPropertyConstants.CODE), accountFundGroupCode, getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_1), getParameterValuesForMessage(ruleValues), getDataDictionaryService().getAttributeLabel(AccountReversion.class, CUKFSPropertyConstants.ACCT_REVERSION_ACCT_NUMBER) }); } } } return valid; }
From source file:eionet.cr.staging.exp.ExportRunner.java
/** * * @param str/*from ww w . j a va 2 s . c o m*/ * @return */ public static LinkedHashMap<String, List<String>> missingConceptsFromString(String str) { LinkedHashMap<String, List<String>> result = new LinkedHashMap<String, List<String>>(); if (StringUtils.isNotBlank(str)) { String[] lines = StringUtils.split(str, '\n'); for (int i = 0; i < lines.length; i++) { String line = lines[i].trim(); String type = StringUtils.substringBefore(line, ":").trim(); if (StringUtils.isNotBlank(type)) { String csv = StringUtils.substringBefore(StringUtils.substringAfter(line, "["), "]").trim(); if (StringUtils.isNotBlank(csv)) { List<String> values = Arrays.asList(StringUtils.split(csv, ", ")); if (!values.isEmpty()) { result.put(type, values); } } } } } return result; }
From source file:edu.cornell.kfs.coa.document.validation.impl.AccountReversionGlobalRule.java
/** * Validates that the sub fund group code on the reversion account is valid as defined by the allowed values in * SELECTION_4 system parameter./*from w w w. j av a2 s. com*/ * * @param acctRev * @return true if valid, false otherwise */ protected boolean validateAccountSubFundGroup(AccountReversionGlobalAccount acctRev) { boolean valid = true; String subFundGroups = SpringContext.getBean(ParameterService.class) .getParameterValueAsString(Reversion.class, CUKFSConstants.Reversion.SELECTION_4); String propertyName = StringUtils.substringBefore(subFundGroups, "="); List<String> ruleValues = Arrays.asList(StringUtils.substringAfter(subFundGroups, "=").split(";")); if (ObjectUtils.isNotNull(ruleValues) && ruleValues.size() > 0) { if (ObjectUtils.isNotNull(acctRev.getAccount())) { String accountSubFundGroupCode = acctRev.getAccount().getSubFundGroupCode(); if (ruleValues != null && ruleValues.size() > 0 && ruleValues.contains(accountSubFundGroupCode)) { valid = false; GlobalVariables.getMessageMap().putError(CUKFSPropertyConstants.ACCT_REVERSION_ACCT_NUMBER, RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_DENIED_VALUES_PARAMETER, new String[] { getDataDictionaryService().getAttributeLabel(SubFundGroup.class, KFSPropertyConstants.SUB_FUND_GROUP_CODE), accountSubFundGroupCode, getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_4), getParameterValuesForMessage(ruleValues), getDataDictionaryService().getAttributeLabel(AccountReversion.class, CUKFSPropertyConstants.ACCT_REVERSION_ACCT_NUMBER) }); } } } return valid; }
From source file:edu.cornell.kfs.coa.document.validation.impl.AccountReversionGlobalRule.java
/** * Validates that the fund group code on the sub fund group on the cash and budget accounts is valid as defined by the * allowed values in SELECTION_1 system parameter. * /*from w w w . j av a 2 s .c o m*/ * @param globalAcctRev * @return */ protected boolean validateAccountFundGroup(AccountReversionGlobal globalAcctRev) { boolean valid = true; String fundGroups = SpringContext.getBean(ParameterService.class).getParameterValueAsString(Reversion.class, CUKFSConstants.Reversion.SELECTION_1); String propertyName = StringUtils.substringBefore(fundGroups, "="); List<String> ruleValues = Arrays.asList(StringUtils.substringAfter(fundGroups, "=").split(";")); if (ObjectUtils.isNotNull(ruleValues) && ruleValues.size() > 0) { if (ObjectUtils.isNotNull(globalAcctRev.getBudgetReversionAccount()) && ObjectUtils.isNotNull(globalAcctRev.getBudgetReversionAccount().getSubFundGroup())) { String budgetAccountFundGroupCode = globalAcctRev.getBudgetReversionAccount().getSubFundGroup() .getFundGroupCode(); if (!ruleValues.contains(budgetAccountFundGroupCode)) { valid = false; GlobalVariables.getMessageMap().putError( MAINTAINABLE_ERROR_PREFIX + CUKFSPropertyConstants.ACCT_REVERSION_BUDGET_REVERSION_ACCT_NUMBER, RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_ALLOWED_VALUES_PARAMETER, new String[] { getDataDictionaryService().getAttributeLabel(FundGroup.class, KFSPropertyConstants.CODE), budgetAccountFundGroupCode, getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_1), getParameterValuesForMessage(ruleValues), getDataDictionaryService().getAttributeLabel(AccountReversion.class, CUKFSPropertyConstants.ACCT_REVERSION_BUDGET_REVERSION_ACCT_NUMBER) }); } } if (ObjectUtils.isNotNull(globalAcctRev.getCashReversionAccount()) && ObjectUtils.isNotNull(globalAcctRev.getCashReversionAccount().getSubFundGroup())) { String cashAccountFundGroupCode = globalAcctRev.getCashReversionAccount().getSubFundGroup() .getFundGroupCode(); if (!ruleValues.contains(cashAccountFundGroupCode)) { valid = false; GlobalVariables.getMessageMap().putError( MAINTAINABLE_ERROR_PREFIX + CUKFSPropertyConstants.ACCT_REVERSION_CASH_REVERSION_ACCT_NUMBER, RiceKeyConstants.ERROR_DOCUMENT_INVALID_VALUE_ALLOWED_VALUES_PARAMETER, new String[] { getDataDictionaryService().getAttributeLabel(FundGroup.class, KFSPropertyConstants.CODE), cashAccountFundGroupCode, getParameterAsStringForMessage(CUKFSConstants.Reversion.SELECTION_1), getParameterValuesForMessage(ruleValues), getDataDictionaryService().getAttributeLabel(AccountReversion.class, CUKFSPropertyConstants.ACCT_REVERSION_CASH_REVERSION_ACCT_NUMBER) }); } } } return valid; }
From source file:bammerbom.ultimatecore.spongeapi.commands.CmdPlugin.java
@Override public void run(final CommandSender cs, String label, final String[] args) { //help//from w w w.ja v a 2 s . c o m if (!r.checkArgs(args, 0) || args[0].equalsIgnoreCase("help")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.help", false, false)) { r.sendMes(cs, "noPermissions"); return; } cs.sendMessage(TextColors.GOLD + "================================"); r.sendMes(cs, "pluginHelpLoad"); r.sendMes(cs, "pluginHelpUnload"); r.sendMes(cs, "pluginHelpEnable"); r.sendMes(cs, "pluginHelpDisable"); r.sendMes(cs, "pluginHelpReload"); r.sendMes(cs, "pluginHelpReloadall"); r.sendMes(cs, "pluginHelpDelete"); r.sendMes(cs, "pluginHelpUpdate"); r.sendMes(cs, "pluginHelpCommands"); r.sendMes(cs, "pluginHelpList"); r.sendMes(cs, "pluginHelpUpdatecheck"); r.sendMes(cs, "pluginHelpUpdatecheckall"); r.sendMes(cs, "pluginHelpDownload"); r.sendMes(cs, "pluginHelpSearch"); cs.sendMessage(TextColors.GOLD + "================================"); } //load else if (args[0].equalsIgnoreCase("load")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.load", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpLoad"); return; } File f = new File(r.getUC().getDataFolder().getParentFile(), args[1].endsWith(".jar") ? args[1] : args[1] + ".jar"); if (!f.exists()) { r.sendMes(cs, "pluginFileNotFound", "%File", args[1].endsWith(".jar") ? args[1] : args[1] + ".jar"); return; } if (!f.canRead()) { r.sendMes(cs, "pluginFileNoReadAcces"); return; } Plugin p; try { p = pm.loadPlugin(f); if (p == null) { r.sendMes(cs, "pluginLoadFailed"); return; } pm.enablePlugin(p); } catch (UnknownDependencyException ex) { r.sendMes(cs, "pluginLoadMissingDependency", "%Message", ex.getMessage() != null ? ex.getMessage() : ""); ex.printStackTrace(); return; } catch (InvalidDescriptionException ex) { r.sendMes(cs, "pluginLoadInvalidDescription"); ex.printStackTrace(); return; } catch (InvalidPluginException ex) { r.sendMes(cs, "pluginLoadFailed"); ex.printStackTrace(); return; } if (p.isEnabled()) { r.sendMes(cs, "pluginLoadSucces"); } else { r.sendMes(cs, "pluginLoadFailed"); } } //unload else if (args[0].equalsIgnoreCase("unload")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.unload", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpUnload"); return; } Plugin p = pm.getPlugin(args[1]); if (p == null) { r.sendMes(cs, "pluginNotFound", "%Plugin", args[1]); return; } List<String> deps = PluginUtil.getDependedOnBy(p.getName()); if (!deps.isEmpty()) { StringBuilder sb = new StringBuilder(); for (String dep : deps) { sb.append(r.neutral); sb.append(dep); sb.append(TextColors.RESET); sb.append(", "); } r.sendMes(cs, "pluginUnloadDependent", "%Plugins", sb.substring(0, sb.length() - 4)); return; } r.sendMes(cs, "pluginUnloadUnloading"); PluginUtil.unregisterAllPluginCommands(p.getName()); HandlerList.unregisterAll(p); Bukkit.getServicesManager().unregisterAll(p); Bukkit.getServer().getMessenger().unregisterIncomingPluginChannel(p); Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(p); Bukkit.getServer().getScheduler().cancelTasks(p); pm.disablePlugin(p); PluginUtil.removePluginFromList(p); r.sendMes(cs, "pluginUnloadUnloaded"); } //enable else if (args[0].equalsIgnoreCase("enable")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.enable", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpEnable"); return; } Plugin p = pm.getPlugin(args[1]); if (p == null) { r.sendMes(cs, "pluginNotFound", "%Plugin", args[1]); return; } if (p.isEnabled()) { r.sendMes(cs, "pluginAlreadyEnabled"); return; } pm.enablePlugin(p); if (p.isEnabled()) { r.sendMes(cs, "pluginEnableSucces"); } else { r.sendMes(cs, "pluginEnableFail"); } } //disable else if (args[0].equalsIgnoreCase("disable")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.disable", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpDisable"); return; } Plugin p = pm.getPlugin(args[1]); if (p == null) { r.sendMes(cs, "pluginNotFound", "%Plugin", args[1]); return; } if (!p.isEnabled()) { r.sendMes(cs, "pluginNotEnabled"); return; } List<String> deps = PluginUtil.getDependedOnBy(p.getName()); if (!deps.isEmpty()) { StringBuilder sb = new StringBuilder(); for (String dep : deps) { sb.append(r.neutral); sb.append(dep); sb.append(TextColors.RESET); sb.append(", "); } r.sendMes(cs, "pluginUnloadDependent", "%Plugins", sb.substring(0, sb.length() - 4)); return; } pm.disablePlugin(p); if (!p.isEnabled()) { r.sendMes(cs, "pluginDisableSucces"); } else { r.sendMes(cs, "pluginDisableFailed"); } } //reload else if (args[0].equalsIgnoreCase("reload")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.reload", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpReload"); return; } Plugin p = pm.getPlugin(args[1]); if (p == null) { r.sendMes(cs, "pluginNotFound", "%Plugin", args[1]); return; } if (!p.isEnabled()) { r.sendMes(cs, "pluginNotEnabled"); return; } pm.disablePlugin(p); pm.enablePlugin(p); r.sendMes(cs, "pluginReloadMessage"); } //reloadall else if (args[0].equalsIgnoreCase("reloadall")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.reloadall", false, false)) { r.sendMes(cs, "noPermissions"); return; } for (Plugin p : pm.getPlugins()) { pm.disablePlugin(p); pm.enablePlugin(p); } r.sendMes(cs, "pluginReloadallMessage"); } //delete else if (args[0].equalsIgnoreCase("delete")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.delete", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpDelete"); return; } String del = args[1]; if (!del.endsWith(".jar")) { del = del + ".jar"; } if (del.contains(File.separator)) { r.sendMes(cs, "pluginDeleteDontLeavePluginFolder"); return; } File f = new File(r.getUC().getDataFolder().getParentFile() + File.separator + del); if (!f.exists()) { r.sendMes(cs, "pluginFileNotFound", "%File", del); return; } if (f.delete()) { r.sendMes(cs, "pluginDeleteSucces"); } else { r.sendMes(cs, "pluginDeleteFailed"); } } //commands else if (args[0].equalsIgnoreCase("commands")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.commands", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpCommands"); return; } Plugin p = pm.getPlugin(args[1]); if (p == null) { r.sendMes(cs, "pluginNotFound", "%Plugin", args[1]); return; } Map<String, Map<String, Object>> cmds = p.getDescription().getCommands(); if (cmds == null) { r.sendMes(cs, "pluginCommandsNoneRegistered"); return; } String command = "plugin " + p.getName(); String pageStr = args.length > 2 ? args[2] : null; UText input = new TextInput(cs); UText output; if (input.getLines().isEmpty()) { if ((r.isInt(pageStr)) || (pageStr == null)) { output = new PluginCommandsInput(cs, args[1].toLowerCase()); } else { r.sendMes(cs, "pluginCommandsPageNotNumber"); return; } } else { output = input; } TextPager pager = new TextPager(output); pager.showPage(pageStr, null, command, cs); } //update else if (args[0].equalsIgnoreCase("update")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.update", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpUpdate"); return; } Plugin p = pm.getPlugin(args[1]); if (p == null) { r.sendMes(cs, "pluginNotFound", "%Plugin", args[1]); return; } URL u = Bukkit.getPluginManager().getPlugin("UltimateCore").getClass().getProtectionDomain() .getCodeSource().getLocation(); File f; try { f = new File(u.toURI()); } catch (URISyntaxException e) { f = new File(u.getPath()); } PluginUtil.unregisterAllPluginCommands(p.getName()); HandlerList.unregisterAll(p); Bukkit.getServicesManager().unregisterAll(p); Bukkit.getServer().getMessenger().unregisterIncomingPluginChannel(p); Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(p); Bukkit.getServer().getScheduler().cancelTasks(p); pm.disablePlugin(p); PluginUtil.removePluginFromList(p); try { Plugin p2 = pm.loadPlugin(f); if (p2 == null) { r.sendMes(cs, "pluginLoadFailed"); return; } pm.enablePlugin(p2); } catch (UnknownDependencyException ex) { r.sendMes(cs, "pluginLoadMissingDependendy", "%Message", ex.getMessage()); ex.printStackTrace(); return; } catch (InvalidDescriptionException ex) { r.sendMes(cs, "pluginLoadFailed"); ex.printStackTrace(); return; } catch (InvalidPluginException ex) { r.sendMes(cs, "pluginLoadFailed"); ex.printStackTrace(); return; } } //list else if (args[0].equalsIgnoreCase("list")) { if (!r.perm(cs, "uc.plugin", false, false) && !r.perm(cs, "uc.plugin.list", false, false)) { r.sendMes(cs, "noPermissions"); return; } r.sendMes(cs, "pluginsList", "%Plugins", PluginUtil.getPluginList()); } //info else if (args[0].equalsIgnoreCase("info")) { if (!r.perm(cs, "uc.plugin.info", false, false) && !r.perm(cs, "uc.plugin", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpInfo"); return; } Plugin p = pm.getPlugin(args[1]); if (p == null) { r.sendMes(cs, "pluginNotFound", "%Plugin", args[1]); return; } PluginDescriptionFile pdf = p.getDescription(); if (pdf == null) { r.sendMes(cs, "pluginLoadInvalidDescription"); return; } String version = pdf.getVersion(); List<String> authors = pdf.getAuthors(); String site = pdf.getWebsite(); List<String> softDep = pdf.getSoftDepend(); List<String> dep = pdf.getDepend(); String name = pdf.getName(); String desc = pdf.getDescription(); if (name != null && !name.isEmpty()) { r.sendMes(cs, "pluginInfoName", "%Name", name); } if (version != null && !version.isEmpty()) { r.sendMes(cs, "pluginInfoVersion", "%Version", version); } if (site != null && !site.isEmpty()) { r.sendMes(cs, "pluginInfoWebsite", "%Website", site); } if (desc != null && !desc.isEmpty()) { r.sendMes(cs, "pluginInfoDescription", "%Description", desc.replaceAll("\r?\n", "")); } if (authors != null && !authors.isEmpty()) { r.sendMes(cs, "pluginInfoAuthor", "%S", ((authors.size() > 1) ? "s" : ""), "%Author", StringUtil.join(TextColors.RESET + ", " + r.neutral, authors)); } if (softDep != null && !softDep.isEmpty()) { r.sendMes(cs, "pluginInfoSoftdeps", "%Softdeps", StringUtil.join(TextColors.RESET + ", " + r.neutral, softDep)); } if (dep != null && !dep.isEmpty()) { r.sendMes(cs, "pluginInfoDeps", "%Deps", StringUtil.join(TextColors.RESET + ", " + r.neutral, dep)); } r.sendMes(cs, "pluginInfoEnabled", "%Enabled", ((p.isEnabled()) ? r.mes("yes") : r.mes("no"))); } //updatecheck else if (args[0].equalsIgnoreCase("updatecheck")) { if (!r.perm(cs, "uc.plugin.updatecheck", false, false) && !r.perm(cs, "uc.plugin", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpUpdatecheck"); return; } Plugin p = pm.getPlugin(args[1]); if (p == null) { r.sendMes(cs, "pluginNotFound", "%Plugin", args[1]); return; } final String tag; try { tag = URLEncoder.encode(r.checkArgs(args, 2) ? args[2] : p.getName(), "UTF-8"); } catch (UnsupportedEncodingException ex) { r.sendMes(cs, "pluginNoUTF8"); return; } if (p.getDescription() == null) { r.sendMes(cs, "pluginLoadInvalidDescription"); return; } final String v = p.getDescription().getVersion() == null ? r.mes("pluginNotSet") : p.getDescription().getVersion(); Runnable ru = new Runnable() { @Override public void run() { try { String n = ""; String pluginUrlString = "http://dev.bukkit.org/bukkit-plugins/" + tag + "/files.rss"; URL url = new URL(pluginUrlString); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(url.openConnection().getInputStream()); doc.getDocumentElement().normalize(); NodeList nodes = doc.getElementsByTagName("item"); Node firstNode = nodes.item(0); if (firstNode.getNodeType() == 1) { Element firstElement = (Element) firstNode; NodeList firstElementTagName = firstElement.getElementsByTagName("title"); Element firstNameElement = (Element) firstElementTagName.item(0); NodeList firstNodes = firstNameElement.getChildNodes(); n = firstNodes.item(0).getNodeValue(); } r.sendMes(cs, "pluginUpdatecheckCurrent", "%Current", v + ""); r.sendMes(cs, "pluginUpdatecheckNew", "%New", n + ""); } catch (Exception ex) { ex.printStackTrace(); r.sendMes(cs, "pluginUpdatecheckFailed"); } } }; Bukkit.getServer().getScheduler().runTaskAsynchronously(r.getUC(), ru); } //updatecheckall else if (args[0].equalsIgnoreCase("updatecheckall")) { if (!r.perm(cs, "uc.plugin.updatecheckall", false, false) && !r.perm(cs, "uc.plugin", false, false)) { r.sendMes(cs, "noPermissions"); return; } final Runnable ru = new Runnable() { @Override public void run() { int a = 0; for (Plugin p : pm.getPlugins()) { if (p.getDescription() == null) { continue; } String version = p.getDescription().getVersion(); if (version == null) { continue; } String n = ""; try { String pluginUrlString = "http://dev.bukkit.org/bukkit-plugins/" + p.getName().toLowerCase() + "/files.rss"; URL url = new URL(pluginUrlString); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(url.openConnection().getInputStream()); doc.getDocumentElement().normalize(); NodeList nodes = doc.getElementsByTagName("item"); Node firstNode = nodes.item(0); if (firstNode.getNodeType() == 1) { Element firstElement = (Element) firstNode; NodeList firstElementTagName = firstElement.getElementsByTagName("title"); Element firstNameElement = (Element) firstElementTagName.item(0); NodeList firstNodes = firstNameElement.getChildNodes(); n = firstNodes.item(0).getNodeValue(); a++; } } catch (Exception e) { continue; } if (n.contains(version)) { continue; } r.sendMes(cs, "pluginUpdatecheckallAvailable", "%Old", version, "%New", n, "%Plugin", p.getName()); } r.sendMes(cs, "pluginUpdatecheckallFinish", "%Amount", a); } }; Bukkit.getServer().getScheduler().runTaskAsynchronously(r.getUC(), ru); } //download else if (args[0].equalsIgnoreCase("download")) { if (!r.perm(cs, "uc.plugin.download", false, false) && !r.perm(cs, "uc.plugin", false, false)) { r.sendMes(cs, "noPermissions"); return; } if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpDownload"); cs.sendMessage(r.negative + "http://dev.bukkit.org/server-mods/" + r.neutral + "ultimate_core" + r.negative + "/"); return; } final Runnable ru = new Runnable() { @Override public void run() { String tag = args[1]; r.sendMes(cs, "pluginDownloadGettingtag"); String pluginUrlString = "http://dev.bukkit.org/server-mods/" + tag + "/files.rss"; String file; try { final URL url = new URL(pluginUrlString); final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(url.openConnection().getInputStream()); doc.getDocumentElement().normalize(); final NodeList nodes = doc.getElementsByTagName("item"); final Node firstNode = nodes.item(0); if (firstNode.getNodeType() == 1) { final Element firstElement = (Element) firstNode; final NodeList firstElementTagName = firstElement.getElementsByTagName("link"); final Element firstNameElement = (Element) firstElementTagName.item(0); final NodeList firstNodes = firstNameElement.getChildNodes(); final String link = firstNodes.item(0).getNodeValue(); final URL dpage = new URL(link); final BufferedReader br = new BufferedReader(new InputStreamReader(dpage.openStream())); final StringBuilder content = new StringBuilder(); String inputLine; while ((inputLine = br.readLine()) != null) { content.append(inputLine); } br.close(); file = StringUtils.substringBetween(content.toString(), "<li class=\"user-action user-action-download\"><span><a href=\"", "\">Download</a></span></li>"); } else { throw new Exception(); } } catch (Exception e) { r.sendMes(cs, "pluginDownloadInvalidtag"); cs.sendMessage(r.negative + "http://dev.bukkit.org/server-mods/" + r.neutral + "ultimate_core" + r.negative + "/"); return; } BufferedInputStream bis; final HttpURLConnection huc; try { huc = (HttpURLConnection) new URL(file).openConnection(); huc.setInstanceFollowRedirects(true); huc.connect(); bis = new BufferedInputStream(huc.getInputStream()); } catch (MalformedURLException e) { r.sendMes(cs, "pluginDownloadInvaliddownloadlink"); return; } catch (IOException e) { r.sendMes(cs, "pluginDownloadFailed", "%Message", e.getMessage()); return; } String[] urlParts = huc.getURL().toString().split("(\\\\|/)"); final String fileName = urlParts[urlParts.length - 1]; r.sendMes(cs, "pluginDownloadCreatingTemp"); File f = new File(System.getProperty("java.io.tmpdir") + File.separator + UUID.randomUUID().toString() + File.separator + fileName); while (f.getParentFile().exists()) { f = new File(System.getProperty("java.io.tmpdir") + File.separator + UUID.randomUUID().toString() + File.separator + fileName); } if (!fileName.endsWith(".zip") && !fileName.endsWith(".jar")) { r.sendMes(cs, "pluginDownloadNotJarOrZip", "%Filename", fileName); return; } f.getParentFile().mkdirs(); BufferedOutputStream bos; try { bos = new BufferedOutputStream(new FileOutputStream(f)); } catch (FileNotFoundException e) { r.sendMes(cs, "pluginDownloadTempNotFound", "%Dir", System.getProperty("java.io.tmpdir")); return; } int b; r.sendMes(cs, "pluginDownloadDownloading"); try { try { while ((b = bis.read()) != -1) { bos.write(b); } } finally { bos.flush(); bos.close(); } } catch (IOException e) { r.sendMes(cs, "pluginDownloadFailed", "%Message", e.getMessage()); return; } if (fileName.endsWith(".zip")) { r.sendMes(cs, "pluginDownloadDecompressing"); PluginUtil.decompress(f.getAbsolutePath(), f.getParent()); } String name = null; for (File fi : PluginUtil.listFiles(f.getParentFile())) { if (!fi.getName().endsWith(".jar")) { continue; } if (name == null) { name = fi.getName(); } r.sendMes(cs, "pluginDownloadMoving", "%File", fi.getName()); try { Files.move(fi, new File( r.getUC().getDataFolder().getParentFile() + File.separator + fi.getName())); } catch (IOException e) { r.sendMes(cs, "pluginDownloadCouldntMove", "%Message", e.getMessage()); } } PluginUtil.deleteDirectory(f.getParentFile()); r.sendMes(cs, "pluginDownloadSucces", "%File", fileName); } }; Bukkit.getServer().getScheduler().runTaskAsynchronously(r.getUC(), ru); } else if (args[0].equalsIgnoreCase("search")) { if (!r.perm(cs, "uc.plugin.search", false, false) && !r.perm(cs, "uc.plugin", false, false)) { r.sendMes(cs, "noPermissions"); return; } int page = 1; if (!r.checkArgs(args, 1)) { r.sendMes(cs, "pluginHelpSearch"); return; } Boolean b = false; if (r.checkArgs(args, 2)) { try { page = Integer.parseInt(args[args.length - 1]); b = true; } catch (NumberFormatException ignored) { } } String search = r.getFinalArg(args, 1); if (b) { search = new StringBuilder(new StringBuilder(search).reverse().toString() .replaceFirst(new StringBuilder(" " + page).reverse().toString(), "")).reverse().toString(); } try { search = URLEncoder.encode(search, "UTF-8"); } catch (UnsupportedEncodingException e) { r.sendMes(cs, "pluginNoUTF8"); return; } final URL u; try { u = new URL("http://dev.bukkit.org/search/?scope=projects&search=" + search + "&page=" + page); } catch (MalformedURLException e) { r.sendMes(cs, "pluginSearchMalformedTerm"); return; } final Runnable ru = new Runnable() { @Override public void run() { final BufferedReader br; try { br = new BufferedReader(new InputStreamReader(u.openStream())); } catch (IOException e) { r.sendMes(cs, "pluginSearchFailed", "%Message", e.getMessage()); return; } String inputLine; StringBuilder content = new StringBuilder(); try { while ((inputLine = br.readLine()) != null) { content.append(inputLine); } } catch (IOException e) { r.sendMes(cs, "pluginSearchFailed", "%Message", e.getMessage()); return; } r.sendMes(cs, "pluginSearchHeader"); for (int i = 0; i < 20; i++) { final String project = StringUtils.substringBetween(content.toString(), " row-joined-to-next\">", "</tr>"); final String base = StringUtils.substringBetween(project, "<td class=\"col-search-entry\">", "</td>"); if (base == null) { if (i == 0) { r.sendMes(cs, "pluginSearchNoResults"); } return; } final Pattern p = Pattern .compile("<h2><a href=\"/bukkit-plugins/([\\W\\w]+)/\">([\\w\\W]+)</a></h2>"); final Matcher m = p.matcher(base); if (!m.find()) { if (i == 0) { r.sendMes(cs, "pluginSearchNoResults"); } return; } final String name = m.group(2).replaceAll("</?\\w+>", ""); final String tag = m.group(1); final int beglen = StringUtils.substringBefore(content.toString(), base).length(); content = new StringBuilder(content.substring(beglen + project.length())); r.sendMes(cs, "pluginSearchResult", "%Name", name, "%Tag", tag); } } }; Bukkit.getServer().getScheduler().runTaskAsynchronously(r.getUC(), ru); } else { cs.sendMessage(TextColors.GOLD + "================================"); r.sendMes(cs, "pluginHelpLoad"); r.sendMes(cs, "pluginHelpUnload"); r.sendMes(cs, "pluginHelpEnable"); r.sendMes(cs, "pluginHelpDisable"); r.sendMes(cs, "pluginHelpReload"); r.sendMes(cs, "pluginHelpReloadall"); r.sendMes(cs, "pluginHelpDelete"); r.sendMes(cs, "pluginHelpUpdate"); r.sendMes(cs, "pluginHelpCommands"); r.sendMes(cs, "pluginHelpList"); r.sendMes(cs, "pluginHelpUpdatecheck"); r.sendMes(cs, "pluginHelpUpdatecheckall"); r.sendMes(cs, "pluginHelpDownload"); r.sendMes(cs, "pluginHelpSearch"); cs.sendMessage(TextColors.GOLD + "================================"); } }
From source file:info.magnolia.cms.gui.control.Tree.java
public String getHtmlChildrenOfOneType(Content parentNode, String itemType) { StringBuffer html = new StringBuffer(); try {// w w w.jav a 2 s . c o m // todo: parentNode - level of this.getPath int left = (parentNode.getLevel()) * this.getIndentionWidth(); Iterator it; if (itemType.equalsIgnoreCase(ITEM_TYPE_NODEDATA)) { List nodeDatas = new ArrayList(parentNode.getNodeDataCollection()); // order them alphabetically Collections.sort(nodeDatas, new Comparator() { public int compare(Object arg0, Object arg1) { return ((NodeData) arg0).getName().compareTo(((NodeData) arg1).getName()); } }); it = nodeDatas.iterator(); } else { it = parentNode.getChildren(itemType).iterator(); } while (it.hasNext()) { Object o = it.next(); Content c = null; NodeData d = null; String handle; String name; boolean hasSub = false; boolean showSub = false; boolean isActivated = false; boolean permissionWrite = false; boolean permissionWriteParent = false; if (itemType.equals(ITEM_TYPE_NODEDATA)) { d = (NodeData) o; handle = d.getHandle(); name = d.getName(); if (d.isGranted(info.magnolia.cms.security.Permission.WRITE)) { permissionWrite = true; } } else { c = (Content) o; handle = c.getHandle(); if (this.getColumns().size() == 0) { name = c.getName(); } else { this.getColumns(0).setWebsiteNode(c); name = this.getColumns(0).getHtml(); } if (c.isGranted(info.magnolia.cms.security.Permission.WRITE)) { permissionWrite = true; } if (c.getAncestor(c.getLevel() - 1).isGranted(info.magnolia.cms.security.Permission.WRITE)) { permissionWriteParent = true; } isActivated = c.getMetaData().getIsActivated(); for (int i = 0; i < this.getItemTypes().size(); i++) { String type = (String) this.getItemTypes().get(i); hasSub = hasSub(c, type); if (hasSub) { if (this.getPathOpen() != null && (this.getPathOpen().indexOf(handle + "/") == 0 //$NON-NLS-1$ || this.getPathOpen().equals(handle))) { showSub = true; } break; } } } // get next if this node is not shown if (!showNode(c, d, itemType)) { continue; } String icon = getIcon(c, d, itemType); String idPre = this.javascriptTree + "_" + handle; //$NON-NLS-1$ String jsHighlightNode = this.javascriptTree + ".nodeHighlight(this,'" //$NON-NLS-1$ + handle + "'," //$NON-NLS-1$ + Boolean.toString(permissionWrite) + ");"; //$NON-NLS-1$ String jsResetNode = this.javascriptTree + ".nodeReset(this,'" + handle + "');"; //$NON-NLS-1$ //$NON-NLS-2$ String jsSelectNode = this.javascriptTree + ".selectNode('" //$NON-NLS-1$ + handle + "'," //$NON-NLS-1$ + Boolean.toString(permissionWrite) + ",'" //$NON-NLS-1$ + itemType + "');"; //$NON-NLS-1$ String jsExpandNode; if (this.getDrawShifter()) { jsExpandNode = this.javascriptTree + ".expandNode('" + handle + "');"; //$NON-NLS-1$ //$NON-NLS-2$ } else { jsExpandNode = jsSelectNode; } String jsHighlightLine = this.javascriptTree + ".moveNodeHighlightLine('" + idPre + "_LineInter');"; //$NON-NLS-1$ //$NON-NLS-2$ String jsResetLine = this.javascriptTree + ".moveNodeResetLine('" + idPre + "_LineInter');"; //$NON-NLS-1$ //$NON-NLS-2$ // lineInter: line between nodes, to allow set cursor between nodes // try to avoid blank images, setting js actions on divs should be ok if (permissionWriteParent) { html.append("<div id=\""); html.append(idPre); html.append("_LineInter\" class=\"mgnlTreeLineInter mgnlLineEnabled\" onmouseover=\""); html.append(jsHighlightLine); html.append("\" onmouseout=\""); html.append(jsResetLine); html.append("\" onmousedown=\""); html.append(this.javascriptTree); html.append(".pasteNode('"); html.append(handle); html.append("'," + Tree.PASTETYPE_ABOVE + ",true);\" ></div>"); } else { html.append("<div id=\""); html.append(idPre); html.append("_LineInter\" class=\"mgnlTreeLineInter mgnlLineDisabled\"></div>"); } html.append("<div id=\""); html.append(idPre); html.append("_DivMain\" style=\"position:relative;top:0;left:0;width:100%;height:18px;\">"); html.append(" "); // do not remove! //$NON-NLS-1$ int paddingLeft = left + 8; if (paddingLeft < 8) { paddingLeft = 8; } html.append("<span id=\""); html.append(idPre); html.append("_Column0Outer\" class=\"mgnlTreeColumn "); html.append(this.javascriptTree); html.append("CssClassColumn0\" style=\"padding-left:"); html.append(paddingLeft); html.append("px;\">"); if (this.getDrawShifter()) { String shifter = StringUtils.EMPTY; if (hasSub) { if (showSub) { if (this.getShifterCollapse() != null) { shifter = this.getShifterCollapse(); } } else { if (this.getShifterExpand() != null) { shifter = this.getShifterExpand(); } } } else { if (this.getShifterEmpty() != null) { shifter = this.getShifterEmpty(); } } if (StringUtils.isNotEmpty(shifter)) { html.append("<img id=\""); html.append(idPre); html.append("_Shifter\" onmousedown=\""); html.append(this.javascriptTree); html.append(".shifterDown('"); html.append(handle); html.append("');\" onmouseout=\""); html.append(this.javascriptTree); html.append(".shifterOut();\" class=\"mgnlTreeShifter\" src=\""); html.append(this.getRequest().getContextPath()); html.append(shifter); html.append("\" />"); } } html.append("<span id="); html.append(idPre); html.append("_Name onmouseover=\""); html.append(jsHighlightNode); html.append("\" onmouseout=\""); html.append(jsResetNode); html.append("\" onmousedown=\""); html.append(jsSelectNode); html.append(this.javascriptTree); html.append(".pasteNode('"); html.append(handle); html.append("'," + Tree.PASTETYPE_SUB + ","); html.append(permissionWrite); html.append(");\">"); if (StringUtils.isNotEmpty(icon)) { html.append("<img id=\""); html.append(idPre); html.append("_Icon\" class=\"mgnlTreeIcon\" src=\""); html.append(this.getRequest().getContextPath()); html.append(icon); html.append("\" onmousedown=\""); html.append(jsExpandNode); html.append("\""); if (this.getIconOndblclick() != null) { html.append(" ondblclick=\""); html.append(this.getIconOndblclick()); html.append("\""); } html.append(" />"); //$NON-NLS-1$ } String dblclick = StringUtils.EMPTY; if (permissionWrite && StringUtils.isNotEmpty(this.getColumns(0).getHtmlEdit())) { dblclick = " ondblclick=\"" + this.javascriptTree + ".editNodeData(this,'" + handle + "',0);\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } html.append("<span class=\"mgnlTreeText\" id=\""); html.append(idPre); html.append("_Column0Main\""); html.append(dblclick); html.append(">"); html.append(name); html.append("</span></span></span>"); //$NON-NLS-1$ html.append( new Hidden(idPre + "_PermissionWrite", Boolean.toString(permissionWrite), false).getHtml()); //$NON-NLS-1$ html.append(new Hidden(idPre + "_ItemType", itemType, false).getHtml()); //$NON-NLS-1$ html.append(new Hidden(idPre + "_IsActivated", Boolean.toString(isActivated), false).getHtml()); //$NON-NLS-1$ for (int i = 1; i < this.getColumns().size(); i++) { String str = StringUtils.EMPTY; TreeColumn tc = this.getColumns(i); if (!itemType.equals(ITEM_TYPE_NODEDATA)) { // content node ItemType.NT_CONTENTNODE and ItemType.NT_CONTENT if (!tc.getIsNodeDataType() && !tc.getIsNodeDataValue()) { tc.setWebsiteNode(c); tc.setId(handle); str = tc.getHtml(); } } else { NodeDataUtil util = new NodeDataUtil(d); if (tc.getIsNodeDataType()) { str = util.getTypeName(d.getType()); } else if (tc.getIsNodeDataValue()) { str = StringEscapeUtils.escapeXml(util.getValueString()); } if (StringUtils.isEmpty(str)) { str = TreeColumn.EMPTY; } tc.setName(name); // workaround, will be passed to js TreeColumn object } tc.setEvent("onmouseover", jsHighlightNode, true); //$NON-NLS-1$ tc.setEvent("onmouseout", jsResetNode, true); //$NON-NLS-1$ tc.setEvent("onmousedown", jsSelectNode, true); //$NON-NLS-1$ html.append("<span class=\"mgnlTreeColumn "); html.append(this.javascriptTree); html.append("CssClassColumn"); html.append(i); html.append("\"><span id=\""); html.append(idPre); html.append("_Column"); html.append(i); html.append("Main\""); html.append(tc.getHtmlCssClass()); html.append(tc.getHtmlEvents()); if (permissionWrite && StringUtils.isNotEmpty(tc.getHtmlEdit())) { html.append(" ondblclick=\""); html.append(this.javascriptTree); html.append(".editNodeData(this,'"); html.append(handle); html.append("',"); html.append(i); html.append(");\""); } html.append(">"); html.append(str); html.append("</span></span>"); } html.append("</div>"); //$NON-NLS-1$ String display = "none"; //$NON-NLS-1$ if (showSub) { display = "block"; //$NON-NLS-1$ } html.append("<div id=\""); html.append(idPre); html.append("_DivSub\" style=\"display:"); html.append(display); html.append(";\">"); if (hasSub) { if (showSub) { String pathRemaining = this.getPathOpen().substring(this.getPathCurrent().length()); if (pathRemaining.length() > 0) { // get rid of first slash (/people/franz -> people/franz) String slash = "/"; //$NON-NLS-1$ if (this.getPathCurrent().equals("/")) { //$NON-NLS-1$ // first slash already removed slash = StringUtils.EMPTY; // no slash needed between pathCurrent and nextChunk } else { pathRemaining = pathRemaining.substring(1); } String nextChunk = StringUtils.substringBefore(pathRemaining, "/"); //$NON-NLS-1$ String pathNext = this.getPathCurrent() + slash + nextChunk; this.setPathCurrent(pathNext); html.append(this.getHtmlChildren()); } } } html.append("</div>\n"); //$NON-NLS-1$ } } catch (RepositoryException e) { if (log.isDebugEnabled()) log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$ } return html.toString(); }