List of usage examples for java.util.regex Pattern quote
public static String quote(String s)
From source file:com.predic8.membrane.core.interceptor.swagger.SwaggerRewriterInterceptor.java
@Override public Outcome handleResponse(Exchange exc) throws Exception { // replacement in swagger.json if (exc.getRequest().getUri().endsWith(swaggerJson) && exc.getResponseContentType().equalsIgnoreCase(MediaType.APPLICATION_JSON_VALUE)) { Swagger swagBody = new SwaggerParser().parse(exc.getResponse().getBodyAsStringDecoded()); swagBody.setHost(exc2originalHostPort(exc)); exc.getResponse().setBodyContent(Json.pretty(swagBody).getBytes(exc.getResponse().getCharset())); }// ww w .jav a 2 s . co m // replacement in json and javascript (specifically UI) if (rewriteUI && (exc.getRequest().getUri().matches("/.*.js(on)?") || exc.getResponse().getHeader().getContentType() != null && exc.getResponse().getHeader().getContentType().equals(MediaType.TEXT_HTML_VALUE))) { String from = "(http(s)?://)" + Pattern.quote(((ServiceProxy) exc.getRule()).getTarget().getHost()) + "(/.*\\.js(on)?)"; String to = "$1" + exc2originalHostPort(exc) + "$3"; byte[] body = exc.getResponse().getBodyAsStringDecoded().replaceAll(from, to) .getBytes(exc.getResponse().getCharset()); exc.getResponse().setBodyContent(body); } return super.handleResponse(exc); }
From source file:com.colinalworth.celltable.columns.rebind.model.ColumnSetModel.java
public String getPaths() { //TODO make this static? StringBuilder sb = new StringBuilder("new String[] {"); Set<String> paths = new HashSet<String>(); for (ColumnModel c : getColumnModels()) { if (c.getPath() != null && c.getPath().length() != 0) { paths.add("\"" + c.getPath().replaceAll(Pattern.quote("\\"), "\\\\") + "\""); }// w ww . j av a 2 s .c o m } sb.append(StringUtils.join(paths, ",")); return sb.append("}").toString(); }
From source file:com.kolich.common.util.secure.KolichStringSigner.java
/** * Given a signature string, extract the relevant payload. * Returns null if no payload could be extracted from within the * signature.//from w w w . j a v a 2 s. com */ private static final String extractPayload(final String signature) { checkNotNull(signature, "Oops, the signature to extract a payload " + "from cannot be null."); // The signature is a base-64 encoded mess of "payload|signature" final String[] tokens = decodeBase64(signature).split(Pattern.quote(SIGNATURE_DELIMITER)); return (tokens.length >= 1) ? decodeBase64(tokens[0]) : null; }
From source file:at.molindo.notify.servlet.NotifyFilterBean.java
@Override public void initFilterBean() throws ServletException { {/* w w w. jav a 2 s . c om*/ if (!StringUtils.empty(_baseUrlProperty)) { String baseUrl = System.getProperty(_baseUrlProperty); if (!StringUtils.empty(baseUrl)) { _baseUrl = baseUrl; } } if (StringUtils.empty(_baseUrl)) { throw new ServletException(String.format("parameter %s is required", PARAMTER_BASE_URL)); } try { _baseUrl = StringUtils.stripTrailing(new URL(_baseUrl).toString(), "/"); } catch (MalformedURLException e) { throw new ServletException( String.format("illegal value for parameter %s: '%s'", PARAMTER_BASE_URL, _baseUrl), e); } } { if (StringUtils.empty(_mountPath)) { _mountPath = DEFAULT_MOUNT_PATH; } _mountPath = StringUtils.stripTrailing(StringUtils.startWith(_mountPath, "/"), "/"); } { if (StringUtils.empty(_pullPrefix)) { _pullPrefix = DEFAULT_PULL_PREFIX; } _pullPrefix = StringUtils.endWith(StringUtils.startWith(_pullPrefix, "/"), "/"); _pullPattern = Pattern.compile("^" + Pattern.quote(_pullPrefix) + "([^/?]+)/([^/?]+).*$"); } { if (StringUtils.empty(_confirmPrefix)) { _confirmPrefix = DEFAULT_CONFIRM_PREFIX; } _confirmPrefix = StringUtils.endWith(StringUtils.startWith(_confirmPrefix, "/"), "/"); _confirmPattern = Pattern.compile("^" + Pattern.quote(_confirmPrefix) + "([^/?]+)/?$"); } }
From source file:com.apt.ajax.controller.AjaxUpload.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w.j a va2 s .co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); String uploadDir = request.getServletContext().getRealPath(File.separator) + "upload"; Gson gson = new Gson(); MessageBean messageBean = new MessageBean(); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ File x = new File(uploadDir); if (!x.exists()) { x.mkdir(); } boolean isMultiplePart = ServletFileUpload.isMultipartContent(request); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); if (!isMultiplePart) { } else { List items = null; try { items = upload.parseRequest(request); if (items != null) { Iterator iterator = items.iterator(); String assignmentId = ""; String stuid = ""; while (iterator.hasNext()) { FileItem item = (FileItem) iterator.next(); if (item.isFormField()) { String fieldName = item.getFieldName(); if (fieldName.equals("assignmentid")) { assignmentId = item.getString(); File c = new File(uploadDir + File.separator + assignmentId); if (!c.exists()) { c.mkdir(); } uploadDir = c.getPath(); if (request.getSession().getAttribute("studentId") != null) { stuid = request.getSession().getAttribute("studentId").toString(); File stuDir = new File(uploadDir + File.separator + stuid); if (!stuDir.exists()) { stuDir.mkdir(); } uploadDir = stuDir.getPath(); } } } else { String itemname = item.getName(); if (itemname == null || itemname.equals("")) { } else { String filename = FilenameUtils.getName(itemname); File f = new File(uploadDir + File.separator + filename); String[] split = f.getPath().split(Pattern.quote(File.separator) + "upload" + Pattern.quote(File.separator)); String save = split[split.length - 1]; if (assignmentId != null && !assignmentId.equals("")) { if (stuid != null && !stuid.equals("")) { } else { Assignment assignment = new AssignmentFacade() .findAssignment(Integer.parseInt(assignmentId)); assignment.setUrl(save); new AssignmentFacade().updateAssignment(assignment); } } item.write(f); messageBean.setStatus(0); messageBean.setMessage("File " + f.getName() + " sucessfuly uploaded"); } } } } gson.toJson(messageBean, out); } catch (Exception ex) { messageBean.setStatus(1); messageBean.setMessage(ex.getMessage()); gson.toJson(messageBean, out); } } } catch (Exception ex) { Logger.getLogger(AjaxUpload.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.att.aro.core.cloud.TraceManager.java
private String folderName(String trace) { String pattern = Pattern.quote(FILE_SEPARATOR); String[] split = trace.split(pattern); String traceName = trace;/*from w w w . j ava2 s.c om*/ if (split.length > 0) { traceName = split[split.length - 1]; } return traceName; }
From source file:net.beaconpe.jraklib.protocol.Packet.java
protected void putAddress(String addr, int port, byte version) { putByte(version);/* ww w . j av a2s. c o m*/ if (version == 4) { for (String section : addr.split(Pattern.quote("."))) { putByte((byte) ((byte) ~(Integer.parseInt(section)) & 0xFF)); } putShort((short) port); } }
From source file:com.alta189.cyborg.api.util.config.AbstractConfiguration.java
public void setPathSeparator(String pathSeparator) { this.pathSeparator = pathSeparator; this.pathSeparatorPattern = Pattern.compile(Pattern.quote(pathSeparator)); }
From source file:br.com.ingenieux.mojo.beanstalk.cmd.env.waitfor.WaitForEnvironmentCommand.java
protected List<Predicate<EnvironmentDescription>> getEnvironmentDescriptionPredicate( WaitForEnvironmentContext context) { // as well as those (which are used as predicate variables, thus being // final)/* w w w. j av a 2 s . c o m*/ final String environmentRef = context.getEnvironmentRef(); final String statusToWaitFor = defaultString(context.getStatusToWaitFor(), "!Terminated"); final String healthToWaitFor = context.getHealth(); // Sanity Check Validate.isTrue(isNotBlank(environmentRef), "EnvironmentRef is blank or null", environmentRef); // some argument juggling final boolean negated = statusToWaitFor.startsWith("!"); // argument juggling List<Predicate<EnvironmentDescription>> result = new ArrayList<Predicate<EnvironmentDescription>>(); if (environmentRef.matches("e-\\p{Alnum}{10}")) { result.add(new Predicate<EnvironmentDescription>() { @Override public boolean apply(EnvironmentDescription t) { return t.getEnvironmentId().equals(environmentRef); } }); info("... with environmentId equal to '%s'", environmentRef); } else if (environmentRef.matches(".*\\Q.elasticbeanstalk.com\\E")) { result.add(new Predicate<EnvironmentDescription>() { @Override public boolean apply(EnvironmentDescription t) { return defaultString(t.getCNAME()).equals(environmentRef); } }); info("... with cname set to '%s'", environmentRef); } else { String tmpRE = Pattern.quote(environmentRef); if (environmentRef.endsWith("*")) { tmpRE = format("^\\Q%s\\E.*", environmentRef.substring(0, -1 + environmentRef.length())); } final String environmentRefNameRE = tmpRE; result.add(new Predicate<EnvironmentDescription>() { @Override public boolean apply(EnvironmentDescription t) { return t.getEnvironmentName().matches(environmentRefNameRE); } }); info("... with environmentName matching re '%s'", environmentRefNameRE); } { // start building predicates with the status one - "![status]" must // be equal to status or not status final int offset = negated ? 1 : 0; final String vStatusToWaitFor = statusToWaitFor.substring(offset); result.add(new Predicate<EnvironmentDescription>() { public boolean apply(EnvironmentDescription t) { boolean result = vStatusToWaitFor.equals(t.getStatus()); if (negated) { result = !result; } debug("testing status '%s' as equal as '%s' (negated? %s, offset: %d): %s", vStatusToWaitFor, t.getStatus(), negated, offset, result); return result; } }); info("... with status %s set to '%s'", (negated ? "*NOT*" : " "), vStatusToWaitFor); } { if (isNotBlank(healthToWaitFor)) { result.add(new Predicate<EnvironmentDescription>() { @Override public boolean apply(EnvironmentDescription t) { return t.getHealth().equals(healthToWaitFor); } }); info("... with health equal to '%s'", healthToWaitFor); } } return result; }
From source file:com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient.java
@Override /** {@inheritDoc} */ public void ensurePath(final String path, final boolean excludingLast) throws KeeperException { PathUtils.validatePath(path);// ww w . j a v a 2 s . c o m assertClusterIdFlagTrue(); final String[] parts = path.substring(1).split(Pattern.quote("/")); final int end = excludingLast ? parts.length - 1 : parts.length; String current = ""; for (int i = 0; i < end; i++) { current += "/" + parts[i]; if (exists(current) == null) { create(current); } } }