Example usage for java.util.regex Pattern split

List of usage examples for java.util.regex Pattern split

Introduction

In this page you can find the example usage for java.util.regex Pattern split.

Prototype

public String[] split(CharSequence input) 

Source Link

Document

Splits the given input sequence around matches of this pattern.

Usage

From source file:org.radeox.filter.ParagraphFilter.java

public String complexFilter(String input, FilterContext context) {

    log.debug("Paragraph Filter Input " + input);
    Pattern patternBreaks = Pattern.compile(breaksRE);

    // attempts to locate lin breaks in the content with ([ \t\r]*[\n]){2}
    String[] p = patternBreaks.split(input);
    if (p.length == 1) {
        // only 1, therefor no embeded paragraphs
        return input;
    }//from   w  w  w . ja  v a 2  s .c  o  m

    StringBuffer sb = new StringBuffer();
    int nsplits = 0;
    // find the last > in the first paragraph
    int ins = p[0].lastIndexOf(">");
    if (ins > 0 && ins + 1 < p[0].length()) {
        // add all upto the last > into the buffer
        sb.append(p[0].substring(0, ins + 1));
        // then put <p class=\"paragraph\">
        sb.append(replaceFirst);
        nsplits++;
        // then append the remainder
        sb.append(p[0].substring(ins + 1));
    } else {
        sb.append(p[0]);

    }

    for (int i = 1; i < p.length - 1; i++) {
        // for all the following, add in </p><p class=\"paragraph\">
        if (nsplits == 0) {
            sb.append(replaceFirst);
            nsplits++;
        } else {
            sb.append(replaceAll);
            nsplits++;
        }
        sb.append(p[i]);
    }

    // in the last block find fidn the first <
    ins = p[p.length - 1].indexOf("<");
    if (ins > 0) {
        // put the standard line para blreak block in </p><p
        // class=\"paragraph\">
        if (nsplits == 0) {
            sb.append(replaceFirst);
            nsplits++;
        } else {
            sb.append(replaceAll);
            nsplits++;
        }
        // append the first part of the last block
        sb.append(p[p.length - 1].substring(0, ins - 1));
        // append the last seperator </p>
        if (nsplits > 0) {
            sb.append(replaceLast);
            nsplits++;
        }
        // append the remainder block
        sb.append(p[p.length - 1].substring(ins - 1));
    } else if (ins == 0) {
        // found "<" inposition found in last block so do </p>
        if (nsplits > 0) {
            sb.append(replaceLast);
            nsplits++;
        }
        sb.append(p[p.length - 1]);
    } else {
        // append the last </p>
        if (nsplits > 0) {
            sb.append(replaceLast);
            nsplits++;
        }
        sb.append(p[p.length - 1]);
    }
    String output = sb.toString();
    log.debug("Paragraph Filter Input " + output);

    return output;
}

From source file:mvm.rya.accumulo.pig.IndexWritingTool.java

public void setVarOrders(String s, Configuration conf) throws MalformedQueryException {

    SPARQLParser parser = new SPARQLParser();
    TupleExpr query = parser.parseQuery(s, null).getTupleExpr();

    List<String> projList = Lists.newArrayList(((Projection) query).getProjectionElemList().getTargetNames());
    String projElems = Joiner.on(";").join(projList);
    conf.set("projElems", projElems);

    Pattern splitPattern1 = Pattern.compile("\n");
    Pattern splitPattern2 = Pattern.compile(",");
    String[] lines = splitPattern1.split(s);

    List<String> varOrders = Lists.newArrayList();
    List<String> varOrderPos = Lists.newArrayList();

    int orderNum = 0;
    int projSizeSq = projList.size() * projList.size();

    for (String t : lines) {

        if (orderNum > projSizeSq) {
            break;
        }// w w w .  j  av a  2 s.  co m

        String[] order = null;
        if (t.startsWith("#prefix")) {
            t = t.substring(7).trim();
            order = splitPattern2.split(t, projList.size());
        }

        String tempVarOrder = "";
        String tempVarOrderPos = "";

        if (order != null) {
            for (String u : order) {
                if (tempVarOrder.length() == 0) {
                    tempVarOrder = u.trim();
                } else {
                    tempVarOrder = tempVarOrder + ";" + u.trim();
                }
                int pos = projList.indexOf(u.trim());
                if (pos < 0) {
                    throw new IllegalArgumentException("Invalid variable order!");
                } else {
                    if (tempVarOrderPos.length() == 0) {
                        tempVarOrderPos = tempVarOrderPos + pos;
                    } else {
                        tempVarOrderPos = tempVarOrderPos + ";" + pos;
                    }
                }
            }

            varOrders.add(tempVarOrder);
            varOrderPos.add(tempVarOrderPos);
        }

        if (tempVarOrder.length() > 0) {
            orderNum++;
        }

    }

    if (orderNum == 0) {
        varOrders.add(projElems);
        String tempVarPos = "";

        for (int i = 0; i < projList.size(); i++) {
            if (i == 0) {
                tempVarPos = Integer.toString(0);
            } else {
                tempVarPos = tempVarPos + ";" + i;
            }
        }
        varOrderPos.add(tempVarPos);

    }

    String[] vOrders = varOrders.toArray(new String[varOrders.size()]);
    String[] vOrderPos = varOrderPos.toArray(new String[varOrderPos.size()]);

    conf.setStrings("varOrders", vOrders);
    conf.setStrings("varOrderPos", vOrderPos);

}

From source file:org.couchpotato.CouchPotato.java

public List<String> loggingPartial(Integer lines, LoggingTypeEnum type)
        throws MalformedURLException, IOException, SocketTimeoutException {
    StringBuilder builder = new StringBuilder();
    if (lines != null) {
        builder.append("&lines=");
        builder.append(lines);/*from   ww w .ja  v  a  2 s. co m*/
    }
    if (type != null) {
        builder.append("&type=");
        builder.append(type.toString().toLowerCase());
    }
    LoggingJson json = this.<LoggingJson>command("logging.partial/", builder.toString(), LoggingJson.class);
    // split will remove the time stamp ... and I want it
    //      Pattern newLine = Pattern.compile("\\\\n\\d{2}\\-\\d{2} \\d{2}:\\d{2}:\\d{2}");
    // Lazy >.> figure this out better later
    Pattern newLine = Pattern.compile("\\\\n");
    return Arrays.asList(newLine.split(json.log));
}

From source file:com.freedomotic.plugins.impl.PluginsManagerImpl.java

@Override
public boolean installBoundle(URL fromURL) {

    try {//from  w  w w . ja va  2s  . c  om
        String url = fromURL.toString();

        if (url.lastIndexOf("&") > -1) {
            //remove any parameter (starts with '&' char) at the end of url
            url = url.substring(0, url.lastIndexOf('&'));
        }

        String filename = url.substring(url.lastIndexOf('/') + 1);

        //extracts plugin name from zip file name
        String pluginNameRegex = "\\-\\d.\\d.";
        Pattern p = Pattern.compile(pluginNameRegex);
        String[] items = p.split(filename);
        String pluginName = items[0];

        //get the zip from the url and copy in plugin/device folder
        if (filename.endsWith(".device")) {
            File zipFile = new File(Info.PATHS.PATH_DEVICES_FOLDER + "/" + filename);
            FetchHttpFiles.download(fromURL, Info.PATHS.PATH_DEVICES_FOLDER, filename);
            unzipAndDelete(zipFile);
            loadSingleBoundle(new File(Info.PATHS.PATH_DEVICES_FOLDER + "/" + pluginName));
        } else if (filename.endsWith(".object")) {
            FetchHttpFiles.download(fromURL, new File(Info.PATHS.PATH_PLUGINS_FOLDER + "/objects"), filename);

            File zipFile = new File(Info.PATHS.PATH_PLUGINS_FOLDER + "/objects/" + filename);
            unzipAndDelete(zipFile);
            loadSingleBoundle(new File(Info.PATHS.PATH_OBJECTS_FOLDER + "/" + pluginName));
        } else {
            LOG.warn("No installable Freedomotic plugins at URL " + fromURL);
        }
    } catch (Exception ex) {
        LOG.error("Error while installing boundle downloaded from " + fromURL, ex);

        return false; //not done
    }

    return true;
}

From source file:org.apache.rya.accumulo.pig.IndexWritingTool.java

public void setVarOrders(final String s, final Configuration conf) throws MalformedQueryException {

    final SPARQLParser parser = new SPARQLParser();
    final TupleExpr query = parser.parseQuery(s, null).getTupleExpr();

    final List<String> projList = Lists
            .newArrayList(((Projection) query).getProjectionElemList().getTargetNames());
    final String projElems = Joiner.on(";").join(projList);
    conf.set("projElems", projElems);

    final Pattern splitPattern1 = Pattern.compile("\n");
    final Pattern splitPattern2 = Pattern.compile(",");
    final String[] lines = splitPattern1.split(s);

    final List<String> varOrders = Lists.newArrayList();
    final List<String> varOrderPos = Lists.newArrayList();

    int orderNum = 0;
    final int projSizeSq = projList.size() * projList.size();

    for (String t : lines) {

        if (orderNum > projSizeSq) {
            break;
        }// w  ww . j  a  v  a 2  s.  com

        String[] order = null;
        if (t.startsWith("#prefix")) {
            t = t.substring(7).trim();
            order = splitPattern2.split(t, projList.size());
        }

        String tempVarOrder = "";
        String tempVarOrderPos = "";

        if (order != null) {
            for (final String u : order) {
                if (tempVarOrder.length() == 0) {
                    tempVarOrder = u.trim();
                } else {
                    tempVarOrder = tempVarOrder + ";" + u.trim();
                }
                final int pos = projList.indexOf(u.trim());
                if (pos < 0) {
                    throw new IllegalArgumentException("Invalid variable order!");
                } else {
                    if (tempVarOrderPos.length() == 0) {
                        tempVarOrderPos = tempVarOrderPos + pos;
                    } else {
                        tempVarOrderPos = tempVarOrderPos + ";" + pos;
                    }
                }
            }

            varOrders.add(tempVarOrder);
            varOrderPos.add(tempVarOrderPos);
        }

        if (tempVarOrder.length() > 0) {
            orderNum++;
        }

    }

    if (orderNum == 0) {
        varOrders.add(projElems);
        String tempVarPos = "";

        for (int i = 0; i < projList.size(); i++) {
            if (i == 0) {
                tempVarPos = Integer.toString(0);
            } else {
                tempVarPos = tempVarPos + ";" + i;
            }
        }
        varOrderPos.add(tempVarPos);

    }

    final String[] vOrders = varOrders.toArray(new String[varOrders.size()]);
    final String[] vOrderPos = varOrderPos.toArray(new String[varOrderPos.size()]);

    conf.setStrings("varOrders", vOrders);
    conf.setStrings("varOrderPos", vOrderPos);

}

From source file:org.apache.storm.st.wrapper.TopoWrap.java

public List<LogData> getLogData(final String componentId)
        throws IOException, TException, MalformedURLException {
    final String logs = getLogs(componentId);
    final String dateRegex = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3}";
    Pattern pattern = Pattern.compile("(?=\\n" + dateRegex + ")");
    final String[] strings = pattern.split(logs);
    final Collection<String> interestingLogs = Collections2.filter(Arrays.asList(strings),
            new Predicate<String>() {
                @Override//from ww w.  ja  va 2  s .c om
                public boolean apply(@Nullable String input) {
                    return input != null && StringDecorator.isDecorated(input);
                }
            });
    final Collection<LogData> logData = Collections2.transform(interestingLogs,
            new Function<String, LogData>() {
                @Nullable
                @Override
                public LogData apply(@Nullable String input) {
                    return new LogData(input);
                }
            });
    final ArrayList<LogData> sortedLogs = new ArrayList<>(logData);
    Collections.sort(sortedLogs);
    log.info("Found " + sortedLogs.size() + " items for component: " + componentId);
    return sortedLogs;
}

From source file:com.mirth.connect.connectors.mllp.ResponseAck.java

public ResponseAck(String ackMessageString) {
    // save the incoming ack message
    this.ackMessageString = ackMessageString;

    try {/*from  ww w.  ja  v  a2s .c  om*/
        if (ackMessageString.startsWith("<")) {
            HL7v2Header headerData = HL7v2XMLQuickParser.getInstance().processMSA(ackMessageString);
            if (headerData.getParseError() == null) {
                setStatus(headerData.getAcknowledgmentCode(), headerData.getAckMessageControlId(),
                        headerData.getAckTextMessage(), headerData.getError());
            } else {
                throw new Exception(headerData.getParseError());
            }
        } else {
            char segmentDelim = '\r';
            char fieldDelim = ackMessageString.charAt(3); // Usually |

            Pattern segmentPattern = Pattern.compile(Pattern.quote(String.valueOf(segmentDelim)));
            Pattern fieldPattern = Pattern.compile(Pattern.quote(String.valueOf(fieldDelim)));

            String msa1 = "";
            String msa2 = "";
            String msa3 = "";
            String err1 = "";
            String[] segments = segmentPattern.split(ackMessageString);
            for (String segment : segments) {
                String[] fields = fieldPattern.split(segment);

                if (fields[0].equals("MSA")) {
                    if (fields.length > 1) {
                        msa1 = fields[1];
                    }
                    if (fields.length > 3) {
                        msa3 = fields[3];
                    }
                } else if (fields[0].equals("ERR")) {
                    if (fields.length > 1) {
                        err1 = fields[1];
                    }
                }
            }

            setStatus(msa1, msa2, msa3, err1);
        }

        logger.debug("ACK: " + ackMessageString);
    } catch (Exception e) {
        errorDescription = " Message is not a valid ACK";
        errorDescription += "\n" + e + "\n" + ackMessageString;
    }
}

From source file:com.log4ic.compressor.utils.Compressor.java

/**
 * URL?//from www. jav  a2s . co  m
 *
 * @param code
 * @param fileUrl
 * @param type
 * @param fileDomain
 * @return
 */
public static String fixUrlPath(HttpServletRequest req, String code, String fileUrl, FileType type,
        String fileDomain) {

    StringBuilder codeBuffer = new StringBuilder();
    switch (type) {
    case GSS:
    case CSS:
    case LESS:
    case MSS:
        logger.debug("URL?...");
        Pattern pattern = Pattern.compile("url\\(\\s*(?!['\"]?(?:data:|about:|#|@))([^)]+)\\)",
                Pattern.CASE_INSENSITIVE);

        Matcher matcher = pattern.matcher(code);

        String[] codeFragments = pattern.split(code);

        fileUrl = fileUrl.substring(0, fileUrl.lastIndexOf("/") + 1);

        int i = 0;
        while (matcher.find()) {
            codeBuffer.append(codeFragments[i]);
            codeBuffer.append("url(");
            MatchResult result = matcher.toMatchResult();
            String url = result.group(1).replaceAll("'|\"", "");
            //???
            if (!HttpUtils.isHttpProtocol(url) && !url.startsWith("/")) {
                url = URI.create(fileUrl + url).normalize().toASCIIString();//?URL
            }

            //??url?http?)??????
            if (StringUtils.isNotBlank(fileDomain) && !HttpUtils.isHttpProtocol(url)) {
                if (!fileDomain.endsWith("/") && !url.startsWith("/")) {
                    fileDomain = fileDomain + "/";
                } else if (fileDomain.endsWith("/") && url.startsWith("/")) {
                    url = url.substring(1);
                }
                if (!HttpUtils.isHttpProtocol(fileDomain)) {
                    fileDomain = "http://" + fileDomain;
                }
                url = fileDomain + url;
            } else {
                url = req.getContextPath() + (url.startsWith("/") ? url : "/" + url);
            }
            codeBuffer.append(url);
            codeBuffer.append(")");
            i++;
        }
        if (i == 0) {
            return code;
        } else {
            if (codeFragments.length > i && StringUtils.isNotBlank(codeFragments[i])) {
                codeBuffer.append(codeFragments[i]);
            }
        }
        logger.debug("URL?...");
        break;
    default:
        return code;
    }
    return codeBuffer.toString();
}

From source file:org.apache.lucene.pinyin.dwarf.PinyinTokenizer.java

@Override
public final boolean incrementToken() throws IOException {
    if (!main_done) {
        clearAttributes();//from   w  ww. ja v  a 2  s.c o  m
        main_done = true;
        int upto = 0;
        char[] buffer = termAtt.buffer();
        // System.out.println(String.valueOf(buffer));
        while (true) {
            final int length = input.read(buffer, upto, buffer.length - upto);
            if (length == -1)
                break;
            upto += length;
            if (upto == buffer.length)
                buffer = termAtt.resizeBuffer(1 + buffer.length);
        }
        termAtt.setLength(upto);
        //?
        String str = ChineseUtils.toSimplified(termAtt.toString());

        termAtt.setEmpty();
        // ??
        /*Iterator<Object> stopwordItem = stopwords.iterator();
        while (stopwordItem.hasNext()) {
          String stopword = String.valueOf((char[]) stopwordItem.next());
          boolean isstop = str.contains(stopword);
          if (isstop) {
            termAtt.setEmpty();
            return false;
          }
        }*/

        StringBuilder cnIKLetters = new StringBuilder(); // ?
        StringBuilder cnCharLetters = new StringBuilder(); // ?
        StringBuilder allPinYinLetters = new StringBuilder(); // ?

        Pattern pattern = Pattern.compile("[\\pP\\s]");
        String[] arrStrings = pattern.split(str);
        for (int k = 0; k < arrStrings.length; k++) {
            String words = arrStrings[k];
            String filterword = filterkeyWords(words);
            if (filterword.length() < pinyinnum + 1) {
                allPinYinLetters.append(getpinyin(filterword)).append(this.padding_char);
            }
            if (openIK) {
                StringReader wordReader = new StringReader(words);
                ikSegmenter = new IKSegmenter(wordReader, this.usedSmart);
                Lexeme nextLexeme = null;
                String nextLexemeStr = "";
                while ((nextLexeme = ikSegmenter.next()) != null) {
                    nextLexemeStr = nextLexeme.getLexemeText();
                    cnIKLetters.append(nextLexemeStr).append(this.padding_char);

                    for (int i = 0; i < nextLexemeStr.length(); i++) {
                        char c = nextLexemeStr.charAt(i);
                        try {
                            String[] strs = PinyinHelper.toHanyuPinyinStringArray(c, format);
                            if (strs.length == 0) {
                                continue;
                            }
                            String first_pinyin = strs[0];

                            // ???2??
                            if (nextLexemeStr.length() > 1) {
                                allPinYinLetters.append(first_pinyin);
                            }
                        } catch (BadHanyuPinyinOutputFormatCombination e) {
                            // throw new RuntimeException();
                        } catch (NullPointerException e) {
                            break;
                        }

                    }
                    allPinYinLetters.append(this.padding_char);
                }
            }
            for (int i = 0; i < words.length(); i++) {
                char c = words.charAt(i);
                // if (c < 128) {
                // stringBuilder.append(c);
                // } else {

                // cnLetters.append(c);
                cnCharLetters.append(c).append(this.padding_char);
                // if (strs != null) {
                // get first result by default
                // String first_value = strs[0];

                // TODO more than one pinyin
                // .

                // .
                // ???2??
                // if (nextLexemeStr.length() > 1) {
                // allPinYinLetters.append(first_value);
                // }
                // ?????
                // if (k == 0 && nextLexemeStr.length() == 1) {
                // allPinYinLetters_without_s.append(first_value);
                // firstLetters_name.append(first_value.charAt(0));
                // }
                // }

            }
            cnCharLetters.append("|||").append(this.padding_char);
        }
        // let's join them

        termAtt.append(allPinYinLetters);
        termAtt.append(this.padding_char);
        // // termAtt.append(cnLetters.toString());
        // termAtt.append(this.padding_char);

        termAtt.append(cnIKLetters);
        // termAtt.append(firstLetters.toString());
        termAtt.append(this.padding_char);
        // termAtt.append(stringBuilder.toString());
        if (!this.strictMode) {
            // termAtt.append(cnCharLetters).append(this.padding_char);
            cnCharLetters_String = cnCharLetters.toString().trim();
            cnarray = cnCharLetters_String.split("\\s+");
        } else {
            this.done = true;
        }
        // termAtt.append(this.padding_char);
        // ???
        // termAtt.append(mergeNGramPinYin(allPinYinLetters.toString()));

        // StringUtils.join(arrStrings, this.padding_char);
        posIncrAtt.setPositionIncrement(1);
        finalOffset = correctOffset(termAtt.toString().split("\\s+").length);
        offsetAtt.setOffset(correctOffset(0), finalOffset);
        typeAtt.setType("<IDEOGRAPHIC>");
        return true;
    } else {
        if (done) {
            return false;
        }

        termAtt.setEmpty();
        String term = cnarray[cn_arr_index];
        termAtt.append(term);
        posIncrAtt.setPositionIncrement(1);
        cn_arr_index++;
        typeAtt.setType("<IDEOGRAPHIC>");
        finalOffset = offsetAtt.endOffset() + term.length();
        offsetAtt.setOffset(correctOffset(offsetAtt.endOffset()), finalOffset);
        if (cn_arr_index == cnarray.length) {
            this.done = true;
        }
    }
    return true;
}

From source file:com.odoo.support.provider.OContentProvider.java

private Cursor createQuery(Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sort) {/*from   w w  w .jav a  2 s .  com*/
    reInitModel();
    SQLiteQueryBuilder query = new SQLiteQueryBuilder();
    boolean withAlias = (projection.length < model.projection().length);
    StringBuffer joins = new StringBuffer();
    String base_table = model.getTableName();
    String base_alias = base_table + "_base";
    HashMap<String, String> projectionMap = new HashMap<String, String>();
    List<String> mJoinTables = new ArrayList<String>();
    for (String col_name : projection) {
        String col = col_name;
        if (col_name.contains(".")) {
            col = col_name.split("\\.")[0];
        }
        OColumn column = model.getColumn(col);
        String display_col = col;
        if (withAlias) {
            display_col = base_alias + "." + col + " AS " + col;
            boolean many2oneJoin = col_name.contains(".");
            if (column.getRelationType() != null && many2oneJoin) {
                OModel rel_model = model.createInstance(column.getType());
                String table = rel_model.getTableName();
                String alias = table;
                alias = table + "_self";
                table += " AS " + alias;
                if (!mJoinTables.contains(alias)) {
                    mJoinTables.add(alias);
                    joins.append(" JOIN ");
                    joins.append(table);
                    joins.append(" ON ");
                    joins.append(base_alias + "." + column.getName());
                    joins.append(" = ");
                    joins.append(alias + "." + OColumn.ROW_ID);
                    joins.append(" ");
                }
                String rel_col = col;
                String rel_col_name = "";
                if (col_name.contains(".")) {
                    rel_col += "_" + col_name.split("\\.")[1];
                    rel_col_name = col_name.split("\\.")[1];
                }
                projectionMap.put(rel_col, alias + "." + rel_col_name + " AS " + rel_col);
            }
        }
        projectionMap.put(col, display_col);
    }
    StringBuffer tables = new StringBuffer();
    tables.append(base_table + ((withAlias) ? " AS " + base_alias : " "));
    tables.append(joins.toString());
    query.setTables(tables.toString());
    query.setProjectionMap(projectionMap);
    StringBuffer whr = new StringBuffer();
    String where = null;
    if (selection != null && selectionArgs != null) {
        if (withAlias) {
            // Check for and
            Pattern pattern = Pattern.compile(" and | AND ");
            String[] data = pattern.split(selection);
            StringBuffer or_string = new StringBuffer();
            for (String token : data) {
                if (token.contains("OR") || token.contains("or")) {
                    or_string.append(token.trim());
                    or_string.append(" OR ");
                } else {
                    whr.append(base_alias + "." + token.trim());
                    whr.append(" AND ");
                }
            }
            if (whr.length() > 0)
                whr.delete(whr.length() - 5, whr.length());
            // Check for or
            if (or_string.length() > 0) {
                if (whr.length() > 0)
                    whr.append(" AND ");
                pattern = Pattern.compile(" or | OR ");
                data = pattern.split(or_string.toString());
                for (String token : data) {
                    if (!token.contains(base_alias)) {
                        if (token.contains("(")) {
                            whr.append("(");
                            token = token.replaceAll("\\(", "");
                            whr.append(base_alias + "." + token.trim());
                        } else if (token.contains(")")) {
                            token = token.replaceAll("\\)", "");
                            whr.append(base_alias + "." + token.trim());
                            whr.append(")");
                        } else {
                            whr.append(base_alias + "." + token.trim());
                        }
                    } else {
                        whr.append(token.trim());
                    }
                    whr.append(" OR ");
                }
                if (whr.length() > 0)
                    whr.delete(whr.length() - 4, whr.length());
            }
        } else {
            whr.append(selection);
        }
        where = whr.toString();
    }
    Cursor c = null;
    int uriMatch = matcher.match(uri);
    switch (uriMatch) {
    case SINGLE_ROW:
        // Return a single entry, by ID.
        String id = uri.getLastPathSegment();
        query.appendWhere(base_alias + "." + OColumn.ROW_ID + " = " + id);
    case COLLECTION:
        c = query.query(model.getReadableDatabase(), null, where, selectionArgs, null, null, sort);
        return c;
    default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }
}