List of usage examples for java.util.regex Matcher appendTail
public StringBuilder appendTail(StringBuilder sb)
From source file:gtu._work.ui.EstoreCodeGenerateUI.java
private void initGUI() { try {//www . jav a 2s . c om BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); jTabbedPane1.setPreferredSize(new java.awt.Dimension(717, 582)); { jPanel1 = new JPanel(); GridLayout jPanel1Layout = new GridLayout(15, 1); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("", null, jPanel1, null); { jLabel1 = new JLabel(); jPanel1.add(jLabel1); jLabel1.setText("\u985e\u5225\u540d\u7a31"); } { classNameText = new JTextField(); jPanel1.add(classNameText); } { jLabel6 = new JLabel(); jPanel1.add(jLabel6); jLabel6.setText("package\u4e2d\u9593\u540d"); } { packageMiddleNameText = new JTextField(); jPanel1.add(packageMiddleNameText); } { jLabel2 = new JLabel(); jPanel1.add(jLabel2); jLabel2.setText("jsp\u8def\u5f91"); } { jspPathText = new JTextField(); jPanel1.add(jspPathText); jspPathText.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { try { String xmlConfigMessage = xmlConfigArea.getText(); if (StringUtils.isBlank(xmlConfigMessage)) { return; } StringBuilder sb = new StringBuilder(); String actionClassPath = jspPathText.getText(); actionClassPath = actionClassPath.replaceFirst("/src/main/webapp", ""); Pattern pattern = Pattern.compile("value=\"[\\w\\/]+\\.jsp\""); Matcher matcher = null; BufferedReader reader = new BufferedReader(new StringReader(xmlConfigMessage)); for (String line = null; (line = reader.readLine()) != null;) { matcher = pattern.matcher(line); if (matcher.find()) { StringBuffer sb2 = new StringBuffer(); matcher.appendReplacement(sb2, "value=\"" + actionClassPath + "\""); matcher.appendTail(sb2); sb.append(sb2 + "\n"); } else { sb.append(line + "\n"); } } xmlConfigArea.setText(sb.toString()); } catch (Exception e) { JCommonUtil.handleException(e); } } }); } { jLabel3 = new JLabel(); jPanel1.add(jLabel3); jLabel3.setText("action\u8def\u5f91"); } { actionPathText = new JTextField(); jPanel1.add(actionPathText); actionPathText.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { try { String xmlConfigMessage = xmlConfigArea.getText(); if (StringUtils.isBlank(xmlConfigMessage)) { return; } StringBuilder sb = new StringBuilder(); String actionClassPath = actionPathText.getText(); System.out.println(actionClassPath); actionClassPath = actionClassPath.replaceAll("/src/main/java/", "") .replace('/', '.').replaceAll(".java", ""); Pattern pattern = Pattern.compile("class=\"com\\.sti\\.[\\w\\.]+Action\""); Matcher matcher = null; BufferedReader reader = new BufferedReader(new StringReader(xmlConfigMessage)); for (String line = null; (line = reader.readLine()) != null;) { matcher = pattern.matcher(line); if (matcher.find()) { StringBuffer sb2 = new StringBuffer(); matcher.appendReplacement(sb2, "class=\"" + actionClassPath + "\""); matcher.appendTail(sb2); sb.append(sb2 + "\n"); } else { sb.append(line + "\n"); } } xmlConfigArea.setText(sb.toString()); } catch (Exception e) { JCommonUtil.handleException(e); } } }); } { jLabel4 = new JLabel(); jPanel1.add(jLabel4); jLabel4.setText("service interface\u8def\u5f91"); } { serviceInterfaceText = new JTextField(); jPanel1.add(serviceInterfaceText); } { jLabel5 = new JLabel(); jPanel1.add(jLabel5); jLabel5.setText("service Impl\u8def\u5f91"); } { serviceImplText = new JTextField(); jPanel1.add(serviceImplText); serviceImplText.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent evt) { try { String xmlConfigMessage = xmlConfigArea.getText(); if (StringUtils.isBlank(xmlConfigMessage)) { return; } StringBuilder sb = new StringBuilder(); String actionClassPath = serviceImplText.getText(); actionClassPath = actionClassPath.replaceFirst("/src/main/java/", "") .replaceAll(".java", "").replace('/', '.'); Pattern pattern = Pattern.compile("class=\"com.sti[\\w\\.]+ServiceImpl\""); Matcher matcher = null; BufferedReader reader = new BufferedReader(new StringReader(xmlConfigMessage)); for (String line = null; (line = reader.readLine()) != null;) { matcher = pattern.matcher(line); if (matcher.find()) { StringBuffer sb2 = new StringBuffer(); matcher.appendReplacement(sb2, "class=\"" + actionClassPath + "\""); matcher.appendTail(sb2); sb.append(sb2 + "\n"); } else { sb.append(line + "\n"); } } xmlConfigArea.setText(sb.toString()); } catch (Exception e) { JCommonUtil.handleException(e); } } }); } { updateBtn = new JButton(); jPanel1.add(updateBtn); updateBtn.setText("\u66f4\u65b0"); updateBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { updateBtnActionPerformed(evt); } }); } { makeFileBtn = new JButton(); jPanel1.add(makeFileBtn); makeFileBtn.setText("\u7522\u751f\u6a94\u6848"); makeFileBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { makeFileBtnActionPerformed(evt); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("xml", null, jPanel2, null); { jScrollPane1 = new JScrollPane(); jPanel2.add(jScrollPane1, BorderLayout.CENTER); { xmlConfigArea = new JTextArea(); jScrollPane1.setViewportView(xmlConfigArea); } } } } pack(); this.setSize(733, 525); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.paxle.crawler.http.impl.HttpCrawler.java
@Modified public synchronized void modified(Map<String, Object> configuration) { /*// w w w. j a v a 2 s . co m * Cleanup old config */ this.cleanup(); /* * Init with changed configuration */ this.connectionManager = new MultiThreadedHttpConnectionManager(); final HttpConnectionManagerParams connectionManagerParams = connectionManager.getParams(); // configure connections per host final Integer maxConnections = (Integer) configuration.get(PROP_MAXCONNECTIONS_PER_HOST); if (maxConnections != null) { connectionManagerParams.setDefaultMaxConnectionsPerHost(maxConnections.intValue()); } // configuring timeouts final Integer connectionTimeout = (Integer) configuration.get(PROP_CONNECTION_TIMEOUT); if (connectionTimeout != null) { connectionManagerParams.setConnectionTimeout(connectionTimeout.intValue()); } final Integer socketTimeout = (Integer) configuration.get(PROP_SOCKET_TIMEOUT); if (socketTimeout != null) { connectionManagerParams.setSoTimeout(socketTimeout.intValue()); } // set new http client this.httpClient = new HttpClient(connectionManager); // the crawler should request and accept content-encoded data final Boolean acceptEncoding = (Boolean) configuration.get(PROP_ACCEPT_ENCODING); if (acceptEncoding != null) { this.acceptEncoding = acceptEncoding.booleanValue(); } // specifies if the crawler should skipp unsupported-mime-types final Boolean skipUnsupportedMimeTypes = (Boolean) configuration.get(PROP_SKIP_UNSUPPORTED_MIMETYPES); if (skipUnsupportedMimeTypes != null) { this.skipUnsupportedMimeTypes = skipUnsupportedMimeTypes.booleanValue(); } // the cookie policy to use for crawling final String propCookiePolicy = (String) configuration.get(PROP_COOKIE_POLICY); this.cookiePolicy = (propCookiePolicy == null || propCookiePolicy.length() == 0) ? CookiePolicy.BROWSER_COMPATIBILITY : propCookiePolicy; // the http-user-agent string that should be used final String userAgent = (String) configuration.get(PROP_USER_AGENT); if (userAgent != null) { StringBuffer buf = new StringBuffer(); Pattern pattern = Pattern.compile("\\$\\{[^\\}]*}"); Matcher matcher = pattern.matcher(userAgent); // replacing property placeholders with system-properties while (matcher.find()) { String placeHolder = matcher.group(); String propName = placeHolder.substring(2, placeHolder.length() - 1); String propValue = System.getProperty(propName); if (propValue != null) matcher.appendReplacement(buf, propValue); } matcher.appendTail(buf); this.userAgent = buf.toString(); } else { // Fallback this.userAgent = "PaxleFramework"; } // download limit in bytes final Integer maxDownloadSize = (Integer) configuration.get(PROP_MAXDOWNLOAD_SIZE); if (maxDownloadSize != null) { this.maxDownloadSize = maxDownloadSize.intValue(); } // limit data transfer rate final Integer transferLimit = (Integer) configuration.get(PROP_TRANSFER_LIMIT); int limitKBps = 0; if (transferLimit != null) limitKBps = transferLimit.intValue(); this.logger.debug("transfer rate limit: " + limitKBps + " kb/s"); // TODO: lrc = (limitKBps > 0) ? new CrawlerTools.LimitedRateCopier(limitKBps) : null; // proxy configuration final Boolean useProxyVal = (Boolean) configuration.get(PROP_PROXY_USE); final String host = (String) configuration.get(PROP_PROXY_HOST); final Integer portVal = (Integer) configuration.get(PROP_PROXY_PORT); if (useProxyVal != null && useProxyVal.booleanValue() && host != null && host.length() > 0 && portVal != null) { this.logger.info(String.format("Proxy is enabled: %s:%d", host, portVal)); final int port = portVal.intValue(); final ProxyHost proxyHost = new ProxyHost(host, port); this.httpClient.getHostConfiguration().setProxyHost(proxyHost); final String user = (String) configuration.get(PROP_PROXY_HOST); final String pwd = (String) configuration.get(PROP_PROXY_PASSWORD); if (user != null && user.length() > 0 && pwd != null && pwd.length() > 0) this.httpClient.getState().setProxyCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(user, pwd)); } else { this.logger.info("Proxy is disabled"); this.httpClient.getHostConfiguration().setProxyHost(null); this.httpClient.getState().clearCredentials(); } }
From source file:eu.planets_project.tb.gui.backing.exp.ExpTypeExecutablePP.java
/** * Looks for the "public String describe()" method, creates a substring until the next appearance of "}" * and finally runs a regexp to remove special chars. * @param javafile//from w ww . j a v a 2 s . c o m * @return */ public String helperParseDescription(String content) { String token1 = "public String describe() {"; String token2 = "}"; String regexp = "[a-z A-Z 0-9 () . \\\\s]+"; int itoken1 = content.indexOf(token1); if (content.indexOf(token1) != -1) { int itoken2 = content.indexOf(token2, itoken1); if (itoken2 != -1) { String text = content.substring(itoken1 + token1.length(), itoken2); Pattern urlpattern = Pattern.compile(regexp); Matcher m = urlpattern.matcher(text); StringBuffer buff = new StringBuffer(); buff = m.appendTail(buff); return buff.toString(); } } return null; }
From source file:com.ibm.jaggr.core.impl.modulebuilder.css.CSSModuleBuilder.java
/** * Minifies a CSS string by removing comments and excess white-space, as well as * some unneeded tokens./*w w w . ja v a 2 s. c om*/ * * @param css The contents of a CSS file as a String * @param res The resource for the CSS file * @return the minified css */ protected String minify(String css, IResource res) { // replace all quoted strings and url(...) patterns with unique ids so that // they won't be affected by whitespace removal. LinkedList<String> quotedStringReplacements = new LinkedList<String>(); Matcher m = quotedStringPattern.matcher(css); StringBuffer sb = new StringBuffer(); int i = 0; while (m.find()) { String text = (m.group(1) != null) ? ("url(" + StringUtils.trim(m.group(1)) + ")") : //$NON-NLS-1$ //$NON-NLS-2$ m.group(0); quotedStringReplacements.add(i, text); String replacement = "%%" + QUOTED_STRING_MARKER + (i++) + "__%%"; //$NON-NLS-1$ //$NON-NLS-2$ m.appendReplacement(sb, ""); //$NON-NLS-1$ sb.append(replacement); } m.appendTail(sb); css = sb.toString(); // Get rid of extra whitespace css = whitespacePattern.matcher(css).replaceAll(" "); //$NON-NLS-1$ css = endsPattern.matcher(css).replaceAll(""); //$NON-NLS-1$ css = closeBracePattern.matcher(css).replaceAll("}"); //$NON-NLS-1$ m = delimitersPattern.matcher(css); sb = new StringBuffer(); while (m.find()) { String text = m.group(1); m.appendReplacement(sb, ""); //$NON-NLS-1$ sb.append(text.length() == 1 ? text : text.replace(" ", "")); //$NON-NLS-1$ //$NON-NLS-2$ } m.appendTail(sb); css = sb.toString(); // restore quoted strings and url(...) patterns m = QUOTED_STRING_MARKER_PAT.matcher(css); sb = new StringBuffer(); while (m.find()) { i = Integer.parseInt(m.group(1)); m.appendReplacement(sb, ""); //$NON-NLS-1$ sb.append(quotedStringReplacements.get(i)); } m.appendTail(sb); css = sb.toString(); return css.toString(); }
From source file:com.glaf.core.util.DBUtils.java
public static String removeOrders(String sql) { Assert.hasText(sql);/* w w w. ja v a 2 s.c om*/ Pattern pattern = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(sql); StringBuffer buf = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(buf, ""); } matcher.appendTail(buf); return buf.toString(); }
From source file:mergedoc.core.Comment.java
/** * ???????//from w ww . ja v a 2 s . co m * <p> * @param o */ private void expandComment(OutputComment o) { // HTML ?????????? if (!o.comment.contains("<")) { return; } // ? int height = o.resultHeight(); // <pre>?<blockquote>?<ol>?<ul> ?? StringBuffer sb = new StringBuffer(); Pattern pat = PatternCache.getPattern("([^\n])(\n(<blockquote>)?<pre>|\n<(blockquote|ol|ul)>)"); Matcher mat = pat.matcher(o.comment); while (height < o.originHeight && mat.find()) { mat.appendReplacement(sb, "$1\n$2"); height++; } mat.appendTail(sb); o.comment = sb.toString(); if (height == o.originHeight) { return; } // </pre>?</blockquote>?</ol>?</ul> ?? sb = new StringBuffer(); pat = PatternCache.getPattern("(</pre>(</blockquote>)?\n|</(blockquote|ol|ul)>\n)([^\n])"); mat = pat.matcher(o.comment); while (height < o.originHeight && mat.find()) { mat.appendReplacement(sb, "$1\n$4"); height++; } mat.appendTail(sb); o.comment = sb.toString(); if (height == o.originHeight) { return; } }
From source file:org.mule.transport.ldap.LdapConnector.java
public String parseStatement(final String stmt, final List params) { if (stmt == null) { return stmt; }//from ww w . j a v a2s.c o m final Matcher m = STATEMENT_ARGS.matcher(stmt); final StringBuffer sb = new StringBuffer(200); while (m.find()) { String key = m.group(); m.appendReplacement(sb, "?"); // Special legacy handling for #[payload] if (key.equals("#[payload]")) { // MULE-3597 logger.warn( "invalid expression template #[payload]. It should be replaced with #[payload:] to conform with the correct expression syntax. Mule has replaced this for you, but may not in future versions."); key = "#[payload:]"; } params.add(key); } m.appendTail(sb); return sb.toString(); }
From source file:org.picketlink.social.standalone.login.ExternalAuthentication.java
/** * <p>// w ww .j a va2 s . com * Get the system property value if the string is of the format ${sysproperty} * </p> * <p> * You can insert default value when the system property is not set, by separating it at the beginning with :: * </p> * <p> * <b>Examples:</b> * </p> * * <p> * ${idp} should resolve to a value if the system property "idp" is set. * </p> * <p> * ${idp::http://localhost:8080} will resolve to http://localhost:8080 if the system property "idp" is not set. * </p> * * @param str * @return */ private String getSystemPropertyAsString(String str) { if (str.contains("${")) { Pattern pattern = Pattern.compile("\\$\\{([^}]+)}"); Matcher matcher = pattern.matcher(str); StringBuffer buffer = new StringBuffer(); String sysPropertyValue = null; while (matcher.find()) { String subString = matcher.group(1); String defaultValue = ""; // Look for default value if (subString.contains("::")) { int index = subString.indexOf("::"); defaultValue = subString.substring(index + 2); subString = subString.substring(0, index); } sysPropertyValue = SecurityActions.getSystemProperty(subString, defaultValue); matcher.appendReplacement(buffer, sysPropertyValue); } matcher.appendTail(buffer); str = buffer.toString(); } return str; }
From source file:io.klerch.alexa.tellask.model.wrapper.AlexaSpeechletResponse.java
private String resolveSlotsInUtterance(final String utterance) { final StringBuffer buffer = new StringBuffer(); // extract all the placeholders found in the utterance final Matcher slotsInUtterance = Pattern.compile("\\{(.*?)\\}").matcher(utterance); // for any of the placeholders ... while (slotsInUtterance.find()) { // ... placeholder-name is the slotName to look after in two places of the output final String slotName = slotsInUtterance.group(1); final AlexaOutputSlot outputSlot = output // prefer directly set output slots .getSlots().stream()/*from ww w.j a v a 2s . co m*/ // which do have the same name as what is found in the utterance .filter(slot -> slot.getName().equals(slotName)).findFirst() // if not directly applied look in provided models for AlexaSlotSave fields .orElse(getSavedSlot(slotName)); Validate.notNull(outputSlot, "Could not replace placeholder with name {" + slotName + "} because no corresponding slot was set in the output."); // RJH - FEB 2017 - Matcher.quoteReplacement on slot input to fix bug // ~ https://github.com/KayLerch/alexa-skills-kit-tellask-java/issues/1 slotsInUtterance.appendReplacement(buffer, Matcher.quoteReplacement(outputSlot.getSsml())); } slotsInUtterance.appendTail(buffer); return "<speak>" + buffer.toString() + "</speak>"; }
From source file:gtu._work.etc.SqlReplacerUI.java
private void initGUI() { try {/*from w ww . j a va2 s .c om*/ BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("jPanel1", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(387, 246)); { jTextArea1 = new JTextArea(); jScrollPane1.setViewportView(jTextArea1); jTextArea1.setText(""); } } } { jPanel2 = new JPanel(); FlowLayout jPanel2Layout = new FlowLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("jPanel2", null, jPanel2, null); { replaceFromText = new JTextField(); jPanel2.add(replaceFromText); replaceFromText.setPreferredSize(new java.awt.Dimension(266, 22)); } { replaceToText = new JTextField(); jPanel2.add(replaceToText); replaceToText.setPreferredSize(new java.awt.Dimension(266, 22)); } { execute = new JButton(); jPanel2.add(execute); execute.setText("execute"); execute.setPreferredSize(new java.awt.Dimension(149, 42)); execute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { String text = jTextArea1.getText(); if (StringUtils.isBlank(text)) { JCommonUtil._jOptionPane_showMessageDialog_error("area empty!"); return; } String fromTxt = replaceFromText.getText(); String toTxt = StringUtils.defaultString(replaceToText.getText()); if (StringUtils.isBlank(fromTxt)) { JCommonUtil._jOptionPane_showMessageDialog_error("fromTxt empty!"); return; } StringBuffer sb = new StringBuffer(); Pattern ptn = Pattern.compile("(.){0,1}" + fromTxt + "(.){0,1}", Pattern.CASE_INSENSITIVE); Matcher mth = null; String[] scopeStrs = { ",", " ", "(", ")", "[", "]" }; BufferedReader reader = new BufferedReader(new StringReader(text)); for (String line = null; (line = reader.readLine()) != null;) { mth = ptn.matcher(line); while (mth.find()) { String scope1 = mth.group(1); String scope2 = mth.group(2); boolean ok1 = scope1.length() == 0 || StringUtils.indexOfAny(scope1, scopeStrs) != -1; boolean ok2 = scope2.length() == 0 || StringUtils.indexOfAny(scope2, scopeStrs) != -1; if (ok1 && ok2) { mth.appendReplacement(sb, scope1 + toTxt + scope2); } } mth.appendTail(sb); sb.append("\n"); } reader.close(); jTextArea1.setText(sb.toString()); } catch (Exception e) { JCommonUtil.handleException(e); } } }); } } } pack(); setSize(400, 300); } catch (Exception e) { //add your error handling code here e.printStackTrace(); } }