Example usage for java.lang String subSequence

List of usage examples for java.lang String subSequence

Introduction

In this page you can find the example usage for java.lang String subSequence.

Prototype

public CharSequence subSequence(int beginIndex, int endIndex) 

Source Link

Document

Returns a character sequence that is a subsequence of this sequence.

Usage

From source file:org.jsconf.core.ConfigurationFactory.java

private List<String> withProfile(String name) {
    List<String> ressourcesName = new ArrayList<>();
    if (this.withProfiles) {
        String[] profiles = this.context.getEnvironment().getActiveProfiles();
        for (String profile : profiles) {
            String nameWithProfile = name;
            int idx = name.lastIndexOf(".");
            if (idx > 0) {
                nameWithProfile = nameWithProfile.subSequence(0, idx) + "-" + profile + name.substring(idx);
            } else {
                nameWithProfile = nameWithProfile + "-" + profile;
            }//from   w  w w  .j av  a 2s . co  m
            ressourcesName.add(nameWithProfile);
        }
    }
    ressourcesName.addAll(getDefinition(name));
    return ressourcesName;
}

From source file:at.gv.egiz.pdfas.cli.Main.java

private static void dumpVerifyResult(VerifyResult verifyResult, String inputFile, int idx,
        String confOutputFile) {/* ww  w .j a  v a  2s  .  c o m*/
    System.out.println("Verification Result:");
    System.out.println("\tValue Check: " + verifyResult.getValueCheckCode().getMessage() + " ["
            + verifyResult.getValueCheckCode().getCode() + "]");
    System.out.println("\tCertificate Check: " + verifyResult.getCertificateCheck().getMessage() + " ["
            + verifyResult.getCertificateCheck().getCode() + "]");
    System.out.println("\tQualified Certificate: " + verifyResult.isQualifiedCertificate());
    System.out.println("\tVerification done: " + verifyResult.isVerificationDone());
    try {
        if (verifyResult.isVerificationDone() && verifyResult.getValueCheckCode().getCode() == 0) {
            String outputFile = null;

            if (confOutputFile == null) {
                if (inputFile.endsWith(".pdf")) {
                    outputFile = inputFile.subSequence(0, inputFile.length() - ".pdf".length()) + "_verified_"
                            + idx + ".pdf";
                } else {
                    outputFile = inputFile + "_verified_" + idx + ".pdf";
                }
            } else {
                if (confOutputFile.endsWith(".pdf")) {
                    outputFile = confOutputFile.subSequence(0, confOutputFile.length() - ".pdf".length()) + "_"
                            + idx + ".pdf";
                } else {
                    outputFile = confOutputFile + "_" + idx + ".pdf";
                }
            }

            File outputPdfFile = new File(outputFile);
            FileOutputStream fos = new FileOutputStream(outputPdfFile, false);
            fos.write(verifyResult.getSignatureData());
            fos.close();
            System.out.println("\tSigned PDF: " + outputFile);
        }
    } catch (Exception e) {
        System.out.println("\tFailed to save signed PDF! [" + e.getMessage() + "]");
        e.printStackTrace();
    }
}

From source file:ffx.ui.FFXSystem.java

/**
 * <p>/*from w  w  w.j  a v  a  2  s  .  co m*/
 * Getter for the field <code>logFile</code>.</p>
 *
 * @return a {@link java.io.File} object.
 */
public File getLogFile() {
    if (logFile == null) {
        if (getFile() == null) {
            return null;
        }
        String fileName = getFile().getName();
        int dot = fileName.lastIndexOf(".");
        fileName = fileName.subSequence(0, dot) + ".log";
        logFile = new File(fileName);
    }
    return logFile;
}

From source file:org.grails.datastore.gorm.finders.DynamicFinder.java

public boolean isMethodMatch(String methodName) {
    return pattern.matcher(methodName.subSequence(0, methodName.length())).find();
}

From source file:com.thoughtworks.go.config.materials.mercurial.HgMaterial.java

boolean isVersionOneDotZeroOrHigher(String hgout) {
    String hgVersion = parseHgVersion(hgout);
    Float aFloat = NumberUtils.createFloat(hgVersion.subSequence(0, 3).toString());
    return aFloat >= 1;
}

From source file:edu.harvard.i2b2.fhir.FhirUtil.java

public static Object getChildThruChain(Resource r, String pathStr, List<Resource> s)
        // is dot separated path
        throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
        InvocationTargetException {
    Class c = FhirUtil.getResourceClass(r);

    String suffix = null;/*from www  . j  a  v  a 2  s.  co  m*/
    String prefix = pathStr;
    logger.trace("pathStr:" + pathStr);

    if (pathStr.indexOf('.') > -1) {
        suffix = pathStr.substring(pathStr.indexOf('.') + 1);
        prefix = pathStr.substring(0, pathStr.indexOf('.'));
    }

    String methodName = prefix.substring(0, 1).toUpperCase() + prefix.subSequence(1, prefix.length());
    Method method = c.getMethod("get" + methodName, null);
    Object o = method.invoke(c.cast(r));

    if (suffix == null) {
        return o;

    } else {
        if (Reference.class.isInstance(o)) {
            Reference rr = Reference.class.cast(o);
            logger.trace("gotc:" + o.getClass());

            /*
             * try { logger.trace("seek:" + JAXBUtil.toXml(rr));
             * logger.trace("seek:" + rr.getReference().getValue()); } catch
             * (JAXBException e) { // TODO Auto-generated catch block
             * e.printStackTrace(); }
             */

            Resource r1 = FhirUtil.findResourceById(rr.getReference().getValue(), s);
            return getChildThruChain(r1, suffix, s);
        } else {
            return getChildThruChain(r, suffix, s);
        }
    }
}

From source file:edu.harvard.i2b2.fhir.FhirUtil.java

public static List<Object> getChildrenThruParPath(Resource r, String pathStr, MetaResourceDb db)
        throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
        InvocationTargetException {

    List<Object> children = new ArrayList<Object>();
    List<Object> resolvedChildren = new ArrayList<Object>();
    List<Resource> s = db.getAll();

    logger.trace("got obj:" + r);
    Class c = FhirUtil.getResourceClass(r);

    String suffix = null;/*from  w  w w . j a  va  2s . c  o  m*/
    String prefix = pathStr;
    logger.trace("pathStr:" + pathStr);

    if (pathStr.indexOf('.') > -1) {
        suffix = pathStr.substring(pathStr.indexOf('.') + 1);
        prefix = pathStr.substring(0, pathStr.indexOf('.'));
    }

    String methodName = prefix.substring(0, 1).toUpperCase() + prefix.subSequence(1, prefix.length());
    Method method = c.getMethod("get" + methodName, null);
    Object o = method.invoke(c.cast(r));

    if (List.class.isInstance(o)) {
        children.addAll((List<Object>) o);
    } else {
        children.add(o);
    }

    if (suffix == null) {
        return children;

    } else {

        for (Object child : children) {

            // if it is a reference resolve the reference
            if (Reference.class.isInstance(child)) {
                Reference rr = Reference.class.cast(child);
                logger.trace("gotc:" + child.getClass());
                Resource r1 = FhirUtil.findResourceById(rr.getReference().getValue(), s);
                resolvedChildren.add(getChildrenThruChain(r1, suffix, s));

            } else {
                resolvedChildren.add(getChildrenThruChain(r, suffix, s));
            }

        }
    }
    return resolvedChildren;
}

From source file:com.edgenius.wiki.render.RenderUtil.java

/**
 * {piece:name=foo}content{piece} - return content between piece macro
 * @param content - markup//  www  . j a v  a 2s  .  co m
 * @return
 */
public static String getPiece(String content, String pieceName) {
    if (StringUtils.isBlank(pieceName))
        return content;

    //do escape first, then find valid {piece}
    CharSequence text = MarkupUtil.hideEscapeMarkup(content);

    Macro pieceMacro = new PieceMacro();
    MacroFilter filter = new MacroFilter();
    filter.setMacroMgr(new MacroManagerImpl());
    filter.init(pieceMacro, false);

    List<Region> regions = filter.getRegions(text);
    if (regions == null || regions.size() == 0) {
        //must return null ! it is required by called method PageService.renderPhasePiece()
        return null;
    }

    BaseMacroParameter mParams = new BaseMacroParameter();
    for (Region region : regions) {
        //check if piece macro name is given name, return first matched
        String piece = content.subSequence(region.getStart(), region.getEnd()).toString();

        //See our issue http://bug.edgenius.com/issues/34
        //and SUN Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337993
        try {
            Matcher m = FilterRegxConstants.PIECE_MACRO_START_TAG_PATTERN.matcher(piece);
            if (m.find()) {
                mParams.setParams(m.group(1));
                if (pieceName.equalsIgnoreCase(mParams.getParam(NameConstants.NAME))) {
                    //find the matched piece! because region.body is escaped content, so substring to get back original context
                    return content.substring(region.getContentStart(), region.getContentEnd());
                }
            }
        } catch (StackOverflowError e) {
            AuditLogger.error("StackOverflow Error in RenderUtil.getPiece. Input[" + piece + "] Pattern ["
                    + FilterRegxConstants.PIECE_MACRO_START_TAG_PATTERN.pattern() + "]");
        } catch (Throwable e) {
            AuditLogger.error("Unexpected error in RenderUtil.getPiece. Input[" + piece + "] Pattern ["
                    + FilterRegxConstants.PIECE_MACRO_START_TAG_PATTERN.pattern() + "]", e);
        }
    }

    //no give piece name
    return null;
}

From source file:edu.harvard.i2b2.fhir.FhirUtil.java

public static List<Object> getChildrenThruChain(Resource r, String pathStr, List<Resource> s)
        // is dot separated path
        throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
        InvocationTargetException {

    List<Object> children = new ArrayList<Object>();
    List<Object> resolvedChildren = new ArrayList<Object>();
    logger.trace("got obj:" + r);
    Class c = FhirUtil.getResourceClass(r);

    String suffix = null;//  w ww.  java2 s  .c o m
    String prefix = pathStr;
    logger.trace("pathStr:" + pathStr);

    if (pathStr.indexOf('.') > -1) {
        suffix = pathStr.substring(pathStr.indexOf('.') + 1);
        prefix = pathStr.substring(0, pathStr.indexOf('.'));
    }

    String methodName = prefix.substring(0, 1).toUpperCase() + prefix.subSequence(1, prefix.length());
    Method method = c.getMethod("get" + methodName, null);
    Object o = method.invoke(c.cast(r));

    if (List.class.isInstance(o)) {
        children.addAll((List<Object>) o);
    } else {
        children.add(o);
    }

    if (suffix == null) {
        return children;

    } else {

        for (Object child : children) {
            if (Reference.class.isInstance(child)) {
                Reference rr = Reference.class.cast(child);
                logger.trace("gotc:" + child.getClass());

                /*
                 * try { logger.trace("seek:" + JAXBUtil.toXml(rr));
                 * logger.trace("seek:" + rr.getReference().getValue()); }
                 * catch (JAXBException e) { // TODO Auto-generated catch
                 * block e.printStackTrace(); }
                 */

                Resource r1 = FhirUtil.findResourceById(rr.getReference().getValue(), s);
                resolvedChildren.add(getChildrenThruChain(r1, suffix, s));

            } else {
                resolvedChildren.add(getChildrenThruChain(r, suffix, s));
            }

        }
    }
    return resolvedChildren;
}

From source file:servlet.CustomerControl.java

protected void doListTickets(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    HttpSession session = request.getSession();

    JSONObject jso0 = new JSONObject();
    JSONArray jsa0 = new JSONArray();
    try {/*from   w  w  w.  j av a  2  s.  co  m*/
        jso0.put("tickets", jsa0);
    } catch (JSONException ex) {
        Logger.getLogger(CustomerControl.class.getName()).log(Level.SEVERE, null, ex);
    }

    User user = (User) session.getAttribute("user");
    int userID;
    int userCredit = 0;
    int userLP = 0;
    if (user != null) {
        userID = user.getUserID();
        userCredit = user.getCredit();
        userLP = user.getTradePoint();
    } else {
        out.println(jso0.toString());
        return;
    }
    ServletContext sc = getServletContext();
    String db_driver = sc.getInitParameter("db_driver"), db_url = sc.getInitParameter("db_url"),
            db_user = sc.getInitParameter("db_user"), db_password = sc.getInitParameter("db_password"),
            db_q_tickets = "SELECT DISTINCT t.ticketID, t.state, s.rowName, s.seatName,"
                    + " (ms.price + s.surcharge) AS 'price', ms.playtime, m.*, h.houseName,"
                    + " c.cinemaName, c.cinemaDistrict, c.cinemaAddress, c.tel, c.image1"
                    + " FROM Ticket t, MovieSession ms, Movie m, Seat s, House h, Cinema c"
                    + " WHERE t.msID = ms.msID" + " AND ms.houseID = h.houseID" + " AND h.cinemaID = c.cinemaID"
                    + " AND h.houseID = s.houseID" + " AND t.seatID = s.seatID" + " AND ms.movieID = m.movieID"
                    + " AND t.userID = ?;";
    try {
        Class.forName(db_driver);
        Connection conn = DriverManager.getConnection(db_url, db_user, db_password);
        PreparedStatement statmt = conn.prepareStatement(db_q_tickets);
        statmt.setInt(1, userID);
        if (statmt.execute()) {
            ResultSet rs = statmt.getResultSet();
            ResultSetMetaData rsmd = rs.getMetaData();
            int numOfColumns = rsmd.getColumnCount();
            while (rs.next()) {
                JSONObject jso1 = new JSONObject();
                jsa0.put(jso1);
                for (int i = 1; i <= numOfColumns; i++) {
                    jso1.put(rsmd.getColumnLabel(i), rs.getString(i));
                }
                String playtime = jso1.getString("playtime");
                jso1.put("date", playtime.substring(0, 10));
                jso1.put("time", playtime.subSequence(11, 16));
            }

        }
        conn.close();
        out.println(jso0.toString());

    } catch (ClassNotFoundException ex) {
        Logger.getLogger(CustomerControl.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(CustomerControl.class.getName()).log(Level.SEVERE, null, ex);
    } catch (JSONException ex) {
        Logger.getLogger(CustomerControl.class.getName()).log(Level.SEVERE, null, ex);
    }
}