List of usage examples for java.lang StringBuilder charAt
char charAt(int index);
From source file:org.carewebframework.vista.mbroker.FMDate.java
/** * Returns the FM string representation of the date. * * @return FM string representation.// w w w . j av a 2 s . com */ public String getFMDate() { Calendar cal = Calendar.getInstance(); cal.setTime(this); StringBuilder sb = new StringBuilder(15); int hour = cal.get(Calendar.HOUR_OF_DAY); if (hour == 0 && hasTime) { hour = 24; cal.add(Calendar.DAY_OF_MONTH, -1); } addFMPiece(sb, cal.get(Calendar.YEAR) - 1700, 0); addFMPiece(sb, cal.get(Calendar.MONTH) + 1, 2); addFMPiece(sb, cal.get(Calendar.DAY_OF_MONTH), 2); if (hasTime) { sb.append('.'); addFMPiece(sb, hour, 2); addFMPiece(sb, cal.get(Calendar.MINUTE), 2); addFMPiece(sb, cal.get(Calendar.SECOND), 2); addFMPiece(sb, cal.get(Calendar.MILLISECOND), 2); for (int i = sb.length() - 1; i >= 0; i--) { char c = sb.charAt(i); if (c == '0') { sb.deleteCharAt(i); } else if (c == '.') { sb.deleteCharAt(i); break; } else { break; } } } return sb.toString(); }
From source file:com.wabacus.system.WabacusResponse.java
private String[] getInitChildSelectboxIdsOnloadMethod() { if (Tools.isEmpty(sChildSelectboxidsOnload)) return null; StringBuilder bufTmp = new StringBuilder(); for (String childidTmp : this.sChildSelectboxidsOnload) { if (Tools.isEmpty(childidTmp)) continue; bufTmp.append(childidTmp).append(";"); }//from w w w. j av a 2s . c om if (bufTmp.length() > 0 && bufTmp.charAt(bufTmp.length() - 1) == ';') bufTmp.deleteCharAt(bufTmp.length() - 1); return bufTmp.length() > 0 ? new String[] { "wx_showChildSelectboxOptionsOnload", "{childids:'" + bufTmp.toString() + "'}" } : null; }
From source file:org.apache.pig.builtin.OrcStorage.java
private String getReqiredColumnNamesString(ResourceSchema schema, boolean[] requiredColumns) { StringBuilder sb = new StringBuilder(); ResourceFieldSchema[] fields = schema.getFields(); for (int i = 0; i < requiredColumns.length; i++) { if (requiredColumns[i]) { sb.append(fields[i]).append(","); }//ww w . j av a 2s . c o m } if (sb.charAt(sb.length() - 1) == ',') { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:org.alfresco.filesys.repo.NodeMonitor.java
/** * The relative path of a renamed/moved node * // w w w . j av a 2s . c o m * ALF-2309: construct the path from the old parent of the moved * node (parentNodeRef) - this will have the correct path * * @param parentNodeRef the old parent of the node * @param nodeName the old name of the childs * @return String */ private String buildRelativePathString(NodeRef parentNodeRef, String nodeName) { Path nodePath = m_nodeService.getPath(parentNodeRef); StringBuilder pathStr = new StringBuilder(); pathStr.append(nodePath.toDisplayPath(m_nodeService, m_permissionService)); if (pathStr.length() == 0 || pathStr.charAt(pathStr.length() - 1) != '/' && pathStr.charAt(pathStr.length() - 1) != '\\') pathStr.append("/"); pathStr.append((String) m_nodeService.getProperty(parentNodeRef, ContentModel.PROP_NAME)).append("\\") .append(nodeName); return pathStr.toString(); }
From source file:org.alfresco.module.vti.web.fp.PropfindMethod.java
/** * <p>//from w w w . j a v a 2s .com * Handle PROPFIND method of the MS-WDVME protocol. * <ul> * <li>1. If MS-Doclib header with value '1' presents in request it check for library existing and return * the MS-Doclib header in response with value of the valid URL that is point to the library that * resource belongs to. * </li> * <li> * 2. If Depth header in request has a value '0' returns properties for the requested resource. * </li> * <li> * 3. If Depth header in request has a value 'infinity' (requested resources should be collection) * returns properties for the requested resource and all resources that are stored in requested * collection. * </li> * </ul> * In case if requested resource was not found then HTTP 404 status is sent to the client. * </p> */ @Override protected void executeImpl() throws WebDAVServerException, Exception { String msDoclib = m_request.getHeader(HEADER_MS_DOCLIB); if (msDoclib != null && msDoclib.equals("1")) { try { getDAVHelper().getParentNodeForPath(getRootNodeRef(), m_strPath); } catch (FileNotFoundException e) { m_response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // TODO: this shouldn't assume the requested URL is the one exposed to the outside world // (may be behind proxy). Change to parse properly. String docLibHref = URLDecoder .decode(m_request.getRequestURL().substring(0, m_request.getRequestURL().lastIndexOf("/"))); m_response.setHeader(HEADER_MS_DOCLIB, docLibHref); return; } m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS); if (logger.isDebugEnabled()) { logger.debug("processing PROPFIND request with uri: " + m_request.getRequestURI()); } FileInfo pathNodeInfo = null; // Check that the path exists pathNodeInfo = pathHelper.resolvePathFileInfo(m_strPath); if (pathNodeInfo == null) { // The path is not valid - send a 404 error back to the client m_response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // Note the null check, as root node may be null in cloud. if (pathNodeInfo.getNodeRef() != null && getFileFolderService().isHidden(pathNodeInfo.getNodeRef())) { // ALF-17662, the path is hidden - send a 404 error back to the client m_response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // Set the response content type m_response.setContentType(WebDAV.XML_CONTENT_TYPE); // Create multistatus response XMLWriter xml = createXMLWriter(); xml.startDocument(); String nsdec = generateNamespaceDeclarations(namespaceMap); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS + nsdec, WebDAV.XML_NS_MULTI_STATUS + nsdec, getDAVHelper().getNullAttributes()); if (containsCollblob) { xml.startElement("http://schemas.microsoft.com/repl/", "repl", "Repl:repl", getDAVHelper().getNullAttributes()); xml.startElement("http://schemas.microsoft.com/repl/", "collblob", "Repl:collblob", getDAVHelper().getNullAttributes()); xml.write(VtiUtils.formatPropfindDate(new Date())); xml.endElement("http://schemas.microsoft.com/repl/", "collblob", "Repl:collblob"); xml.endElement("http://schemas.microsoft.com/repl/", "repl", "Repl:repl"); } xml.write("\n"); // Create the path for the current location in the tree StringBuilder baseBuild = new StringBuilder(256); baseBuild.append(""); if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar) { baseBuild.append(WebDAVHelper.PathSeperatorChar); } String basePath = baseBuild.toString(); // Output the response for the root node, depth zero try { generateResponseForNode(xml, pathNodeInfo, basePath); } catch (Exception e) { m_response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // If additional levels are required and the root node is a folder then recurse to the required // level and output node details a level at a time if (depth != DEPTH_ZERO && pathNodeInfo.isFolder()) { // Create the initial list of nodes to report List<FileInfo> nodeInfos = new ArrayList<FileInfo>(10); nodeInfos.add(pathNodeInfo); int curDepth = WebDAV.DEPTH_1; // List of next level of nodes to report List<FileInfo> nextNodeInfos = null; if (depth > WebDAV.DEPTH_1) { nextNodeInfos = new ArrayList<FileInfo>(10); } // Loop reporting each level of nodes to the requested depth while (curDepth <= depth && nodeInfos != null) { // Clear out the next level of nodes, if required if (nextNodeInfos != null) { nextNodeInfos.clear(); } // Output the current level of node(s), the node list should // only contain folder nodes for (FileInfo curNodeInfo : nodeInfos) { // Get the list of child nodes for the current node List<FileInfo> childNodeInfos = getDAVHelper().getChildren(curNodeInfo); // can skip the current node if it doesn't have children if (childNodeInfos.size() == 0) { continue; } // Output the child node details // Generate the base path for the current parent node baseBuild.setLength(0); try { String pathSnippet = null; if ((pathNodeInfo.getNodeRef() == null) && (curNodeInfo.getNodeRef() == null)) { pathSnippet = "/"; } else { pathSnippet = getDAVHelper().getPathFromNode(pathNodeInfo.getNodeRef(), curNodeInfo.getNodeRef()); } baseBuild.append(pathSnippet); } catch (FileNotFoundException e) { // move to the next node continue; } int curBaseLen = baseBuild.length(); // Output the child node details for (FileInfo curChildInfo : childNodeInfos) { // ALF-17662, do not show link nodes and hidden documents // Note the null check, as node may be null in cloud. final boolean isHidden = curChildInfo.getNodeRef() != null && getFileFolderService().isHidden(curChildInfo.getNodeRef()); if (curChildInfo.isLink() == false && !isHidden) { // Build the path for the current child node baseBuild.setLength(curBaseLen); baseBuild.append(WebDAVHelper.PathSeperatorChar + curChildInfo.getName()); // Output the current child node details try { generateResponseForNode(xml, curChildInfo, baseBuild.toString()); } catch (Exception e) { m_response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // If the child is a folder add it to the list of next level nodes if (nextNodeInfos != null && curChildInfo.isFolder()) { nextNodeInfos.add(curChildInfo); } } } } // Update the current tree depth curDepth++; // Move the next level of nodes to the current node list nodeInfos.clear(); if (nextNodeInfos != null) { nodeInfos.addAll(nextNodeInfos); } } } // Close the outer XML element xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS); // Send remaining data flushXML(xml); }
From source file:com.xybase.utils.StringUtils.java
/** * Convert a string to a valid camel case string * * @param inputString the input string to convert to camel case * @param firstCharacterUppercase when true first word will be converted to upper case as well * @return camel case of the input//from w w w . j a v a2 s . co m */ public static String getCamelCaseString(String inputString, boolean firstCharacterUppercase) { StringBuilder sb = new StringBuilder(); boolean nextUpperCase = false; for (int i = 0; i < inputString.length(); i++) { char c = inputString.charAt(i); switch (c) { case '_': case '-': case '@': case '$': case '#': case ' ': if (sb.length() > 0) { nextUpperCase = true; } break; default: if (nextUpperCase) { sb.append(Character.toUpperCase(c)); nextUpperCase = false; } else { sb.append(Character.toLowerCase(c)); } break; } } if (firstCharacterUppercase) { sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); } return sb.toString(); }
From source file:fr.dutra.confluence2wordpress.wp.WordpressClient.java
private WordpressPost convertToPost(Map<String, Object> map) { WordpressPost post = new WordpressPost(); Object postId = map.get("postid"); post.setPostId(Integer.valueOf(postId.toString())); post.setDraft(false);/*w ww.ja v a2 s .c o m*/ Object authorId = map.get("wp_author_id"); post.setAuthorId(authorId == null ? null : Integer.valueOf(authorId.toString())); Date dateUtc = (Date) map.get("dateCreated"); post.setDateCreated(convertFromNaiveUTC(dateUtc)); StringBuilder body = new StringBuilder(); if (map.get("description") != null) { body.append((String) map.get("description")); } if (map.get("mt_text_more") != null) { //tricky: if the post is saved on wordpress side, //even without modification, wordpress will append an "\n" before the "more" tag //but if the post has never been edited on wordpress, //then the "\n" is missing if (body.length() > 0 && body.charAt(body.length() - 1) != '\n') { body.append("\n"); } body.append("<!--more-->"); body.append((String) map.get("mt_text_more")); } post.setBody(body.toString()); String title = (String) map.get("title"); post.setTitle(title); post.setDraft(!"publish".equals(map.get("post_status"))); @SuppressWarnings("unchecked") List<String> categoryNames = (List<String>) map.get("categories"); post.setCategoryNames(new ArrayList<String>(categoryNames)); //optional field List<String> tagNames = CollectionUtils.split((String) map.get("mt_keywords"), ","); if (tagNames != null) { post.setTagNames(new ArrayList<String>(tagNames)); } String slug = (String) map.get("wp_slug"); post.setPostSlug(slug); String permaLink = (String) map.get("permaLink"); post.setLink(permaLink); return post; }
From source file:org.alfresco.filesys.repo.NodeMonitor.java
private StringBuilder calculateDisplayPath(final NodeRef nodeRef) { return AuthenticationUtil.runAs(new RunAsWork<StringBuilder>() { @Override//from w w w.j a v a 2 s. c o m public StringBuilder doWork() throws Exception { // Get the full path to the file/folder node Path nodePath = m_nodeService.getPath(nodeRef); String fName = (String) m_nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); // Build the share relative path to the node StringBuilder result = new StringBuilder(); result.append(nodePath.toDisplayPath(m_nodeService, m_permissionService)); if ((0 == result.length()) || ('/' != (result.charAt(result.length() - 1)) && ('\\' != result.charAt(result.length() - 1)))) { result.append("\\"); } return result.append(fName); } }, AuthenticationUtil.SYSTEM_USER_NAME); }
From source file:org.apache.syncope.core.persistence.jpa.dao.JPAAnySearchDAO.java
@Override @SuppressWarnings("unchecked") protected <T extends Any<?>> List<T> doSearch(final Set<String> adminRealms, final SearchCond cond, final int page, final int itemsPerPage, final List<OrderByClause> orderBy, final AnyTypeKind kind) { try {//from w ww . j ava 2s . c o m List<Object> parameters = Collections.synchronizedList(new ArrayList<>()); SearchSupport svs = new SearchSupport(kind); Pair<String, Set<String>> filter = getAdminRealmsFilter(adminRealms, svs, parameters); // 1. get the query string from the search condition StringBuilder queryString = getQuery(buildEffectiveCond(cond, filter.getRight()), parameters, svs); // 2. take into account realms and ordering OrderBySupport obs = parseOrderBy(kind, svs, orderBy); if (queryString.charAt(0) == '(') { queryString.insert(0, buildSelect(obs)); queryString.append(buildWhere(svs, obs)); } else { queryString.insert(0, buildSelect(obs).append('(')); queryString.append(')').append(buildWhere(svs, obs)); } queryString.append(filter.getLeft()).append(buildOrderBy(obs)); // 3. prepare the search query Query query = entityManager().createNativeQuery(queryString.toString()); // 4. page starts from 1, while setFirtResult() starts from 0 query.setFirstResult(itemsPerPage * (page <= 0 ? 0 : page - 1)); if (itemsPerPage >= 0) { query.setMaxResults(itemsPerPage); } // 5. populate the search query with parameter values fillWithParameters(query, parameters); // 6. Prepare the result (avoiding duplicates) return buildResult(query.getResultList(), kind); } catch (Exception e) { LOG.error("While searching for {}", kind, e); } return Collections.emptyList(); }
From source file:net.sf.jabref.importer.fileformat.BibtexParser.java
/** * pushes buffer back into input/* w ww . j a v a 2 s . c om*/ * * @param stringBuilder * @throws IOException can be thrown if buffer is bigger than LOOKAHEAD */ private void unreadBuffer(StringBuilder stringBuilder) throws IOException { for (int i = stringBuilder.length() - 1; i >= 0; --i) { unread(stringBuilder.charAt(i)); } }