org.apache.commons.lang.text.StrTokenizer Java Examples

The following examples show how to use org.apache.commons.lang.text.StrTokenizer. 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: ProxyItem.java    From http4e with Apache License 2.0 6 votes vote down vote up
/**
 * @param proxysettings
 *           String to convert
 * @return
 * @throws Exception
 */
public static ProxyItem createFromString( String proxysettings) throws Exception{
   ProxyItem returnvalue = null;
   try {
      StrTokenizer tokenizer = new StrTokenizer(proxysettings, DELIMITER);
      String[] tokenArray = tokenizer.getTokenArray();
      String name = tokenArray[0];
      String host = tokenArray[1];
      int port = Integer.parseInt(tokenArray[2]);
      returnvalue = new ProxyItem(host, port, name, true);
   } catch (Exception e) {
      throw new Exception("Error while parsing proxysettings", e);
   }

   return returnvalue;
}
 
Example #2
Source File: MessageStoreListener.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public Object getRawMessage(Map threadContext) throws ListenerException {
	Object rawMessage = super.getRawMessage(threadContext);
	if (rawMessage != null && sessionKeys != null) {
		MessageWrapper messageWrapper = (MessageWrapper)rawMessage;
		try {
			StrTokenizer strTokenizer = StrTokenizer.getCSVInstance().reset(messageWrapper.getMessage().asString());
			messageWrapper.setMessage(new Message((String)strTokenizer.next()));
			int i = 0;
			while (strTokenizer.hasNext()) {
				threadContext.put(sessionKeysList.get(i), strTokenizer.next());
				i++;
			}
		} catch (IOException e) {
			throw new ListenerException("cannot convert message",e);
		}
	}
	return rawMessage;
}
 
Example #3
Source File: EditSdkDialogTabAbstract.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public String isValid(String value) {
    if (value == null || value.isEmpty()) {
        return null;
    }
    String arr[] = new StrTokenizer(value, ';', '"').getTokenArray();
    for (String d : arr) {
        d = d.trim();
        if (!d.isEmpty()) {
            final String ILLEGAL_CHARS = " /\\*:?<>|\""; //$NON-NLS-1$
            for (int i=0; i<ILLEGAL_CHARS.length(); ++i) {
                if (d.indexOf(ILLEGAL_CHARS.charAt(i))>= 0) {
                    return errorInvalid;
                }
            }
        }
    }
    return null;
}
 
Example #4
Source File: DBConfiguration.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a String back to connection parameters.
 * @param input String from configuration
 * @return JDBC connection parameters
 */
protected static Properties propertiesFromString(String input) {
  if (input != null && !input.isEmpty()) {
    Properties result = new Properties();
    StrTokenizer propertyTokenizer = StrTokenizer.getCSVInstance(input);
    StrTokenizer valueTokenizer = StrTokenizer.getCSVInstance();
    valueTokenizer.setDelimiterChar('=');
    while (propertyTokenizer.hasNext()){
      valueTokenizer.reset(propertyTokenizer.nextToken());
      String[] values = valueTokenizer.getTokenArray();
      if (values.length==2) {
        result.put(values[0], values[1]);
      }
    }
    return result;
  } else {
    return null;
  }
}
 
Example #5
Source File: IpUtil.java    From bootshiro with MIT License 6 votes vote down vote up
public static String getIpFromRequest(HttpServletRequest request) {
    String ip;
    boolean found = false;
    if ((ip = request.getHeader(X_FORWARDED_FOR)) != null) {
        StrTokenizer tokenizer = new StrTokenizer(ip, ",");
        while (tokenizer.hasNext()) {
            ip = tokenizer.nextToken().trim();
            if (isIPv4Valid(ip) && !isIPv4Private(ip)) {
                found = true;
                break;
            }
        }
    }
    if (!found) {
        ip = request.getRemoteAddr();
    }
    return ip;
}
 
Example #6
Source File: ExtendedCSVIngestHelper.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
protected StrTokenizer configureTokenizer(StrTokenizer tokenizer) {
    // Remove the trim matcher, trim in preProcessRawData instead so
    // we don't lost any trailing whitespace on the last metadata pair
    // on the record
    return tokenizer.setTrimmerMatcher(StrMatcher.noneMatcher());
}
 
Example #7
Source File: FolderModel.java    From http4e with Apache License 2.0 5 votes vote down vote up
public FolderModel( String availableProxiesString, String availableKeystoresString) {
   this.availableProxies.add(ProxyItem.createDirectConnectionProxy());
   for (String proxysettings : new StrTokenizer(availableProxiesString, "#").getTokenArray()) {
      try {
         this.availableProxies.add(ProxyItem.createFromString(proxysettings));
      } catch (Exception e) {
         // TODO handle error
      }
   }
   this.availableKeystore = availableKeystoresString;
}
 
Example #8
Source File: UriTemplate.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public UriTemplate(String pattern) {
    this.pattern = pattern;
    this.segments = new ArrayList<Segment>();

    StrTokenizer tokenizer = new StrTokenizer(pattern, '/');
    while (tokenizer.hasNext()) {
        segments.add(new Segment(tokenizer.nextToken()));
    }
}
 
Example #9
Source File: TravelerServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean isEmployee(final TravelerDetail traveler) {
    final String param = getParameterService().getParameterValueAsString(TemParameterConstants.TEM_DOCUMENT.class, EMPLOYEE_TRAVELER_TYPE_CODES);
    List<String> employeeTypes = StrTokenizer.getCSVInstance(param).getTokenList();

    return employeeTypes.contains(StringUtils.defaultString(traveler.getTravelerTypeCode()));
}
 
Example #10
Source File: TempListLookupAction.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Parses the methodToCall parameter which contains the lock information in a known format. Populates a
 * BudgetConstructionLockSummary that represents the record to unlock.
 *
 * @param methodToCallString - request parameter containing lock information
 * @return lockSummary populated from request parameter
 */
protected BudgetConstructionLockSummary populateLockSummary(String methodToCallString) {
    BudgetConstructionLockSummary lockSummary = new BudgetConstructionLockSummary();

    // parse lock fields from methodToCall parameter
    String lockType = StringUtils.substringBetween(methodToCallString, KFSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
    String lockFieldsString = StringUtils.substringBetween(methodToCallString, KFSConstants.METHOD_TO_CALL_PARM9_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM9_RIGHT_DEL);
    String lockUser = StringUtils.substringBetween(methodToCallString, KFSConstants.METHOD_TO_CALL_PARM3_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM3_RIGHT_DEL);

    // space was replaced by underscore for html
    lockSummary.setLockType(StringUtils.replace(lockType, "_", " "));
    lockSummary.setLockUserId(lockUser);

    // parse key fields
    StrTokenizer strTokenizer = new StrTokenizer(lockFieldsString, BCConstants.LOCK_STRING_DELIMITER);
    strTokenizer.setIgnoreEmptyTokens(false);
    String fiscalYear = strTokenizer.nextToken();
    if (fiscalYear != null) {
        lockSummary.setUniversityFiscalYear(Integer.parseInt(fiscalYear));
    }

    lockSummary.setChartOfAccountsCode(strTokenizer.nextToken());
    lockSummary.setAccountNumber(strTokenizer.nextToken());
    lockSummary.setSubAccountNumber(strTokenizer.nextToken());
    lockSummary.setPositionNumber(strTokenizer.nextToken());

    return lockSummary;
}
 
Example #11
Source File: CSVReaderBase.java    From datawave with Apache License 2.0 4 votes vote down vote up
public void setTokenizer(StrTokenizer _tokenizer) {
    this._tokenizer = _tokenizer;
}
 
Example #12
Source File: SendEmaiWithGmail.java    From spring-boot with Apache License 2.0 4 votes vote down vote up
/**
 * 用 commons 发送简单邮件 用 [email protected] (登录密码为 pass)发送邮件
 * 
 * @author jianghui
 * @param userName
 *            gmail 用户名 test
 * @param password
 *            gmail 密码 pass
 * @param subject
 *            邮件标题
 * @param simpleEmailBody
 *            邮件内容
 * @param from
 *            邮件显示的发信人.实际的发信地址为 gamil 邮箱地址
 * @param to
 *            收件人邮件地址
 * @param cc
 *            抄送人邮件地址,多个地址用分号";"隔开,如果没有,则为空字符串""
 * @param bcc
 *            密送人邮件地址,多个地址用分号";"隔开,如果没有,则为空字符串""
 * @throws EmailException
 */
public void sendsimpleEmail(String userName, String password,
		String subject, String simpleEmailBody, String from, String to,
		String cc, String bcc) throws EmailException {

	// 创建SimpleEmail对象
	SimpleEmail email = new SimpleEmail();

	// 显示调试信息用于IED中输出
	email.setDebug(true);

	// 设置发送电子邮件的邮件服务器
	email.setHostName("smtp.gmail.com");

	// 邮件服务器是否使用ssl加密方式gmail就是,163就不是)
	email.setSSL(Boolean.TRUE);

	// 设置smtp端口号(需要查看邮件服务器的说明ssl加密之后端口号是不一样的)
	email.setSmtpPort(465);

	// 设置发送人的账号/密码
	email.setAuthentication(userName, password);

	// 显示的发信人地址,实际地址为gmail的地址
	email.setFrom(from);
	// 设置发件人的地址/称呼
	// email.setFrom("[email protected]", "发送人");

	// 收信人地址
	email.addTo(to);
	// 设置收件人的账号/称呼)
	// email.addTo("[email protected]", "收件人");

	// 多个抄送地址
	StrTokenizer stokenCC = new StrTokenizer(cc.trim(), ";");
	// 开始逐个抄送地址
	for (int i = 0; i < stokenCC.getTokenArray().length; i++) {
		email.addCc((String) stokenCC.getTokenArray()[i]);
	}

	// 多个密送送地址
	StrTokenizer stokenBCC = new StrTokenizer(bcc.trim(), ";");
	// 开始逐个抄送地址
	for (int i = 0; i < stokenBCC.getTokenArray().length; i++) {
		email.addBcc((String) stokenBCC.getTokenArray()[i]);
	}

	// Set the charset of the message.
	email.setCharset("UTF-8");

	email.setSentDate(new Date());

	// 设置标题,但是不能设置编码,commons 邮件的缺陷
	email.setSubject(subject);

	// 设置邮件正文
	email.setMsg(simpleEmailBody);

	// 就是send发送
	email.send();

	// 这个是我自己写的。
	System.out.println("The SimpleEmail send sucessful!");

}
 
Example #13
Source File: SendEmaiWithGmail.java    From spring-boot with Apache License 2.0 4 votes vote down vote up
public void sendsimpleEmail2(Email email, String userName, String password,
		String subject, String simpleEmailBody, String from, String to,
		String cc, String bcc) throws EmailException {

	// 创建SimpleEmail对象

	// 显示调试信息用于IED中输出
	email.setDebug(true);

	// 设置发送电子邮件的邮件服务器
	email.setHostName("smtp.gmail.com");

	// 邮件服务器是否使用ssl加密方式gmail就是,163就不是)
	email.setSSL(Boolean.TRUE);

	// 设置smtp端口号(需要查看邮件服务器的说明ssl加密之后端口号是不一样的)
	email.setSmtpPort(465);

	// 设置发送人的账号/密码
	email.setAuthentication(userName, password);

	// 显示的发信人地址,实际地址为gmail的地址
	email.setFrom(from);
	// 设置发件人的地址/称呼
	// email.setFrom("[email protected]", "发送人");

	// 收信人地址
	email.addTo(to);
	// 设置收件人的账号/称呼)
	// email.addTo("[email protected]", "收件人");

	// 多个抄送地址
	StrTokenizer stokenCC = new StrTokenizer(cc.trim(), ";");
	// 开始逐个抄送地址
	for (int i = 0; i < stokenCC.getTokenArray().length; i++) {
		email.addCc((String) stokenCC.getTokenArray()[i]);
	}

	// 多个密送送地址
	StrTokenizer stokenBCC = new StrTokenizer(bcc.trim(), ";");
	// 开始逐个抄送地址
	for (int i = 0; i < stokenBCC.getTokenArray().length; i++) {
		email.addBcc((String) stokenBCC.getTokenArray()[i]);
	}

	// Set the charset of the message.
	email.setCharset("UTF-8");

	email.setSentDate(new Date());

	// 设置标题,但是不能设置编码,commons 邮件的缺陷
	email.setSubject(subject);

	// 设置邮件正文
	email.setMsg(simpleEmailBody);

	// 就是send发送
	email.send();

	// 这个是我自己写的。
	System.out.println("The SimpleEmail send sucessful!");

}
 
Example #14
Source File: SendEmaiWithGmail.java    From spring-boot with Apache License 2.0 4 votes vote down vote up
/**
 * 发送 html 格式的邮件
 * 
 * @param userName
 * @param password
 * @param subject
 * @param from
 * @param to
 * @param cc
 * @param bcc
 * @throws EmailException
 * @throws java.net.MalformedURLException
 */
public void sendHTMLEmail(String userName, String password, String subject,
		String from, String to, String cc, String bcc)
		throws EmailException, MalformedURLException {

	// 创建SimpleEmail对象
	HtmlEmail email = new HtmlEmail();

	// 显示调试信息用于IED中输出
	email.setDebug(true);

	// 设置发送电子邮件的邮件服务器
	email.setHostName("smtp.gmail.com");

	// 邮件服务器是否使用ssl加密方式gmail就是,163就不是)
	email.setSSL(Boolean.TRUE);

	// 设置smtp端口号(需要查看邮件服务器的说明ssl加密之后端口号是不一样的)
	email.setSmtpPort(465);

	// 设置发送人的账号/密码
	email.setAuthentication(userName, password);

	// 显示的发信人地址,实际地址为gmail的地址
	email.setFrom(from);
	// 设置发件人的地址/称呼
	// email.setFrom("[email protected]", "发送人");

	// 收信人地址
	email.addTo(to);
	// 设置收件人的账号/称呼)
	// email.addTo("[email protected]", "收件人");

	// 多个抄送地址
	StrTokenizer stokenCC = new StrTokenizer(cc.trim(), ";");
	// 开始逐个抄送地址
	for (int i = 0; i < stokenCC.getTokenArray().length; i++) {
		email.addCc((String) stokenCC.getTokenArray()[i]);
	}

	// 多个密送送地址
	StrTokenizer stokenBCC = new StrTokenizer(bcc.trim(), ";");
	// 开始逐个抄送地址
	for (int i = 0; i < stokenBCC.getTokenArray().length; i++) {
		email.addBcc((String) stokenBCC.getTokenArray()[i]);
	}

	// Set the charset of the message.
	email.setCharset("UTF-8");

	email.setSentDate(new Date());

	// 设置标题,但是不能设置编码,commons 邮件的缺陷
	email.setSubject(subject);

	// === 以上同 simpleEmail

	// ===html mail 内容
	StringBuffer msg = new StringBuffer();
	msg.append("<html><body>");
	// embed the image and get the content id

	// 远程图片
	URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
	String cid = email.embed(url, "Apache logo");
	msg.append("<img src=\"cid:").append(cid).append("\">");

	// 本地图片
	File img = new File("d:/java.gif");
	msg.append("<img src=cid:").append(email.embed(img)).append(">");
	msg.append("</body></html>");

	// === html mail 内容

	// ==== // set the html message
	email.setHtmlMsg(msg.toString());
	// set the alternative message
	email.setTextMsg("Your email client does not support HTML messages");
	// send the email
	email.send();
	System.out.println("The HtmlEmail send sucessful!");

}
 
Example #15
Source File: LinuxCommandParser.java    From bistoury with GNU General Public License v3.0 4 votes vote down vote up
private static String[] splitIgnoreQuotes(String line) {
    StrTokenizer tokenizer = new StrTokenizer(line, StrMatcher.spaceMatcher());
    tokenizer.setIgnoreEmptyTokens(true);
    tokenizer.setQuoteMatcher(StrMatcher.quoteMatcher());
    return tokenizer.getTokenArray();
}
 
Example #16
Source File: SSLEditor.java    From http4e with Apache License 2.0 4 votes vote down vote up
protected String[] parseString( String stringList){
   StrTokenizer tokenizer = new StrTokenizer(stringList, DELIMITER);
   return tokenizer.getTokenArray();
}
 
Example #17
Source File: ProxyItemListEditor.java    From http4e with Apache License 2.0 4 votes vote down vote up
protected String[] parseString( String stringList){
   StrTokenizer tokenizer = new StrTokenizer(stringList, DELIMITER);
   return tokenizer.getTokenArray();
}
 
Example #18
Source File: CSVReaderBase.java    From datawave with Apache License 2.0 4 votes vote down vote up
public StrTokenizer getTokenizer() {
    return _tokenizer;
}
 
Example #19
Source File: AbstractLaunchDelegate.java    From xds-ide with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Prepare command line list. Gets command line in usual form like:
 * c:\dir\some.exe -arg1 "quo ted" $(varname) Before processing this string:
 * - All possible '\r' and '\n' characters will be replaced with spaces ' '
 * - All eclipse variables will be opened - All quotes will be opened
 * @param sdk 
 * 
 * @param cmdline
 * @return List with commandline items
 * @throws CoreException
 */
protected List<String> prepareCommandline(Sdk sdk, String cmdline) throws CoreException {
    cmdline = cmdline.replace('\n', ' ').replace('\r', ' ');
    cmdline = VariableUtils.performStringSubstitution(sdk, cmdline);
    String arr[] = new StrTokenizer(cmdline, ' ', '"').getTokenArray();
    return new ArrayList<>(Arrays.asList(arr));
}
 
Example #20
Source File: CSVIngestHelper.java    From datawave with Apache License 2.0 2 votes vote down vote up
/**
 * Allow classes extending this class to modify the StrTokenizer being used.
 * 
 * @param tokenizer
 *            The StrTokenizer that will be used on each Event
 */
protected StrTokenizer configureTokenizer(StrTokenizer tokenizer) {
    return tokenizer;
}