List of usage examples for org.apache.commons.lang3 StringUtils strip
public static String strip(String str, final String stripChars)
Strips any of a set of characters from the start and end of a String.
From source file:org.xlrnet.metadict.engines.leo.LeoEngine.java
/** * Extracts the domain information from a given representation string. * <p>//from ww w . j a v a 2 s . com * Example: * If the input is "drive-in restaurant [cook.]", then the domain is "cook." * * @param representation * The input string. * @return the domain string or null if none could be found */ @Nullable private String extractAbbreviationString(String representation) { String substring = StringUtils.substringBetween(representation, "[abbr.:", "]"); if (substring != null) return StringUtils.strip(substring, " \u00A0\n\t\r"); return null; }
From source file:org.xlrnet.metadict.engines.leo.LeoEngine.java
private void processAdditionalForms(EntryType entryType, DictionaryObjectBuilder dictionaryObjectBuilder, Language language, String representation) { // Try to extract verb tenses in english and german dictionary: if (entryType == EntryType.VERB && (Language.ENGLISH.equals(language) || Language.GERMAN.equals(language))) { String tensesString = StringUtils.substringBetween(representation, "|", "|"); if (tensesString != null) { String[] tensesArray = StringUtils.split(tensesString, ","); if (tensesArray.length != 2) { LOGGER.warn("Tenses array {} has unexpected length {} instead of 2", tensesArray, tensesArray.length); }/*from w ww. j a v a2s. com*/ dictionaryObjectBuilder.setAdditionalForm(GrammaticalTense.PAST_TENSE, StringUtils.strip(tensesArray[0], " \u00A0\n\t\r")); dictionaryObjectBuilder.setAdditionalForm(GrammaticalTense.PAST_PERFECT, StringUtils.strip(tensesArray[1], " \u00A0\n\t\r")); } } }
From source file:org.xwiki.resource.internal.entity.DefaultEntityResourceActionLister.java
@Override public void initialize() throws InitializationException { // Parse the Struts config file (struts-config.xml) to extract all available actions List<String> actionNames = new ArrayList<>(); SAXBuilder builder = new SAXBuilder(); // Make sure we don't require an Internet Connection to parse the Struts config file! builder.setEntityResolver(new EntityResolver() { @Override// w w w . ja v a2s . com public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new StringReader("")); } }); // Step 1: Get a stream on the Struts config file if it exists InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource()); if (strutsConfigStream != null) { // Step 2: Parse the Strust config file, looking for action names Document document; try { document = builder.build(strutsConfigStream); } catch (JDOMException | IOException e) { throw new InitializationException( String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e); } Element mappingElement = document.getRootElement().getChild("action-mappings"); for (Element element : mappingElement.getChildren("action")) { // We extract the action name from the path mapping. Note that we cannot use the "name" attribute since // it's not reliable (it's not unique) and for example the sanveandcontinue action uses "save" as its // "name" element value. actionNames.add(StringUtils.strip(element.getAttributeValue("path"), "/")); } } this.strutsActionNames = actionNames; }
From source file:org.xwiki.url.internal.container.ContextAndActionURLNormalizer.java
@Override public void initialize() { if (this.environment instanceof ServletEnvironment) { for (String mapping : ((ServletEnvironment) this.environment).getServletContext() .getServletRegistration("action").getMappings()) { this.validServletMappings.add(StringUtils.strip(mapping, IGNORED_MAPPING_CHARACTERS)); }//from www . j av a 2s . c o m } if (!this.validServletMappings.isEmpty()) { this.defaultServletMapping = this.validServletMappings.iterator().next(); } }
From source file:org.xwiki.url.internal.container.ContextAndActionURLNormalizer.java
@Override public ExtendedURL normalize(ExtendedURL partialURL) { String contextPath = StringUtils.strip(getContextPath(), URL_SEGMENT_DELIMITER); if (contextPath == null) { throw new RuntimeException(String.format("Failed to normalize the URL [%s] since the " + "application's Servlet context couldn't be computed.", partialURL)); }// w w w. j a v a2 s . c o m List<String> segments = new ArrayList<>(); if (StringUtils.isNotEmpty(contextPath)) { segments.add(contextPath); } String servletPath = getActionServletMapping(); if (StringUtils.isNotEmpty(servletPath)) { segments.add(servletPath); } segments.addAll(partialURL.getSegments()); return new ExtendedURL(segments, partialURL.getParameters()); }
From source file:org.xwiki.url.internal.container.ContextAndActionURLNormalizer.java
/** * Get the path prefix used for the Struts Action Servlet, either a prefix similar to the one used in the current * request if it also passes through the Action servlet, or using the default path configured for it. * * @return a path used for triggering the Struts Action Servlet (may be the empty string) *//*w w w . j a va 2s.c o m*/ protected String getActionServletMapping() { String result = this.defaultServletMapping; if (this.container.getRequest() instanceof ServletRequest) { HttpServletRequest hsRequest = ((ServletRequest) this.container.getRequest()).getHttpServletRequest(); result = StringUtils.strip(hsRequest.getServletPath(), IGNORED_MAPPING_CHARACTERS); if (!this.validServletMappings.contains(result)) { // The current request doesn't pass through the Action servlet, don't reuse the path prefix result = this.defaultServletMapping; } } return result; }
From source file:org.xwiki.url.internal.container.ExtendedURLURLNormalizer.java
@Override public ExtendedURL normalize(ExtendedURL partialURL) { String contextPath = StringUtils.strip(getContextPath(), URL_SEGMENT_DELIMITER); if (contextPath == null) { throw new RuntimeException(String.format("Failed to normalize the URL [%s] since the " + "application's Servlet context couldn't be computed.", partialURL)); }//w w w. j ava2s. co m List<String> segments = new ArrayList<>(); if (StringUtils.isNotEmpty(contextPath)) { segments.add(contextPath); } segments.addAll(partialURL.getSegments()); return new ExtendedURL(segments, partialURL.getParameters()); }
From source file:org.xwiki.url.internal.standard.ContextAndActionURLNormalizer.java
@Override public ExtendedURL normalize(ExtendedURL partialURL) { String contextPath = StringUtils.strip(getContextPath(), URL_SEGMENT_DELIMITER); if (contextPath == null) { throw new RuntimeException(String.format("Failed to normalize the URL [%s] since the " + "application's Servlet context couldn't be computed.", partialURL)); }/* ww w .j a v a 2 s .c o m*/ List<String> segments = new ArrayList<>(); if (StringUtils.isNotEmpty(contextPath)) { segments.add(contextPath); } List<String> servletPath = getActionAndWikiServletMapping(); for (String segment : servletPath) { if (StringUtils.isNotEmpty(segment)) { segments.add(segment); } } segments.addAll(partialURL.getSegments()); return new ExtendedURL(segments, partialURL.getParameters()); }
From source file:rapture.series.children.cleanup.DefaultFolderCleanupService.java
@Override public void addForReview(final String uniqueId, final String folderPath) { if (!StringUtils.isBlank(StringUtils.strip(folderPath, PathConstants.PATH_SEPARATOR))) { if (log.isTraceEnabled()) { log.trace(String.format("Adding folder [%s] in repo [%s]", folderPath, uniqueId)); }/*from www . ja v a2 s .co m*/ executor.submit(new Runnable() { @Override public void run() { final CleanupInfo cleanupInfo = repoIdToInfo.get(uniqueId); if (cleanupInfo != null) { cleanupInfo.addFolderForReview(folderPath); } else { if (log.isDebugEnabled()) { log.debug(String.format("Trying to clean up folder [%s] in unregistered repo [%s]", folderPath, uniqueId)); } } } }); } }
From source file:rems.Global.java
public static void exprtToHTMLDet(ResultSet recsdtst, ResultSet grpsdtst, String fileNm, String rptTitle, boolean isfirst, boolean islast, boolean shdAppnd, String orntnUsd, String imgCols) { try {/* w w w . j av a2 s.c o m*/ imgCols = "," + StringUtils.strip(imgCols, ",") + ","; String cption = ""; if (isfirst) { cption = "<caption align=\"top\">" + rptTitle + "</caption>"; Global.strSB.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"[]><html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"ltr\" lang=\"en-US\" xml:lang=\"en\"><head><meta http-equiv=\"Content-Type\" " + "content=\"text/html; charset=utf-8\">" + System.getProperty("line.separator") + "<title>" + rptTitle + "</title>" + System.getProperty("line.separator") + "<link rel=\"stylesheet\" href=\"../amcharts/rpt.css\" type=\"text/css\"></head><body>"); Files.copy( new File(Global.getOrgImgsDrctry() + "/" + String.valueOf(Global.UsrsOrg_ID) + ".png") .toPath(), new File(Global.getRptDrctry() + "/amcharts_2100/images/" + String.valueOf(Global.UsrsOrg_ID) + ".png").toPath(), StandardCopyOption.REPLACE_EXISTING); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), "/amcharts_2100/images/" + String.valueOf(Global.UsrsOrg_ID) + ".png"); } //Org Name String orgNm = Global.getOrgName(Global.UsrsOrg_ID); String pstl = Global.getOrgPstlAddrs(Global.UsrsOrg_ID); //Contacts Nos String cntcts = Global.getOrgContactNos(Global.UsrsOrg_ID); //Email Address String email = Global.getOrgEmailAddrs(Global.UsrsOrg_ID); Global.strSB .append("<p><img src=\"../images/" + String.valueOf(Global.UsrsOrg_ID) + ".png\">" + orgNm + "<br/>" + pstl + "<br/>" + cntcts + "<br/>" + email + "<br/>" + "</p>") .append(System.getProperty("line.separator")); } int fullPgWdthVal = 800; if (orntnUsd.equals("Portrait")) { fullPgWdthVal = 700; } int wdth = 0; String finalStr = " "; String algn = "left"; String[] rptGrpVals = { "Group Title", "Group Page Width Type", "Group Min-Height", "Show Group Border", "Group Display Type", "No of Vertical Divs In Group", "Comma Separated Col Nos", "Data Label Max Width%", "Comma Separated Hdr Nms", "Column Delimiter", "Row Delimiter" }; String grpTitle = ""; String grpPgWdth = ""; int grpMinHght = 0; String shwBrdr = "Show"; String grpDsplyTyp = "Details"; int grpColDvsns = 4;//Use 1 for Images others 2 or 4 String colnums = ""; String lblmaxwdthprcnt = "35"; String tblrHdrs = ""; String clmDlmtrs = ""; String rwDlmtrs = ""; int divwdth = 0; /* 1. For each detail group create a div and fieldset with legend & border based on group settings * 2a. if detail display then create required no of td in tr1 of a table, create new tr if no of columns is not exhausted * i.e if no of vertical divs=4 no rows=math.ceil(no cols*0.5)/ * else no rows=no cols * for each col display label and data if vrtcl divs is 2 or 4 else display only data * 2b. if tabular create table with headers according to defined headers * split data according to rows and cols and display them in this table * 2. Get all column nos within the group and create their labels and data using settings * 3. if col nos is image then use full defined page width else create no of defined columns count * 4. if * */ grpsdtst.last(); recsdtst.last(); int grpdtcnt = grpsdtst.getRow(); int rowsdtcnt = recsdtst.getRow(); grpsdtst.beforeFirst(); recsdtst.beforeFirst(); ResultSetMetaData recsdtstmd = recsdtst.getMetaData(); ResultSetMetaData grpsdtstmd = grpsdtst.getMetaData(); for (int a = 0; a < rowsdtcnt; a++) { recsdtst.next(); Global.strSB.append("<table style=\"margin-top:5px;min-width:" + String.valueOf(fullPgWdthVal + 50) + "px;\">" + cption + "<tbody>").append(System.getProperty("line.separator")); Global.strSB.append("<tr><td>").append(System.getProperty("line.separator")); for (int d = 0; d < grpdtcnt; d++) { grpsdtst.next(); wdth = 35; grpTitle = grpsdtst.getString(1); grpPgWdth = grpsdtst.getString(2); grpMinHght = Integer.parseInt(grpsdtst.getString(3)); shwBrdr = grpsdtst.getString(4); grpDsplyTyp = grpsdtst.getString(5); grpColDvsns = Integer.parseInt(grpsdtst.getString(6));//Use 1 for Images others 2 or 4 colnums = grpsdtst.getString(7); lblmaxwdthprcnt = grpsdtst.getString(8); tblrHdrs = grpsdtst.getString(9); clmDlmtrs = grpsdtst.getString(10); rwDlmtrs = grpsdtst.getString(11); wdth = Integer.parseInt(lblmaxwdthprcnt); if (grpPgWdth.equals("Half Page Width")) { divwdth = (int) (fullPgWdthVal / 2); } else { divwdth = (int) (fullPgWdthVal / 1); } Global.strSB.append("<div style=\"float:left;min-width:" + String.valueOf(divwdth - 50) + "px;padding:10px;\">").append(System.getProperty("line.separator"));//min-height:" + (grpMinHght + 20).ToString() + "px; if (shwBrdr.equals("Show")) { Global.strSB .append("<fieldset style=\"min-width:" + String.valueOf(divwdth - 80) + "px;\">") .append(System.getProperty("line.separator"));//min-height:" + (grpMinHght).ToString() + "px; Global.strSB.append("<legend>" + grpTitle + "</legend>") .append(System.getProperty("line.separator")); } String w = "\\,"; String[] colNumbers = colnums.split(w); int noofRws = 1; wdth = ((divwdth - 90) * wdth) / 100; if (grpDsplyTyp.equals("DETAIL")) { if (grpColDvsns == 4) { noofRws = (int) Math.ceil((double) colNumbers.length / (double) 2); } else { noofRws = colNumbers.length; } Global.strSB .append("<table style=\"min-width:" + String.valueOf(divwdth - 90) + "px;margin-top:5px;border:none;\" border=\"0\"><tbody>") .append(System.getProperty("line.separator")); if (grpColDvsns == 4) { for (int h = 0; h < colNumbers.length; h++) { if ((h % 2) == 0) { Global.strSB.append("<tr>").append(System.getProperty("line.separator")); } int clnm = -1; clnm = Integer.parseInt(colNumbers[h]); if (clnm >= 0) { String frsh = ""; Global.strSB.append( "<td style=\"border-bottom:none;border-left:none;font-weight:bolder;\" align=\"" + algn + "\" width=\"" + wdth + "px\">") .append(System.getProperty("line.separator")); frsh = recsdtstmd.getColumnName(clnm + 1).trim() + ": "; Global.strSB.append( Global.breakTxtDownHTML(frsh, (wdth / 7)).replace(" ", " ")); Global.strSB.append("</td>").append(System.getProperty("line.separator")); Global.strSB .append("<td style=\"border-bottom:none;border-left:none;\" align=\"" + algn + "\" width=\"" + (divwdth - 90 - wdth) + "px\">") .append(System.getProperty("line.separator")); if (imgCols.contains("," + clnm + ",")) { frsh = recsdtst.getString(clnm + 1).trim(); File file = new File(Global.dataBasDir + frsh); // if file doesnt exists, then create it if (!file.exists()) { String extnsn = FilenameUtils.getExtension(Global.dataBasDir + frsh); Files.copy(new File(Global.dataBasDir + frsh).toPath(), new File(Global.getRptDrctry() + "/amcharts_2100/images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn).toPath(), StandardCopyOption.REPLACE_EXISTING); Global.strSB .append("<p><img src=\"../images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn + "\" style=\"width:auto;height::" + grpMinHght + "px;\">" + "</p>") .append(System.getProperty("line.separator")); } } else { frsh = recsdtst.getString(clnm + 1).trim() + " "; Global.strSB .append(Global.breakTxtDownHTML(frsh, ((divwdth - 90 - wdth) / 7)) .replace(" ", " ")); } Global.strSB.append("</td>").append(System.getProperty("line.separator")); } if ((h % 2) == 1) { Global.strSB.append("</tr>").append(System.getProperty("line.separator")); } } } else if (grpColDvsns == 2) { for (int h = 0; h < colNumbers.length; h++) { Global.strSB.append("<tr>").append(System.getProperty("line.separator")); int clnm = -1; clnm = Integer.parseInt(colNumbers[h]); if (clnm >= 0) { String frsh = ""; Global.strSB.append( "<td style=\"border-bottom:none;border-left:none;font-weight:bold;\" align=\"" + algn + "\" width=\"" + wdth + "px\">") .append(System.getProperty("line.separator")); frsh = recsdtstmd.getColumnName(clnm + 1).trim() + ": "; Global.strSB.append( Global.breakTxtDownHTML(frsh, ((wdth) / 7)).replace(" ", " ")); Global.strSB.append("</td>").append(System.getProperty("line.separator")); Global.strSB .append("<td style=\"border-bottom:none;border-left:none;\" align=\"" + algn + "\" width=\"" + (divwdth - 90 - wdth) + "px\">") .append(System.getProperty("line.separator")); if (imgCols.contains("," + clnm + ",")) { frsh = recsdtst.getString(clnm + 1).trim(); File file = new File(Global.dataBasDir + frsh); // if file doesnt exists, then create it if (!file.exists()) { String extnsn = FilenameUtils.getExtension(Global.dataBasDir + frsh); Files.copy(new File(Global.dataBasDir + frsh).toPath(), new File(Global.getRptDrctry() + "/amcharts_2100/images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn).toPath(), StandardCopyOption.REPLACE_EXISTING); Global.strSB .append("<p><img src=\"../images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn + "\" style=\"width:auto;height:" + grpMinHght + "px;\">" + "</p>") .append(System.getProperty("line.separator")); } } else { frsh = recsdtst.getString(clnm + 1).trim() + " "; Global.strSB .append(Global.breakTxtDownHTML(frsh, ((divwdth - 90 - wdth) / 7)) .replace(" ", " ")); } Global.strSB.append("</td>"); } Global.strSB.append("</tr>"); } } else if (grpColDvsns == 1) { for (int h = 0; h < colNumbers.length; h++) { Global.strSB.append("<tr>"); int clnm = -1; clnm = Integer.parseInt(colNumbers[h]); if (clnm >= 0) { String frsh = ""; Global.strSB .append("<td style=\"border-bottom:none;border-left:none;\" align=\"" + algn + "\" width=\"" + (divwdth - 90) + "px\">") .append(System.getProperty("line.separator")); if (imgCols.contains("," + clnm + ",")) { frsh = recsdtst.getString(clnm + 1).trim(); File file = new File(Global.dataBasDir + frsh); // if file doesnt exists, then create it if (!file.exists()) { String extnsn = FilenameUtils.getExtension(Global.dataBasDir + frsh); Files.copy(new File(Global.dataBasDir + frsh).toPath(), new File(Global.getRptDrctry() + "/amcharts_2100/images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn).toPath(), StandardCopyOption.REPLACE_EXISTING); Global.strSB .append("<p><img src=\"../images/" + String.valueOf(Global.runID) + "_" + String.valueOf(a) + String.valueOf(clnm) + extnsn + "\" style=\"width:auto;height:" + grpMinHght + "px;\">" + "</p>") .append(System.getProperty("line.separator")); } } else { frsh = recsdtst.getString(clnm + 1).trim() + " "; Global.strSB.append(Global.breakTxtDownHTML(frsh, ((divwdth - 90) / 7)) .replace(" ", " ")); } Global.strSB.append("</td>"); } Global.strSB.append("</tr>"); } } Global.strSB.append("</tbody></table>"); } else { } if (shwBrdr.equals("Show")) { Global.strSB.append("</fieldset>"); } Global.strSB.append("</div>"); } Global.strSB.append("</td></tr>"); Global.strSB.append("</tbody></table><br/><br/>").append(System.getProperty("line.separator")); } if (islast) { Global.strSB.append("</body></html>"); File file = new File(fileNm); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); bw.write(Global.strSB.toString()); bw.close(); if (Global.callngAppType.equals("DESKTOP")) { Global.upldImgsFTP(9, Global.getRptDrctry(), "/amcharts_2100/samples/" + String.valueOf(Global.runID) + ".html"); } } } catch (IOException ex) { } catch (SQLException ex) { } catch (NumberFormatException ex) { } }