List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:com.datos.vfs.impl.DefaultFileSystemManager.java
/** * Resolves a name, relative to the root. * * @param base the base filename// w w w.j a v a2 s . c o m * @param name the name * @param scope the {@link NameScope} * @return The FileName of the file. * @throws FileSystemException if an error occurs. */ @Override public FileName resolveName(final FileName base, final String name, final NameScope scope) throws FileSystemException { final FileName realBase; if (base != null && VFS.isUriStyle() && base.isFile()) { realBase = base.getParent(); } else { realBase = base; } final StringBuilder buffer = new StringBuilder(name); // Adjust separators UriParser.fixSeparators(buffer); String scheme = UriParser.extractScheme(buffer.toString()); // Determine whether to prepend the base path if (name.length() == 0 || (scheme == null && buffer.charAt(0) != FileName.SEPARATOR_CHAR)) { // Supplied path is not absolute if (!VFS.isUriStyle()) { // when using uris the parent already do have the trailing "/" buffer.insert(0, FileName.SEPARATOR_CHAR); } buffer.insert(0, realBase.getPath()); } // Normalise the path final FileType fileType = UriParser.normalisePath(buffer); // Check the name is ok final String resolvedPath = buffer.toString(); if (!AbstractFileName.checkName(realBase.getPath(), resolvedPath, scope)) { throw new FileSystemException("vfs.provider/invalid-descendent-name.error", name); } String fullPath; if (scheme != null) { fullPath = resolvedPath; } else { scheme = realBase.getScheme(); fullPath = realBase.getRootURI() + resolvedPath; } final FileProvider provider = providers.get(scheme); if (provider != null) { // TODO: extend the filename parser to be able to parse // only a pathname and take the missing informations from // the base. Then we can get rid of the string operation. // // String fullPath = base.getRootURI() + // resolvedPath.substring(1); return provider.parseUri(realBase, fullPath); } // An unknown scheme - hand it to the default provider - if possible if (scheme != null && defaultProvider != null) { return defaultProvider.parseUri(realBase, fullPath); } // TODO: avoid fallback to this point // this happens if we have a virtual filesystem (no provider for scheme) return ((AbstractFileName) realBase).createName(resolvedPath, fileType); }
From source file:it.unibas.spicy.model.mapping.operators.TGDToLogicalString.java
private String generateEqualityString(List<Expression> equalities, List<List<FormulaVariable>> variables, boolean with) { StringBuilder localResult = new StringBuilder(); StringBuilder prefix = new StringBuilder(); if (useSaveFormat) { if (with) { prefix.append("\n").append(generateIndent()).append("with "); } else {/*from w w w .java2 s . com*/ prefix.append(",\n").append(generateIndent()); } } else { prefix.append(",\n").append(generateIndent()); } for (int i = 0; i < equalities.size(); i++) { Expression expression = equalities.get(i).clone(); if (utility.setVariableDescriptions(expression, variables)) { if (useSaveFormat) { String expressionString = expression.toSaveString(); if (with) { expressionString = expressionString.replaceAll("==", "="); } localResult.append(expressionString); } else { localResult.append(expression.toString()); } if (i != equalities.size() - 1) { localResult.append(", "); } } } if (!localResult.toString().isEmpty()) { localResult.insert(0, prefix.toString()); } return localResult.toString(); }
From source file:ch.systemsx.cisd.openbis.generic.server.CommonServer.java
private String createTemplateForType(EntityKind entityKind, boolean autoGenerate, EntityTypePE entityType, boolean addComments, boolean withExperiments) { List<String> columns = new ArrayList<String>(); switch (entityKind) { case SAMPLE:// w w w .ja v a 2 s .co m if (autoGenerate == false) { columns.add(NewSample.IDENTIFIER_COLUMN); } columns.add(NewSample.CONTAINER); columns.add(NewSample.PARENT); if (withExperiments) columns.add(NewSample.EXPERIMENT); for (SampleTypePropertyTypePE etpt : ((SampleTypePE) entityType).getSampleTypePropertyTypes()) { columns.add(etpt.getPropertyType().getCode()); } break; case MATERIAL: columns.add(NewMaterial.CODE); for (MaterialTypePropertyTypePE etpt : ((MaterialTypePE) entityType).getMaterialTypePropertyTypes()) { columns.add(etpt.getPropertyType().getCode()); } break; default: break; } StringBuilder sb = new StringBuilder(); for (String column : columns) { if (sb.length() != 0) { sb.append("\t"); } sb.append(column); } if (entityKind.equals(EntityKind.SAMPLE) && addComments) { sb.insert(0, NewSample.SAMPLE_REGISTRATION_TEMPLATE_COMMENT); } return sb.toString(); }
From source file:com.github.hateoas.forms.affordance.Affordance.java
/** * Affordance represented as http link header value. * * @return link header value/*w w w. ja v a2s .c om*/ */ public String asHeader() { StringBuilder result = new StringBuilder(); for (Map.Entry<String, List<String>> linkParamEntry : linkParams.entrySet()) { if (result.length() != 0) { result.append("; "); } String linkParamEntryKey = linkParamEntry.getKey(); if ("rel".equals(linkParamEntryKey) || "rev".equals(linkParamEntryKey)) { result.append(linkParamEntryKey).append("="); result.append("\"").append(StringUtils.collectionToDelimitedString(linkParamEntry.getValue(), " ")) .append("\""); } else { StringBuilder linkParams = new StringBuilder(); for (String value : linkParamEntry.getValue()) { if (linkParams.length() != 0) { linkParams.append("; "); } linkParams.append(linkParamEntryKey).append("="); linkParams.append("\"").append(value).append("\""); } result.append(linkParams); } } String linkHeader = "<" + partialUriTemplate.asComponents().toString() + ">; "; return result.insert(0, linkHeader).toString(); }
From source file:org.ryancutter.barcajolt.BarcaJolt.java
/** * Execute GET and collect response//from ww w .j a v a 2 s. c o m * * @param getURL Requested GET operation. Will be appended to HOST. * * @return JSONObject Results of GET operation. Will return null for HTTP status codes other * than 200. */ private JSONObject get(String getURL, boolean arrayResult) { // set up DefaultHttpClient and other objects StringBuilder builder = new StringBuilder(); DefaultHttpClient client = new DefaultHttpClient(); HttpHost host = new HttpHost(mHost, mPort, mProtocol); HttpGet get = new HttpGet(getURL); client.getCredentialsProvider().setCredentials(new AuthScope(host.getHostName(), host.getPort()), new UsernamePasswordCredentials(mUsername, mPassword)); JSONObject jObject = null; try { // execute GET and collect results if valid response HttpResponse response = client.execute(host, get); StatusLine status = response.getStatusLine(); int statusCode = status.getStatusCode(); if (statusCode == 200) { BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); for (String line = null; (line = reader.readLine()) != null;) { builder.append(line); } try { // check if this is the result of BarcaJolt.getDBs(). since Cloudant returns a JSONArray // rather than JSONObject for /_all_dbs requests, this class temporarily wraps the array // like {"dbs":["database1", "database2"]}. unwrapped in BarcaJolt.getDBs() if (arrayResult) { builder.insert(0, "{'dbs' : "); builder.append("}"); } jObject = new JSONObject(builder.toString()); } catch (JSONException e) { Log.e(TAG, "JSONException converting StringBuilder to JSONObject", e); } } else { // we only want to process 200's // TODO process non-200's in a more clever way Log.e(TAG, "Bad HttoResponse status: " + new Integer(statusCode).toString()); return null; } } catch (ClientProtocolException e) { Log.e(TAG, "ClientProtocolException", e); } catch (IOException e) { Log.e(TAG, "DefaultHttpClient IOException", e); } // let go of resources client.getConnectionManager().shutdown(); return jObject; }
From source file:gov.nih.nci.cagrid.sdk4query.processor.PublicDataCQL2ParameterizedHQL.java
/** * Applies query modifiers to the HQL query * * @param mods/*from w w w .j a v a2 s. co m*/ * The modifiers to apply * @param hql * The HQL to apply the modifications to * * Modified by Sue Pan to always return id or name (the attribute * stored in CSM as the protected data) as the first item, to * filter out non-public data * */ private void handleQueryModifier(QueryModifier mods, StringBuilder hql) { // data in caNanoLab were secured based on ids String secureAttribute = "id"; StringBuilder prepend = new StringBuilder(); if (mods.isCountOnly()) { prepend.append("select "); if (mods.getDistinctAttribute() != null) { prepend.append("distinct ").append(secureAttribute).append(", ") .append(mods.getDistinctAttribute()); } else { prepend.append("distinct ").append(secureAttribute); } } else { prepend.append("select "); if (mods.getDistinctAttribute() != null) { prepend.append("distinct ").append(secureAttribute).append(", ") .append(mods.getDistinctAttribute()); } else { prepend.append(secureAttribute).append(", "); for (int i = 0; i < mods.getAttributeNames().length; i++) { prepend.append(mods.getAttributeNames(i)); if (i + 1 < mods.getAttributeNames().length) { prepend.append(", "); } } } } prepend.append(' '); hql.insert(0, prepend.toString()); }
From source file:de.jcup.egradle.core.util.GradleResourceLinkCalculator.java
private GradleHyperLinkResult internalCreateLink(String line, int offsetInLine) { /* e.g. abc defg Test abc */ /* ^-- Test must be identified */ String rightSubString = line.substring(offsetInLine); StringBuilder content = new StringBuilder(); for (char c : rightSubString.toCharArray()) { if (Character.isWhitespace(c)) { break; }//from w ww .j a v a 2 s.c o m if (c == '{') { break; } if (c == ',') { break; } if (c == '(') { break; } if (c == ')') { break; } if (c == '[') { break; } if (c == '<') { break; } if (c == '>') { break; } if (c == '.') { break; } if (!Character.isJavaIdentifierPart(c)) { return null; } content.append(c); } if (StringUtils.isBlank(content)) { return null; } String leftSubString = line.substring(0, offsetInLine); char[] leftCharsArray = leftSubString.toCharArray(); ArrayUtils.reverse(leftCharsArray); int startPos = offsetInLine; for (char c : leftCharsArray) { if (c == '(') { break; } if (c == '<') { break; } if (c == '.') { break; } if (Character.isWhitespace(c)) { break; } if (!Character.isJavaIdentifierPart(c)) { return null; } startPos--; content.insert(0, c); } String linkContent = content.toString(); char firstChar = linkContent.charAt(0); if (!Character.isJavaIdentifierStart(firstChar)) { return null; } /* * currently this calculator only supports correct Type syntax means * first char MUST be upper cased */ if (!Character.isUpperCase(firstChar)) { return null; } GradleHyperLinkResult result = new GradleHyperLinkResult(); result.linkOffsetInLine = startPos; result.linkContent = linkContent; result.linkLength = linkContent.length(); return result; }
From source file:gov.nih.nci.cagrid.sdk4query.processor.PublicDataCQL2ParameterizedHQL.java
/** * Converts CQL to parameterized HQL suitable for use with Hibernate * v3.2.0ga and the caCORE SDK version 4.0 * * @param query/*w ww .j a va2s. c o m*/ * The query to convert * @return A parameterized HQL Query representing the CQL query * @throws QueryProcessingException */ public ParameterizedHqlQuery convertToHql(CQLQuery query) throws QueryProcessingException { // create a string builder to build up the HQL StringBuilder rawHql = new StringBuilder(); // create the list in which parameters will be placed List<java.lang.Object> parameters = new LinkedList<java.lang.Object>(); // determine if the target has subclasses List<String> subclasses = typesInfoUtil.getSubclasses(query.getTarget().getName()); boolean hasSubclasses = !(subclasses == null || subclasses.size() == 0); LOG.debug(query.getTarget().getName() + (hasSubclasses ? " has " + subclasses.size() + " subclasses" : " has no subclasse")); // begin processing at the target level // // processTarget(query.getTarget(), rawHql, parameters, hasSubclasses); // modified by Sue Pan to turn off checking of subclasses. There is a // reported // bug GForge Bug #18649 related to generating the correct HQL for // subclasses mapped by table per // hierarchy inheritance. processTarget(query.getTarget(), rawHql, parameters, false); // apply query modifiers if (query.getQueryModifier() != null) { handleQueryModifier(query.getQueryModifier(), rawHql); } else { // select only unique objects rawHql.insert(0, "Select distinct (" + TARGET_ALIAS + ") "); } // build the final query object ParameterizedHqlQuery hqlQuery = new ParameterizedHqlQuery(rawHql.toString(), parameters); return hqlQuery; }
From source file:com.flozano.socialauth.util.OAuthConsumer.java
/** * Generates Authorization header. The OAuth Protocol Parameters are sent in * the Authorization header. Parameter names and values are encoded. For * each parameter, the name is immediately followed by an '=' character * (ASCII code 61), a '"' character (ASCII code 34), the parameter value * (MAY be empty), and another '"' character (ASCII code 34).Parameters are * separated by a comma character (ASCII code 44). * * @param params/* w ww. jav a 2s . c om*/ * Parameters to generate header value * @return Authorize header value * @throws Exception */ public String getAuthHeaderValue(final Map<String, String> params) throws Exception { LOG.debug("Genrating Authorization header for given parameters : " + params); StringBuilder headerStr = new StringBuilder(); String[] REQUIRED_OAUTH_HEADERS_TO_SIGN = new String[] { OAUTH_CONSUMER_KEY, OAUTH_NONCE, OAUTH_TIMESTAMP, OAUTH_SIGNATURE_METHOD }; for (String key : REQUIRED_OAUTH_HEADERS_TO_SIGN) { String value = HttpUtil.encodeURIComponent(params.get(key)); headerStr.append(',').append(key).append('=').append('"').append(value).append('"'); } if (params.get(OAUTH_VERSION) != null) { headerStr.append(',').append(OAUTH_VERSION).append('=').append('"') .append(HttpUtil.encodeURIComponent(params.get(OAUTH_VERSION))).append('"'); } if (params.get(OAUTH_TOKEN) != null) { headerStr.append(',').append(OAUTH_TOKEN).append('=').append('"') .append(HttpUtil.encodeURIComponent(params.get(OAUTH_TOKEN))).append('"'); } if (params.get(OAUTH_SIGNATURE) != null) { headerStr.append(',').append(OAUTH_SIGNATURE).append('=').append('"') .append(HttpUtil.encodeURIComponent(params.get(OAUTH_SIGNATURE))).append('"'); } headerStr.setCharAt(0, ' '); headerStr.insert(0, "OAuth"); LOG.debug("Authorize Header : " + headerStr.toString()); return headerStr.toString(); }
From source file:com.gitblit.utils.JGitUtils.java
/** * Returns the list of notes entered about the commit from the refs/notes * namespace. If the repository does not exist or is empty, an empty list is * returned./* www . j a v a 2 s . c o m*/ * * @param repository * @param commit * @return list of notes */ public static List<GitNote> getNotesOnCommit(Repository repository, RevCommit commit) { List<GitNote> list = new ArrayList<GitNote>(); if (!hasCommits(repository)) { return list; } List<RefModel> noteBranches = getNoteBranches(repository, true, -1); for (RefModel notesRef : noteBranches) { RevTree notesTree = JGitUtils.getCommit(repository, notesRef.getName()).getTree(); // flat notes list String notePath = commit.getName(); String text = getStringContent(repository, notesTree, notePath); if (!StringUtils.isEmpty(text)) { List<RevCommit> history = getRevLog(repository, notesRef.getName(), notePath, 0, -1); RefModel noteRef = new RefModel(notesRef.displayName, null, history.get(history.size() - 1)); GitNote gitNote = new GitNote(noteRef, text); list.add(gitNote); continue; } // folder structure StringBuilder sb = new StringBuilder(commit.getName()); sb.insert(2, '/'); notePath = sb.toString(); text = getStringContent(repository, notesTree, notePath); if (!StringUtils.isEmpty(text)) { List<RevCommit> history = getRevLog(repository, notesRef.getName(), notePath, 0, -1); RefModel noteRef = new RefModel(notesRef.displayName, null, history.get(history.size() - 1)); GitNote gitNote = new GitNote(noteRef, text); list.add(gitNote); } } return list; }