List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:au.org.ala.biocache.dao.TaxonDAOImpl.java
void outputLayer(String metadataUrlRoot, String rank, String taxon, Writer out) throws Exception { String normalised = taxon.replaceFirst("\\([A-Za-z]*\\) ", "").replace(" ", "_").replace("&", "&"); //remove the subgenus, replace spaces with underscores String normalisedTitle = taxon.replaceFirst("\\([A-Za-z]*\\) ", "").replace("&", "&"); //remove the subgenus, replace spaces with underscores out.write("<Layer queryable=\"1\"><Name>" + rank + ":" + normalised + "</Name><Title>" + rank + ":" + normalisedTitle + "</Title>" + "<MetadataURL type=\"TC211\">\n" + "<Format>text/html</Format>\n" + "<OnlineResource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\"" + " xlink:href=\"" + metadataUrlRoot + "?q=" + rank + ":" + URLEncoder.encode(taxon, "UTF-8") + "\"/>\n" + "</MetadataURL>" + "</Layer>"); out.flush();//www . j ava 2s . c o m }
From source file:info.fcrp.keepitsafe.security.KeepRoleEvaluator.java
private boolean checkRole(RoleMap roleMap, Authentication authentication, Object permission) { String[] roles = null;//www. java 2 s . com if ("king".equals(permission)) { if (roleMap.getKing() != null) { roles = roleMap.getKing().split(";"); } } else if ("commoner".equals(permission)) { if (roleMap.getCommoner() != null) { roles = roleMap.getCommoner().split(";"); } } for (String role : roles) { if (role.startsWith("user:")) { User user = (User) authentication.getPrincipal(); if (role.replaceFirst("user:", "").equals(user.getUsername())) { return true; } } else if (authentication.getAuthorities().contains(role)) { return true; } } return false; }
From source file:org.ecside.common.H2DriverManagerDataSource.java
public void setUrl(String url) { if (!StringUtils.hasText(url)) { throw new IllegalArgumentException("url must not be empty"); }/*from w w w. j av a 2 s .c om*/ url = url.replaceFirst(C_RootRealPath, rootRealPath); super.setUrl(url.trim()); }
From source file:dentex.youtube.downloader.docs.TranslatorsListActivity.java
private String ianaDecode(String encoded) { encoded = encoded.replaceFirst("ar", "ar (Arabic)").replaceFirst("zh-CN", "zh-CN (Chinese, China)") .replaceFirst("zh-HK", "zh-HK (Chinese, Hong Kong)") .replaceFirst("zh-TW", "zh-TW (Chinese, Taiwan)").replaceFirst("da", "da (Danish)") .replaceFirst("nl", "nl (Dutch)").replaceFirst("fr", "fr (French)") .replaceFirst("de", "de (German)").replaceFirst("grk", "grk (Greek)") .replaceFirst("he", "he (Hebrew)").replaceFirst("hu-HU", "hu-HU (Hungarian, Hungary)") .replaceFirst("it", "it (Italian)").replaceFirst("ko", "ko (Korean)") .replaceFirst("pl-PL", "pl-PL (Polish, Poland)") .replaceFirst("pt-BR", "pt-BR (Portuguese, Brazil)") .replaceFirst("pt-PT", "pt-PT (Portuguese, Portugal)").replaceFirst("ru", "ru (Russian)") .replaceFirst("sk-SK", "sk-SK (Slovak)").replaceFirst("sl-SI", "sl-SI (Slovenian)") .replaceFirst("es", "es (Spanish)").replaceFirst("tr-TR", "tr-TR (Turkish)") .replaceFirst("vi", "vi (Vietnamese)").replaceFirst("pes-IR", "pes-IR (Western Farsi, Iran)"); return encoded; }
From source file:eu.lunisolar.magma.doc.FileProcessor.java
private void print(String line) { try {//www. ja v a 2 s. c o m out.append(line.replaceFirst("^\\s*\\*\\s*", "")); out.append("\n"); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.wavemaker.tools.project.upgrade.six_dot_four.RemoveMySQLHBMCatalogUpgradeTask.java
@Override public void doUpgrade(Project project, UpgradeInfo upgradeInfo) { Folder servicesFolder = project.getRootFolder().getFolder("services"); // Don't bother if we do not have services try {/*w w w .j av a 2s. c o m*/ if (servicesFolder.exists()) { Resource servicesDir = project.getProjectRoot().createRelative("services/"); ArrayList<String> mySQLServices = new ArrayList<String>(); try { // Find MySQL Services IOFileFilter propFilter = FileFilterUtils.andFileFilter(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("properties")); List<File> propFiles = new UpgradeFileFinder(propFilter).findFiles(servicesDir.getFile()); Iterator<File> propIt = propFiles.iterator(); while (propIt.hasNext()) { File propFile = propIt.next(); String propContent = FileUtils.readFileToString(propFile); if (propContent.contains(mySQLStr)) { String propFileName = propFile.getName(); int index = propFileName.lastIndexOf("."); if (index > 0 && index <= propFileName.length()) { mySQLServices.add(propFileName.substring(0, index)); } } } // Find HBM files in MySQLServices Iterator<String> servIt = mySQLServices.iterator(); while (servIt.hasNext()) { IOFileFilter hbmFilter = FileFilterUtils.andFileFilter(FileFilterUtils.fileFileFilter(), FileFilterUtils.suffixFileFilter("hbm.xml")); String path = servIt.next(); Resource mySQLServiceDir = servicesDir .createRelative(path.endsWith("/") ? path : path + "/"); List<File> hbmFiles = new UpgradeFileFinder(hbmFilter).findFiles(mySQLServiceDir.getFile()); Iterator<File> hbmIt = hbmFiles.iterator(); while (hbmIt.hasNext()) { File hbmFile = hbmIt.next(); String hbmContent = FileUtils.readFileToString(hbmFile); hbmContent.replaceFirst(catalogStr, replaceStr); FileUtils.writeStringToFile(hbmFile, hbmContent); System.out .println("Project upgrade: Catalog removed from " + hbmFile.getAbsolutePath()); } } if (!mySQLServices.isEmpty()) { upgradeInfo.addMessage("\nMySQL Catalog upgrade task completed. See wm.log for details"); } else { System.out.println("Project Upgrade: No MySQL Services found"); } } catch (IOException ioe) { upgradeInfo .addMessage("\nError removing Catalog from MySQL Services. Check wm.log for details."); ioe.printStackTrace(); } } else { System.out.println("Project Upgrade: No Services found"); } } catch (IOException e) { throw new WMRuntimeException(e); } }
From source file:com.urbancode.x2o.xml.XmlWrite.java
public void makeXml(Object object, Document doc, Element parent) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { String className = object.getClass().getCanonicalName(); String nameSpace = persistConf.getNameSpaceForClassName(className); String prefix = persistConf.getPrefixForNameSpace(nameSpace); String elemName = persistConf.getElementForClassName(className); Element element = doc.createElementNS(nameSpace, prefix + ":" + elemName); if (parent == null) { doc.appendChild(element);//from w ww .j a v a 2 s . c o m } else { parent.appendChild(element); } List<Method> methods = findMethodsForClass("get", object.getClass()); for (Method method : methods) { Object methodResult = method.invoke(object); // if the result is a list of Tasks, // then iterate through each one and write it out as a sub-element if (methodResult instanceof List<?>) { for (Task nextTask : (List<Task>) methodResult) { makeXml(nextTask, doc, element); } } // if the result is a Task, // then write it out as a sub-element else if (methodResult instanceof Task) { makeXml(methodResult, doc, element); } // if the result is not any of the above, // then write it out as an attribute else { String attrName = method.getName(); attrName = attrName.replaceFirst("get", ""); attrName = convertFromCamelCase(attrName); if (methodResult == null || "null".equals(methodResult)) { methodResult = ""; } String resultString = methodResult.toString(); element.setAttribute(attrName, resultString); } } }
From source file:com.groupon.odo.controllers.PluginController.java
/** * Fetches a resource from a plugin jar with the given pluginName * Returns 404 if the resource cannot be found */// ww w .jav a2s . co m @RequestMapping(value = "/api/resource/{pluginName}/**", method = RequestMethod.GET) public @ResponseBody byte[] getResourceFile(Model model, @PathVariable String pluginName, HttpServletRequest request) throws Exception { try { String url = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); String fileName = url.replaceFirst("/api/resource/" + pluginName + "/", ""); return PluginManager.getInstance().getResource(pluginName, fileName); } catch (Exception e) { throw new ResourceNotFoundException(); } }
From source file:de.knurt.fam.template.util.TemplateHtml.java
/** * return a url like {@link #getHref(String)} but as relative path. this is * only needed in very specific cases where a reverse proxy is working on a * different port then the application and does not map it right. *///from www . j a v a2 s. co m public String getRelativeHref(String resourceName) { String result = this.getHref(resourceName); return result.replaceFirst("http(s){0,1}:\\/\\/[^\\/]+\\/", "/"); }
From source file:com.dotcms.content.elasticsearch.business.ESIndexHelper.java
/** * Finds file within the directory named "snapshot-" * @param snapshotDirectory/*from w ww . j a va 2 s .c om*/ * @return * @throws IOException */ public String findSnapshotName(File snapshotDirectory) throws IOException { String name = null; if (snapshotDirectory.isDirectory()) { class SnapshotVisitor extends SimpleFileVisitor<Path> { private String fileName; public String getFileName() { return fileName; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().startsWith(SNAPSHOT_PREFIX)) { fileName = file.getFileName().toString(); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } } Path directory = Paths.get(snapshotDirectory.getAbsolutePath()); SnapshotVisitor snapshotVisitor = new SnapshotVisitor(); Files.walkFileTree(directory, snapshotVisitor); String fullName = snapshotVisitor.getFileName(); if (fullName != null) { name = fullName.replaceFirst(SNAPSHOT_PREFIX, ""); } } return name; }