protected long getParentMessageId(String recipient, Message message) throws Exception { if (!StringUtil.startsWith(recipient, MBUtil.MESSAGE_POP_PORTLET_PREFIX)) { return MBUtil.getParentMessageId(message); } int pos = recipient.indexOf(CharPool.AT); if (pos < 0) { return MBUtil.getParentMessageId(message); } String target = recipient.substring(MBUtil.MESSAGE_POP_PORTLET_PREFIX.length(), pos); String[] parts = StringUtil.split(target, StringPool.PERIOD); long parentMessageId = 0; if (parts.length == 2) { parentMessageId = GetterUtil.getLong(parts[1]); } if (parentMessageId > 0) { return parentMessageId; } return MBUtil.getParentMessageId(message); }
public static Set<String> getMacAddresses() { if (_macAddresses != null) { return new HashSet<String>(_macAddresses); } Set<String> macAddresses = new HashSet<String>(); String osName = System.getProperty("os.name"); String executable = null; String arguments = null; if (StringUtil.startsWith(osName, "win")) { executable = "ipconfig"; arguments = "/all"; } else { if (StringUtil.startsWith(osName, "aix")) { executable = "netstat"; arguments = "-ina"; } else { executable = "ifconfig"; arguments = "-a"; } File sbinDir = new File("/sbin", executable); if (sbinDir.exists()) { executable = "/sbin/".concat(executable); } } try { Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(new String[] {executable, arguments}); macAddresses = getMacAddresses(osName, process.getInputStream()); } catch (Exception e) { _log.error(e, e); } _macAddresses = macAddresses; return new HashSet<String>(macAddresses); }
/** * Returns the full, absolute URL (including the portal's URL) of the navigation item's layout. * * @return the full, absolute URL of the navigation item's layout * @throws Exception if an exception occurred */ public String getRegularFullURL() throws Exception { String portalURL = PortalUtil.getPortalURL(_request); String regularURL = getRegularURL(); if (StringUtil.startsWith(regularURL, portalURL) || Validator.isUrl(regularURL)) { return regularURL; } else { return portalURL.concat(regularURL); } }
public static Set<String> getMacAddresses(String osName, InputStream processInputStream) throws Exception { Set<String> macAddresses = new HashSet<String>(); Pattern macAddressPattern = _macAddressPattern1; if (StringUtil.startsWith(osName, "aix")) { macAddressPattern = _macAddressPattern2; } String processOutput = StringUtil.read(processInputStream); String[] lines = StringUtil.split(processOutput, CharPool.NEW_LINE); for (String line : lines) { Matcher matcher = macAddressPattern.matcher(line); if (!matcher.find()) { continue; } String macAddress = matcher.group(1); macAddress = macAddress.toLowerCase(); macAddress = macAddress.replace(CharPool.DASH, CharPool.COLON); macAddress = macAddress.replace(CharPool.PERIOD, CharPool.COLON); StringBuilder sb = new StringBuilder(17); sb.append(macAddress); for (int i = 1; i < 5; ++i) { int pos = (i * 3) - 1; if (sb.charAt(pos) != CharPool.COLON) { sb.insert((i - 1) * 3, CharPool.NUMBER_0); } } if (sb.length() < 17) { sb.insert(15, CharPool.NUMBER_0); } macAddress = sb.toString(); macAddresses.add(macAddress); } return macAddresses; }
@Override protected String reword(String data) throws IOException { UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new UnsyncStringReader(data)); boolean createTable = false; StringBundler sb = new StringBundler(); String line = null; while ((line = unsyncBufferedReader.readLine()) != null) { if (StringUtil.startsWith(line, "create table")) { createTable = true; } else if (line.startsWith(ALTER_COLUMN_NAME)) { String[] template = buildColumnNameTokens(line); line = StringUtil.replace( "alter table @table@ change column @old-column@ " + "@new-column@ @type@;", REWORD_TEMPLATE, template); } else if (line.startsWith(ALTER_COLUMN_TYPE)) { String[] template = buildColumnTypeTokens(line); line = StringUtil.replace( "alter table @table@ modify @old-column@ @type@;", REWORD_TEMPLATE, template); } int pos = line.indexOf(";"); if (createTable && (pos != -1)) { createTable = false; line = line.substring(0, pos) + " engine " + PropsValues.DATABASE_MYSQL_ENGINE + line.substring(pos); } sb.append(line); sb.append("\n"); } unsyncBufferedReader.close(); return sb.toString(); }