Example usage for java.lang StringBuilder lastIndexOf

List of usage examples for java.lang StringBuilder lastIndexOf

Introduction

In this page you can find the example usage for java.lang StringBuilder lastIndexOf.

Prototype

@Override
    public int lastIndexOf(String str) 

Source Link

Usage

From source file:org.wso2.carbon.apimgt.impl.APIManagerConfiguration.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 w  w w . ja  v a  2  s  .  co m
    key.deleteCharAt(key.lastIndexOf("."));

    return key.toString();
}

From source file:org.alfresco.mobile.android.application.fragments.fileexplorer.LibraryFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    mediaTypeId = (Integer) getArguments().get(ARGUMENT_MEDIATYPE_ID);

    // String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=?";
    StringBuilder selection = new StringBuilder(MediaStore.Files.FileColumns.MEDIA_TYPE + "=?");
    String selectionFinal = selection.toString();
    List<String> argumentsList = new ArrayList<String>();
    argumentsList.add(Integer.toString(mediaTypeId));
    if (mediaTypeId == 0) {
        String mimeType = null;// w  w w .jav  a2 s .  c o  m
        selection.append(" AND " + MediaStore.Files.FileColumns.MIME_TYPE + " IN (");
        for (String extension : OFFICE_EXTENSION) {
            mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
            argumentsList.add(mimeType);
            selection.append(" ? ,");
        }
        selectionFinal = selection.toString().substring(0, selection.lastIndexOf(",")) + ")";
    }
    String[] arguments = new String[argumentsList.size()];
    arguments = argumentsList.toArray(arguments);

    setListShown(false);
    String[] projection = new String[] { MediaStore.Files.FileColumns._ID, MediaStore.Files.FileColumns.TITLE,
            MediaStore.Files.FileColumns.DISPLAY_NAME, MediaStore.Files.FileColumns.MIME_TYPE,
            MediaStore.Files.FileColumns.DATA };
    Uri baseUri = MediaStore.Files.getContentUri("external");
    return new CursorLoader(getActivity(), baseUri, projection, selectionFinal, arguments,
            MediaStore.Files.FileColumns.DATA + " ASC");
}

From source file:fi.cosky.sdk.API.java

private String readDataFromConnection(HttpURLConnection connection) {
    InputStream is = null;/*w  ww  .  ja  v  a2  s. c o  m*/
    BufferedReader br = null;
    StringBuilder sb = null;
    try {
        is = connection.getInputStream();
        br = new BufferedReader(new InputStreamReader(is));

        sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line).append("\n");
        }
        String eTag = null;
        if ((eTag = connection.getHeaderField("ETag")) != null) {
            sb.insert(sb.lastIndexOf("}"), ",\"VersionNumber\":" + eTag + "");
        }
    } catch (IOException e) {
        System.out.println("Could not read data from connection");
    }
    return sb.toString();
}

From source file:com.ace.console.service.sys.impl.ResourceServiceImpl.java

/**
 * ?  ? :?/* ww  w.  jav  a  2s . c om*/
 *
 * @param resource
 * @return
 */
public String findActualResourceIdentity(Resources resource) {

    if (resource == null) {
        return null;
    }

    StringBuilder s = new StringBuilder(resource.getIdentity());

    boolean hasResourceIdentity = !StringUtils.isEmpty(resource.getIdentity());

    Resources parent = selectById(resource.getParentId());
    while (parent != null) {
        if (!StringUtils.isEmpty(parent.getIdentity())) {
            s.insert(0, parent.getIdentity() + ":");
            hasResourceIdentity = true;
        }
        parent = selectById(parent.getParentId());
    }

    // ?  
    if (!hasResourceIdentity) {
        return "";
    }

    //?: ??
    int length = s.length();
    if (length > 0 && s.lastIndexOf(":") == length - 1) {
        s.deleteCharAt(length - 1);
    }

    //? ?*
    /**
     boolean hasChildren = false;
     for (Resources r : resourcesMapper.getList()) {
     if (resource.getId().equals(r.getParentId())) {
     hasChildren = true;
     break;
     }
     }
     **/

    if (resource.isHasChildren()) {
        s.append(":*");
    }

    return s.toString();
}

From source file:com.ace.erp.service.sys.impl.ResourceServiceImpl.java

/**
 * ?  ? :?//w  ww .ja v  a  2 s.c o  m
 *
 * @param resource
 * @return
 */
public String findActualResourceIdentity(Resource resource) {

    if (resource == null) {
        return null;
    }

    StringBuilder s = new StringBuilder(resource.getIdentity());

    boolean hasResourceIdentity = !StringUtils.isEmpty(resource.getIdentity());

    Resource parent = resourceMapper.getOne(resource.getParentId());
    while (parent != null) {
        if (!StringUtils.isEmpty(parent.getIdentity())) {
            s.insert(0, parent.getIdentity() + ":");
            hasResourceIdentity = true;
        }
        parent = resourceMapper.getOne(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 : resourceMapper.getList()) {
     if (resource.getId().equals(r.getParentId())) {
     hasChildren = true;
     break;
     }
     }
     **/

    if (resource.isHasChildren()) {
        s.append(":*");
    }

    return s.toString();
}

From source file:org.geomajas.layer.wms.WmsLayer.java

/**
 * Build the base part of the url (doesn't change for getMap or getFeatureInfo requests).
 * //from   www .j a v  a 2s.  c  o m
 * @param targetUrl
 *            base url
 * @param width
 *            image width
 * @param height
 *            image height
 * @param box
 *            bounding box
 * @return base WMS url
 * @throws GeomajasException
 *             missing parameter
 */
private StringBuilder formatBaseUrl(String targetUrl, int width, int height, Bbox box)
        throws GeomajasException {
    try {
        StringBuilder url = new StringBuilder(targetUrl);
        int pos = url.lastIndexOf("?");
        if (pos > 0) {
            url.append("&SERVICE=WMS");
        } else {
            url.append("?SERVICE=WMS");
        }
        String layers = getId();
        if (layerInfo.getDataSourceName() != null) {
            layers = layerInfo.getDataSourceName();
        }
        url.append("&layers=");
        url.append(URLEncoder.encode(layers, "UTF8"));
        url.append("&WIDTH=");
        url.append(Integer.toString(width));
        url.append("&HEIGHT=");
        url.append(Integer.toString(height));
        DecimalFormat decimalFormat = new DecimalFormat(); // create new as this is not thread safe
        decimalFormat.setDecimalSeparatorAlwaysShown(false);
        decimalFormat.setGroupingUsed(false);
        decimalFormat.setMinimumFractionDigits(0);
        decimalFormat.setMaximumFractionDigits(100);
        DecimalFormatSymbols symbols = new DecimalFormatSymbols();
        symbols.setDecimalSeparator('.');
        decimalFormat.setDecimalFormatSymbols(symbols);

        url.append("&bbox=");
        url.append(decimalFormat.format(box.getX()));
        url.append(",");
        url.append(decimalFormat.format(box.getY()));
        url.append(",");
        url.append(decimalFormat.format(box.getMaxX()));
        url.append(",");
        url.append(decimalFormat.format(box.getMaxY()));
        url.append("&format=");
        url.append(format);
        url.append("&version=");
        url.append(version);
        if ("1.3.0".equals(version)) {
            url.append("&crs=");
        } else {
            url.append("&srs=");
        }
        url.append(URLEncoder.encode(layerInfo.getCrs(), "UTF8"));
        url.append("&styles=");
        url.append(styles);
        if (null != parameters) {
            for (Parameter p : parameters) {
                url.append("&");
                url.append(URLEncoder.encode(p.getName(), "UTF8"));
                url.append("=");
                url.append(URLEncoder.encode(p.getValue(), "UTF8"));
            }
        }
        if (useProxy && null != securityContext.getToken()) {
            url.append("&userToken=");
            url.append(securityContext.getToken());
        }
        return url;
    } catch (UnsupportedEncodingException uee) {
        throw new IllegalStateException("Cannot find UTF8 encoding?", uee);
    }
}

From source file:ffx.potential.parsers.PDBFileMatcher.java

private void fixFile(FileFilePair currentPair, PDBFileReader filereader) throws IOException {
    File matchFile = currentPair.getMatchedFile();
    Structure matchStructure = currentPair.getStructure();
    if (matchStructure == null) {
        matchStructure = filereader.getStructure(matchFile);
    }//from   ww w .  j  av  a  2  s .c o m

    File sourceFile = currentPair.getSourceFile();
    if (sourceFile == null) {
        throw new IOException(String.format("No source file was matched to file %s", matchFile.toString()));
    }

    Structure sourceStructure = null;
    if (fixAtoms) {
        sourceStructure = filereader.getStructure(sourceFile);
        Atom[] matchAtoms = StructureTools.getAllAtomArray(matchStructure);
        for (Atom matchAtom : matchAtoms) {
            Atom sourceAtom = getMatchingAtom(matchAtom, sourceStructure, robustMatch);
            if (fixBFactors) {
                matchAtom.setTempFactor(sourceAtom.getTempFactor());
            }
        }
        // Other methods can go here.
    }
    if (fixSSBonds) {
        if (sourceStructure == null) {
            sourceStructure = filereader.getStructure(sourceFile);
        }
        List<SSBond> sourceBonds = sourceStructure.getSSBonds();
        List<SSBond> matchBonds = matchStructure.getSSBonds();
        for (SSBond sourceBond : sourceBonds) {
            boolean isContained = false;
            for (SSBond matchBond : matchBonds) {
                if (compareSSBonds(matchBond, sourceBond)) {
                    isContained = true;
                    break;
                }
            }
            if (!isContained) {
                matchStructure.addSSBond(sourceBond.clone());
            }
        }
    }
    if (fixCryst) {
        if (sourceStructure == null) {
            sourceStructure = filereader.getStructure(sourceFile);
        }
        PDBCrystallographicInfo crystalInfo = sourceStructure.getCrystallographicInfo();
        try {
            PDBCrystallographicInfo duplicateInfo = cloneCrystalInfo(crystalInfo);
            matchStructure.setCrystallographicInfo(duplicateInfo);
        } catch (IllegalArgumentException ex) {
            logger.warning(String.format(
                    " No crystal information for source structure " + "%s: nothing attached to file %s",
                    sourceFile.toString(), matchFile.toString()));
        }
    }
    String pdb = matchStructure.toPDB();
    if (headerLink) {
        StringBuilder pdbBuilder = new StringBuilder(pdb);
        int position = pdbBuilder.lastIndexOf("REMARK ");
        int remarkNumber = 4;
        if (position >= 0) {
            String nextLine = pdbBuilder.substring(position, position + 1000);
            int offset = nextLine.indexOf("%n");
            if (offset < 0) {
                nextLine = pdbBuilder.substring(position);
                offset = nextLine.indexOf("%n");
            }
            position += offset;
            String[] tok = nextLine.split(" +", 3);
            try {
                remarkNumber = Integer.parseInt(tok[1]) + 1;
            } catch (NumberFormatException ex) {
                // Silent.
            }
        }

        String toInsert = String.format("REMARK%4d SOURCE FILE: %s", remarkNumber, sourceFile.getName());
        toInsert = toInsert
                .concat(String.format("REMARK%4d RMSD:%11.6f ANGSTROMS", remarkNumber, currentPair.getRMSD()));
        pdbBuilder.insert(position, toInsert);
        pdb = pdbBuilder.toString();
    }

    File newFile = createVersionedCopy(matchFile);
    try (BufferedWriter bw = new BufferedWriter(new FileWriter(newFile))) {
        try {
            bw.write(pdb);
        } catch (IOException ex) {
            logger.warning(String.format(" Error writing to file %s", newFile.getName()));
        }
    }
}

From source file:com.impetus.kundera.client.cassandra.dsdriver.DSClient.java

/**
 * Creates the select query./*from  ww w  .  j av  a 2s .  c  o m*/
 * 
 * @param rowId
 *            the row id
 * @param metadata
 *            the metadata
 * @param tableName
 *            the table name
 * @return the string builder
 */
private StringBuilder createSelectQuery(Object rowId, EntityMetadata metadata, String tableName) {
    MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
            .getMetamodel(metadata.getPersistenceUnit());

    CQLTranslator translator = new CQLTranslator();

    String select_Query = translator.SELECTALL_QUERY;
    select_Query = StringUtils.replace(select_Query, CQLTranslator.COLUMN_FAMILY,
            translator.ensureCase(new StringBuilder(), tableName, false).toString());
    StringBuilder builder = new StringBuilder(select_Query);

    builder.append(CQLTranslator.ADD_WHERE_CLAUSE);
    onWhereClause(metadata, rowId, translator, builder, metaModel, metadata.getIdAttribute());
    builder.delete(builder.lastIndexOf(CQLTranslator.AND_CLAUSE), builder.length());

    return builder;
}

From source file:us.mn.state.health.lims.reports.action.implementation.HaitiPatientReport.java

protected String getResultNote(Result result) {
    if (result != null) {
        List<Note> notes = NoteUtil.getNotesForObjectAndTable(result.getId(), RESULT_REFERENCE_TABLE_ID);

        if (!(notes == null || notes.isEmpty())) {

            Collections.sort(notes, new Comparator<Note>() {
                @Override/*from ww w. j  a va 2 s.c  o  m*/
                public int compare(Note o1, Note o2) {
                    return Integer.parseInt(o1.getId()) - Integer.parseInt(o2.getId());
                }
            });

            StringBuilder noteBuilder = new StringBuilder();

            for (Note note : notes) {
                noteBuilder.append(note.getText());
                noteBuilder.append("<br/>");
            }

            noteBuilder.setLength(noteBuilder.lastIndexOf("<br/>"));

            return noteBuilder.toString();
        }
    }
    return null;
}

From source file:org.apache.synapse.endpoints.dispatch.AbstractDispatcher.java

@SuppressWarnings("unchecked")
protected void removeSessionID(MessageContext synCtx, String key) {

    if (key != null) {
        Map headerMap = getTransportHeaderMap(synCtx);
        if (headerMap != null) {
            Object cookieObj = headerMap.remove(key);

            if (cookieObj instanceof String) {
                String cookie = (String) cookieObj;
                if (log.isDebugEnabled()) {
                    log.debug("Cookies String : " + cookie);
                }//  www.j ava  2s. com

                String[] sessionIds = cookie.split(";");

                if (sessionIds == null || sessionIds.length == 0) {
                    if (log.isDebugEnabled()) {
                        log.debug("Cannot find a session id for the cookie : " + cookie);
                    }
                    return;
                }
                // reset
                StringBuilder newCookie = new StringBuilder("");

                for (int i = 0; i < sessionIds.length; i++) {
                    String sessionId = sessionIds[i];
                    if (sessionId != null && (sessionId.indexOf("JSESSIONID") != -1
                            || sessionId.indexOf("PHPSESSID") != -1 || sessionId.indexOf("phpMyAdmin") != -1
                            || sessionId.indexOf("wordpress_test_cookie") != -1)) {
                        if (log.isDebugEnabled()) {
                            log.debug("Extracted SessionID : " + sessionId);
                        }
                        // do not add this session id back 
                        continue;
                    }
                    newCookie.append(sessionId + "; ");
                }

                String modifiedCookie = ("".equals(newCookie.toString()) ? ""
                        : newCookie.substring(0, newCookie.lastIndexOf(";")));

                log.debug("Modified Cookie header: " + modifiedCookie);

                // add the modified Cookie header
                headerMap.put(key, modifiedCookie);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Couldn't find the " + key + " header to find the session");
                }
            }
        }
    }
}