Example usage for java.util Properties store

List of usage examples for java.util Properties store

Introduction

In this page you can find the example usage for java.util Properties store.

Prototype

public void store(OutputStream out, String comments) throws IOException 

Source Link

Document

Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the #load(InputStream) load(InputStream) method.

Usage

From source file:cn.com.xdays.xshop.action.admin.InstallAction.java

public String save() throws URISyntaxException, IOException, DocumentException {
    if (isInstalled()) {
        return ajaxJsonErrorMessage("SHOP++?????");
    }/*from  www . ja va2 s .  c o 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 {
        Class.forName("com.mysql.jdbc.Driver");
        // ?
        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 (Exception 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:net.sf.nmedit.nomad.core.Nomad.java

protected void storeProperties() {
    // store properties
    SystemPropertyFactory factory = SystemPropertyFactory.sharedInstance().getFactory();
    if (factory instanceof NomadPropertyFactory) {
        Properties p = ((NomadPropertyFactory) factory).getProperties();

        try {//from   w ww  .j a va2s .  c o  m
            OutputStream out = new BufferedOutputStream(new FileOutputStream(getCorePropertiesFile()));
            p.store(out, "do not edit");
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:org.eclipse.virgo.ide.runtime.internal.core.Server20Handler.java

private void createRepositoryConfiguration(IServerBehaviour serverBehaviour, String fileName) {
    // copy com.springsource.repository.properties into the stage and add the stage repository
    File serverHome = ServerUtils.getServer(serverBehaviour).getRuntimeBaseDirectory().toFile();
    Properties properties = new Properties();
    try {//from   ww w  .  j a v  a 2 s .  c  o  m
        properties.load(new FileInputStream(new File(serverHome, "config" + File.separatorChar + fileName)));
    } catch (FileNotFoundException e) {
        // TODO CD add logging
    } catch (IOException e) {
        // TODO CD add logging
    }

    properties.put("stage.type", "watched");
    properties.put("stage.watchDirectory", "stage");

    String chain = properties.getProperty("chain");
    chain = "stage" + (StringUtils.hasLength(chain) ? "," + chain : "");
    properties.put("chain", chain);

    try {
        File stageDirectory = new File(serverHome, "stage");
        if (!stageDirectory.exists()) {
            stageDirectory.mkdirs();
        }
        properties.store(new FileOutputStream(new File(serverHome, "stage" + File.separator + fileName)),
                "Generated by SpringSource dm Server Tools "
                        + ServerCorePlugin.getDefault().getBundle().getVersion());
    } catch (FileNotFoundException e) {
        // TODO CD add logging
    } catch (IOException e) {
        // TODO CD add logging
    }
}

From source file:org.gvnix.dynamic.configuration.roo.addon.config.PropertiesListDynamicConfiguration.java

/**
 * {@inheritDoc}/*from   w w w  .  j  av a  2s  .co  m*/
 */
@Override
public void write(DynPropertyList dynProps) {

    OutputStream outputStream = null;

    // Get the property files to write from resources
    String resources = pathResolver.getIdentifier(LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, ""), "");
    List<FileDetails> files = getFiles(resources);
    for (FileDetails f : files) {

        try {

            // Get properties from the file
            MutableFile file = fileManager.updateFile(f.getCanonicalPath());
            Properties props = new Properties();
            props.load(file.getInputStream());
            for (DynProperty dynProp : dynProps) {

                // If property belongs to file and exists on file, update it
                String key = getKeyValue(dynProp.getKey());
                if (isPropertyRelatedToFile(dynProp, file)) {
                    if (props.containsKey(key)) {

                        props.put(key, dynProp.getValue());

                    } else {

                        LOGGER.log(Level.WARNING, "Property key ".concat(dynProp.getKey())
                                .concat(" to put value not exists on file"));
                    }
                }
            }
            outputStream = file.getOutputStream();
            props.store(outputStream, null);

        } catch (IOException ioe) {
            throw new IllegalStateException(ioe);
        } finally {
            IOUtils.closeQuietly(outputStream);
        }
    }
}

From source file:de.akquinet.innovation.continuous.UniqueVersionMojo.java

public void updateReleaseProperties(String newVersion) throws IOException {
    Properties properties = new Properties();
    File releaseFile = new File(project.getBasedir(), "release.properties");
    if (releaseFile.exists()) {
        FileInputStream fis = new FileInputStream(releaseFile);
        properties.load(fis);//w  w w. j  av a2 s .co  m
        IOUtils.closeQuietly(fis);
    }

    properties.put("scm.tag", project.getArtifactId() + "-" + newVersion);
    String oldVersion = project.getVersion();
    // For all projects set:
    //project.rel.org.myCompany\:projectA=1.2
    //project.dev.org.myCompany\:projectA=1.3-SNAPSHOT
    for (MavenProject project : reactor) {
        properties.put("project.rel." + project.getGroupId() + ":" + project.getArtifactId(), newVersion);
        properties.put("project.dev." + project.getGroupId() + ":" + project.getArtifactId(), oldVersion);
    }

    FileOutputStream fos = new FileOutputStream(releaseFile);
    properties.store(fos, "File edited by the continuous-version-maven-plugin");
    IOUtils.closeQuietly(fos);
}

From source file:fr.fastconnect.factory.tibco.bw.maven.bwengine.AbstractServiceEngineMojo.java

private void startEngine() throws IOException, MojoExecutionException {
    Properties engineProperties = new Properties();
    engineProperties.setProperty("tibco.clientVar." + getServiceName() + "/HTTP-service-port",
            getBWEnginePort());/*from   ww  w. j  a  v a2  s  .c om*/
    engineProperties.setProperty("bw.plugin.jms.recoverOnStartupError", "true");

    //      engineProperties.setProperty("Hawk.Enabled", "true");
    //      engineProperties.setProperty("ServiceAgent.builtinResource.serviceagent.Class", "com.tibco.plugin.brp.BRPServiceAgent");
    //      engineProperties.setProperty("bw.platform.services.retreiveresources.Enabled", "true");

    // cration du fichier de proprits (charg dans le BWEngine avec l'option "-p")
    File propertyFile = new File(directory, "bwengine.properties");
    propertyFile.createNewFile();

    FileOutputStream fos = new FileOutputStream(propertyFile);
    engineProperties.store(fos, null);
    fos.close();

    // merge aliases file into the properties file of the bwengine
    File aliasesFile = new File(directory, ALIASES_FILE);
    if (aliasesFile.exists()) {
        FileUtils.write(propertyFile, FileUtils.readFileToString(aliasesFile), true);
    }

    ArrayList<String> arguments = new ArrayList<String>();
    arguments.add("-name");
    arguments.add(getServiceName() + " Web Service");
    arguments.add("-p"); // properties file
    //arguments.add("-a"); // alias file
    arguments.add(propertyFile.getAbsolutePath());
    arguments.add(getProjectToRunPath().getAbsolutePath());
    getLog().info(BWENGINE_STARTING);

    ArrayList<File> tras = new ArrayList<File>();
    tras.add(tibcoBWEngineTRAPath);

    launchTIBCOBinary(tibcoBWEnginePath, tras, arguments, directory, getServiceFailureMessage(), false, false);
}

From source file:net.sf.nmedit.nordmodular.Installer.java

private void storeSynthConfiguration(List<NordModular> synthList) {
    MidiID midiID = new MidiID();

    Properties properties = new Properties();
    properties.put("nordmodular.count", Integer.toString(synthList.size()));
    for (int i = 0; i < synthList.size(); i++) {
        String prefix = "nordmodular." + i + ".";
        NordModular synth = synthList.get(i);
        properties.put(prefix + "name", synth.getName());
        putMidiInfo(properties, prefix + "midi.in.", synth.getPCInPort().getPlug(), midiID, true);
        putMidiInfo(properties, prefix + "midi.out.", synth.getPCOutPort().getPlug(), midiID, false);
    }//w  w w.  j  av  a  2  s .  c  o m

    OutputStream out = null;

    try {
        out = new BufferedOutputStream(new FileOutputStream(getSynthPropertyFile()));

        properties.store(out, "generated file, do not edit");
    } catch (IOException e) {
        // ignore
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
}

From source file:com.kyne.webby.rtk.web.WebServer.java

public void saveBukkitConf(final String paramProperties) throws IOException {
    String decodedProperties = URLDecoder.decode(paramProperties, "UTF-8");
    FileOutputStream fos = null;/* w  w  w  .  j  a va2s  .  co m*/
    OutputStreamWriter osw = null;
    try {
        final Properties properties = new Properties();
        fos = new FileOutputStream("server.properties");
        osw = new OutputStreamWriter(fos, "UTF8");
        for (final String property : decodedProperties.split("&")) {
            final String[] propertyArray = property.split("=");
            final String key = propertyArray[0];
            if (!"dataConf".equals(key)) { //System parameter
                final String value = propertyArray.length == 2 ? propertyArray[1] : "" /* empty value */;
                properties.setProperty(key, value);
            }
        }

        properties.store(osw, "Minecraft server properties");
    } finally {
        IOUtils.closeQuietly(osw);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.spelling.io.SpellingErrorInContextEvaluator.java

@Override
public void collectionProcessComplete() throws AnalysisEngineProcessException {
    super.collectionProcessComplete();

    writeOutput(performanceCounter.getFilePerformanceOverview(Mode.detection));

    writeOutput(performanceCounter.getFilePerformanceOverview(Mode.correction));

    writeOutput(performanceCounter.getMicroPerformanceOverview(Mode.detection));
    writeOutput(performanceCounter.getMacroPerformanceOverview(Mode.detection));

    writeOutput(performanceCounter.getMicroPerformanceOverview(Mode.correction));
    writeOutput(performanceCounter.getMacroPerformanceOverview(Mode.correction));

    // write an additional properties file for easy aggregation in the lab
    if (labWriter != null) {
        Properties props = new Properties();
        props.setProperty("P-detection", String.valueOf(performanceCounter.getMicroPrecision(Mode.detection)));
        props.setProperty("R-detection", String.valueOf(performanceCounter.getMicroRecall(Mode.detection)));
        props.setProperty("F-detection", String.valueOf(performanceCounter.getMicroFMeasure(Mode.detection)));
        props.setProperty("P-correction",
                String.valueOf(performanceCounter.getMicroPrecision(Mode.correction)));
        props.setProperty("R-correction", String.valueOf(performanceCounter.getMicroRecall(Mode.correction)));
        props.setProperty("F-correction", String.valueOf(performanceCounter.getMicroFMeasure(Mode.correction)));
        try {/*from www . j  ava  2 s .  c  om*/
            props.store(labWriter, null);
        } catch (IOException e) {
            throw new AnalysisEngineProcessException(e);
        }
    }
}