Example usage for org.dom4j Node setText

List of usage examples for org.dom4j Node setText

Introduction

In this page you can find the example usage for org.dom4j Node setText.

Prototype

void setText(String text);

Source Link

Document

Sets the text data of this node or this method will throw an UnsupportedOperationException if it is read-only.

Usage

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

/** Looks for variables of type: ${http_repo*} in REPO_URL property and replaces it. Example:
  *    <repositories>//from  www .j  a  v  a  2s. c o  m
  *        <repository id="repo-id" name="tw-repo">
  *          <pluginConfiguration id="yum" version="1"/>
  *          <configuration>
  *            <property>
  *              <key>REPO_URL</key>
  *              <value>http://192.168.0.101:8081/${http_repo1}</value>
  *            </property>
  *
  *     TO
  *
  *    <repositories>
  *        <repository id="repo-id" name="tw-repo">
  *          <pluginConfiguration id="yum" version="1"/>
  *          <configuration>
  *            <property>
  *              <key>REPO_URL</key>
  *              <value>http://192.168.0.101:8081/pkgrepo-RANDOM1234</value>
  *            </property>
  *
  *      AND return a map which contains: {"http_repo1" => "pkgrepo-RANDOM1234"}
 */
public Map<String, String> replacePackageRepositoryURIForHttpBasedRepos(Map<String, String> currentRepoNames) {
    Pattern httpRepoNameVariablePattern = Pattern.compile("\\$\\{(http_repo[^\\}]*)\\}");
    Map<String, String> httpRepoNameInConfigToItsNameAtRuntime = new HashMap<String, String>(currentRepoNames);

    List<Element> allRepoUrlPropertyKeys = root()
            .selectNodes("/cruise//repositories/repository/configuration/property/key[text()='REPO_URL']");
    for (Element repoUrlKeyElement : allRepoUrlPropertyKeys) {
        Node repoUrlPropertyInConfig = repoUrlKeyElement.getParent().selectSingleNode("value");
        String existingValueOfRepoUrl = repoUrlPropertyInConfig.getText();

        Matcher matcherForVariable = httpRepoNameVariablePattern.matcher(existingValueOfRepoUrl);
        if (matcherForVariable.find()) {
            String variableName = matcherForVariable.group(1);

            String replacementRepoName = httpRepoNameInConfigToItsNameAtRuntime.get(variableName);
            if (!httpRepoNameInConfigToItsNameAtRuntime.containsKey(variableName)) {
                replacementRepoName = "pkgrepo-" + RandomStringUtils.randomAlphanumeric(10);
                httpRepoNameInConfigToItsNameAtRuntime.put(variableName, replacementRepoName);
            }

            String replacementRepoURL = existingValueOfRepoUrl
                    .replaceFirst(httpRepoNameVariablePattern.pattern(), replacementRepoName);
            repoUrlPropertyInConfig.setText(replacementRepoURL);
        }
    }

    return httpRepoNameInConfigToItsNameAtRuntime;
}

From source file:com.xebia.mojo.dashboard.reports.html.CloverDashboardReport.java

License:Apache License

private void changeImageSrc(MavenProject subProject, Node node) throws MojoExecutionException {
    List list = xmlUtil.findNodes(node, ".//img");

    for (int i = 0; i < list.size(); i++) {
        Node aNode = (Node) list.get(i);

        if (aNode instanceof Element) {
            Element anElement = (Element) aNode;
            Node srcAtt = anElement.attribute("src");
            srcAtt.setText(DashboardUtil.determineCompletePath(subProject) + "clover/" + srcAtt.getText());
        }/*from  w  w w  .  j ava 2  s .com*/
    }
}

From source file:com.zg.action.admin.InstallAction.java

public String save() throws URISyntaxException, IOException, DocumentException {
    if (isInstalled()) {
        return ajaxJsonErrorMessage("SHOP++?????");
    }//from   w  w w . ja  va 2 s .co  m
    if (StringUtils.isEmpty(databaseHost)) {
        return ajaxJsonErrorMessage("?!");
    }
    if (StringUtils.isEmpty(databasePort)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(databaseUsername)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(databasePassword)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(databaseName)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(adminUsername)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(adminPassword)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(installStatus)) {
        Map<String, String> jsonMap = new HashMap<String, String>();
        jsonMap.put(STATUS, "requiredCheckFinish");
        return ajaxJson(jsonMap);
    }

    String jdbcUrl = "jdbc:mysql://" + databaseHost + ":" + databasePort + "/" + databaseName
            + "?useUnicode=true&characterEncoding=UTF-8";
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        // ?
        connection = DriverManager.getConnection(jdbcUrl, databaseUsername, databasePassword);
        DatabaseMetaData databaseMetaData = connection.getMetaData();
        String[] types = { "TABLE" };
        resultSet = databaseMetaData.getTables(null, databaseName, "%", types);
        if (StringUtils.equalsIgnoreCase(installStatus, "databaseCheck")) {
            Map<String, String> jsonMap = new HashMap<String, String>();
            jsonMap.put(STATUS, "databaseCheckFinish");
            return ajaxJson(jsonMap);
        }

        // ?
        if (StringUtils.equalsIgnoreCase(installStatus, "databaseCreate")) {
            StringBuffer stringBuffer = new StringBuffer();
            BufferedReader bufferedReader = null;
            String sqlFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI()
                    .getPath() + SQL_INSTALL_FILE_NAME;
            bufferedReader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(sqlFilePath), "UTF-8"));
            String line = "";
            while (null != line) {
                line = bufferedReader.readLine();
                stringBuffer.append(line);
                if (null != line && line.endsWith(";")) {
                    System.out.println("[SHOP++?]SQL: " + line);
                    preparedStatement = connection.prepareStatement(stringBuffer.toString());
                    preparedStatement.executeUpdate();
                    stringBuffer = new StringBuffer();
                }
            }
            String insertAdminSql = "INSERT INTO `admin` VALUES ('402881862bec2a21012bec2bd8de0003','2010-10-10 0:0:0','2010-10-10 0:0:0','','admin@shopxx.net',b'1',b'0',b'0',b'0',NULL,NULL,0,NULL,'?','"
                    + DigestUtils.md5Hex(adminPassword) + "','" + adminUsername + "');";
            String insertAdminRoleSql = "INSERT INTO `admin_role` VALUES ('402881862bec2a21012bec2bd8de0003','402881862bec2a21012bec2b70510002');";
            preparedStatement = connection.prepareStatement(insertAdminSql);
            preparedStatement.executeUpdate();
            preparedStatement = connection.prepareStatement(insertAdminRoleSql);
            preparedStatement.executeUpdate();
        }
    } catch (SQLException e) {
        e.printStackTrace();
        return ajaxJsonErrorMessage("???!");
    } finally {
        try {
            if (resultSet != null) {
                resultSet.close();
                resultSet = null;
            }
            if (preparedStatement != null) {
                preparedStatement.close();
                preparedStatement = null;
            }
            if (connection != null) {
                connection.close();
                connection = null;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    // ???
    String configFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath()
            + JDBC_CONFIG_FILE_NAME;
    Properties properties = new Properties();
    properties.put("jdbc.driver", "com.mysql.jdbc.Driver");
    properties.put("jdbc.url", jdbcUrl);
    properties.put("jdbc.username", databaseUsername);
    properties.put("jdbc.password", databasePassword);
    properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    properties.put("hibernate.show_sql", "false");
    properties.put("hibernate.format_sql", "false");
    OutputStream outputStream = new FileOutputStream(configFilePath);
    properties.store(outputStream, JDBC_CONFIG_FILE_DESCRIPTION);
    outputStream.close();

    // ??
    String backupWebConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI()
            .getPath() + BACKUP_WEB_CONFIG_FILE_NAME;
    String backupApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader()
            .getResource("").toURI().getPath() + BACKUP_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String backupCompassApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader()
            .getResource("").toURI().getPath() + BACKUP_COMPASS_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String backupSecurityApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader()
            .getResource("").toURI().getPath() + BACKUP_SECURITY_APPLICATION_CONTEXT_CONFIG_FILE_NAME;

    String webConfigFilePath = new File(
            Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath()).getParent() + "/"
            + WEB_CONFIG_FILE_NAME;
    String applicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("")
            .toURI().getPath() + APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String compassApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader()
            .getResource("").toURI().getPath() + COMPASS_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String securityApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader()
            .getResource("").toURI().getPath() + SECURITY_APPLICATION_CONTEXT_CONFIG_FILE_NAME;

    FileUtils.copyFile(new File(backupWebConfigFilePath), new File(webConfigFilePath));
    FileUtils.copyFile(new File(backupApplicationContextConfigFilePath),
            new File(applicationContextConfigFilePath));
    FileUtils.copyFile(new File(backupCompassApplicationContextConfigFilePath),
            new File(compassApplicationContextConfigFilePath));
    FileUtils.copyFile(new File(backupSecurityApplicationContextConfigFilePath),
            new File(securityApplicationContextConfigFilePath));

    // ??
    //String systemConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + SystemConfigUtils.CONFIG_FILE_NAME;
    File systemConfigFile = new File(
            ConfigurationManager.getConfigProperties(SystemConfigUtils.CONFIG_FILE_PATH_NAME));
    SAXReader saxReader = new SAXReader();
    Document document = saxReader.read(systemConfigFile);
    Element rootElement = document.getRootElement();
    Element systemConfigElement = rootElement.element("systemConfig");
    Node isInstalledNode = document.selectSingleNode("/shopxx/systemConfig/isInstalled");
    if (isInstalledNode == null) {
        isInstalledNode = systemConfigElement.addElement("isInstalled");
    }
    isInstalledNode.setText("true");
    try {
        OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML?
        outputFormat.setEncoding("UTF-8");// XML?
        outputFormat.setIndent(true);// ?
        outputFormat.setIndent("   ");// TAB?
        outputFormat.setNewlines(true);// ??
        XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(systemConfigFile), outputFormat);
        xmlWriter.write(document);
        xmlWriter.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ajaxJsonSuccessMessage("SHOP++?????");
}

From source file:com.zuuyii.action.admin.InstallAction.java

public String save() throws URISyntaxException, IOException, DocumentException {
    if (isInstalled()) {
        return ajaxJsonErrorMessage("SHOP++?????");
    }/*from  w  w  w .j  a  va2  s  . co m*/
    if (StringUtils.isEmpty(databaseHost)) {
        return ajaxJsonErrorMessage("?!");
    }
    if (StringUtils.isEmpty(databasePort)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(databaseUsername)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(databasePassword)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(databaseName)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(adminUsername)) {
        return ajaxJsonErrorMessage("???!");
    }
    if (StringUtils.isEmpty(adminPassword)) {
        return ajaxJsonErrorMessage("??!");
    }
    if (StringUtils.isEmpty(installStatus)) {
        Map<String, String> jsonMap = new HashMap<String, String>();
        jsonMap.put(STATUS, "requiredCheckFinish");
        return ajaxJson(jsonMap);
    }

    String jdbcUrl = "jdbc:mysql://" + databaseHost + ":" + databasePort + "/" + databaseName
            + "?useUnicode=true&characterEncoding=UTF-8";
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        // ?
        connection = DriverManager.getConnection(jdbcUrl, databaseUsername, databasePassword);
        DatabaseMetaData databaseMetaData = connection.getMetaData();
        String[] types = { "TABLE" };
        resultSet = databaseMetaData.getTables(null, databaseName, "%", types);
        if (StringUtils.equalsIgnoreCase(installStatus, "databaseCheck")) {
            Map<String, String> jsonMap = new HashMap<String, String>();
            jsonMap.put(STATUS, "databaseCheckFinish");
            return ajaxJson(jsonMap);
        }

        // ?
        if (StringUtils.equalsIgnoreCase(installStatus, "databaseCreate")) {
            StringBuffer stringBuffer = new StringBuffer();
            BufferedReader bufferedReader = null;
            String sqlFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI()
                    .getPath() + SQL_INSTALL_FILE_NAME;
            bufferedReader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(sqlFilePath), "UTF-8"));
            String line = "";
            while (null != line) {
                line = bufferedReader.readLine();
                stringBuffer.append(line);
                if (null != line && line.endsWith(";")) {
                    System.out.println("[SHOP++?]SQL: " + line);
                    preparedStatement = connection.prepareStatement(stringBuffer.toString());
                    preparedStatement.executeUpdate();
                    stringBuffer = new StringBuffer();
                }
            }
            String insertAdminSql = "INSERT INTO `Admin` VALUES ('402881862bec2a21012bec2bd8de0003','2010-10-10 0:0:0','2010-10-10 0:0:0','','admin@shopxx.net',b'1',b'0',b'0',b'0',NULL,NULL,0,NULL,'?','"
                    + DigestUtils.md5Hex(adminPassword) + "','" + adminUsername + "');";
            String insertAdminRoleSql = "INSERT INTO `Admin_Role` VALUES ('402881862bec2a21012bec2bd8de0003','402881862bec2a21012bec2b70510002');";
            preparedStatement = connection.prepareStatement(insertAdminSql);
            preparedStatement.executeUpdate();
            preparedStatement = connection.prepareStatement(insertAdminRoleSql);
            preparedStatement.executeUpdate();
        }
    } catch (SQLException e) {
        e.printStackTrace();
        return ajaxJsonErrorMessage("???!");
    } finally {
        try {
            if (resultSet != null) {
                resultSet.close();
                resultSet = null;
            }
            if (preparedStatement != null) {
                preparedStatement.close();
                preparedStatement = null;
            }
            if (connection != null) {
                connection.close();
                connection = null;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    // ???
    String configFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath()
            + JDBC_CONFIG_FILE_NAME;
    Properties properties = new Properties();
    properties.put("jdbc.driver", "com.mysql.jdbc.Driver");
    properties.put("jdbc.url", jdbcUrl);
    properties.put("jdbc.username", databaseUsername);
    properties.put("jdbc.password", databasePassword);
    properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    properties.put("hibernate.show_sql", "false");
    properties.put("hibernate.format_sql", "false");
    OutputStream outputStream = new FileOutputStream(configFilePath);
    properties.store(outputStream, JDBC_CONFIG_FILE_DESCRIPTION);
    outputStream.close();

    // ??
    /*String backupWebConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + BACKUP_WEB_CONFIG_FILE_NAME;
    String backupApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + BACKUP_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String backupCompassApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + BACKUP_COMPASS_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String backupSecurityApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + BACKUP_SECURITY_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
            
    String webConfigFilePath = new File(Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath()).getParent() + "/" + WEB_CONFIG_FILE_NAME;
    String applicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String compassApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + COMPASS_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
    String securityApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + SECURITY_APPLICATION_CONTEXT_CONFIG_FILE_NAME;
            
    FileUtils.copyFile(new File(backupWebConfigFilePath), new File(webConfigFilePath));
    FileUtils.copyFile(new File(backupApplicationContextConfigFilePath), new File(applicationContextConfigFilePath));
    FileUtils.copyFile(new File(backupCompassApplicationContextConfigFilePath), new File(compassApplicationContextConfigFilePath));
    FileUtils.copyFile(new File(backupSecurityApplicationContextConfigFilePath), new File(securityApplicationContextConfigFilePath));
    */
    // ??
    String systemConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI()
            .getPath() + SystemConfigUtil.CONFIG_FILE_NAME;
    File systemConfigFile = new File(systemConfigFilePath);
    SAXReader saxReader = new SAXReader();
    Document document = saxReader.read(systemConfigFile);
    Element rootElement = document.getRootElement();
    Element systemConfigElement = rootElement.element("systemConfig");
    Node isInstalledNode = document.selectSingleNode("/shopxx/systemConfig/isInstalled");
    if (isInstalledNode == null) {
        isInstalledNode = systemConfigElement.addElement("isInstalled");
    }
    isInstalledNode.setText("true");
    try {
        OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML?
        outputFormat.setEncoding("UTF-8");// XML?
        outputFormat.setIndent(true);// ?
        outputFormat.setIndent("   ");// TAB?
        outputFormat.setNewlines(true);// ??
        XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(systemConfigFile), outputFormat);
        xmlWriter.write(document);
        xmlWriter.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ajaxJsonSuccessMessage("SHOP++?????");
}

From source file:datasource.Settings.java

License:Open Source License

public void set(String Program, String Module, String Setting, String Value) {
    Node n = getSetting(Program, Module, Setting);
    if (!Value.equals(n.getText())) {
        shallSave = true;/*from w w w  .j a  v  a2s  .com*/
        n.setText(Value);
    }
}

From source file:datasource.Settings.java

License:Open Source License

public void set(String Program, String Module, String Setting, boolean Value) {
    Node n = getSetting(Program, Module, Setting);
    boolean previousValue = (n.getText().equals("true"));

    if (Value != previousValue) {
        shallSave = true;//w  w w  . java 2s.  co  m

        if (Value) {
            n.setText("true");
        } else {
            n.setText("false");
        }
    }
}

From source file:dk.netarkivet.common.utils.XmlUtils.java

License:Open Source License

/**
 * Set a XmlNode defined by the given XPath to the given value.
 *
 * @param doc the Document, which is being modified
 * @param xpath the given XPath//from  ww w.ja v a2 s  .c om
 * @param value the given value
 * @throws IOFailure If the given XPath was not found in the document
 */
public static void setNode(Document doc, String xpath, String value) {
    ArgumentNotValid.checkNotNull(doc, "Document doc");
    ArgumentNotValid.checkNotNullOrEmpty(xpath, "String xpath");
    ArgumentNotValid.checkNotNull(value, "String value");

    Node xpathNode = doc.selectSingleNode(xpath);
    if (xpathNode == null) {
        throw new IOFailure("Element '" + xpath + "' could not be found in the document '"
                + doc.getRootElement().getName() + "'!");
    }
    xpathNode.setText(value);
}

From source file:dk.netarkivet.harvester.datamodel.H1HeritrixTemplate.java

License:Open Source License

/**
 * Auxiliary method to modify the orderXMLdoc Document with respect to setting the maximum number of objects to be
 * retrieved per domain. This method updates 'group-max-fetch-success' element of the QuotaEnforcer pre-fetch
 * processor node (org.archive.crawler.frontier.BdbFrontier) with the value of the argument forceMaxObjectsPerDomain
 *
 * @param orderXMLdoc/*from w ww  .j av  a2s. c  o  m*/
 * @param forceMaxObjectsPerDomain The maximum number of objects to retrieve per domain, or 0 for no limit.
 * @throws PermissionDenied If unable to replace the frontier node of the orderXMLdoc Document
 * @throws IOFailure If the group-max-fetch-success element is not found in the orderXml. TODO The
 * group-max-fetch-success check should also be performed in TemplateDAO.create, TemplateDAO.update
 */
public static void editOrderXML_maxObjectsPerDomain(Document orderXMLdoc, long forceMaxObjectsPerDomain,
        boolean maxObjectsIsSetByQuotaEnforcer) {

    String xpath = (maxObjectsIsSetByQuotaEnforcer ? GROUP_MAX_FETCH_SUCCESS_XPATH : QUEUE_TOTAL_BUDGET_XPATH);

    Node orderXmlNode = orderXMLdoc.selectSingleNode(xpath);
    if (orderXmlNode != null) {
        orderXmlNode.setText(String.valueOf(forceMaxObjectsPerDomain));
    } else {
        throw new IOFailure("Unable to locate " + xpath + " element in order.xml: " + orderXMLdoc.asXML());
    }
}

From source file:dk.netarkivet.harvester.datamodel.H1HeritrixTemplate.java

License:Open Source License

/**
 * Activates or deactivate the quota-enforcer, depending on budget definition. Object limit can be defined either by
 * using the queue-total-budget property or the quota enforcer. Which is chosen is set by the argument
 * maxObjectsIsSetByQuotaEnforcer}'s value. So quota enforcer is set as follows:
 * <ul>/* w  w  w .j a v a2  s  . c  o m*/
 * <li>Object limit is not set by quota enforcer, disabled only if there is no byte limit.</li>
 * <li>Object limit is set by quota enforcer, so it should be enabled whether a byte or object limit is set.</li>
 * </ul>
 *
 * @param orderXMLdoc the template to modify
 * @param maxObjectsIsSetByQuotaEnforcer Decides whether the maxObjectsIsSetByQuotaEnforcer or not.
 * @param forceMaxBytesPerDomain The number of max bytes per domain enforced (can be no limit)
 * @param forceMaxObjectsPerDomain The number of max objects per domain enforced (can be no limit)
 */
public static void editOrderXML_configureQuotaEnforcer(Document orderXMLdoc,
        boolean maxObjectsIsSetByQuotaEnforcer, long forceMaxBytesPerDomain, long forceMaxObjectsPerDomain) {

    boolean quotaEnabled = true;

    if (!maxObjectsIsSetByQuotaEnforcer) {
        // Object limit is not set by quota enforcer, so it should be disabled only
        // if there is no byte limit.
        quotaEnabled = forceMaxBytesPerDomain != Constants.HERITRIX_MAXBYTES_INFINITY;

    } else {
        // Object limit is set by quota enforcer, so it should be enabled whether
        // a byte or object limit is set.
        quotaEnabled = forceMaxObjectsPerDomain != Constants.HERITRIX_MAXOBJECTS_INFINITY
                || forceMaxBytesPerDomain != Constants.HERITRIX_MAXBYTES_INFINITY;
    }

    String xpath = QUOTA_ENFORCER_ENABLED_XPATH;
    Node qeNode = orderXMLdoc.selectSingleNode(xpath);
    if (qeNode != null) {
        qeNode.setText(Boolean.toString(quotaEnabled));
    } else {
        throw new IOFailure("Unable to locate " + xpath + " element in order.xml: " + orderXMLdoc.asXML());
    }
}

From source file:dk.netarkivet.harvester.datamodel.H1HeritrixTemplate.java

License:Open Source License

@Override
public void configureQuotaEnforcer(boolean maxObjectsIsSetByQuotaEnforcer, long forceMaxBytesPerDomain,
        long forceMaxObjectsPerDomain) {
    Document orderXMLdoc = this.template;
    boolean quotaEnabled = true;

    if (!maxObjectsIsSetByQuotaEnforcer) {
        // Object limit is not set by quota enforcer, so it should be disabled only
        // if there is no byte limit.
        quotaEnabled = forceMaxBytesPerDomain != Constants.HERITRIX_MAXBYTES_INFINITY;

    } else {/*from  w  w w.  j  a  v  a 2s. com*/
        // Object limit is set by quota enforcer, so it should be enabled whether
        // a byte or object limit is set.
        quotaEnabled = forceMaxObjectsPerDomain != Constants.HERITRIX_MAXOBJECTS_INFINITY
                || forceMaxBytesPerDomain != Constants.HERITRIX_MAXBYTES_INFINITY;
    }

    String xpath = QUOTA_ENFORCER_ENABLED_XPATH;
    Node qeNode = orderXMLdoc.selectSingleNode(xpath);
    if (qeNode != null) {
        qeNode.setText(Boolean.toString(quotaEnabled));
    } else {
        throw new IOFailure("Unable to locate " + xpath + " element in order.xml: " + orderXMLdoc.asXML());
    }
}