List of usage examples for java.util.regex Pattern quote
public static String quote(String s)
From source file:com.sangupta.dryrun.mongo.DryRunAntPath.java
private static String quote(String s, int start, int end) { if (start == end) { return ""; }//from w ww . j av a 2s . c om return Pattern.quote(s.substring(start, end)); }
From source file:com.amazonaws.utility.AwsHostNameUtils.java
/** * Attempts to parse the region name from an endpoint based on conventions * about the endpoint format./*w ww . j a va 2 s. co m*/ * * @param host the hostname to parse * @param serviceHint an optional hint about the service for the endpoint * @return the region parsed from the hostname, or * "us-east-1" if no region information * could be found */ public static String parseRegionName(final String host, final String serviceHint) { if (host.endsWith(".amazonaws.com")) { int index = host.length() - ".amazonaws.com".length(); return parseStandardRegionName(host.substring(0, index)); } if (serviceHint != null) { if (serviceHint.equals("cloudsearch") && !host.startsWith("cloudsearch.")) { // CloudSearch domains use the nonstandard domain format // [domain].[region].cloudsearch.[suffix]. Matcher matcher = EXTENDED_CLOUDSEARCH_ENDPOINT_PATTERN.matcher(host); if (matcher.matches()) { return matcher.group(1); } } // If we have a service hint, look for 'service.[region]' or // 'service-[region]' in the endpoint's hostname. Pattern pattern = Pattern.compile("^(?:.+\\.)?" + Pattern.quote(serviceHint) + "[.-]([a-z0-9-]+)\\."); Matcher matcher = pattern.matcher(host); if (matcher.find()) { return matcher.group(1); } } // Endpoint is totally non-standard; guess us-east-1 for lack of a // better option. return "us-east-1"; }
From source file:gr.abiss.calipso.util.SpaceUtils.java
public static void copySpace(CalipsoService calipso, Space spaceFrom, Space space) { // clear any old roles/tmpls calipso.bulkUpdateDeleteRolesAndTemplatesForSpace(space); // start with metadata String xml = spaceFrom.getMetadata().getXmlString(); // roles//from w ww . j ava2 s . c om List<SpaceRole> rolesFrom = calipso.findSpaceRolesForSpace(spaceFrom); Map<String, SpaceRole> rolesTo = new HashMap<String, SpaceRole>(); if (CollectionUtils.isNotEmpty(rolesFrom)) { for (SpaceRole roleFrom : rolesFrom) { String roleDescription = roleFrom.getDescription(); SpaceRole roleTo = new SpaceRole(space, roleDescription, roleFrom.getRoleType()); rolesTo.put(roleDescription, roleTo); xml = xml.replaceAll(Pattern.quote(roleFrom.getRoleCode()), roleTo.getRoleCode()); // useful? for (RoleSpaceStdField roleSpaceStdField : calipso.findSpaceFieldsBySpaceRole(roleFrom)) { roleTo.add(new RoleSpaceStdField(null, roleTo, roleSpaceStdField.getStdField(), roleSpaceStdField.getFieldMask())); } space.add(roleTo); } } // add fields and translations for custom fields List<Field> fieldsToCopy = spaceFrom.getMetadata().getFieldList(); //List<ItemFieldCustomAttribute> newFieldCustomAttributes = new LinkedList<ItemFieldCustomAttribute>(); space.getMetadata().setXmlString(xml); if (CollectionUtils.isNotEmpty(fieldsToCopy)) { for (Field fieldFrom : fieldsToCopy) { // copy custom attribute ItemFieldCustomAttribute attrFrom = calipso.loadItemCustomAttribute(spaceFrom, fieldFrom.getName().getText()); if (attrFrom != null) { ItemFieldCustomAttribute attrTo = new ItemFieldCustomAttribute(); copy(calipso, space, attrFrom, attrTo); Field fieldTo = space.getMetadata().getField(fieldFrom.getName().getText()); fieldTo.setCustomAttribute(attrTo); String fieldKey = fieldFrom.getName().getText(); List<I18nStringResource> resources = calipso.getPropertyTranslations(fieldKey, spaceFrom); spaceFrom.setPropertyTranslations(fieldKey, resources); Map<String, String> labelsToCopy = spaceFrom.getPropertyTranslations(fieldKey); if (MapUtils.isNotEmpty(labelsToCopy)) { Map<String, String> newlabels = new HashMap<String, String>(); for (String locale : labelsToCopy.keySet()) { if (locale.equals(calipso.getDefaultLocale()) || space.getSupportedLanguages().contains(new Language(locale))) { newlabels.put(locale, labelsToCopy.get(locale)); } } space.setPropertyTranslations(fieldKey, newlabels); } //spaceFrom.setTranslations(null); } } // Map<Name, Field> fieldsToTranslate = space.getMetadata().getFields(); } // copy templates List<ItemRenderingTemplate> templatesFrom = calipso.getItemRenderingTemplates(spaceFrom); logger.info("Adding templates to new space"); Map<String, ItemRenderingTemplate> newTemplates = new HashMap<String, ItemRenderingTemplate>(); logger.info("Adding templates to new space: " + templatesFrom); if (CollectionUtils.isNotEmpty(templatesFrom)) { int templateNameSuffix = 0; for (ItemRenderingTemplate templateFrom : templatesFrom) { ItemRenderingTemplate templateTo = new ItemRenderingTemplate(templateFrom); // keep a reference to add to space roles newTemplates.put(templateTo.getDescription(), templateTo); space.add(templateTo); // change the unsaved template name templateNameSuffix = templateNameSuffix + 1; templateTo.setDescription(space.getPrefixCode() + "-template-" + templateNameSuffix); calipso.storeItemRenderingTemplate(templateTo); } logger.info("Added templates to new space: " + space.getItemRenderingTemplates()); // iterate roles from the original space to add the item rendering templates // to the new space roles for (SpaceRole roleFrom : rolesFrom) { SpaceRole roleTo = rolesTo.get(roleFrom.getDescription()); Map<String, RenderingTemplate> roleTemplatesFrom = roleFrom.getItemRenderingTemplates(); if (MapUtils.isNotEmpty(roleTemplatesFrom)) { Map<String, RenderingTemplate> roleTemplatesTo = new HashMap<String, RenderingTemplate>(); for (String key : roleTemplatesFrom.keySet()) { String templateDescription = ((ItemRenderingTemplate) roleTemplatesFrom.get(key)) .getDescription(); RenderingTemplate templateTo = newTemplates.get(templateDescription); roleTemplatesTo.put(key, templateTo); } roleTo.setItemRenderingTemplates(roleTemplatesTo); logger.info( "Added templates to new role (" + roleTo.getDescription() + "): " + roleTemplatesTo); } } } }
From source file:com.github.wnameless.json.unflattener.JsonUnflattener.java
private String objectKey() { return "[^" + Pattern.quote(separator.toString()) + "\\[\\]]+"; }
From source file:net.sf.jabref.logic.util.Version.java
/** * @param version must be in form of X.X (e.g., 3.3; 3.4dev) *///from ww w .j a va 2 s .co m public Version(String version) { if ((version == null) || "".equals(version) || version.equals(BuildInfo.UNKNOWN_VERSION)) { return; } String[] versionParts = version.split("dev"); String[] versionNumbers = versionParts[0].split(Pattern.quote(".")); try { this.major = Integer.parseInt(versionNumbers[0]); this.minor = versionNumbers.length >= 2 ? Integer.parseInt(versionNumbers[1]) : 0; this.patch = versionNumbers.length >= 3 ? Integer.parseInt(versionNumbers[2]) : 0; this.fullVersion = version; this.isDevelopmentVersion = version.contains("dev"); } catch (NumberFormatException exception) { LOGGER.warn("Invalid version string used: " + version, exception); } }
From source file:ch.oakmountain.tpa.web.TpaWebPersistor.java
public static void createMatrix(String name, String outputDir, IMatrix matrix, String htmlData) throws Exception { LOGGER.info("Creating matrix " + name + "...."); String content = IOUtils.toString(TpaWebPersistor.class.getResourceAsStream("/matrix.html")); content = content.replaceAll(Pattern.quote("$JSONNAME$"), Matcher.quoteReplacement(name)) .replaceAll(Pattern.quote("$HTML$"), Matcher.quoteReplacement(htmlData)); FileUtils.writeStringToFile(Paths.get(outputDir + File.separator + name + ".html").toFile(), content); File file = new File(outputDir + File.separator + name + ".json"); writeMatrix(file, matrix);/*from w w w. ja v a2 s. c om*/ TpaPersistorUtils.copyFromResourceToDir("d3.v2.min.js", outputDir); TpaPersistorUtils.copyFromResourceToDir("miserables.css", outputDir); LOGGER.info("... created matrix " + name + "."); }
From source file:forge.util.FileSection.java
/** * Parses the.//from w ww . j ava 2s.c om * * @param lines the lines * @param kvSeparator the kv separator * @return the file section */ public static FileSection parse(final Iterable<String> lines, final String kvSeparator) { final FileSection result = new FileSection(); final Pattern splitter = Pattern.compile(Pattern.quote(kvSeparator)); for (final String dd : lines) { final String[] v = splitter.split(dd, 2); result.lines.put(v[0].trim(), v.length > 1 ? v[1].trim() : ""); } return result; }
From source file:com.itude.mobile.mobbl.core.util.StringUtilities.java
public static String stripCharacter(String inputString, char stripCharacter) { return inputString.replaceAll(Pattern.quote(Character.toString(stripCharacter)), ""); }
From source file:de.fu_berlin.inf.dpp.intellij.project.fs.PathImp.java
public PathImp(final String path) { this.path = path; String splitPath = path;/*w ww . j ava2s . com*/ //We must remove the first slash, otherwise String.split would //create an empty string as first segment if (path.startsWith("\\") || path.startsWith("/")) { splitPath = path.substring(1); } //"foo\bla.txt" is a valid linux path, which would not be handled // correctly by the separatorsToUnix. However, IntelliJ does not handle // these paths correctly and the FS Synchronizer logs an error when // encountering one. Thus it is not possible that PathImp is called with // such a path and we can safely use this method. splitPath = FilenameUtils.separatorsToUnix(splitPath); segments = splitPath.split(Pattern.quote(FILE_SEPARATOR)); }
From source file:com.spleefleague.core.command.BasicCommand.java
public BasicCommand(CorePlugin plugin, String name, String usage, Rank requiredRank, Rank... additionalRanks) { this.plugin = plugin; this.name = name; this.requiredRank = requiredRank; this.additionalRanks = Sets.newHashSet(additionalRanks); usage = usage.replaceAll(Pattern.quote("<command>"), name); this.usages = StringUtils.split(usage, "\n"); plugin.getCommand(name).setExecutor(this); }