List of usage examples for java.lang StringBuilder lastIndexOf
@Override public int lastIndexOf(String str)
From source file:org.jahia.bin.DefaultPostAction.java
public ActionResult doExecute(HttpServletRequest req, RenderContext renderContext, Resource resource, final JCRSessionWrapper session, final Map<String, List<String>> parameters, URLResolver urlResolver) throws Exception { JCRNodeWrapper newNode = null;//from w w w . j a va 2 s . com String[] subPaths = Patterns.SLASH.split(urlResolver.getPath()); String lastPath = subPaths[subPaths.length - 1]; JCRNodeWrapper node = null; StringBuilder realPath = new StringBuilder(); String startPath = ""; int index = 0; for (String subPath : subPaths) { index++; if (StringUtils.isNotBlank(subPath) && !"*".equals(subPath) && index != subPaths.length) { realPath.append("/").append(subPath); try { session.getNode(JCRContentUtils.escapeNodePath(realPath.toString())); startPath = ""; } catch (PathNotFoundException e) { if ("".equals(startPath)) { startPath = realPath.substring(0, realPath.lastIndexOf("/")); } } } } startPath = "".equals(startPath) ? realPath.toString() : startPath; realPath = realPath.delete(0, realPath.length()); index = 0; for (String subPath : subPaths) { index++; if (StringUtils.isNotBlank(subPath) && !"*".equals(subPath) && index != subPaths.length) { realPath.append("/").append(subPath); if (realPath.toString().contains(startPath)) { try { node = session.getNode(JCRContentUtils.escapeNodePath(realPath.toString())); } catch (PathNotFoundException e) { if (node != null) { if (!node.isCheckedOut()) { session.checkout(node); } String parentType = "jnt:contentList"; if (parameters.containsKey(Render.PARENT_TYPE)) { parentType = parameters.get(Render.PARENT_TYPE).get(0); } node = node.addNode(subPath, parentType); } } } } } if (node != null) { String nodeType = null; if (parameters.containsKey(Render.NODE_TYPE)) { nodeType = parameters.get(Render.NODE_TYPE).get(0); } if (StringUtils.isBlank(nodeType)) { // resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing nodeType Property"); return ActionResult.BAD_REQUEST; } String nodeName = null; if (parameters.containsKey(Render.NODE_NAME)) { nodeName = parameters.get(Render.NODE_NAME).get(0); } boolean forceCreation = false; if (!"*".equals(lastPath)) { nodeName = lastPath; } else { forceCreation = true; } try { newNode = createNode(req, parameters, node, nodeType, nodeName, forceCreation); final FileUpload fileUpload = (FileUpload) req.getAttribute(FileUpload.FILEUPLOAD_ATTRIBUTE); if (fileUpload != null && fileUpload.getFileItems() != null && fileUpload.getFileItems().size() > 0) { final Map<String, DiskFileItem> stringDiskFileItemMap = fileUpload.getFileItems(); for (Map.Entry<String, DiskFileItem> itemEntry : stringDiskFileItemMap.entrySet()) { newNode.uploadFile(itemEntry.getValue().getName(), itemEntry.getValue().getInputStream(), JCRContentUtils.getMimeType(itemEntry.getValue().getName(), itemEntry.getValue().getContentType())); } } session.save(); } catch (CompositeConstraintViolationException e) { List<JSONObject> jsonErrors = new ArrayList<JSONObject>(); for (ConstraintViolationException exception : e.getErrors()) { jsonErrors.add(getJSONConstraintError(exception)); } JSONObject jsonObject = new JSONObject(); jsonObject.put("validationError", jsonErrors); return new ActionResult(HttpServletResponse.SC_BAD_REQUEST, null, jsonObject); } catch (ConstraintViolationException e) { JSONObject jsonObject = new JSONObject(); jsonObject.put("validationError", Arrays.asList(getJSONConstraintError(e))); return new ActionResult(HttpServletResponse.SC_BAD_REQUEST, null, jsonObject); } final String nodeId = newNode.getIdentifier(); if (parameters.containsKey(Render.AUTO_ASSIGN_ROLE) && !JahiaUserManagerService.isGuest(session.getUser())) { JCRTemplate.getInstance().doExecuteWithSystemSessionAsUser(session.getUser(), session.getWorkspace().getName(), null, new JCRCallback<Object>() { public Object doInJCR(JCRSessionWrapper rootSession) throws RepositoryException { JCRNodeWrapper createdNode = rootSession.getNodeByUUID(nodeId); List<String> roles = parameters.get(Render.AUTO_ASSIGN_ROLE); createdNode.grantRoles("u:" + session.getUser().getName(), new HashSet<String>(roles)); rootSession.save(); return null; } }); } if (parameters.containsKey(Render.AUTO_CHECKIN) && (parameters.get(Render.AUTO_CHECKIN)).get(0).length() > 0) { newNode.checkpoint(); } } String sessionID = ""; HttpSession httpSession = req.getSession(false); if (httpSession != null) { sessionID = httpSession.getId(); } String nodeIdentifier = null; if (newNode != null) { nodeIdentifier = newNode.getIdentifier(); } if (loggingService.isEnabled()) { loggingService.logContentEvent(renderContext.getUser().getName(), req.getRemoteAddr(), sessionID, nodeIdentifier, urlResolver.getPath(), parameters.get(Render.NODE_TYPE).get(0), "nodeCreated", new JSONObject(parameters).toString()); } if (newNode != null) { return new ActionResult(HttpServletResponse.SC_CREATED, newNode.getPath(), Render.serializeNodeToJSON(newNode)); } else { return null; } }
From source file:ccc.cli.Schema.java
private void runScript(final Connection newConnection, final String create) { LOG.info("Running script: " + create); final List<String> statements = Resources.readIntoList(create, Charset.forName("UTF-8")); final StringBuilder statement = new StringBuilder(); int statementCount = 0; for (final String line : statements) { if (line.trim().length() < 1) { if (0 < statement.length()) { LOG.info("Executing statement: " + statement); execute(newConnection, statement.toString()); statement.setLength(0);//ww w . ja va2 s . c om statementCount++; } } else if (!line.trim().startsWith("--")) { statement.append(line); if (!create.toLowerCase().contains("oracle")) { statement.append("\n"); } else { if (statement.lastIndexOf(";") != statement.length() - 1) { statement.append(" "); } } } else { LOG.info("Ignoring: " + line); } } if (0 < statement.length()) { LOG.debug("Executing statement: " + statement); execute(newConnection, statement.toString()); statementCount++; } LOG.info("Statements to process: " + statementCount); }
From source file:org.openbravo.advpaymentmngt.actionHandler.AddPaymentActionHandler.java
/** * @param allselection/* w w w.j a v a2 s . c o m*/ * Selected Rows in Credit to use grid * @return a String with the concatenation of the selected rows ids */ private String getSelectedCreditLinesIds(JSONArray allselection) throws JSONException { StringBuilder sb = new StringBuilder(); sb.append("("); for (int i = 0; i < allselection.length(); i++) { JSONObject selectedRow = allselection.getJSONObject(i); sb.append(selectedRow.getString("id") + ","); } sb.replace(sb.lastIndexOf(","), sb.lastIndexOf(",") + 1, ")"); return sb.toString(); }
From source file:net.duckling.ddl.web.controller.team.ConfigTeamController.java
private String getUIDString(String[] uids) { StringBuilder result = new StringBuilder(); if (null != uids && uids.length > 0) { for (String uid : uids) { result.append(uid + ","); }/* www . ja va 2 s . c om*/ result.replace(result.lastIndexOf(","), result.length(), ""); } return result.toString(); }
From source file:org.lazulite.boot.autoconfigure.osaam.shiro.sys.resource.service.ResourceService.java
/** * ? ? :?/*from w w w . j a v a2 s. c om*/ * * @param resource * @return */ public String findActualResourceIdentity(Resource resource) { if (resource == null) { return null; } StringBuilder s = new StringBuilder(resource.getIdentity() == null ? "" : resource.getIdentity()); boolean hasResourceIdentity = !StringUtils.isEmpty(resource.getIdentity()); Resource parent = findOne(resource.getParentId()); while (parent != null) { if (!StringUtils.isEmpty(parent.getIdentity())) { s.insert(0, parent.getIdentity() + ":"); hasResourceIdentity = true; } parent = findOne(parent.getParentId()); } // ? if (!hasResourceIdentity) { return ""; } //?: ?? int length = s.length(); if (length > 0 && s.lastIndexOf(":") == length - 1) { s.deleteCharAt(length - 1); } //? ?* boolean hasChildren = false; for (Resource r : findAll()) { if (resource.getId().equals(r.getParentId())) { hasChildren = true; break; } } if (hasChildren) { s.append(":*"); } return s.toString(); }
From source file:com.impetus.kundera.utils.KunderaCoreUtils.java
/** * Prepares composite key as a lucene key. * // w w w . jav a2 s . c o m * @param m * entity metadata * @param metaModel * meta model. * @param compositeKey * composite key instance * @return redis key */ public static String prepareCompositeKey(final SingularAttribute attribute, final MetamodelImpl metaModel, final Object compositeKey) { Field[] fields = attribute.getBindableJavaType().getDeclaredFields(); EmbeddableType embeddable = metaModel.embeddable(attribute.getBindableJavaType()); StringBuilder stringBuilder = new StringBuilder(); try { for (Field f : fields) { if (!ReflectUtils.isTransientOrStatic(f)) { if (metaModel.isEmbeddable( ((AbstractAttribute) embeddable.getAttribute(f.getName())).getBindableJavaType())) { f.setAccessible(true); stringBuilder.append( prepareCompositeKey((SingularAttribute) embeddable.getAttribute(f.getName()), metaModel, f.get(compositeKey))) .append(LUCENE_COMPOSITE_KEY_SEPERATOR); } else { String fieldValue = PropertyAccessorHelper.getString(compositeKey, f); fieldValue = fieldValue.replaceAll("[^a-zA-Z0-9]", "_"); stringBuilder.append(fieldValue); stringBuilder.append(LUCENE_COMPOSITE_KEY_SEPERATOR); } } } } catch (IllegalAccessException e) { logger.error(e.getMessage()); } catch (IllegalArgumentException e) { logger.error("Error during prepare composite key, Caused by {}.", e); throw new PersistenceException(e); } if (stringBuilder.length() > 0) { stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(LUCENE_COMPOSITE_KEY_SEPERATOR)); } return stringBuilder.toString(); }
From source file:us.mn.state.health.lims.common.services.NoteService.java
private String notesToString(boolean prefixType, boolean prefixTimestamp, String noteSeparator, List<Note> noteList, boolean excludeExternPrefix) { if (noteList.isEmpty()) { return null; }/* w w w . j a va 2 s . c om*/ StringBuilder builder = new StringBuilder(); for (Note note : noteList) { if (prefixType) { builder.append(getNotePrefix(note, excludeExternPrefix)); builder.append(" "); } if (prefixTimestamp) { builder.append(getNoteTimestamp(note)); builder.append(" "); } if (prefixType || prefixTimestamp) { builder.append(": "); } builder.append(note.getText()); builder.append(StringUtil.blankIfNull(noteSeparator)); } if (!GenericValidator.isBlankOrNull(noteSeparator)) { builder.setLength(builder.lastIndexOf(noteSeparator)); } return builder.toString(); }
From source file:Model.MDengue.java
public void addCluster(String pStrString) throws ParseException { IDataStorage objDS = CDataStorageFactory.getMasterStorage(); StringBuilder objSB = new StringBuilder(); objSB.append("INSERT INTO `dengue`(`polygon`, `region`, `noOfPeopleInfected`, `severity`)" + "VALUES "); JSONParser jsonParser = new JSONParser(); JSONArray aryJSON = (JSONArray) jsonParser.parse(pStrString); for (Object objJson : aryJSON) { objSB.append("('"); JSONObject objInnerObj = (JSONObject) objJson; objSB.append(objInnerObj.get("XYs").toString()); objSB.append("','"); objSB.append(objInnerObj.get("Location").toString()); objSB.append("','"); objSB.append(objInnerObj.get("Cases").toString()); objSB.append("','"); if (Integer.parseInt(objInnerObj.get("Cases").toString()) < 10) { objSB.append("warning'),"); } else {//from w w w.ja v a 2s . c om objSB.append("alert'),"); } } objSB.deleteCharAt(objSB.lastIndexOf(",")); objSB.append(";"); System.out.println(objSB); objDS.openConnection(); objDS.executeScalar("truncate table dengue"); objDS.executeScalar(objSB.toString()); objDS.closeConnection(); }
From source file:org.wso2.carbon.identity.application.authentication.framework.config.builder.FileBasedConfigurationBuilder.java
private String getKey(Stack<String> nameStack) { StringBuilder key = new StringBuilder(); for (int i = 0; i < nameStack.size(); i++) { String name = nameStack.elementAt(i); key.append(name).append("."); }/*from ww w. j a v a2 s . c om*/ key.deleteCharAt(key.lastIndexOf(".")); return key.toString(); }
From source file:edu.cornell.kfs.coa.document.validation.impl.AccountReversionGlobalRule.java
/** * Returns a comma separated String of values * //from w w w .ja v a 2s. c o m * @param values * @return */ public String getParameterValuesForMessage(Collection<String> values) { StringBuilder result = new StringBuilder(); if (ObjectUtils.isNotNull(values) && values.size() > 0) { for (String value : values) { result.append(value); result.append(","); } result.replace(result.lastIndexOf(","), result.length(), KFSConstants.EMPTY_STRING); } return result.toString(); }