Example usage for org.apache.commons.configuration XMLConfiguration setProperty

List of usage examples for org.apache.commons.configuration XMLConfiguration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration XMLConfiguration setProperty.

Prototype

public void setProperty(String key, Object value) 

Source Link

Usage

From source file:com.litt.core.security.license.gui.ConfigPanel.java

/**
 * Create the panel./*from  ww w.ja v  a  2  s . co m*/
 */
public ConfigPanel(final Gui gui) {
    GridBagLayout gbl_configPanel = new GridBagLayout();
    gbl_configPanel.columnWidths = new int[] { 0, 0, 0, 0 };
    gbl_configPanel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    gbl_configPanel.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE };
    gbl_configPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0,
            Double.MIN_VALUE };
    this.setLayout(gbl_configPanel);

    JLabel label_18 = new JLabel("?");
    GridBagConstraints gbc_label_18 = new GridBagConstraints();
    gbc_label_18.insets = new Insets(0, 0, 5, 5);
    gbc_label_18.anchor = GridBagConstraints.EAST;
    gbc_label_18.gridx = 0;
    gbc_label_18.gridy = 0;
    this.add(label_18, gbc_label_18);

    comboBox_config = new JComboBox();
    comboBox_config.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                try {
                    LicenseConfig licenseConfig = (LicenseConfig) e.getItem();
                    File licenseFile = new File(licenseConfig.getLicenseFilePath());
                    currentLicenseConfig = licenseConfig;
                    loadLicense(licenseFile);
                    gui.setCurrentLicenseConfig(currentLicenseConfig);
                } catch (Exception e1) {
                    JOptionPane.showMessageDialog(self, e1.getMessage());
                }
            }
        }
    });
    GridBagConstraints gbc_comboBox_config = new GridBagConstraints();
    gbc_comboBox_config.insets = new Insets(0, 0, 5, 5);
    gbc_comboBox_config.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBox_config.gridx = 1;
    gbc_comboBox_config.gridy = 0;
    this.add(comboBox_config, gbc_comboBox_config);

    JButton button_3 = new JButton("?");
    button_3.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {

            try {
                comboBox_config.removeAllItems();

                File configFile = new File(Gui.HOME_PATH + File.separator + "config.xml");

                Document document = XmlUtils.readXml(configFile);
                Element rootE = document.getRootElement();
                List productList = rootE.elements();
                for (int i = 0; i < productList.size(); i++) {
                    Element productE = (Element) productList.get(i);
                    String productCode = productE.attributeValue("code");

                    List customerList = productE.elements();
                    for (int j = 0; j < customerList.size(); j++) {
                        Element customerE = (Element) customerList.get(j);
                        String customerCode = customerE.attributeValue("code");

                        LicenseConfig licenseConfig = new LicenseConfig();
                        licenseConfig.setProductCode(productCode);
                        licenseConfig.setCustomerCode(customerCode);
                        licenseConfig.setLicenseId(customerE.elementText("licenseId"));
                        licenseConfig.setEncryptedLicense(customerE.elementText("encryptedLicense"));
                        licenseConfig.setRootFilePath(Gui.HOME_PATH);
                        licenseConfig.setLicenseFilePath(Gui.HOME_PATH + File.separator + productCode
                                + File.separator + customerCode + File.separator + "license.xml");
                        licenseConfig.setPriKeyFilePath(
                                Gui.HOME_PATH + File.separator + productCode + File.separator + "private.key");
                        licenseConfig.setPubKeyFilePath(
                                Gui.HOME_PATH + File.separator + productCode + File.separator + "license.key");
                        comboBox_config.addItem(licenseConfig);
                        if (i == 0 && j == 0) {
                            File licenseFile = new File(licenseConfig.getLicenseFilePath());
                            currentLicenseConfig = licenseConfig;
                            loadLicense(licenseFile);
                            gui.setCurrentLicenseConfig(currentLicenseConfig);

                            btnDelete.setEnabled(true);
                        }
                    }
                }

            } catch (Exception e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(self, e1.getMessage());
            }

        }
    });

    btnDelete = new JButton();
    btnDelete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (currentLicenseConfig != null) {
                try {
                    String productCode = currentLicenseConfig.getProductCode();
                    String customerCode = currentLicenseConfig.getCustomerCode();
                    //congfig.xml
                    File configFile = new File(Gui.HOME_PATH + File.separator + "config.xml");
                    Document document = XmlUtils.readXml(configFile);

                    Element customerNode = (Element) document.selectSingleNode(
                            "//product[@code='" + productCode + "']/customer[@code='" + customerCode + "']");
                    if (customerNode != null) {
                        customerNode.detach();
                        XmlUtils.writeXml(configFile, document);
                    }
                    //                  
                    File licensePathFile = new File(currentLicenseConfig.getLicenseFilePath());
                    if (licensePathFile.exists()) {
                        FileUtils.deleteDirectory(licensePathFile.getParentFile());
                    }

                    //comboboxitem
                    comboBox_config.removeItemAt(comboBox_config.getSelectedIndex());
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (Exception e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                if (comboBox_config.getItemCount() <= 0) {
                    btnDelete.setEnabled(false);
                }

            }
        }
    });
    btnDelete.setEnabled(false);
    btnDelete.setIcon(new ImageIcon(ConfigPanel.class.getResource("/images/icon_delete.png")));
    GridBagConstraints gbc_btnDelete = new GridBagConstraints();
    gbc_btnDelete.insets = new Insets(0, 0, 5, 0);
    gbc_btnDelete.gridx = 2;
    gbc_btnDelete.gridy = 0;
    add(btnDelete, gbc_btnDelete);
    GridBagConstraints gbc_button_3 = new GridBagConstraints();
    gbc_button_3.insets = new Insets(0, 0, 5, 5);
    gbc_button_3.gridx = 1;
    gbc_button_3.gridy = 1;
    this.add(button_3, gbc_button_3);

    JLabel lblid = new JLabel("?ID");
    GridBagConstraints gbc_lblid = new GridBagConstraints();
    gbc_lblid.anchor = GridBagConstraints.EAST;
    gbc_lblid.insets = new Insets(0, 0, 5, 5);
    gbc_lblid.gridx = 0;
    gbc_lblid.gridy = 2;
    this.add(lblid, gbc_lblid);

    textField_licenseId = new JTextField();
    GridBagConstraints gbc_textField_licenseId = new GridBagConstraints();
    gbc_textField_licenseId.insets = new Insets(0, 0, 5, 5);
    gbc_textField_licenseId.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_licenseId.gridx = 1;
    gbc_textField_licenseId.gridy = 2;
    this.add(textField_licenseId, gbc_textField_licenseId);
    textField_licenseId.setColumns(10);

    JLabel label = new JLabel("?");
    GridBagConstraints gbc_label = new GridBagConstraints();
    gbc_label.anchor = GridBagConstraints.EAST;
    gbc_label.insets = new Insets(0, 0, 5, 5);
    gbc_label.gridx = 0;
    gbc_label.gridy = 3;
    add(label, gbc_label);

    comboBox_licenseType = new JComboBox(MapComboBoxModel.getLicenseTypeOptions().toArray());
    GridBagConstraints gbc_comboBox_licenseType = new GridBagConstraints();
    gbc_comboBox_licenseType.insets = new Insets(0, 0, 5, 5);
    gbc_comboBox_licenseType.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBox_licenseType.gridx = 1;
    gbc_comboBox_licenseType.gridy = 3;
    add(comboBox_licenseType, gbc_comboBox_licenseType);

    JLabel label_23 = new JLabel("???");
    GridBagConstraints gbc_label_23 = new GridBagConstraints();
    gbc_label_23.anchor = GridBagConstraints.EAST;
    gbc_label_23.insets = new Insets(0, 0, 5, 5);
    gbc_label_23.gridx = 0;
    gbc_label_23.gridy = 4;
    this.add(label_23, gbc_label_23);

    textField_productName = new JTextField();
    GridBagConstraints gbc_textField_productName = new GridBagConstraints();
    gbc_textField_productName.insets = new Insets(0, 0, 5, 5);
    gbc_textField_productName.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_productName.gridx = 1;
    gbc_textField_productName.gridy = 4;
    this.add(textField_productName, gbc_textField_productName);
    textField_productName.setColumns(10);

    JLabel label_24 = new JLabel("???");
    GridBagConstraints gbc_label_24 = new GridBagConstraints();
    gbc_label_24.anchor = GridBagConstraints.EAST;
    gbc_label_24.insets = new Insets(0, 0, 5, 5);
    gbc_label_24.gridx = 0;
    gbc_label_24.gridy = 5;
    this.add(label_24, gbc_label_24);

    textField_companyName = new JTextField();
    GridBagConstraints gbc_textField_companyName = new GridBagConstraints();
    gbc_textField_companyName.insets = new Insets(0, 0, 5, 5);
    gbc_textField_companyName.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_companyName.gridx = 1;
    gbc_textField_companyName.gridy = 5;
    this.add(textField_companyName, gbc_textField_companyName);
    textField_companyName.setColumns(10);

    JLabel label_25 = new JLabel("??");
    GridBagConstraints gbc_label_25 = new GridBagConstraints();
    gbc_label_25.anchor = GridBagConstraints.EAST;
    gbc_label_25.insets = new Insets(0, 0, 5, 5);
    gbc_label_25.gridx = 0;
    gbc_label_25.gridy = 6;
    this.add(label_25, gbc_label_25);

    textField_customerName = new JTextField();
    GridBagConstraints gbc_textField_customerName = new GridBagConstraints();
    gbc_textField_customerName.insets = new Insets(0, 0, 5, 5);
    gbc_textField_customerName.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_customerName.gridx = 1;
    gbc_textField_customerName.gridy = 6;
    this.add(textField_customerName, gbc_textField_customerName);
    textField_customerName.setColumns(10);

    JLabel label_26 = new JLabel("");
    GridBagConstraints gbc_label_26 = new GridBagConstraints();
    gbc_label_26.anchor = GridBagConstraints.EAST;
    gbc_label_26.insets = new Insets(0, 0, 5, 5);
    gbc_label_26.gridx = 0;
    gbc_label_26.gridy = 7;
    this.add(label_26, gbc_label_26);

    textField_version = new JTextField();
    GridBagConstraints gbc_textField_version = new GridBagConstraints();
    gbc_textField_version.insets = new Insets(0, 0, 5, 5);
    gbc_textField_version.fill = GridBagConstraints.HORIZONTAL;
    gbc_textField_version.gridx = 1;
    gbc_textField_version.gridy = 7;
    this.add(textField_version, gbc_textField_version);
    textField_version.setColumns(10);

    JLabel label_27 = new JLabel("");
    GridBagConstraints gbc_label_27 = new GridBagConstraints();
    gbc_label_27.insets = new Insets(0, 0, 5, 5);
    gbc_label_27.gridx = 0;
    gbc_label_27.gridy = 8;
    this.add(label_27, gbc_label_27);

    datePicker_expiredDate = new DatePicker(new Date(), "yyyy-MM-dd", null, null);
    //datePicker_expiredDate.setTimePanleVisible(false);
    GridBagConstraints gbc_datePicker_expiredDate = new GridBagConstraints();
    gbc_datePicker_expiredDate.anchor = GridBagConstraints.WEST;
    gbc_datePicker_expiredDate.insets = new Insets(0, 0, 5, 5);
    gbc_datePicker_expiredDate.gridx = 1;
    gbc_datePicker_expiredDate.gridy = 8;
    this.add(datePicker_expiredDate, gbc_datePicker_expiredDate);

    JButton button_5 = new JButton("");
    button_5.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {

            if (currentLicenseConfig != null) {
                try {
                    File priKeyFile = new File(currentLicenseConfig.getPriKeyFilePath());
                    File licenseFile = new File(currentLicenseConfig.getLicenseFilePath());

                    //??
                    License license = new License();
                    license.setLicenseId(textField_licenseId.getText());
                    license.setLicenseType(
                            ((MapComboBoxModel) comboBox_licenseType.getSelectedItem()).getValue().toString());
                    license.setProductName(textField_productName.getText());
                    license.setCompanyName(textField_companyName.getText());
                    license.setCustomerName(textField_customerName.getText());
                    license.setVersion(Version.parseVersion(textField_version.getText()));
                    license.setCreateDate(new Date());
                    license.setExpiredDate(Utility.parseDate(datePicker_expiredDate.getText()));

                    //????
                    DigitalSignatureTool utils = new DigitalSignatureTool("DSA");
                    utils.readPriKey(priKeyFile.getAbsolutePath()); //??
                    String signedData = utils.sign(license.toString()); //??????
                    license.setSignature(signedData);

                    LicenseManager.writeLicense(license, licenseFile);
                    //config.xml
                    String licenseContent = XmlUtils.readXml(licenseFile).asXML();
                    //DES
                    ISecurity security = new DESTool(currentLicenseConfig.getLicenseId(), Algorithm.BLOWFISH);
                    licenseContent = security.encrypt(licenseContent);

                    txt_encryptContent.setText(licenseContent);
                    currentLicenseConfig.setEncryptedLicense(licenseContent);
                    System.out.println(licenseContent);
                    File configFile = new File(Gui.HOME_PATH + File.separator + "config.xml");

                    XMLConfiguration config = new XMLConfiguration(configFile);
                    config.setAutoSave(true);

                    config.setProperty("product.customer.encryptedLicense", licenseContent);

                    //??zip?
                    File customerPath = licenseFile.getParentFile();
                    //???license?????
                    File licensePath = new File(customerPath.getParent(), "license");
                    if (!licensePath.exists() && !licensePath.isDirectory()) {
                        licensePath.mkdir();
                    } else {
                        FileUtils.cleanDirectory(licensePath);
                    }

                    //?
                    FileUtils.copyDirectory(customerPath, licensePath);
                    String currentTime = FormatDateTime.formatDateTimeNum(new Date());
                    ZipUtils.zip(licensePath, new File(licensePath.getParentFile(),
                            currentLicenseConfig.getCustomerCode() + "-" + currentTime + ".zip"));

                    //license
                    FileUtils.deleteDirectory(licensePath);

                    JOptionPane.showMessageDialog(self, "??");
                } catch (Exception e1) {
                    e1.printStackTrace();
                    JOptionPane.showMessageDialog(self, e1.getMessage());
                }
            } else {
                JOptionPane.showMessageDialog(self, "???");
            }
        }
    });
    GridBagConstraints gbc_button_5 = new GridBagConstraints();
    gbc_button_5.insets = new Insets(0, 0, 5, 5);
    gbc_button_5.gridx = 1;
    gbc_button_5.gridy = 9;
    this.add(button_5, gbc_button_5);

    JScrollPane scrollPane = new JScrollPane();
    GridBagConstraints gbc_scrollPane = new GridBagConstraints();
    gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
    gbc_scrollPane.fill = GridBagConstraints.BOTH;
    gbc_scrollPane.gridx = 1;
    gbc_scrollPane.gridy = 10;
    this.add(scrollPane, gbc_scrollPane);

    txt_encryptContent = new JTextArea();
    txt_encryptContent.setLineWrap(true);
    scrollPane.setViewportView(txt_encryptContent);

    //      txt_encryptContent = new JTextArea(20, 20);
    //      GridBagConstraints gbc_6 = new GridBagConstraints();
    //      gbc_6.gridx = 1;
    //      gbc_6.gridy = 10;
    //      this.add(txt_encryptContent, gbc_6);

}

From source file:com.dfki.av.sudplan.vis.wiz.DataSourceSelectionPanel.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    JFileChooser jfc = new JFileChooser();
    jfc.addChoosableFileFilter(new FileNameExtensionFilter("ESRI Shapfile (*.shp)", "shp", "Shp", "SHP"));
    jfc.addChoosableFileFilter(new FileNameExtensionFilter("Zip file (*.zip)", "zip", "ZIP", "Zip"));
    XMLConfiguration xmlConfig = Configuration.getXMLConfiguration();
    String path = xmlConfig.getString("sudplan3D.working.dir");
    File dir;/*from ww  w  .  ja va 2 s  .  co  m*/
    if (path != null) {
        dir = new File(path);
        if (dir.exists()) {
            jfc.setCurrentDirectory(dir);
        }
    }
    int retValue = jfc.showOpenDialog(this);

    if (retValue == JFileChooser.APPROVE_OPTION) {
        File f = jfc.getSelectedFile();
        if (f != null) {
            jLabel1.setText(f.getAbsolutePath());
            file = f;
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("No shp file selected.");
        }
    }
    dir = jfc.getCurrentDirectory();
    path = dir.getAbsolutePath();
    xmlConfig.setProperty("sudplan3D.working.dir", path);
}

From source file:it.imtech.configuration.ChooseServer.java

/**
 * Setta il percorso del file di configurazione se  la prima volta che
 * viene avviata l'applicazione//from   w ww.  j a v a  2 s.com
 *
 * @param change Definisce se  l'avvio dell'applicazione o se si vuole
 * modificare il percorso
 * @throws MalformedURLException
 * @throws ConfigurationException
 */
private XMLConfiguration setConfigurationPaths(boolean change, XMLConfiguration internalConf,
        ResourceBundle bundle) {
    URL urlConfig = null;
    XMLConfiguration configuration = null;

    try {
        String text = Utility.getBundleString("setconf", bundle);
        String title = Utility.getBundleString("setconf2", bundle);

        internalConf.setAutoSave(true);

        String n = internalConf.getString("configurl[@path]");

        if (n.isEmpty()) {
            String s = (String) JOptionPane.showInputDialog(new Frame(), text, title, JOptionPane.PLAIN_MESSAGE,
                    null, null, "http://phaidrastatic.cab.unipd.it/xml/config.xml");

            //If a string was returned, say so.
            if ((s != null) && (s.length() > 0)) {
                internalConf.setProperty("configurl[@path]", s);
                urlConfig = new URL(s);
            } else {
                logger.info("File di configurazione non settato");
            }
        } else {
            urlConfig = new URL(n);
        }

        if (urlConfig != null) {
            if (Globals.DEBUG)
                configuration = new XMLConfiguration(new File(Globals.JRPATH + Globals.DEBUG_XML));
            else
                configuration = new XMLConfiguration(urlConfig);
        }
    } catch (final MalformedURLException ex) {
        logger.error(ex.getMessage());
        JOptionPane.showMessageDialog(new Frame(), Utility.getBundleString("exc_conf_1", bundle));
    } catch (final ConfigurationException ex) {
        logger.error(ex.getMessage());
        JOptionPane.showMessageDialog(new Frame(), Utility.getBundleString("exc_conf_2", bundle));
    }

    return configuration;
}

From source file:it.imtech.configuration.StartWizard.java

/**
 * Retrieve online configuration filepath
 *
 * @throws MalformedURLException/* w  w  w . j  a va 2s .  com*/
 * @throws ConfigurationException
 */
private XMLConfiguration setConfigurationPaths(XMLConfiguration internalConf, ResourceBundle bundle) {
    XMLConfiguration configuration = null;

    try {
        String text = Utility.getBundleString("setconf", bundle);
        String title = Utility.getBundleString("setconf2", bundle);

        internalConf.setAutoSave(true);

        String n = internalConf.getString("configurl[@path]");

        if (n.isEmpty()) {
            String s = (String) JOptionPane.showInputDialog(new Frame(), text, title, JOptionPane.PLAIN_MESSAGE,
                    null, null, "http://phaidrastatic.cab.unipd.it/xml/config.xml");

            //If a string was returned, say so.
            if ((s != null) && (s.length() > 0)) {
                internalConf.setProperty("configurl[@path]", s);
                Globals.URL_CONFIG = new URL(s);
            } else {
                logger.info("File di configurazione non settato");
            }
        } else {
            if (Globals.ONLINE) {
                Globals.URL_CONFIG = new URL(n);
            }
        }

        if (Globals.URL_CONFIG != null) {
            if (Globals.DEBUG)
                configuration = new XMLConfiguration(new File(Globals.JRPATH + Globals.DEBUG_XML));
            else
                configuration = new XMLConfiguration(Globals.URL_CONFIG);
        } else {
            if (!Globals.ONLINE) {
                configuration = new XMLConfiguration(
                        new File(Globals.USER_DIR + Utility.getSep() + Globals.FOLD_XML + "config.xml"));
            }
        }
    } catch (final MalformedURLException ex) {
        logger.error(ex.getMessage());
        JOptionPane.showMessageDialog(new Frame(), Utility.getBundleString("exc_conf_1", bundle));
    } catch (final ConfigurationException ex) {
        logger.error(ex.getMessage());
        JOptionPane.showMessageDialog(new Frame(), Utility.getBundleString("exc_conf_2", bundle));
    }

    return configuration;
}

From source file:com.dfki.av.sudplan.ui.MainFrame.java

private void miOpenDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miOpenDataActionPerformed
    try {//  ww  w .  ja  va2  s .com
        String cmd = evt.getActionCommand();
        final JFileChooser fc = new JFileChooser();

        FileFilter fileFilter;
        // Set file filter..
        if (cmd.equalsIgnoreCase(miOpenKMLFile.getActionCommand())) {
            fileFilter = new FileNameExtensionFilter("KML/KMZ File", "kml", "kmz");
        } else if (cmd.equalsIgnoreCase(miAddGeoTiff.getActionCommand())) {
            fileFilter = new FileNameExtensionFilter("GeoTiff File ( *.tif, *.tiff)", "tif", "tiff");
        } else if (cmd.equalsIgnoreCase(miAddShape.getActionCommand())) {
            fileFilter = new FileNameExtensionFilter("ESRI Shapefile (*.shp)", "shp", "SHP");
        } else if (cmd.equalsIgnoreCase(miAddShapeZip.getActionCommand())) {
            fileFilter = new FileNameExtensionFilter("ESRI Shapefile ZIP (*.zip)", "zip", "ZIP");
        } else {
            log.warn("No valid action command.");
            fileFilter = null;
        }
        fc.setFileFilter(fileFilter);

        // Set latest working directory...
        XMLConfiguration xmlConfig = Configuration.getXMLConfiguration();
        String path = xmlConfig.getString("sudplan3D.working.dir");
        File dir;
        if (path != null) {
            dir = new File(path);
            if (dir.exists()) {
                fc.setCurrentDirectory(dir);
            }
        }

        // Show dialog...
        int ret = fc.showOpenDialog(this);

        // Save currently selected working directory...
        dir = fc.getCurrentDirectory();
        path = dir.getAbsolutePath();
        xmlConfig.setProperty("sudplan3D.working.dir", path);

        if (ret != JFileChooser.APPROVE_OPTION) {
            return;
        }

        if (cmd.equalsIgnoreCase(miOpenKMLFile.getActionCommand())) {
            wwPanel.addKMLLayer(fc.getSelectedFile());
        } else if (cmd.equalsIgnoreCase(miAddGeoTiff.getActionCommand())) {
            wwPanel.addGeoTiffLayer(fc.getSelectedFile());
        } else if (cmd.equalsIgnoreCase(miAddShape.getActionCommand())
                || cmd.equalsIgnoreCase(miAddShapeZip.getActionCommand())) {
            IVisAlgorithm algo = VisAlgorithmFactory.newInstance(VisPointCloud.class.getName());
            if (algo != null) {
                wwPanel.addLayer(fc.getSelectedFile(), algo, null);
            } else {
                log.error("VisAlgorithm {} not supported.", VisPointCloud.class.getName());
                JOptionPane.showMessageDialog(this, "Algorithm not supported.", "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        } else {
            log.warn("No valid action command.");
        }
    } catch (Exception ex) {
        log.error(ex.toString());
        JOptionPane.showMessageDialog(this, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests the clone() method.//from w w  w  . j  a v  a2 s  .c  o m
 */
@Test
public void testClone() {
    Configuration c = (Configuration) conf.clone();
    assertTrue(c instanceof XMLConfiguration);
    XMLConfiguration copy = (XMLConfiguration) c;
    assertNotNull(conf.getDocument());
    assertNull(copy.getDocument());
    assertNotNull(conf.getFileName());
    assertNull(copy.getFileName());

    copy.setProperty("element3", "clonedValue");
    assertEquals("value", conf.getString("element3"));
    conf.setProperty("element3[@name]", "originalFoo");
    assertEquals("foo", copy.getString("element3[@name]"));
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests setting an attribute on the root element.
 *///from   w w w  .j  a v  a 2  s.  c  o m
@Test
public void testSetRootAttribute() throws ConfigurationException {
    conf.setProperty("[@test]", "true");
    assertEquals("Root attribute not set", "true", conf.getString("[@test]"));
    conf.save(testSaveConf);
    XMLConfiguration checkConf = new XMLConfiguration();
    checkConf.setFile(testSaveConf);
    checkSavedConfig(checkConf);
    assertTrue("Attribute not found after save", checkConf.containsKey("[@test]"));
    checkConf.setProperty("[@test]", "newValue");
    checkConf.save();
    conf = checkConf;
    checkConf = new XMLConfiguration();
    checkConf.setFile(testSaveConf);
    checkSavedConfig(checkConf);
    assertEquals("Attribute not modified after save", "newValue", checkConf.getString("[@test]"));
}

From source file:logica.EstacionMet.java

/**
 * Encargado de actualizar y guardar la informacion de un sensor en los 
 * resumenes XML//from  w ww .  j  a  v  a2  s  .  co  m
 * 
 * @param registro El manejador de XML
 * @param sensorID El id del sensor cuyo resumen hay que actualizar
 * @param tipo El tipo de sensor cuyo resumen hay que actualizar
 * @param medicionS La medicion del sensor
 */
private void resumenSave(XMLConfiguration registro, Integer sensorID, String tipo, String medicionS) {
    try {
        // Busco si ya hay algun registro del sensor.
        List<String> idsRegistro = registro.getList(String.format("estacion%d.sensor.id", ID));
        int index = -1;

        for (String id : idsRegistro) {
            if (Integer.valueOf(id).equals(sensorID)) {
                index = idsRegistro.indexOf(String.valueOf(sensorID));
                break;
            }
        }
        // Si ya hay, actualizo
        if (index != -1) {
            float medicion; // Medicion actual en float
            String nMedicionesS; // Numero de mediciones
            int nMediciones;
            String maximoS; // Valor maximo de las mediciones
            float maximo;
            String minimoS; // Valor minimo de las mediciones
            float minimo;
            String medioS; // Valor medio de las mediciones
            float medio;

            // Cargo los valores
            nMedicionesS = registro.getString(String.format("estacion%d.sensor(%d).mediciones", ID, index));
            maximoS = registro.getString(String.format("estacion%d.sensor(%d).maximo", ID, index));
            minimoS = registro.getString(String.format("estacion%d.sensor(%d).minimo", ID, index));
            medioS = registro.getString(String.format("estacion%d.sensor(%d).medio", ID, index));

            // Aumento en uno la cantidad de mediciones
            nMediciones = Integer.valueOf(nMedicionesS) + 1;
            registro.setProperty(String.format("estacion%d.sensor(%d).mediciones", ID, index),
                    String.valueOf(nMediciones));

            // Recalculo maximo y minimo
            medicion = Float.valueOf(medicionS.split(" ")[0]);
            maximo = Float.valueOf(maximoS.split(" ")[0]);
            minimo = Float.valueOf(minimoS.split(" ")[0]);

            if (medicion > maximo)
                registro.setProperty(String.format("estacion%d.sensor(%d).maximo", ID, index), medicionS);
            if (medicion < minimo)
                registro.setProperty(String.format("estacion%d.sensor(%d).minimo", ID, index), medicionS);

            // Recalculo el valor medio
            medio = Float.valueOf(medioS.split(" ")[0]);

            medio = (medio + medicion) / 2;
            registro.setProperty(String.format("estacion%d.sensor(%d).medio", ID, index),
                    String.valueOf(medio));
        } else { // Si no, creo y cargo los valores como iniciales
            index = idsRegistro.size();
            registro.addProperty(String.format("estacion%d.sensor(%d).id", ID, index), sensorID.toString());
            registro.addProperty(String.format("estacion%d.sensor(%d).tipo", ID, index), tipo);
            registro.addProperty(String.format("estacion%d.sensor(%d).maximo", ID, index), medicionS);
            registro.addProperty(String.format("estacion%d.sensor(%d).minimo", ID, index), medicionS);
            registro.addProperty(String.format("estacion%d.sensor(%d).medio", ID, index), medicionS);
            registro.addProperty(String.format("estacion%d.sensor(%d).mediciones", ID, index), "1");
        }

        registro.save();
    } catch (ConfigurationException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
    }
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests string properties with list delimiters when delimiter parsing is
 * disabled//  ww w.j a  v  a2 s.c  o m
 */
@Test
public void testSaveWithDelimiterParsingDisabled() throws ConfigurationException {
    XMLConfiguration conf = new XMLConfiguration();
    conf.setExpressionEngine(new XPathExpressionEngine());
    conf.setDelimiterParsingDisabled(true);
    conf.setAttributeSplittingDisabled(true);
    conf.setFile(new File(testProperties));
    conf.load();

    assertEquals("a,b,c", conf.getString("split/list3/@values"));
    assertEquals(0, conf.getMaxIndex("split/list3/@values"));
    assertEquals("a\\,b\\,c", conf.getString("split/list4/@values"));
    assertEquals("a,b,c", conf.getString("split/list1"));
    assertEquals(0, conf.getMaxIndex("split/list1"));
    assertEquals("a\\,b\\,c", conf.getString("split/list2"));
    // save the configuration
    conf.save(testSaveConf.getAbsolutePath());

    // read the configuration and compare the properties
    XMLConfiguration checkConfig = new XMLConfiguration();
    checkConfig.setFileName(testSaveConf.getAbsolutePath());
    checkSavedConfig(checkConfig);
    XMLConfiguration config = new XMLConfiguration();
    config.setFileName(testFile2);
    // config.setExpressionEngine(new XPathExpressionEngine());
    config.setDelimiterParsingDisabled(true);
    config.setAttributeSplittingDisabled(true);
    config.load();
    config.setProperty("Employee[@attr1]", "3,2,1");
    assertEquals("3,2,1", config.getString("Employee[@attr1]"));
    config.save(testSaveFile.getAbsolutePath());
    config = new XMLConfiguration();
    config.setFileName(testSaveFile.getAbsolutePath());
    // config.setExpressionEngine(new XPathExpressionEngine());
    config.setDelimiterParsingDisabled(true);
    config.setAttributeSplittingDisabled(true);
    config.load();
    config.setProperty("Employee[@attr1]", "1,2,3");
    assertEquals("1,2,3", config.getString("Employee[@attr1]"));
    config.setProperty("Employee[@attr2]", "one, two, three");
    assertEquals("one, two, three", config.getString("Employee[@attr2]"));
    config.setProperty("Employee.text", "a,b,d");
    assertEquals("a,b,d", config.getString("Employee.text"));
    config.setProperty("Employee.Salary", "100,000");
    assertEquals("100,000", config.getString("Employee.Salary"));
    config.save(testSaveFile.getAbsolutePath());
    checkConfig = new XMLConfiguration();
    checkConfig.setFileName(testSaveFile.getAbsolutePath());
    checkConfig.setExpressionEngine(new XPathExpressionEngine());
    checkConfig.setDelimiterParsingDisabled(true);
    checkConfig.setAttributeSplittingDisabled(true);
    checkConfig.load();
    assertEquals("1,2,3", checkConfig.getString("Employee/@attr1"));
    assertEquals("one, two, three", checkConfig.getString("Employee/@attr2"));
    assertEquals("a,b,d", checkConfig.getString("Employee/text"));
    assertEquals("100,000", checkConfig.getString("Employee/Salary"));
}

From source file:org.apache.qpid.server.store.berkeleydb.HATestClusterCreator.java

public void modifyClusterNodeBdbAddress(int brokerPortNumberToBeMoved, int newBdbPort) {
    final BrokerConfigHolder brokerConfigHolder = _brokerConfigurations.get(brokerPortNumberToBeMoved);
    final XMLConfiguration virtualHostConfig = brokerConfigHolder.getTestVirtualhosts();

    final String configKey = getConfigKey("highAvailability.nodeHostPort");
    final String oldBdbHostPort = virtualHostConfig.getString(configKey);

    final String[] oldHostAndPort = StringUtils.split(oldBdbHostPort, ":");
    final String oldHost = oldHostAndPort[0];

    final String newBdbHostPort = oldHost + ":" + newBdbPort;

    virtualHostConfig.setProperty(configKey, newBdbHostPort);
    collectConfig(brokerPortNumberToBeMoved, brokerConfigHolder.getTestConfiguration(), virtualHostConfig);
}