Example usage for java.util Properties storeToXML

List of usage examples for java.util Properties storeToXML

Introduction

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

Prototype

public void storeToXML(OutputStream os, String comment) throws IOException 

Source Link

Document

Emits an XML document representing all of the properties contained in this table.

Usage

From source file:org.aludratest.cloud.impl.app.CloudManagerApplicationHolder.java

private void writePreferences(File f, Preferences prefs) {
    // compress to properties
    Properties p = new Properties();
    copyToProperties(prefs, null, p);/*from www  .  j a  v  a2  s .  c  om*/
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(f);
        p.storeToXML(fos, "AludraTest Cloud Manager auto-generated config file. DO NOT MODIFY!!");
    } catch (IOException e) {
        LOG.error("Could not write preferences file " + f.getAbsolutePath(), e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
}

From source file:ua.com.ecotep.debtprevention.AuthParamsController.java

@FXML
private void handleSaveAction(ActionEvent event) {
    if (adminName.textProperty().get().length() == 0) {
        AlertDialog.showSimpleMessage(// w ww.  jav a  2s .  co m
                "? ? `? ?  .",
                AlertDialog.ICON_INFO, currentStage);
        return;
    }
    if (databasePath.getText().length() == 0) {
        AlertDialog.showSimpleMessage("?  ?   .",
                AlertDialog.ICON_INFO, currentStage);
        return;
    }
    if ((adminPassword.getText().length() < 3)
            || (!adminPassword.getText().equals(adminPasswordCopy.getText()))) {
        AlertDialog.showSimpleMessage(
                "?  ,   ???.",
                AlertDialog.ICON_INFO, currentStage);
        return;
    }
    DataOutputStream out = null;
    try {
        ConfigEncoder ce = new ConfigEncoder();
        File file = new File("debtpreventing.xml");
        Properties properties = new Properties();

        if (!file.exists()) {
            file.createNewFile();
            properties.setProperty("serverpath",
                    new String(Base64.encodeBase64(ce.encode(databasePath.getText()))));
            properties.setProperty("user", new String(Base64.encodeBase64(ce.encode(adminName.getText()))));
            properties.setProperty("md5", new String(Base64.encodeBase64(ce.encode(adminPassword.getText()))));
            properties.storeToXML(new FileOutputStream(file), "");
        }

        mainApp.showAuthScene();
    } catch (Exception ex) {
        Logger.getLogger(AuthParamsController.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException ex) {
                Logger.getLogger(AuthParamsController.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:org.mili.ant.PropertiesReplacerImplTest.java

@Before
public void setUp() throws IOException {
    dir.delete();/*from   w w w .  j  a  v  a  2s .co  m*/
    dir.mkdirs();
    Properties props = new Properties();
    props.setProperty("st", "abbas");
    props.setProperty("xy", "8080");
    props.store(new FileOutputStream(propFile), "");

    Properties ab = new Properties();
    ab.setProperty("a0.b0", "1098");
    ab.setProperty("a1.b1", "1099");
    ab.store(new FileOutputStream(abFile), "");
    Properties cd = new Properties();
    cd.setProperty("", "");
    cd.store(new FileOutputStream(cdFile), "");
    Properties xy = new Properties();
    xy.setProperty("x0.y0", "1098");
    xy.setProperty("x1.y1", "1099");
    xy.store(new FileOutputStream(xyFile), "");
    Properties p = new Properties();
    p.setProperty("st", "abbas");
    p.setProperty("xy", "8080");
    p.storeToXML(new FileOutputStream(xmlPropFile), "");
}

From source file:org.exist.netedit.Task.java

/**
 * Store task description into FS as XML doc
 * @throws IOException/*w  w w.  j ava  2 s .c  o m*/
 */
public void store() throws IOException {
    Properties prop = new Properties();
    prop.put("download-from", downloadFrom);
    prop.put("upload-to", uploadTo);
    prop.put("file", tmp.getAbsolutePath());
    prop.put("modified", new Long(tmp.lastModified()).toString());
    File fld = netEdit.getMeta();
    if (!fld.isDirectory()) {
        fld.mkdirs();
    }
    String name = Integer.toHexString(downloadFrom.hashCode()) + ".xml";
    File meta = new File(fld, name);
    if (!meta.exists()) {
        meta.createNewFile();
    }
    FileOutputStream os = new FileOutputStream(meta);
    prop.storeToXML(os, "net-edit task description");
    os.close();
}

From source file:io.wcm.tooling.commons.contentpackagebuilder.ContentPackage.java

/**
 * Build java Properties XML file./*from  ww w  .  j  a  v a  2s  . c  om*/
 * @param path Path
 * @throws IOException
 */
private void buildPropertiesFile(String path) throws IOException {
    Properties properties = new Properties();
    properties.put("packageFormatVersion", "2");
    properties.put("requiresRoot", "false");

    for (Map.Entry<String, Object> entry : metadata.getVars().entrySet()) {
        String value = ObjectUtils.toString(entry.getValue());
        if (StringUtils.isNotEmpty(value)) {
            properties.put(entry.getKey(), value);
        }
    }

    zip.putNextEntry(new ZipEntry(path));
    try {
        properties.storeToXML(zip, null);
    } finally {
        zip.closeEntry();
    }
}

From source file:net.theblackchamber.crypto.implementations.SecurePropertiesTest.java

@Test
public void testCreateNewSecurePropertiesFromXml() {
    try {//from w w  w.  j  av  a2  s .  c o  m

        File keyfile = temporaryFolder.newFile("test.key");

        assertTrue(keyfile.exists());
        KeyConfig config = new KeyConfig(keyfile, "TEST", null, SupportedAlgorithms.AES, "aes-key");
        KeystoreUtils.generateAESSecretKey(config);

        assertTrue(FileUtils.sizeOf(keyfile) > 0);

        Properties clearProperties = new Properties();
        clearProperties.setProperty("key-path", keyfile.getPath());
        clearProperties.setProperty("entry-name", "aes-key");
        clearProperties.setProperty("keystore-password", "TEST");

        File propertiesFile = temporaryFolder.newFile("test.xml");
        OutputStream stream = new FileOutputStream(propertiesFile);
        clearProperties.storeToXML(stream, "comment");
        stream.close();
        assertTrue(propertiesFile.exists());
        assertTrue(FileUtils.sizeOf(keyfile) > 0);

        InputStream is = new FileInputStream(propertiesFile);
        SecureProperties sProperties = new SecureProperties();
        sProperties.loadFromXML(is);
        assertNotNull(sProperties);
        assertNotNull(sProperties.getProperty("entry-name"));

    } catch (Throwable t) {
        t.printStackTrace();
        fail();
    }
}

From source file:de.blinkt.openvpn.ActivityDashboard.java

@Override
protected void onCreate(android.os.Bundle savedInstanceState) {
    Log.i("ibVPN", "onCreate dashboard.");
    super.onCreate(savedInstanceState);
    // set theme by code, this will improve the speed.
    setTheme(R.style.blinkt_lolTheme);/*from  w w w.  ja  v a2s. c o  m*/
    setContentView(R.layout.mydash);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    myToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(myToolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setTitle("");
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    myToolbar.setNavigationIcon(R.drawable.ic_action_menu);
    myToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mDrawerLayout.openDrawer(Gravity.LEFT);
            //  Toast.makeText(ActivityDashboard.this, "Back clicked!",     Toast.LENGTH_SHORT).show();
            Log.d("Clicked", "drawer open");
        }
    });

    findViewById(R.id.textview_checkip).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(ActivityDashboard.this, ActivityContactUs.class);
            startActivity(intent);
        }
    });

    // Set the adapter for the list view
    //   mDrawerList.setAdapter(new ArrayAdapter<String>(this,
    //           R.layout.drawer_list_item, mDrawerTitles));
    mDrawerTitles = new ArrayList<>();
    mDrawerTitles.add(new NavDrawerItem(R.drawable.ic_action_menu, "Settings"));
    mDrawerTitles.add(new NavDrawerItem(R.drawable.ic_action_menu, "Connection Log"));
    mDrawerTitles.add(new NavDrawerItem(R.drawable.ic_action_menu, "Purchase"));
    mDrawerTitles.add(new NavDrawerItem(R.drawable.ic_action_menu, "Log out"));

    mDrawerList.setAdapter(new NavDrawerAdapter(this, R.layout.drawer_list_item, mDrawerTitles));
    //         Set the list's click listener
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    //        Log.d("toolbartitle",myToolbar.getTitle().toString());

    m_manager = ProfileManager.getInstance(this);

    //        mPager = (ViewPager) findViewById(R.id.pager);

    // new the handler here, so it will not leak.
    if (m_handler == null)
        m_handler = new ExtendHandler(this);
    else
        m_handler.setContext(this);
    m_remote = new RemoteAPI(this, m_handler);
    m_timer = new Timer();

    setStatus(Status.Disconnected);

    // get data from intent.
    final Intent intent = getIntent();
    m_username = intent.getStringExtra("username");
    m_password = intent.getStringExtra("password");
    m_userid = intent.getStringExtra("userid");

    // delete the vpn log.
    File file = new File(getCacheDir(), "vpnlog.txt");
    if (file.exists())
        file.delete();
    //TODO fix On Register
    // get package and server name.
    Log.d("m_password", m_password);
    m_remote.getUserService(m_userid, m_password);
    m_waitdlg = ProgressDialog.show(this, "Loading Servers", "Waiting for server reply...", true, false);

    TextView view2 = (TextView) findViewById(R.id.textview_serverlist);
    VpnStatus.addStateListener(this);

    // start internet checker timer, will not stop this.

    view2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(ActivityDashboard.this, ActivityServerList.class);
            intent.putExtra("userid", m_userid);
            intent.putExtra("username", m_userid);
            intent.putExtra("password", m_password);

            startActivity(i);

        }
    });
    m_timer.schedule(new NetStateCheckTask(this), 3000, 3000);
    try {
        FileInputStream fi = new FileInputStream(getFilesDir() + "/setting.xml");
        Log.d("d", "get files directory : " + getFilesDir().toString());

        Properties xml = new Properties();
        xml.loadFromXML(fi);
        String first_login = xml.getProperty("FIRST_LOGIN");
        if (first_login == null) {
            xml.setProperty("FIRST_LOGIN", String.valueOf(new Date().getTime()));
            FileOutputStream fo = new FileOutputStream(getFilesDir() + "/setting.xml");
            xml.storeToXML(fo, null);
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:org.webdavaccess.LocalFileSystemStorage.java

private void saveCustomProperties(Properties newProperties, String resourceUri) {
    if (newProperties == null || newProperties.size() == 0)
        return;//from www .  j  a  v  a  2  s .c  o m

    resourceUri = normalize(resourceUri);
    File file = getPropertiesFile(resourceUri);
    if (file == null)
        return;
    Properties persisted = new Properties();
    // Properties file exists, load it so we can add new properties
    if (file.exists()) {
        InputStream in = null;
        try {
            in = new FileInputStream(file);
            persisted.loadFromXML(in);
        } catch (Exception e) {
            log.warn("Failed to get properties from cache for " + resourceUri);
            return;
        } finally {
            if (in != null)
                try {
                    in.close();
                } catch (Exception e) {
                }
        }
    }
    // Add new properties with key format of: resourceUri + "|" + key
    Enumeration en = newProperties.keys();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        persisted.setProperty(getResourcePropertyKey(resourceUri, key), newProperties.getProperty(key));
    }
    // Store the updates properties
    OutputStream os = null;
    try {
        os = new FileOutputStream(file);
        persisted.storeToXML(os, "");
    } catch (Exception e) {
        log.warn("Failed to store properties for " + resourceUri);
    } finally {
        if (os != null)
            try {
                os.close();
            } catch (Exception e) {
            }
    }
}

From source file:de.blinkt.openvpn.ActivityDashboard.java

public void onConnect(View v) {
    Log.d("ibVPN", "getCurrentServer:" + getCurrentServer());

    if (!isInternetAvailable(this)) {
        Toast toast = Toast.makeText(this, "Network is unreachable.", Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();/*from  w ww  .  j  ava  2s .co  m*/
        return;
    }

    if (((Button) v).getText().toString().equalsIgnoreCase(getString(R.string.text_connect))) {
        setStatus(Status.Connecting);
        dicojugar = false;
        //            m_openvpn = new OpenVPN(m_handler, this);    // new it here, so cancel will not crash.
        String server = getCurrentServer();
        // get session name.
        TextView locationServer = (TextView) findViewById(R.id.view_location);
        String session = locationServer.toString();
        Log.d("Seleceted item", session);

        // connecting to server.
        String port = getProperty("PORT");
        String proto = getProperty("PROTOCOL");

        setLogin(m_username, m_password);
        setRemote(server, port == null ? "1197" : port);
        setSession(session);
        setProtocol(proto == null ? "tcp" : proto);

        //            m_openvpn.connect();    // start the service, but it is not connected.

        updateOvpnConfigFromAssets(m_server, m_port, m_proto, m_extra);

        m_vpnprofile = createVPNProfile();
        m_vpnprofile.mUsername = m_username;
        m_vpnprofile.mPassword = m_password;
        m_manager.addProfile(m_vpnprofile);
        m_manager.saveProfile(this, m_vpnprofile);
        m_manager.saveProfileList(this);

        //            gotoMainActivity();
        //            ProfileManager.updateLRU(this, m_vpnprofile);
        //            VPNLaunchHelper.startOpenVpn(m_vpnprofile, getBaseContext());

        startVPN(m_vpnprofile);
        //            permissionConnect();
        m_date = System.currentTimeMillis();
    } else if (((Button) v).getText().toString().equalsIgnoreCase(getString(R.string.text_cancel))) {
        //            m_openvpn.cancel();
        if (VpnStatus.isVPNActive()) {
            if (mService != null) {
                try {
                    mService.stopVPN(false);
                } catch (RemoteException e) {
                    VpnStatus.logException(e);
                }
            }
        }
        setStatus(Status.Disconnected);
        //mixpanelTrack("Cancel Connection", null);
    } else if (((Button) v).getText().toString().equalsIgnoreCase(getString(R.string.text_disconnect))) {
        //            .disconnect();

        if (VpnStatus.isVPNActive()) {
            if (mService != null) {
                try {
                    mService.stopVPN(false);
                } catch (RemoteException e) {
                    VpnStatus.logException(e);
                }
            }
        }
        setStatus(Status.Disconnected);
        dicojugar = true;

        String dura = formatTime(System.currentTimeMillis() - m_date);
        Log.d("ibVPN", "Session Duration: " + dura);

        JSONObject props = new JSONObject();
        mixpanelAdd(props, "Session Duration", dura);
        //mixpanelTrack("Disconnect", props);
        Log.d("ibVPN", "props: " + props);

        try {
            FileInputStream fi = new FileInputStream(getFilesDir() + "/setting.xml");
            Log.d("d", "get files directory : " + getFilesDir().toString());
            Properties xml = new Properties();
            xml.loadFromXML(fi);

            String first_login = xml.getProperty("FIRST_LOGIN");
            String first_conn = xml.getProperty("FIRST_CONNECTED");
            if (first_conn == null) {
                first_conn = String.valueOf(new Date().getTime());
                xml.setProperty("FIRST_CONNECTED", first_conn);
                FileOutputStream fo = new FileOutputStream(getFilesDir() + "/setting.xml");
                xml.storeToXML(fo, null);

                JSONObject json = new JSONObject();
                mixpanelAdd(json, "First Login Time", first_login);
                mixpanelAdd(json, "First Connected Time", first_conn);
                mixpanelAdd(json, "Accomodation Time",
                        String.valueOf(Long.parseLong(first_conn) - Long.parseLong(first_login)));
                //mixpanelTrack("Application 1st Time Connected", json);
                Log.d("ibVPN", "props: " + json);
            }
        } catch (Exception e) {
            System.out.println(e);
        }

        JSONObject logs = new JSONObject();
        mixpanelAdd(logs, "Data", loadLogFromFile());
        //mixpanelTrack("Connection Log", logs);
    }
}

From source file:org.webdavaccess.LocalFileSystemStorage.java

/**
 * Delete properties for given resource//from w  ww  .jav a  2s . c o m
 * 
 * @param resourceUri for which to delete properties
 */
public void deleteProperties(String resourceUri, Properties propertiesToDelete) {
    resourceUri = normalize(resourceUri);
    // Try cache first
    Properties props = (Properties) mPropertiesCache.get(resourceUri);
    if (props != null)
        mPropertiesCache.remove(resourceUri);
    File file = getPropertiesFile(resourceUri);
    if (file == null || !file.exists()) {
        return;
    }
    InputStream in = null;
    Properties persisted = new Properties();
    try {
        in = new FileInputStream(file);
        persisted.loadFromXML(in);
    } catch (Exception e) {
        log.warn("Failed to get properties from cache for " + resourceUri);
        return;
    } finally {
        if (in != null)
            try {
                in.close();
            } catch (Exception e) {
            }
    }
    boolean changed = false;
    Enumeration en = persisted.keys();
    HashMap toRemove = new HashMap();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        if (isResourceProperty(resourceUri, key)) {
            if (propertiesToDelete != null) {
                String newKey = getPropertyKey(resourceUri, key);
                if (propertiesToDelete.getProperty(newKey) != null)
                    toRemove.put(key, persisted.getProperty(key));
            } else {
                toRemove.put(key, persisted.getProperty(key));
            }
        }
    }
    changed = !toRemove.isEmpty();
    for (Iterator it = toRemove.keySet().iterator(); it.hasNext();) {
        String key = (String) it.next();
        persisted.remove(key);
    }
    if (changed) {
        // Store the updates properties
        OutputStream os = null;
        try {
            os = new FileOutputStream(file);
            persisted.storeToXML(os, "");
        } catch (Exception e) {
            log.warn("Failed to store properties for " + resourceUri);
        } finally {
            if (os != null)
                try {
                    os.close();
                } catch (Exception e) {
                }
        }
    }
}