List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:it.geosolutions.geostore.core.security.password.AbstractGeoStorePasswordEncoder.java
protected String removePrefix(String encPass) { return encPass.replaceFirst(getPrefix() + GeoStorePasswordEncoder.PREFIX_DELIMTER, ""); }
From source file:jeplus.EPlusWinTools.java
/** * Update the problem setup by replacing the searchstrings in the IDF template * file with the newvals strings, and save the new file in the working directory * with the given name + ".idf".//from ww w.j a v a 2 s . c o m * @param fn The target IDF file without the extension * @param IDFTemplate The template IDF file that contains the search strings * @param searchstrings The list of search strings to be looked up * @param newvals The list of new values to be used to replace the search strings * @param TargetDir The working directory in which the new IDF file will be saved. * @return state of execution * @deprecated Use the one with the same name */ public static boolean updateIDFFile(String fn, String IDFTemplate, String[] searchstrings, String[] newvals, String TargetDir) { boolean success = true; // Load and edit the template file try (BufferedReader ins = new BufferedReader(new FileReader(IDFTemplate)); PrintWriter outs = new PrintWriter(new FileWriter(TargetDir + fn))) { String line = ins.readLine(); int n = searchstrings.length; while (line != null) { for (int i = 0; i < n; i++) { line = line.replaceFirst(searchstrings[i], newvals[i]); } outs.println(line); line = ins.readLine(); } outs.flush(); } catch (Exception ex) { logger.error("", ex); success = false; } return success; }
From source file:org.apache.solr.client.solrj.io.sql.DriverImpl.java
protected URI processUrl(String url) throws SQLException { URI uri;//from www . java 2s.c o m try { uri = new URI(url.replaceFirst("jdbc:", "")); } catch (URISyntaxException e) { throw new SQLException(e); } if (uri.getAuthority() == null) { throw new SQLException("The zkHost must not be null"); } return uri; }
From source file:com.nextep.designer.sqlgen.oracle.generator.OracleTriggerGenerator.java
@Override public IGenerationResult generateFullSQL(Object model) { final ITrigger t = (ITrigger) model; final String triggerName = getName(t); final String rawName = t.getName(); final INamedObject table = (INamedObject) VersionHelper.getReferencedItem(t.getTriggableRef()); final String tableName = getName((IDatabaseObject<?>) table); ISQLScript s = getSqlScript(t.getName(), t.getDescription(), ScriptType.TRIGGER); s.appendSQL(prompt("Creating trigger '" + rawName + "' on table '" + table.getName() + "'...")); // Creating the intro creation statement if not user-defined if (!t.isCustom()) { s.appendSQL("CREATE OR REPLACE TRIGGER ").appendSQL(triggerName).appendSQL(" ") .appendSQL(t.getTime().name()).appendSQL(" "); if (t.getEvents().size() == 0) { LOGGER.warn(//from w w w . j av a2 s . c om t.getType().getName() + " " + rawName + ": No events defined for this trigger, skipping."); return null; } boolean first = true; for (TriggerEvent e : t.getEvents()) { if (first) { first = false; } else { s.appendSQL(" OR "); } s.appendSQL(e.name()); } s.appendSQL(" ON ").appendSQL(tableName).appendSQL(NEWLINE); s.appendSQL("FOR EACH ROW").appendSQL(NEWLINE); } else { s.appendSQL("CREATE OR REPLACE "); } // Appending SQL source code final String sql = t.getSql(); final String convertedSql = sql.replaceFirst("(?i)" + rawName, triggerName); s.appendSQL(convertedSql.trim()).appendSQL(NEWLINE); if (!t.isCustom()) { s.appendSQL(NEWLINE); } closeLastStatement(s); s.appendSQL("SHOW ERRORS").appendSQL(NEWLINE); // Building result IGenerationResult r = GenerationFactory.createGenerationResult(); r.addAdditionScript(new DatabaseReference(t.getType(), rawName), s); return r; }
From source file:com.codeveo.lago.bot.stomp.client.AbstractHttpLagoBot.java
private String toWsUrl(String lagoUrl) { return lagoUrl.replaceFirst("http://", "ws://"); }
From source file:no.dusken.common.plugin.ldapplugin.auth.DuskenLdapAuthoritiesPopulator.java
/** * This method should be overridden if required to obtain any additional * roles for the given user (on top of those obtained from the standard * search implemented by this class)./*from www. j a va 2 s . c om*/ * * @param user the context representing the user who's roles are required * @param username the username representing the user who's roles are required * @return the extra roles which will be merged with those returned by the group search */ @Override protected Set<GrantedAuthority> getAdditionalRoles(DirContextOperations user, String username) { // this is like "employeeNumber: 396" String employeeNumberString = user.getStringAttribute("employeeNumber"); // get the last number employeeNumberString = employeeNumberString.replaceFirst("employeeNumber: ", ""); Long employeeNumber = Long.parseLong(employeeNumberString); // I need this: SpringSecurityLdapTemplate ldapTemplate = new SpringSecurityLdapTemplate(getContextSource()); String groupSearchFilter = "memberID=" + employeeNumber; //noinspection unchecked Set<String> userRoles = ldapTemplate.searchForSingleAttributeValues(getGroupSearchBase(), groupSearchFilter, new String[] { user.getDn().toString(), username }, "roleName"); Set<GrantedAuthority> set = new HashSet<GrantedAuthority>(); for (String role : userRoles) { set.add(new GrantedAuthorityImpl("ROLE_" + role.toUpperCase().replaceAll(" ", "_"))); } return set; }
From source file:com.runwaysdk.dataaccess.io.RunwayClasspathEntityResolver.java
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId.startsWith("classpath:")) { systemId = systemId.replaceFirst("classpath:", ""); } else {//from w w w.j a v a2 s. c om return null; } // We're fetching from the root classloader, which means the equivalent of having a / at the beginning of the path // For some reason, when you do put a preceeding / the root classloader won't find the resource. This is dumb so I'm // going to remove preceeding slashes to stop it from not finding a valid resource. if (systemId.startsWith("/")) { systemId = systemId.replaceFirst("/", ""); } InputSource inputSource = null; try { URL url = this.getClass().getClassLoader().getResource(systemId); if (url == null) { throw new Exception("ClassLoader.getResource returned null."); } inputSource = new InputSource(url.toURI().toString()); if (inputSource.getSystemId() == null) { throw new Exception( "ClassLoader.getResource returned a url, but inputSource.getSystemId returned null."); } log.debug("Runway SAX parser successfully resolved resource on classpath [" + systemId + "] to [" + inputSource.getSystemId() + "]."); return inputSource; } catch (Exception e) { log.fatal("Runway SAX parser unable to resolve resource on classpath [" + systemId + "].", e); return null; } }
From source file:ch.sbb.releasetrain.webui.DirectorRunnerGui.java
private String replaceNode(String in, String node, String value) { return in.replaceFirst("<" + node + ">(.*)</" + node + ">", "<" + node + ">" + value + "</" + node + ">"); }
From source file:gov.nih.nci.cabio.portal.portlet.RESTProxyServletController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { try {//from ww w.j a v a 2 s .co m String relativeURL = request.getParameter("relativeURL"); if (relativeURL == null) { log.error("Null relativeURL parameter"); return null; } String qs = request.getQueryString(); if (qs == null) { qs = ""; } qs = qs.replaceFirst("relativeURL=(.*?)&", ""); qs = URLDecoder.decode(qs, "UTF-8"); String url = caBIORestURL + relativeURL + "?" + qs; log.info("Proxying URL: " + url); URI uri = new URI(url, false); HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(); method.setURI(uri); client.executeMethod(method); response.setContentType(method.getResponseHeader("Content-Type").getValue()); CopyUtils.copy(method.getResponseBodyAsStream(), response.getOutputStream()); } catch (Exception e) { throw new ServletException("Unable to connect to caBIO", e); } return null; }
From source file:de.codecentric.boot.admin.config.AdminClientProperties.java
private String append(String uri, String path) { String baseUri = uri.replaceFirst("/+$", ""); if (StringUtils.isEmpty(path)) { return baseUri; }/* w w w. ja va2s . co m*/ String normPath = path.replaceFirst("^/+", "").replaceFirst("/+$", ""); return baseUri + "/" + normPath; }