List of usage examples for org.apache.commons.lang StringUtils stripStart
public static String stripStart(String str, String stripChars)
Strips any of a set of characters from the start of a String.
From source file:org.punksearch.searcher.EasyQueryParser.java
private String prepareItem(String item) { if (item.startsWith("+") || item.startsWith("-")) { item = item.substring(1);/* w w w .j av a2 s . c o m*/ } if (isFastSearch) { // don't allow user to use "*someterm" search item = StringUtils.stripStart(item, "*"); } return !isExpandTerms ? item : isFastSearch ? item + "*" : "*" + item + "*"; }
From source file:org.rapidcontext.core.storage.Path.java
/** * Creates a new path from a parent and a child string * representation (similar to a file system path). * * @param parent the parent index path * @param path the string path to parse *///from w w w .j av a 2s.c om public Path(Path parent, String path) { this.parts = (parent == null) ? ArrayUtils.EMPTY_STRING_ARRAY : parent.parts; path = StringUtils.stripStart(path, "/"); this.index = path.equals("") || path.endsWith("/"); path = StringUtils.stripEnd(path, "/"); if (!path.equals("")) { String[] child = path.split("/"); String[] res = new String[this.parts.length + child.length]; for (int i = 0; i < this.parts.length; i++) { res[i] = this.parts[i]; } for (int i = 0; i < child.length; i++) { res[this.parts.length + i] = child[i]; } this.parts = res; } }
From source file:org.structr.web.servlet.DeploymentServlet.java
@Override protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { try (final Tx tx = StructrApp.getInstance().tx()) { if (!ServletFileUpload.isMultipartContent(request)) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getOutputStream()/*from w w w. j av a2s. com*/ .write("ERROR (400): Request does not contain multipart content.\n".getBytes("UTF-8")); return; } final SecurityContext securityContext; try { securityContext = getConfig().getAuthenticator().initializeAndExamineRequest(request, response); } catch (AuthenticationException ae) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.getOutputStream().write("ERROR (401): Invalid user or password.\n".getBytes("UTF-8")); return; } if (securityContext.getUser(false) == null && !Settings.DeploymentAllowAnonymousUploads.getValue()) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.getOutputStream().write("ERROR (401): Anonymous uploads forbidden.\n".getBytes("UTF-8")); return; } // Ensure access mode is frontend securityContext.setAccessMode(AccessMode.Frontend); request.setCharacterEncoding("UTF-8"); // Important: Set character encoding before calling response.getWriter() !!, see Servlet Spec 5.4 response.setCharacterEncoding("UTF-8"); // don't continue on redirects if (response.getStatus() == 302) { return; } final String pathInfo = request.getPathInfo(); String type = null; if (StringUtils.isNotBlank(pathInfo)) { type = SchemaHelper.normalizeEntityName(StringUtils.stripStart(pathInfo.trim(), "/")); } uploader.setFileSizeMax(MEGABYTE * Settings.DeploymentMaxFileSize.getValue()); uploader.setSizeMax(MEGABYTE * Settings.DeploymentMaxRequestSize.getValue()); response.setContentType("text/html"); final List<FileItem> fileItemsList = uploader.parseRequest(request); final Iterator<FileItem> fileItemsIterator = fileItemsList.iterator(); final Map<String, Object> params = new HashMap<>(); while (fileItemsIterator.hasNext()) { final FileItem item = fileItemsIterator.next(); try { final String directoryPath = "/tmp/" + UUID.randomUUID(); final String filePath = directoryPath + ".zip"; File file = new File(filePath); Files.write(IOUtils.toByteArray(item.getInputStream()), file); unzip(file, directoryPath); DeployCommand deployCommand = StructrApp.getInstance(securityContext) .command(DeployCommand.class); final Map<String, Object> attributes = new HashMap<>(); attributes.put("source", directoryPath + "/" + StringUtils.substringBeforeLast(item.getName(), ".")); deployCommand.execute(attributes); file.deleteOnExit(); File dir = new File(directoryPath); dir.deleteOnExit(); } catch (IOException ex) { logger.warn("Could not upload file", ex); } } tx.success(); } catch (FrameworkException | IOException | FileUploadException t) { logger.error("Exception while processing request", t); UiAuthenticator.writeInternalServerError(response); } }
From source file:org.structr.web.servlet.UploadServlet.java
@Override protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { try (final Tx tx = StructrApp.getInstance().tx()) { if (!ServletFileUpload.isMultipartContent(request)) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getOutputStream()/*from ww w .j av a2s . c o m*/ .write("ERROR (400): Request does not contain multipart content.\n".getBytes("UTF-8")); return; } final SecurityContext securityContext = getConfig().getAuthenticator() .initializeAndExamineRequest(request, response); if (securityContext.getUser(false) == null && Boolean.FALSE.equals(Boolean.parseBoolean( StructrApp.getConfigurationValue("UploadServlet.allowAnonymousUploads", "false")))) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.getOutputStream().write("ERROR (403): Anonymous uploads forbidden.\n".getBytes("UTF-8")); return; } // Ensure access mode is frontend securityContext.setAccessMode(AccessMode.Frontend); request.setCharacterEncoding("UTF-8"); // Important: Set character encoding before calling response.getWriter() !!, see Servlet Spec 5.4 response.setCharacterEncoding("UTF-8"); // don't continue on redirects if (response.getStatus() == 302) { return; } final String pathInfo = request.getPathInfo(); String type = null; if (StringUtils.isNotBlank(pathInfo)) { type = SchemaHelper.normalizeEntityName(StringUtils.stripStart(pathInfo.trim(), "/")); } uploader.setFileSizeMax(MEGABYTE * Long.parseLong(StructrApp.getConfigurationValue("UploadServlet.maxFileSize", MAX_FILE_SIZE))); uploader.setSizeMax(MEGABYTE * Long .parseLong(StructrApp.getConfigurationValue("UploadServlet.maxRequestSize", MAX_REQUEST_SIZE))); response.setContentType("text/html"); final PrintWriter out = response.getWriter(); List<FileItem> fileItemsList = uploader.parseRequest(request); Iterator<FileItem> fileItemsIterator = fileItemsList.iterator(); final Map<String, Object> params = new HashMap<>(); while (fileItemsIterator.hasNext()) { final FileItem item = fileItemsIterator.next(); if (item.isFormField()) { params.put(item.getFieldName(), item.getString()); } else { try { final String contentType = item.getContentType(); boolean isImage = (contentType != null && contentType.startsWith("image")); boolean isVideo = (contentType != null && contentType.startsWith("video")); // Override type from path info if (params.containsKey(NodeInterface.type.jsonName())) { type = (String) params.get(NodeInterface.type.jsonName()); } final Class cls = type != null ? SchemaHelper.getEntityClassForRawType(type) : (isImage ? Image.class : (isVideo ? VideoFile.class : org.structr.dynamic.File.class)); final String name = item.getName().replaceAll("\\\\", "/"); final org.structr.dynamic.File newFile = FileHelper.createFile(securityContext, IOUtils.toByteArray(item.getInputStream()), contentType, cls); newFile.setProperty(AbstractNode.name, PathHelper.getName(name)); if (!newFile.validatePath(securityContext, null)) { newFile.setProperty(AbstractNode.name, name.concat("_").concat(FileHelper.getDateString())); } PropertyMap additionalProperties = PropertyMap.inputTypeToJavaType(securityContext, cls, params); for (PropertyKey key : additionalProperties.keySet()) { newFile.setProperty(key, additionalProperties.get(key)); } // upload trigger newFile.notifyUploadCompletion(); // Just write out the uuids of the new files out.write(newFile.getUuid()); } catch (IOException ex) { logger.log(Level.WARNING, "Could not upload file", ex); } } } tx.success(); } catch (FrameworkException | IOException | FileUploadException t) { t.printStackTrace(); logger.log(Level.SEVERE, "Exception while processing request", t); UiAuthenticator.writeInternalServerError(response); } }
From source file:org.wikipedia.vlsergey.secretary.dom.WikiDOMUtils.java
public static void trimLeft(Content content) { if (content instanceof ArticleFragment) { final List<? extends Content> children = ((ArticleFragment) content).getChildren(); if (children.size() != 0) trimLeft(children.get(0));/*from w w w . j ava2s . c o m*/ return; } else if (content instanceof Text) { Text text = (Text) content; String string = text.getText(); string = StringUtils.stripStart(string, " \t\n\r"); text.setText(string); return; } else if (content instanceof Section || content instanceof Template) { return; } throw new UnsupportedOperationException(content.getClass().getName()); }
From source file:rapture.repo.cassandra.key.PathStripper.java
public static String stripPrefix(String prefix) { prefix = StringUtils.trimToEmpty(prefix); prefix = StringUtils.stripEnd(prefix, "/"); prefix = StringUtils.stripStart(prefix, "/"); if (StringUtils.isBlank(prefix)) { prefix = CassFolderHandler.DOLLAR_ROOT; }/*from ww w . j a v a2 s. c o m*/ return prefix; }
From source file:rapture.repo.integration.MongoUnversionedRepoTest.java
@Override protected String getConfig(String authority) { return String.format("REP {} USING MONGODB { prefix=\"%s\"} on integrationTest", StringUtils.stripStart(authority, "/")); }
From source file:rapture.repo.integration.MongoVersionedRepoTest.java
@Override protected String getConfig(String authority) { return String.format("NREP {} USING MONGODB { prefix=\"%s\"} on integrationTest", StringUtils.stripStart(authority, "/")); }
From source file:rapture.repo.integration.PgUnversionedRepoTest.java
@Override protected String getConfig(String authority) { return String.format("REP {} USING POSTGRES { prefix=\"%s\" }", StringUtils.stripStart(authority, "/")); }
From source file:rapture.repo.integration.PgVersionedRepoTest.java
@Override protected String getConfig(String authority) { return String.format("NREP {} USING POSTGRES { prefix=\"%s\" }", StringUtils.stripStart(authority, "/")); }