Example usage for java.util.regex Pattern MULTILINE

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

Introduction

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

Prototype

int MULTILINE

To view the source code for java.util.regex Pattern MULTILINE.

Click Source Link

Document

Enables multiline mode.

Usage

From source file:csiro.pidsvc.mappingstore.ManagerJson.java

@SuppressWarnings("unchecked")
public JSONObject getLookupConfig(String ns) throws SQLException {
    PreparedStatement pst = null;
    ResultSet rs = null;//from www  .  ja va  2s  .com
    JSONObject ret = new JSONObject();
    JSONArray jsonArr;
    String lookupType;

    try {
        pst = _connection.prepareStatement(
                "SELECT ns, type, behaviour_type, behaviour_value FROM lookup_ns WHERE ns = ?;SELECT key, value FROM lookup WHERE ns = ?;");
        pst.setString(1, ns);
        pst.setString(2, ns);

        if (pst.execute()) {
            rs = pst.getResultSet();
            if (rs.next()) {
                lookupType = rs.getString("type");
                ret.put("ns", rs.getString("ns"));
                ret.put("type", lookupType);
                ret.put("default", JSONObjectHelper.create("type", rs.getString("behaviour_type"), "value",
                        rs.getString("behaviour_value")));

                pst.getMoreResults();
                rs = pst.getResultSet();
                if (lookupType.equalsIgnoreCase("Static")) {
                    jsonArr = new JSONArray();
                    while (rs.next()) {
                        jsonArr.add(JSONObjectHelper.create("key", rs.getString(1), "value", rs.getString(2)));
                    }
                    ret.put("lookup", jsonArr);
                } else if (lookupType.equalsIgnoreCase("HttpResolver")) {
                    if (rs.next()) {
                        final Pattern reType = Pattern.compile("^T:(.+)$",
                                Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
                        final Pattern reExtract = Pattern.compile("^E:(.+)$",
                                Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
                        final Pattern reNamespace = Pattern.compile("^NS:(.+?):(.+)$",
                                Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
                        Matcher m;
                        String buf = rs.getString(2);

                        try {
                            JSONObject jsonPart = new JSONObject();
                            jsonPart.put("endpoint", rs.getString(1));

                            // Type.
                            m = reType.matcher(buf);
                            m.find();
                            jsonPart.put("type", m.group(1));

                            // Extractor.
                            m = reExtract.matcher(buf);
                            m.find();
                            jsonPart.put("extractor", m.group(1));

                            // Namespaces.
                            m = reNamespace.matcher(buf);
                            jsonArr = new JSONArray();
                            while (m.find()) {
                                jsonArr.add(JSONObjectHelper.create("prefix", m.group(1), "uri", m.group(2)));
                            }
                            jsonPart.put("namespaces", jsonArr);

                            ret.put("lookup", jsonPart);
                        } catch (Exception e) {
                            _logger.debug(e);
                            return null;
                        }
                    }
                }
            }
        }
    } finally {
        if (rs != null)
            rs.close();
        if (pst != null)
            pst.close();
    }
    return ret;
}

From source file:org.apache.phoenix.hive.HiveTestUtil.java

private String getCommands(String tname) {
    String commands = qMap.get(tname);
    StringBuilder newCommands = new StringBuilder(commands.length());
    int lastMatchEnd = 0;
    Matcher commentMatcher = Pattern.compile("^--.*$", Pattern.MULTILINE).matcher(commands);
    while (commentMatcher.find()) {
        newCommands.append(commands.substring(lastMatchEnd, commentMatcher.start()));
        newCommands.append(commentMatcher.group().replaceAll("(?<!\\\\);", "\\\\;"));
        lastMatchEnd = commentMatcher.end();
    }/*from  w ww .  j  a  v a2 s .  c  o m*/
    newCommands.append(commands.substring(lastMatchEnd, commands.length()));
    commands = newCommands.toString();
    return commands;
}

From source file:org.wso2.carbon.event.processor.core.internal.util.helper.EventProcessorHelper.java

/**
 * Sets an annotation name for a given execution plan to be true or false.
 * For example, when an execution plan has the statement "@Plan:statistics('false')" and false need to be set to true,
 * then this helper method can be used./*from ww  w. j av a 2 s . c o m*/
 *
 * @param executionPlan        Existing execution plan, either having the annotation name set to be true/false,
 *                             or the annotation name is not present in the execution plan at all.
 * @param annotationName       The annotation name which needs to be set to true/false.
 *                             For example, in Siddhi statement @Plan:name('false'), 'name' will be the annotation name.
 * @param isAnnotationNameTrue Whether the annotation name need to be set to true or false.
 * @return New execution plan with the given plan annotation name set to be true.
 */
public static String setExecutionPlanAnnotationName(String executionPlan, String annotationName,
        boolean isAnnotationNameTrue) {
    String newExecutionPlan = null;
    String planHeader = "";
    String planBody = "";
    String planHeaderLineRegex = EventProcessorConstants.PLAN_HEADER_LINE_REGEX;

    String regexToBeReplaced = "^\\s*" + //beginning of line with zero or more whitespaces
            EventProcessorConstants.ANNOTATION_TOKEN_AT + EventProcessorConstants.ANNOTATION_PLAN
            + EventProcessorConstants.ANNOTATION_TOKEN_COLON + annotationName + "\\"
            + EventProcessorConstants.ANNOTATION_TOKEN_OPENING_BRACKET + //bracket is escaped, because the literal is meant.
            EventProcessorConstants.SIDDHI_SINGLE_QUOTE + !isAnnotationNameTrue
            + EventProcessorConstants.SIDDHI_SINGLE_QUOTE + "\\"
            + EventProcessorConstants.ANNOTATION_TOKEN_CLOSING_BRACKET; //bracket is escaped, because the literal is meant.

    String replacement = EventProcessorConstants.ANNOTATION_TOKEN_AT + EventProcessorConstants.ANNOTATION_PLAN
            + EventProcessorConstants.ANNOTATION_TOKEN_COLON + annotationName
            + EventProcessorConstants.ANNOTATION_TOKEN_OPENING_BRACKET
            + EventProcessorConstants.SIDDHI_SINGLE_QUOTE + isAnnotationNameTrue
            + EventProcessorConstants.SIDDHI_SINGLE_QUOTE
            + EventProcessorConstants.ANNOTATION_TOKEN_CLOSING_BRACKET;

    Matcher matcher = Pattern.compile(regexToBeReplaced, Pattern.MULTILINE).matcher(executionPlan);

    if (matcher.find()) { //statement with annotation name set to false, is already in the plan; In that case, false will be replaced with true.

        //finding the whitespaces given by the user before "@Plan:name()" statement and prepending those at replacement.
        String[] matchSplitArray = matcher.group().split(EventProcessorConstants.ANNOTATION_TOKEN_AT);
        String whitespaces = "";
        if (matchSplitArray.length > 1) {
            whitespaces += matchSplitArray[0];
        }

        replacement = whitespaces + replacement;
        newExecutionPlan = matcher.replaceFirst(replacement);

    } else { //statement with annotation name is not there in the plan; it'll be inserted.
        String[] planHeaderArray = executionPlan.split(EventProcessorConstants.SIDDHI_LINE_SEPARATER);
        for (int i = 0; i < planHeaderArray.length; i++) {
            if (planHeaderArray[i].matches(planHeaderLineRegex)) {
                if (planHeaderArray[i].matches(EventProcessorConstants.END_OF_PLAN_HEADER_COMMENT_REGEX)) {
                    break;
                }
                planHeader += planHeaderArray[i] + EventProcessorConstants.SIDDHI_LINE_SEPARATER;
            } else {
                break;
            }
        }
        planBody = executionPlan.replace(planHeader, "");
        newExecutionPlan = planHeader + replacement + EventProcessorConstants.SIDDHI_LINE_SEPARATER
                + EventProcessorConstants.SIDDHI_LINE_SEPARATER + planBody;
    }
    return newExecutionPlan;
}

From source file:fusion.Fusion.java

private static void parseINAData() throws FileNotFoundException, IOException {
    try (Scanner scanner = new Scanner(new File("dataINA/dataset_novideoperson.ttl"))
            .useDelimiter(Pattern.compile("^\\s*$", Pattern.MULTILINE))) {
        // On parcourt le fichier avec les donnees
        while (scanner.hasNext()) {
            String token = scanner.next();
            String propName = "";
            String propValue = "";
            token = new String(token.trim().getBytes(), Charset.forName("UTF-8"));

            // for (Integer name: distinctURLs.keySet()){
            // String value = new String(distinctURLs.get(name).getBytes(),
            // Charset.forName("UTF-8"));
            for (URI name : instances.keySet()) {
                Instance inst = instances.get(name); // Moins optimise que
                // de parcourir les
                // distinctURLs ?
                URI value = inst.getUri();
                if (token.contains(value.toString())) { // le scanner lit l'URL
                    try (Scanner scannerToken = new Scanner(token)) {
                        while (scannerToken.hasNextLine()) {
                            String line = scannerToken.nextLine();
                            line = line.trim();
                            // properties start with "notice:"
                            if (line.startsWith("notice")) {
                                if (line.contains(" ")) {
                                    propName = line.substring(7, line.indexOf(" "));
                                    propValue = line.substring(line.indexOf(" ")).trim().replaceAll("\\s+",
                                            " ");

                                    // Instance inst = instances.get(value);

                                    // add property in map if it doesn't
                                    // exist
                                    Property prop;
                                    if (!inst.containsProperty(propName)) {
                                        prop = new Property(propName);
                                        inst.addToProperties(prop);
                                    } else
                                        prop = inst.getProperty(propName);

                                    // get datatype values
                                    if (propValue.startsWith("\"")) {
                                        propValue = StringUtils.removeStart(propValue, "\"");
                                        propValue = StringUtils.substringBeforeLast(propValue, "\"");
                                        Value val = new Value(propValue);
                                        if (value.toString().contains("dbpedia")) {
                                            val.setSource(sources.get("fr.dbpedia.org"));
                                        } else {
                                            val.setSource(sources.get("www.ina.fr"));
                                        }

                                        if (!prop.containsValue(propValue)) //
                                            prop.addToValues(val);

                                    }/*www. j av a 2s .c  o  m*/
                                }

                                //   System.out.println("=== "+line);
                            } // LineStarts(notice)
                              // System.out.println("*** "+line);
                        }
                    }
                }
            }
        }
    }
}

From source file:org.parosproxy.paros.db.paros.ParosTableHistory.java

@Override
public List<Integer> getHistoryList(long sessionId, int histType, String filter, boolean isRequest)
        throws DatabaseException {
    try {/*  w ww .j a v  a2s  .  c  o  m*/
        PreparedStatement psReadSearch = getConnection().prepareStatement("SELECT * FROM HISTORY WHERE "
                + SESSIONID + " = ? AND " + HISTTYPE + " = ? ORDER BY " + HISTORYID);
        ResultSet rs = null;
        Vector<Integer> v = new Vector<>();
        try {

            Pattern pattern = Pattern.compile(filter, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
            Matcher matcher = null;

            psReadSearch.setLong(1, sessionId);
            psReadSearch.setInt(2, histType);
            rs = psReadSearch.executeQuery();
            while (rs.next()) {
                if (isRequest) {
                    matcher = pattern.matcher(rs.getString(REQHEADER));
                    if (matcher.find()) {
                        // ZAP: Changed to use the method Integer.valueOf.
                        v.add(Integer.valueOf(rs.getInt(HISTORYID)));
                        continue;
                    }
                    matcher = pattern.matcher(rs.getString(REQBODY));
                    if (matcher.find()) {
                        // ZAP: Changed to use the method Integer.valueOf.
                        v.add(Integer.valueOf(rs.getInt(HISTORYID)));
                        continue;
                    }
                } else {
                    matcher = pattern.matcher(rs.getString(RESHEADER));
                    if (matcher.find()) {
                        // ZAP: Changed to use the method Integer.valueOf.
                        v.add(Integer.valueOf(rs.getInt(HISTORYID)));
                        continue;
                    }
                    matcher = pattern.matcher(rs.getString(RESBODY));
                    if (matcher.find()) {
                        // ZAP: Changed to use the method Integer.valueOf.
                        v.add(Integer.valueOf(rs.getInt(HISTORYID)));
                        continue;
                    }
                }

            }
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {
                    // Ignore
                }
            }
            psReadSearch.close();
        }

        return v;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}

From source file:org.olat.core.util.i18n.I18nManager.java

/**
 * Find all i18n items that contain a given search string in their value. The
 * search string can contain '*' as a wild-card
 * //  w  w w .  j a v a2s.  com
 * @param searchString The search string, case-insensitive. * are treated as
 *          wild-cards
 * @param searchLocale The locale where to search
 * @param targetLocale The locale that should be used as result target
 * @param limitToBundleName The name of a bundle in which the keys should be
 *          searched or NULL to search in all bundles
 * @param includeBundlesChildren true: also find the keys in the bundles
 *          children; false: find only the keys in the exact bundle name. When
 *          limitToBundeName is set to NULL the includeBundlesChildren will
 *          always be set to true
 * @return List of i18n items
 */
public List<I18nItem> findI18nItemsByValueSearch(String searchString, Locale searchLocale, Locale targetLocale,
        String limitToBundleName, boolean includeBundlesChildren) {
    List<String> allBundles = I18nModule.getBundleNamesContainingI18nFiles();
    List<I18nItem> foundTranslationItems = new LinkedList<I18nItem>();
    searchString = searchString.toLowerCase();
    String[] parts = searchString.split("\\*");
    // Build pattern
    String regexpSearchString = "^.*";
    for (String part : parts) {
        regexpSearchString += Pattern.quote(part) + ".*";
    }
    regexpSearchString += "$";
    Pattern p = Pattern.compile(regexpSearchString, Pattern.MULTILINE);
    // Search in all bundles and keys for that pattern
    for (String bundleName : allBundles) {
        if (limitToBundleName == null || limitToBundleName.equals(bundleName)
                || (includeBundlesChildren && bundleName.startsWith(limitToBundleName))) {
            Properties properties = getResolvedProperties(searchLocale, bundleName);
            Properties metadataProperties = getPropertiesWithoutResolvingRecursively(null, bundleName);
            int bundlePriority = getBundlePriority(bundleName);
            for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                String value = (String) entry.getValue();
                Matcher m = p.matcher(value.toLowerCase());
                if (m.find()) {
                    String key = (String) entry.getKey();
                    int keyPriority = getKeyPriority(metadataProperties, key, bundleName);
                    I18nItem i18nItem = new I18nItem(bundleName, key, targetLocale, bundlePriority,
                            keyPriority);
                    foundTranslationItems.add(i18nItem);
                }
            }
        }
    }
    return foundTranslationItems;
}

From source file:gtu._work.ui.JSFMakerUI.java

void resetPasteClipboardHtmlToJtable() {
    String content = ClipboardUtil.getInstance().getContents();
    Pattern tdStartPattern = Pattern.compile("<[tT][dDhH][^>]*>");
    Pattern tdEndPattern = Pattern.compile("</[tT][dDhH]>");
    Pattern innerPattern_HasTag = Pattern.compile("<[\\w:]+\\s[^>]*value=\"([^\"]*)\"[^>]*>",
            Pattern.MULTILINE);
    Matcher innerMatcher = null;/*from   w  w  w  .j a  v  a2s . c  om*/
    Scanner scan = new Scanner(content);
    Scanner tdScan = null;
    String currentContent = null;
    String tdContent = null;
    StringBuilder sb = new StringBuilder();
    scan.useDelimiter("<tr>");
    for (; scan.hasNext();) {
        boolean anyMatcher = false;

        tdScan = new Scanner(scan.next());
        tdScan.useDelimiter(tdStartPattern);
        while (tdScan.hasNext()) {
            tdScan.useDelimiter(tdEndPattern);
            if (tdScan.hasNext()) {
                tdContent = tdScan.next().replaceAll(tdStartPattern.pattern(), "");
                {
                    innerMatcher = innerPattern_HasTag.matcher(tdContent.toString());
                    if (innerMatcher.find()) {
                        currentContent = StringUtils.defaultIfEmpty(innerMatcher.group(1), "&nbsp;");
                        //                            System.out.format("1[%s]\n", currentContent);
                        sb.append(currentContent + "\t");
                        continue;
                    }
                    currentContent = tdContent.toString().replaceAll("<[\\w:=,.#;/'?\"\\s\\{\\}\\(\\)\\[\\]]+>",
                            "");
                    currentContent = currentContent.replaceAll("[\\s\t\n]", "");
                    currentContent = StringUtils.defaultIfEmpty(currentContent, "&nbsp;");
                    //                        System.out.format("2[%s]\n", currentContent);
                    sb.append(currentContent + "\t");
                    anyMatcher = true;
                }
            }
            tdScan.useDelimiter(tdStartPattern);
        }
        if (anyMatcher) {
            sb.append("\n");
        }
    }
    scan.close();
    ClipboardUtil.getInstance().setContents(sb);
    System.out.println("####################################");
    System.out.println(sb);
    System.out.println("####################################");
}

From source file:wjhk.jupload2.policies.DefaultUploadPolicy.java

/**
 * The default behavior (see {@link DefaultUploadPolicy}) is to check that
 * the stringUploadSuccess applet parameter is present in the response from
 * the server. The return is tested, in the order below: <DIR> <LI>False, if
 * the stringUploadError is found. An error message is then displayed. <LI>
 * True, if the stringUploadSuccess is null or empty (no test at all). <LI>
 * True, if the stringUploadSuccess string is present in the
 * serverOutputBody. <LI>True, If previous condition is not filled, but the
 * HTTP header "HTTP(.*)200OK$" is present: the test is currently non
 * blocking, because I can not test all possible HTTP configurations.<BR>
 * <LI>False if the previous conditions are not fullfilled. </DIR> <BR>
 * This method also looks for the stringUploadWarning regular expression.
 * Each time it is matched, the found message is displayed to the user.
 * /*from   w ww .j a v  a 2 s . c o  m*/
 * @param status
 *            The HTTP response code
 * @param msg
 *            The status message from the first line of the response (e.g.
 *            "200 OK").
 * @param body
 *            The body of the HTTP answer.
 * @return True or False, indicating if the upload is a success or not.
 * @see UploadPolicy#checkUploadSuccess(int, String, String)
 */
public boolean checkUploadSuccess(int status, String msg, String body) throws JUploadException {
    boolean bReturn = false;

    if (getDebugLevel() > 100) {
        // Let's have a little time to check the upload messages written on
        // the progress bar.
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
        }
    }

    this.lastResponseBody = body;
    this.lastResponseMessage = msg;
    displayDebug("HTTP status: " + msg, 30);
    // HTTP-100 correction, thanks to Marc Reidy
    if ((status != 200) && (status != 100))
        throw new JUploadExceptionUploadFailed("Received HTTP status " + msg);

    // HTTP-100 "continue", in case we're uploading
    // to an ASP.NET development server. We should
    // continue sending...
    if (status == 100)
        return true;

    // Let's analyze the body returned, line by line. The end of line
    // character may be CR, LF, or CRLF. We navigate through the body, and
    // replace any end of line character by a uniform CRLF.
    Matcher matcherError, matcherWarning;
    String line;
    Pattern p = Pattern.compile("[\\r\\n]", Pattern.MULTILINE);
    String[] lines = p.split(body);
    StringBuffer sbBodyWithUniformCRLF = new StringBuffer(body.length());
    for (int i = 0; i < lines.length; i += 1) {
        line = lines[i];
        sbBodyWithUniformCRLF.append(line).append("\r\n");

        boolean bStatus = true;
        List<Map<String, String>> uploads = null;
        try {
            JSONArray jsonArray = new JSONArray(line);
            uploads = new ArrayList<Map<String, String>>(jsonArray.length());
            for (int j = 0; j < jsonArray.length(); j++) {
                JSONObject jsonObj = jsonArray.getJSONObject(j);
                Map<String, String> map = new HashMap<String, String>();
                String[] names = JSONObject.getNames(jsonObj);
                for (String name : names)
                    map.put(name, jsonObj.getString(name));
                uploads.add(map);
                if (!"SUCCESS".equals(map.get("status"))) {
                    bStatus = false;
                } else {
                    System.out.println("Upload of " + map.get("name") + " completed successfully");
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        // FIXME some empty lines are given by the server
        // Let's remove the empty line: with the p pattern, a multiline is
        // generated each time a \r\n is received, that is: for each line.
        if (line == null || line.equals("")) {
            // An empty line. Let's go the next line.
            continue;
        }

        // Check if this is a success
        // The success string should be in the http body
        if (getStringUploadSuccess() != null && !getStringUploadSuccess().equals("")) {
            if (this.patternSuccess.matcher(line).matches()) {
                // We go on. There may be some WARNING message, hereafter.
                bReturn = true;
            }
        }
        if (bStatus)
            bReturn = true;

        // Check if this is an error
        if (getStringUploadError() != null && !getStringUploadError().equals("")) {
            matcherError = this.patternError.matcher(line);
            if (matcherError.matches()) {
                String errmsg = "An error occurs during upload (but the applet couldn't find the error message)";
                if (matcherError.groupCount() > 0) {
                    if (!matcherError.group(1).equals("")) {
                        // Let's do a (very simple) formatting: one line to
                        // 100 characters
                        errmsg = formatMessage(matcherError.group(1));
                    }
                }
                this.lastResponseMessage = errmsg;
                throw new JUploadExceptionUploadFailed(errmsg);
            }
        } // getStringUploadError

        // Check if this is an warning
        if (getStringUploadWarning() != null && !getStringUploadWarning().equals("")) {
            matcherWarning = this.patternWarning.matcher(line);
            if (matcherWarning.matches()) {
                String warnmsg = "A warning occurs during upload (but the applet couldn't find the warning message)";
                if (matcherWarning.groupCount() > 0) {
                    if (!matcherWarning.group(1).equals("")) {
                        warnmsg = formatMessage(matcherWarning.group(1));
                    }
                }
                this.lastResponseMessage = warnmsg;
                displayWarn(warnmsg);
                alertStr(warnmsg);
            }
        } // getStringUploadWarning

    } // while(st.hasMoreTokens())

    if (bReturn) {
        return true;
    }

    // We found no stringUploadSuccess nor stringUploadError
    if (getStringUploadSuccess() == null || getStringUploadSuccess().equals("")) {
        // No chance to check the correctness of this upload. -> Assume Ok
        return true;
    }

    // stringUploadSuccess was defined but we did not find it.
    // This is most certainly an error as http-status 200 does *not* refer
    // to the correctness of the content. It merely means that the protocol
    // handling was ok. -> throw an exception
    throw new JUploadExceptionUploadFailedSuccessNotFound(
            getClass().getName() + ".checkUploadSuccess(): The regexp string \"" + getStringUploadSuccess()
                    + "\" was not found in the response body");
}

From source file:org.voltdb.regressionsuites.RegressionSuite.java

static protected void verifyProcFails(Client client, String expectedPattern, String storedProc, Object... args)
        throws IOException {

    String what;//from  w  ww .j a  va2s .com
    if (storedProc.compareTo("@AdHoc") == 0) {
        what = "the statement \"" + args[0] + "\"";
    } else {
        what = "the stored procedure \"" + storedProc + "\"";
    }

    try {
        client.callProcedure(storedProc, args);
    } catch (ProcCallException pce) {
        String msg = pce.getMessage();
        String diagnostic = "Expected " + what + " to throw an exception matching the pattern \""
                + expectedPattern + "\", but instead it threw an exception containing \"" + msg + "\".";
        Pattern pattern = Pattern.compile(expectedPattern, Pattern.MULTILINE);
        assertTrue(diagnostic, pattern.matcher(msg).find());
        return;
    }

    String diagnostic = "Expected " + what + " to throw an exception matching the pattern \"" + expectedPattern
            + "\", but instead it threw nothing.";
    fail(diagnostic);
}

From source file:de.geeksfactory.opacclient.apis.Bibliotheca.java

@Override
public ReservationResult reservation(DetailledItem item, Account acc, int useraction, String selection)
        throws IOException {
    String reservation_info = item.getReservation_info();

    Document doc = null;/*  w  w  w .ja va 2s  .c o  m*/

    if (useraction == MultiStepResult.ACTION_CONFIRMATION) {
        List<NameValuePair> nameValuePairs = new ArrayList<>(2);
        nameValuePairs.add(new BasicNameValuePair("make_allvl", "Bestaetigung"));
        nameValuePairs.add(new BasicNameValuePair("target", "makevorbest"));
        httpPost(opac_url + "/index.asp", new UrlEncodedFormEntity(nameValuePairs), getDefaultEncoding());
        return new ReservationResult(MultiStepResult.Status.OK);
    } else if (selection == null || useraction == 0) {
        String html = httpGet(opac_url + "/" + reservation_info, getDefaultEncoding());
        doc = Jsoup.parse(html);

        if (doc.select("input[name=AUSWEIS]").size() > 0) {
            // Needs login
            List<NameValuePair> nameValuePairs = new ArrayList<>(2);
            nameValuePairs.add(new BasicNameValuePair("AUSWEIS", acc.getName()));
            nameValuePairs.add(new BasicNameValuePair("PWD", acc.getPassword()));
            if (data.has("db")) {
                try {
                    nameValuePairs.add(new BasicNameValuePair("vkontodb", data.getString("db")));
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            nameValuePairs.add(new BasicNameValuePair("B1", "weiter"));
            nameValuePairs.add(new BasicNameValuePair("target", doc.select("input[name=target]").val()));
            nameValuePairs.add(new BasicNameValuePair("type", "VT2"));
            html = httpPost(opac_url + "/index.asp", new UrlEncodedFormEntity(nameValuePairs),
                    getDefaultEncoding());
            doc = Jsoup.parse(html);
        }
        if (doc.select("select[name=" + branch_inputfield + "]").size() == 0) {
            if (doc.select("select[name=VZST]").size() > 0) {
                branch_inputfield = "VZST";
            }
        }
        if (doc.select("select[name=" + branch_inputfield + "]").size() > 0) {
            List<Map<String, String>> branches = new ArrayList<>();
            for (Element option : doc.select("select[name=" + branch_inputfield + "]").first().children()) {
                String value = option.text().trim();
                String key;
                if (option.hasAttr("value")) {
                    key = option.attr("value");
                } else {
                    key = value;
                }
                Map<String, String> selopt = new HashMap<>();
                selopt.put("key", key);
                selopt.put("value", value);
                branches.add(selopt);
            }
            _res_target = doc.select("input[name=target]").attr("value");
            ReservationResult result = new ReservationResult(MultiStepResult.Status.SELECTION_NEEDED);
            result.setActionIdentifier(ReservationResult.ACTION_BRANCH);
            result.setSelection(branches);
            return result;
        }
    } else if (useraction == ReservationResult.ACTION_BRANCH) {
        List<NameValuePair> nameValuePairs = new ArrayList<>(2);
        nameValuePairs.add(new BasicNameValuePair(branch_inputfield, selection));
        nameValuePairs.add(new BasicNameValuePair("button2", "weiter"));
        nameValuePairs.add(new BasicNameValuePair("target", _res_target));
        String html = httpPost(opac_url + "/index.asp", new UrlEncodedFormEntity(nameValuePairs),
                getDefaultEncoding());
        doc = Jsoup.parse(html);
    }

    if (doc == null) {
        return new ReservationResult(MultiStepResult.Status.ERROR);
    }

    if (doc.select("input[name=target]").size() > 0) {
        if (doc.select("input[name=target]").attr("value").equals("makevorbest")) {
            List<String[]> details = new ArrayList<>();

            if (doc.getElementsByClass("kontomeldung").size() == 1) {
                details.add(new String[] { doc.getElementsByClass("kontomeldung").get(0).text().trim() });
            }
            Pattern p = Pattern.compile("geb.hr", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
            for (Element div : doc.select(".kontozeile_center")) {
                for (String text : Jsoup.parse(div.html().replaceAll("(?i)<br[^>]*>", "br2n")).text()
                        .split("br2n")) {
                    if (p.matcher(text).find() && !text.contains("usstehend")
                            && text.contains("orbestellung")) {
                        details.add(new String[] { text.trim() });
                    }
                }
            }

            if (doc.select("#vorbest").size() > 0 && doc.select("#vorbest").val().contains("(")) {
                // Erlangen uses "Kostenpflichtige Vorbestellung (1 Euro)"
                // as the label of its reservation button
                details.add(new String[] { doc.select("#vorbest").val().trim() });
            }

            for (Element row : doc.select(".kontozeile_center table tr")) {
                if (row.select(".konto_feld").size() == 1 && row.select(".konto_feldinhalt").size() == 1) {
                    details.add(new String[] { row.select(".konto_feld").text().trim(),
                            row.select(".konto_feldinhalt").text().trim() });
                }
            }
            ReservationResult result = new ReservationResult(MultiStepResult.Status.CONFIRMATION_NEEDED);
            result.setDetails(details);
            return result;
        }
    }

    if (doc.getElementsByClass("kontomeldung").size() == 1) {
        return new ReservationResult(MultiStepResult.Status.ERROR,
                doc.getElementsByClass("kontomeldung").get(0).text());
    }

    return new ReservationResult(MultiStepResult.Status.ERROR,
            stringProvider.getString(StringProvider.UNKNOWN_ERROR));
}