List of usage examples for org.apache.commons.lang StringUtils stripToEmpty
public static String stripToEmpty(String str)
Strips whitespace from the start and end of a String returning an empty String if null
input.
From source file:com.da.img.BoradHipList.java
protected void executeURL(String p_page) throws IOException, ClientProtocolException, URISyntaxException { DefaultHttpClient httpclient = new DefaultHttpClient(); try {// w ww .j av a 2 s.c om HttpGet httpget = executeLogin(httpclient); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = ""; // /bank/story_mn.php?p_userid=bluesman&p_snum=201&p_num=35788 // String strUrl = // "http://story.soraspace.info/bank/story_mn.php?p_userid=bluesman&p_snum=201&p_num=35821"; // : // http://photo.soraspace.info/album/theme/pic_list.php?p_anum=173&p_ix=3&p_gnum=351 // http://photo.soraspace.info/album/theme/pic_list.php?p_page=1&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt= // http://photo.soraspace.info/album/theme/pic_list.php?p_page=2&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt= // http://photo.soraspace.info/album/theme/pic_list.php?p_page=3&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt= // http://photo.soraspace.info/album/theme/pic_list.php?p_page=3&p_sort=D&p_anum=351&p_gnum=351&p_soption=&p_stxt= String imgUrl; // p_anum=244&p_ix=1 ? // p_anum=281&p_ix=2 // p_anum=173&p_ix=3 ? // p_gnum= 351 : mom , 481: lip , 352: hip, // 354:ga,353:leg,442:pussy, String SaveFilePath = "c:/temp/173"; String p_gnum = "352"; List<ImageVo> lst = null; int max_page = 10000; String output = ""; InputStream istream; int init_page = 1; if (!"".equals(StringUtils.stripToEmpty(p_page))) { init_page = Integer.parseInt(p_page); } for (int i = init_page; i < max_page; i++) { lst = getBoardList(httpclient, httpget, responseHandler, p_gnum, String.valueOf(i)); for (ImageVo vo : lst) { // continue; imgUrl = vo.getImgUrl(); // "http://photo2.soraspace.info/thumbnail.php?p_imgwidth=1104&p_imgheight=1104&p_width=1104&p_height=1104&p_imgfile=%2F%2F201205%2F22%2Fsk650%2F%2F1501694.jpg&verify=%2F%90%F9%B7%D6%D0%12%0EF%17%B8M%DA%A4L%C4"; istream = getDownloadUrlInputStream(httpclient, httpget, imgUrl); // System.out.println("result = " + istream.toString()); output = SaveFilePath + "/" + p_gnum + "/" + org.apache.commons.lang.StringUtils.leftPad(String.valueOf(i), 4, "0") + "/" + vo.getFileName(); fileDownCopy(output, istream); if (istream != null) { istream.close(); } } } } catch (Exception ex) { System.out.println("ERROR: " + ex.getLocalizedMessage()); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.dream.messaging.engine.DataHandler.java
/** * Generate object property value, the message content is String. * //from w w w . j a v a 2 s . c o m * @param data the data * @param node the node * * @return the object */ public Object createValue(String data, Node node) { String clsname = QueryNode.getAttribute(node, ElementAttr.Attr_Class); try { Class cls = null; Object value = null; if (clsname == null || clsname.equalsIgnoreCase(ElementClassType.CLASS_STRING)) { value = StringUtils.stripToEmpty(data); } else if (clsname.equalsIgnoreCase(ElementClassType.CLASS_INT) || clsname.equalsIgnoreCase(ElementClassType.CLASS_COUNTER)) { try { value = Integer.valueOf(data.trim()); } catch (NumberFormatException e) { value = 0; } } else if (clsname.equalsIgnoreCase(ElementClassType.CLASS_LONG)) { try { value = Long.valueOf(data.trim()); } catch (NumberFormatException e) { value = 0; } } else if (clsname.equalsIgnoreCase(ElementClassType.CLASS_DOUBLE)) { try { value = Float.valueOf(data.trim()); } catch (NumberFormatException e) { value = Float.valueOf("0"); } } else if (clsname.equalsIgnoreCase(ElementClassType.CLASS_FLOAT)) { try { value = Double.valueOf(data.trim()); } catch (NumberFormatException e) { value = Double.valueOf("0"); } } else if (clsname.equalsIgnoreCase(ElementClassType.CLASS_DECIMAL)) { try { value = new java.math.BigDecimal(data.trim()); } catch (NumberFormatException e) { value = java.math.BigDecimal.ZERO; } } else if (clsname.equalsIgnoreCase(ElementClassType.CLASS_DATE) || clsname.equalsIgnoreCase(ElementClassType.CLASS_TIME)) { String format = QueryNode.getAttribute(node, ElementAttr.Attr_Format); SimpleDateFormat sdf = new SimpleDateFormat(format); try { value = sdf.parse(data); } catch (ParseException e) { value = data; } } else { cls = Class.forName(clsname); Constructor c = cls.getConstructor(String.class); value = c.newInstance(new Object[] { data }); } return value; } catch (ClassNotFoundException e) { return null; } catch (IllegalArgumentException e) { return null; } catch (InstantiationException e) { return null; } catch (IllegalAccessException e) { return null; } catch (InvocationTargetException e) { return null; } catch (SecurityException e) { return null; } catch (NoSuchMethodException e) { return null; } }
From source file:com.da.img.SoStroyInfoList.java
protected void executeURL(String p_page, String p_author_id, String p_gnum) throws IOException, ClientProtocolException, URISyntaxException { DefaultHttpClient httpclient = new DefaultHttpClient(); try {/*from w w w. j a v a 2 s . c o m*/ HttpGet httpget = executeLogin(httpclient); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = ""; // /bank/story_mn.php?p_userid=bluesman&p_snum=201&p_num=35788 // String strUrl = // "http://story.soraspace.info/bank/story_mn.php?p_userid=bluesman&p_snum=201&p_num=35821"; // : // http://photo.soraspace.info/album/theme/pic_list.php?p_anum=173&p_ix=3&p_gnum=351 // http://photo.soraspace.info/album/theme/pic_list.php?p_page=1&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt= // http://photo.soraspace.info/album/theme/pic_list.php?p_page=2&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt= // http://photo.soraspace.info/album/theme/pic_list.php?p_page=3&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt= // http://photo.soraspace.info/album/theme/pic_list.php?p_page=3&p_sort=D&p_anum=351&p_gnum=351&p_soption=&p_stxt= // p_anum=244&p_ix=1 ? // p_anum=281&p_ix=2 // p_anum=173&p_ix=3 ? // p_gnum= 351 : mom , 481: lip , 352: hip, // 354:ga,353:leg,442:pussy, // /honor/author_board_list.php?p_userid=bluesman&p_soption=storyname&p_stxt=? // String p_gnum ="481"; List<ImageVo> lst = null; int max_page = 10000; int init_page = 1; if (!"".equals(StringUtils.stripToEmpty(p_page))) { init_page = Integer.parseInt(p_page); } // init_page = 17; SAVE_DIR = STORY_DIR + "/story/" + p_author_id; //p_author_id ="we"; for (int i = init_page; i < max_page; i++) { lst = getBoardList(httpclient, httpget, responseHandler, p_gnum, String.valueOf(i), p_author_id); System.out.println("Story Size: " + lst.size()); if (lst.size() < 1) { break; } } } catch (Exception ex) { ex.printStackTrace(System.out); System.out.println("ERROR: " + ex.getLocalizedMessage()); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.da.daum.DaumOk211List.java
protected void executeURL(String p_page, String p_author_id, String p_gnum) throws IOException, ClientProtocolException, URISyntaxException { HttpClient httpclient = null;/*from ww w. j a v a2 s.co m*/ try { httpclient = getPoolHttpClient(); String responseBody = ""; String strUrl = ""; String file = ""; //httpclient.setRedirectHandler(new spaceRedirectHandler()); List<DaumListVo> lst = null; executeLogin(httpclient); this.parser = new DaumOk211Parser(); int max_page = 100000; int init_page = 1; // p_page="1"; String viewBody = ""; if (!"".equals(StringUtils.stripToEmpty(p_page))) { init_page = Integer.parseInt(p_page); } String output = "", bodyAndComment = ""; InputStream istream; for (int i = init_page; i < max_page; i++) { lst = getBoardList(httpclient, String.valueOf(i)); if (lst.size() < 1) { break; } for (DaumListVo vo : lst) { strUrl = host_url + vo.getViewUrl(); System.out.println("========================================="); System.out.println(strUrl); System.out.println("========================================="); file = SAVE_DIR + "/" + CAFE_TYPE + "/" + BOARD_TYPE + "/" + vo.getRnum() + "." + vo.getSubject().replaceAll("\\*", "").replaceAll("\\/", "_").replaceAll("\"", "_") + "_" + vo.getIdAlais().replaceAll("\\*", "").replaceAll("\\/", "_") .replaceAll("\"", "_").replaceAll("\\?", "") + "_" + vo.getCreatYmd() + ""; file = StringUtils.replace(file, "|", ""); file = StringUtils.replace(file, ".", ""); file += ".txt"; System.out.println("save file:" + file); // ? responseBody = execGetUrl(httpclient, strUrl); //? ? saveImageFile(httpclient, responseBody, vo); // String comment = getSaveComment(httpclient, vo); bodyAndComment = saveViewFile(responseBody, file) + "\r\n\r\n" + comment; FileHelper.createFile(file); FileUtils.writeStringToFile(new File(file), bodyAndComment, "utf-8"); // ? //strUrl+/comments?page=1 // ? ? . /316 //strUrl = host_url+"/CHILIL/LPN/"+vo.getRnum()+"/comments?page=1"; // List<DaumListVo> lstComment = parser.setDaumListVoCommentList(responseBody, "316", commentPageMap); } } } catch (Exception ex) { ex.printStackTrace(System.out); System.out.println("ERROR: " + ex.getLocalizedMessage()); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.da.daum.DaumCafeList.java
protected void executeURL(String p_page, String p_author_id, String p_gnum) throws IOException, ClientProtocolException, URISyntaxException { HttpClient httpclient = null;/* w w w .ja v a 2 s.c o m*/ try { httpclient = getPoolHttpClient(); String responseBody = ""; String strUrl = ""; String file = ""; //httpclient.setRedirectHandler(new spaceRedirectHandler()); List<DaumListVo> lst = null; executeLogin(httpclient); this.parser = new DaumCafeParser(); int max_page = 10000; int init_page = 1; p_page = "1"; String viewBody = ""; if (!"".equals(StringUtils.stripToEmpty(p_page))) { init_page = Integer.parseInt(p_page); } for (int i = init_page; i < max_page; i++) { lst = getBoardList(httpclient, String.valueOf(i)); if (lst.size() < 1) { break; } for (DaumListVo vo : lst) { strUrl = host_url + vo.getViewUrl(); System.out.println("========================================="); System.out.println(strUrl); System.out.println("========================================="); file = SAVE_DIR + "/user/" + vo.getIdAlais().replaceAll("\\*", "").replaceAll("\\/", "_") + ".txt"; responseBody = execGetUrl(httpclient, strUrl); viewBody = parser.setDaumView(responseBody); viewBody = this.htmlRemove(viewBody); System.out.println("save file:" + file); FileHelper.createFile(file); FileUtils.writeStringToFile(new File(file), viewBody, "utf-8"); } } } catch (Exception ex) { ex.printStackTrace(System.out); System.out.println("ERROR: " + ex.getLocalizedMessage()); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.da.daum.DaumCafeJw0List.java
protected void executeURL(String p_page, String p_author_id, String p_gnum) throws IOException, ClientProtocolException, URISyntaxException { HttpClient httpclient = null;/*www.j a v a 2s . co m*/ try { httpclient = getPoolHttpClient(); String responseBody = ""; String strUrl = ""; String file = ""; //httpclient.setRedirectHandler(new spaceRedirectHandler()); List<DaumListVo> lst = null; executeLogin(httpclient); this.parser = new DaumCafeJw0Parser(); int max_page = 10000; int init_page = 1; p_page = "1"; String viewBody = ""; if (!"".equals(StringUtils.stripToEmpty(p_page))) { init_page = Integer.parseInt(p_page); } String output = "", bodyAndComment = ""; InputStream istream; for (int i = init_page; i < max_page; i++) { lst = getBoardList(httpclient, String.valueOf(i)); if (lst.size() < 1) { break; } for (DaumListVo vo : lst) { strUrl = host_url + vo.getViewUrl(); System.out.println("========================================="); System.out.println(strUrl); System.out.println("========================================="); file = SAVE_DIR + "/" + BOARD_TYPE + "/" + vo.getRnum() + "." + vo.getSubject().replaceAll("\\*", "").replaceAll("\\/", "_").replaceAll("\"", "_") + "_" + vo.getIdAlais().replaceAll("\\*", "").replaceAll("\\/", "_").replaceAll("\"", "_") + "_" + vo.getCreatYmd() + "" + ".txt"; System.out.println("save file:" + file); // ? responseBody = execGetUrl(httpclient, strUrl); //? ? saveImageFile(httpclient, responseBody, vo); // String comment = getSaveComment(httpclient, vo); bodyAndComment = saveViewFile(responseBody, file) + "\r\n\r\n" + comment; FileHelper.createFile(file); FileUtils.writeStringToFile(new File(file), bodyAndComment, "utf-8"); // ? //strUrl+/comments?page=1 // ? ? . /316 //strUrl = host_url+"/CHILIL/LPN/"+vo.getRnum()+"/comments?page=1"; // List<DaumListVo> lstComment = parser.setDaumListVoCommentList(responseBody, "316", commentPageMap); } } } catch (Exception ex) { ex.printStackTrace(System.out); System.out.println("ERROR: " + ex.getLocalizedMessage()); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.atlassian.theplugin.idea.config.serverconfig.GenericServerConfigForm.java
public synchronized void saveData() { if (serverCfg == null) { return;//from ww w.ja va 2 s . c o m } if (StringUtils.stripToEmpty(serverName.getText()).length() == 0) { return; } serverCfg.setName(serverName.getText()); serverCfg.setUrl(serverUrl.getText()); serverCfg.setUsername(username.getText()); serverCfg.setPassword(String.valueOf(password.getPassword())); serverCfg.setPasswordStored(true); serverCfg.setEnabled(cbEnabled.isSelected()); serverCfg.setUseDefaultCredentials(useDefault.isSelected()); if (serverCfg.getUrl().length() > 0) { cbEnabled.setEnabled(true); } else { cbEnabled.setEnabled(false); } serverCfg.setShared(cbShared.isSelected()); }
From source file:com.da.daum.DaumCafeOneLineList.java
protected void executeURL(String p_page, String p_author_id, String p_gnum) throws IOException, ClientProtocolException, URISyntaxException { HttpClient httpclient = null;//from ww w .jav a 2 s.c o m String output = SAVE_DIR + "/" + CAFE_NM + "/" + BOARD_TYPE + "/_oneLine.txt"; FileHelper.createFile(output); FileWriter fw = new FileWriter(output); BufferedWriter bw = new BufferedWriter(fw); try { httpclient = getPoolHttpClient(); String responseBody = ""; String strUrl = ""; String file = ""; //httpclient.setRedirectHandler(new spaceRedirectHandler()); List<DaumListVo> lst = null; executeLogin(httpclient); this.parser = new DaumCafeOneLineParser(); int max_page = 100000; int init_page = 1; p_page = "1"; String viewBody = ""; if (!"".equals(StringUtils.stripToEmpty(p_page))) { init_page = Integer.parseInt(p_page); } String bodyAndComment = ""; InputStream istream; // ?? . for (int i = init_page; i < max_page; i++) { lst = getBoardList(httpclient, String.valueOf(i)); if (lst.size() < 1) { break; } // for (DaumListVo vo : lst) { //strUrl = host_url+vo.getViewUrl(); /*System.out.println("========================================="); System.out.println(strUrl); System.out.println("=========================================");*/ /*file = SAVE_DIR+"/"+BOARD_TYPE+"/"+vo.getRnum()+"."+vo.getSubject().replaceAll("\\*", "").replaceAll("\\/", "_").replaceAll("\"", "_")+"_" +vo.getIdAlais().replaceAll("\\*", "").replaceAll("\\/", "_").replaceAll("\"", "_") +"_"+vo.getCreatYmd()+"" +".txt"; System.out.println("save file:"+file);*/ // ? //responseBody = execGetUrl(httpclient,strUrl); // // //vo.setRnum("56700"); String comment = getSaveComment(httpclient, vo); file = SAVE_DIR + "/" + CAFE_NM + "/" + BOARD_TYPE + "/" + vo.getIdAlais().replaceAll("\\*", "").replaceAll("\\/", "_").replaceAll("\"", "_") .replaceAll("\\*", "_").replaceAll("\\?", "_").replaceAll(":", "_") + "_" + vo.getCreatYmd().replaceAll(":", "_") + "_" + vo.getRnum() + ".txt"; System.out.println("save file:" + file); bodyAndComment = vo.getIdAlais() + "|" + vo.getCreatYmd() + "\r\n" + vo.getSubject() + "\r\n\r\n" + comment; FileHelper.createFile(file); FileUtils.writeStringToFile(new File(file), bodyAndComment, "utf-8"); bw.write(bodyAndComment); } } } catch (Exception ex) { ex.printStackTrace(System.out); System.out.println("ERROR: " + ex.getLocalizedMessage()); } finally { bw.close(); fw.close(); httpclient.getConnectionManager().shutdown(); } }
From source file:com.da.img.SoStroyAllList.java
protected void executeURL(String p_page, String p_author_id, String p_gnum) throws IOException, ClientProtocolException, URISyntaxException { DefaultHttpClient httpclient = new DefaultHttpClient(); try {// w ww. java2s.co m List<AuthorVo> lstAuthor = executeAuthorList(p_page, p_author_id, p_gnum); HttpGet httpget = executeLogin(httpclient); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = ""; // http://story.soraspace.info/honor/honor_list_02.php // http://story.soraspace.info/honor/honor_list_03.php // http://story.soraspace.info/honor/honor_list_04.php // http://story.soraspace.info/honor/honor_list_05.php List<ImageVo> lst = null; int max_page = 10000; int init_page = 1; if (!"".equals(StringUtils.stripToEmpty(p_page))) { init_page = Integer.parseInt(p_page); } // init_page = 17; for (AuthorVo vo : lstAuthor) { SAVE_DIR = STORY_DIR + "/story/" + vo.getAuthorAlias() + "(" + vo.getAuthorId() + ")"; p_author_id = vo.getAuthorId(); for (int i = init_page; i < max_page; i++) { lst = getBoardList(httpclient, httpget, responseHandler, p_gnum, String.valueOf(i), p_author_id); System.out.println("Story Size: " + lst.size()); if (lst.size() < 1) { break; } } } } catch (Exception ex) { ex.printStackTrace(System.out); System.out.println("ERROR: " + ex.getLocalizedMessage()); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.pc.dailymile.DailyMileClient.java
/** * Add a workout//from ww w.j av a 2 s . co m * * @param consumer * an authenticated consumer * @param workout * @param message * @return the id of the workout that was created */ public Long addWorkout(Workout workout, String message) { Entry entry = new Entry(); entry.setMessage(StringUtils.stripToEmpty(message)); entry.setWorkout(workout); try { return addEntry(entry); } catch (Exception e) { throw new RuntimeException("Unable to add workout", e); } }