List of usage examples for org.apache.commons.configuration XMLConfiguration XMLConfiguration
public XMLConfiguration(URL url) throws ConfigurationException
XMLConfiguration
. From source file:com.termmed.reconciliation.ChangeConsolidator.java
/** * Gets the params.//from ww w. j a va 2 s. c o m * * @return the params * @throws ConfigurationException the configuration exception */ private void getParams() throws ConfigurationException { try { xmlConfig = new XMLConfiguration(config); } catch (ConfigurationException e) { log.info("ChangeConsolidator - Error happened getting params file." + e.getMessage()); throw e; } relationship = xmlConfig.getString(I_Constants.RELATIONSHIP_FILE); String snapshotFinal = xmlConfig.getString(I_Constants.CONSOLIDATED_SNAPSHOT_FILE); snapshotFinalFile = new File(snapshotFinal); String deltaFinal = xmlConfig.getString(I_Constants.CONSOLIDATED_DELTA_FILE); deltaFinalFile = new File(deltaFinal); additionalCharType = xmlConfig.getString(I_Constants.ADDITIONAL_RELS_SNAPSHOT_FILE); List<String> prevRelFiles = xmlConfig.getList(I_Constants.PREVIOUS_INFERRED_RELATIONSHIP_FILES); if (prevRelFiles != null && prevRelFiles.size() > 0) { previousInferredRelationshipsFile = new String[prevRelFiles.size()]; prevRelFiles.toArray(previousInferredRelationshipsFile); } releaseDate = xmlConfig.getString(I_Constants.RELEASEDATE); log.info("Consolidator - Parameters:"); log.info("Input file : " + relationship); log.info("Previous Relationship files : "); if (previousInferredRelationshipsFile != null) { for (String relFile : previousInferredRelationshipsFile) { log.info(relFile); } } log.info("Snapshot final file : " + snapshotFinal); log.info("Delta final file : " + deltaFinal); log.info("Release date : " + releaseDate); }
From source file:edu.kit.dama.scheduler.servlet.JobSchedulerInitializerListener.java
/** * Load configuration from XML-File//from w w w . ja va2 s. com */ private void loadConfiguration() { URL configURL; HierarchicalConfiguration hc; try { configURL = DataManagerSettings.getConfigurationURL(); LOGGER.debug("Loading configuration from {}", configURL); hc = new HierarchicalConfiguration(new XMLConfiguration(configURL)); LOGGER.debug("Configuration successfully loaded"); } catch (ConfigurationException ex) { // error in configuration // reason see debug log message: LOGGER.warn("Failed to load configuration, using default values.", ex); loadDefaultConfiguration(); return; } SubnodeConfiguration configurationAt = hc.configurationAt(CONFIG_ROOT); if (configurationAt != null) { String jobStoreDriverParam = null; try { jobStoreDriverParam = configurationAt.getString(JOB_STORE_DRIVER, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_DRIVER); } if (jobStoreDriverParam != null) { jobStoreDriver = jobStoreDriverParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_DRIVER, DEFAULT_JOB_STORE_DRIVER); jobStoreDriver = DEFAULT_JOB_STORE_DRIVER; } String jobStoreConnectionStringParam = null; try { jobStoreConnectionStringParam = configurationAt.getString(JOB_STORE_CONNECTION_STRING, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_CONNECTION_STRING); } if (jobStoreConnectionStringParam != null) { jobStoreConnectionString = jobStoreConnectionStringParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_CONNECTION_STRING, DEFAULT_JOB_STORE_CONNECTION_STRING); jobStoreConnectionString = DEFAULT_JOB_STORE_CONNECTION_STRING; } String jobStoreUserParam = null; try { jobStoreUserParam = configurationAt.getString(JOB_STORE_USER, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_USER); } if (jobStoreUserParam != null) { jobStoreUser = jobStoreUserParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_USER, DEFAULT_JOB_STORE_USER); jobStoreUser = DEFAULT_JOB_STORE_USER; } String jobStorePasswordParam = null; try { jobStorePasswordParam = configurationAt.getString(JOB_STORE_PASSWORD, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", JOB_STORE_PASSWORD); } if (jobStoreUserParam != null) { jobStorePassword = jobStorePasswordParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", JOB_STORE_PASSWORD, DEFAULT_JOB_STORE_PASSWORD); jobStorePassword = DEFAULT_JOB_STORE_PASSWORD; } Boolean waitOnShutdownParam = null; try { waitOnShutdownParam = configurationAt.getBoolean(CONFIG_WAIT_ON_SHUTDOWN, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", CONFIG_WAIT_ON_SHUTDOWN); } if (waitOnShutdownParam != null) { waitOnShutdown = waitOnShutdownParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", CONFIG_WAIT_ON_SHUTDOWN, DEFAULT_WAIT_ON_SHUTDOWN); waitOnShutdown = DEFAULT_WAIT_ON_SHUTDOWN; } Boolean addDefaultSchedulesParam = null; try { addDefaultSchedulesParam = configurationAt.getBoolean(ADD_DEFAULT_SCHEDULES, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", ADD_DEFAULT_SCHEDULES); } if (addDefaultSchedulesParam != null) { addDefaultSchedules = addDefaultSchedulesParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", ADD_DEFAULT_SCHEDULES, DEFAULT_ADD_DEFAULT_SCHEDULES); addDefaultSchedules = DEFAULT_ADD_DEFAULT_SCHEDULES; } Integer startDelaySecondsParam = null; try { startDelaySecondsParam = configurationAt.getInteger(CONFIG_START_DELAY_SECONDS, null); } catch (ConversionException ex) { LOGGER.error("Failed to parse parameter '{}'.", CONFIG_START_DELAY_SECONDS); } if (startDelaySecondsParam != null) { startDelaySeconds = startDelaySecondsParam; } else { LOGGER.info("No parameter '{}' defined, defaulting to {}.", CONFIG_START_DELAY_SECONDS, DEFAULT_START_DELAY_SECONDS); startDelaySeconds = DEFAULT_START_DELAY_SECONDS; } } else { LOGGER.info("No scheduler configuration node found in datamanager config. Using default values."); } }
From source file:it.imtech.configuration.StartWizard.java
/** * Sets the version and default locale/*from ww w. j a v a 2 s.c o m*/ * @return */ private XMLConfiguration setConfiguration() { XMLConfiguration config = null; try { config = new XMLConfiguration(Globals.INTERNAL_CONFIG); Globals.CURRENT_VERSION = config.getString("version[@current]"); mainFrame.setTitle("Phaidra Importer v." + config.getString("version[@current]")); String locale = config.getString("locale.current[@value]"); Globals.CURRENT_LOCALE = new Locale(locale); } catch (ConfigurationException ex) { logger.error(ex.getMessage()); Globals.CURRENT_LOCALE = new Locale("en"); } return config; }
From source file:com.ccl.jersey.codegen.SimpleMetaDataExporter.java
private void handleDict() { try {//from www . j a v a2 s. co m XMLConfiguration config = new XMLConfiguration("dict.xml"); HierarchicalConfiguration.Node root = config.getRoot(); if (root.hasChildren()) { List<ConfigurationNode> dicts = root.getChildren("dict"); for (int i = 0; i < dicts.size(); i++) { String name = config.getString("dict(" + i + ")[@name]"); String label = config.getString("dict(" + i + ")[@label]"); String table = config.getString("dict(" + i + ")[@table]"); String column = config.getString("dict(" + i + ")[@column]"); Map<String, DictType> dictTypeMap = registerDictTypes.get(table); if (null == dictTypeMap) { dictTypeMap = new HashMap<>(); } registerDictTypes.put(table, dictTypeMap); DictType dictType = new DictType(name, label, table, column); dictTypeMap.put(column, dictType); if (dicts.get(i).getChildrenCount() > 0) { List<ConfigurationNode> configurationNodes = dicts.get(i).getChildren("item"); for (int j = 0; j < configurationNodes.size(); j++) { String itemName = config.getString("dict(" + i + ").item(" + j + ")[@name]"); Integer itemValue = config.getInt("dict(" + i + ").item(" + j + ")[@value]"); String itemLabel = config.getString("dict(" + i + ").item(" + j + ")[@label]"); dictType.getItems().add(new DictItemType(itemName, itemValue, itemLabel)); } } } } } catch (ConfigurationException e) { e.printStackTrace(); } }
From source file:it.imtech.configuration.StartWizard.java
/** * Retrieve online configuration filepath * * @throws MalformedURLException//from w ww .j a v a2s.c o m * @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.termmed.statistics.db.importer.ImportManager.java
/** * Execute.//w w w . java 2 s .c o m * * @throws IOException Signals that an I/O exception has occurred. * @throws Exception the exception */ public void execute() throws IOException, Exception { logger.info("Starting import manager process"); createFolders(); importer = new Importer(); if (!existingTables()) { DbSetup dbSetup = new DbSetup(connection); dbSetup.execute(); dbSetup = null; } XMLConfiguration xmlConfig; try { xmlConfig = new XMLConfiguration(configFile); } catch (ConfigurationException e) { logger.error("ClassificationRunner - Error happened getting params configFile." + e.getMessage()); throw e; } refsetId = xmlConfig.getString("refsetId"); releaseDependencies = CurrentFile.get().getReleaseDependenciesFullFolders() != null && CurrentFile.get().getReleaseDependenciesFullFolders().size() > 0; this.releaseDate = xmlConfig.getString("releaseDate"); this.previousReleaseDate = xmlConfig.getString("previousReleaseDate"); this.reducedSnapshotFolder = new File("reducedSnapshotFolder"); if (!reducedSnapshotFolder.exists()) { reducedSnapshotFolder.mkdirs(); } this.previousReducedSnapshotFolder = new File("previousReducedSnapshotFolder"); if (!previousReducedSnapshotFolder.exists()) { previousReducedSnapshotFolder.mkdirs(); } if (DependentFile.get() != null) { CurrentFile.get().setSnapshotExtensionLanguage(DependentFile.get().getSnapshotLanguageFile()); } else { CurrentFile.get().setSnapshotExtensionLanguage(xmlConfig.getString("extensionLanguageSnapshotFile")); } List<HierarchicalConfiguration> fields = xmlConfig.configurationsAt("reports.reportDescriptor"); if (fields != null) { for (HierarchicalConfiguration sub : fields) { String report = sub.getString("filename"); String value = sub.getString("execute"); if (value.toLowerCase().equals("true")) { logger.info("Getting config for report " + report); ReportConfig reportCfg = ResourceUtils.getReportConfig(report); for (TABLE table : reportCfg.getInputFile()) { switch (table) { case STATEDROOTDESC: if (rootDesc) { continue; } rootDesc = true; break; case CONCEPTS: if (concepts) { continue; } concepts = true; break; case DESCRIPTIONS: if (descriptions) { continue; } descriptions = true; break; case DESCRIPTIONS_PREVIOUS: if (descriptions_pre) { continue; } descriptions_pre = true; break; case EXT_LANGUAGE: if (extLanguage) { continue; } extLanguage = true; break; case RELATIONSHIPS: if (relationships) { continue; } relationships = true; break; case STATEDRELS: if (statedRels) { continue; } statedRels = true; break; case TCLOSUREINFERRED: if (tClosureInferred) { continue; } tClosureInferred = true; break; case TCLOSURESTATED: if (tClosureStated) { continue; } tClosureStated = true; break; case CONCEPTS_PREVIOUS: if (concepts_pre) { continue; } concepts_pre = true; break; case RELATIONSHIPS_PREVIOUS: if (relationships_pre) { continue; } relationships_pre = true; break; case STATEDRELS_PREVIOUS: if (statedRels_pre) { continue; } statedRels_pre = true; break; case LANGUAGE_PREVIOUS: if (refsetId != null && !refsetId.equals("")) { Integer[] newfields = new Integer[] { 2, 4, 6 }; String[] newValues = new String[] { "1", refsetId, "900000000000548007" }; table.setFieldFilter(newfields); table.setFieldFilterValue(newValues); } if (lang_pre) { continue; } lang_pre = true; break; case LANGUAGE: if (refsetId != null && !refsetId.equals("")) { Integer[] newfields = new Integer[] { 2, 4, 6 }; String[] newValues = new String[] { "1", refsetId, "900000000000548007" }; table.setFieldFilter(newfields); table.setFieldFilterValue(newValues); } if (lang) { continue; } lang = true; break; case TCLOSURESTATED_PREVIOUS: if (tClosureStated_pre) { continue; } tClosureStated_pre = true; break; case SAME_AS_ASSOCIATIONS: if (same_associations) { continue; } same_associations = true; break; } ImportRf2Table(table); } System.out.println(report + " " + value); } } } logger.info("Updating date to " + releaseDate); saveNewDate(I_Constants.RELEASE_DATE, releaseDate); logger.info("Updating previous date to " + previousReleaseDate); saveNewDate(I_Constants.PREVIOUS_RELEASE_DATE, previousReleaseDate); fields = xmlConfig.configurationsAt("sp_params.param"); params = new HashMap<String, String>(); if (fields != null) { for (HierarchicalConfiguration sub : fields) { String paramName = sub.getString("name"); String value = sub.getString("value"); if (value.equals("$param")) { value = xmlConfig.getString(paramName); } params.put(paramName, value); } } logger.info("End of import manager process"); }
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests constructing an XMLConfiguration from a non existing file and later * saving to this file./*from w w w . j av a 2s .com*/ */ @Test public void testLoadAndSaveFromFile() throws Exception { // If the file does not exist, an empty config is created conf = new XMLConfiguration(testSaveConf); assertTrue(conf.isEmpty()); conf.addProperty("test", "yes"); conf.save(); conf = new XMLConfiguration(testSaveConf); assertEquals("yes", conf.getString("test")); }
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests loading a configuration from a URL. *///from w w w.j a v a 2 s . com @Test public void testLoadFromURL() throws Exception { URL url = new File(testProperties).toURI().toURL(); conf = new XMLConfiguration(url); assertEquals("value", conf.getProperty("element")); assertEquals(url, conf.getURL()); }
From source file:com.litt.core.security.license.gui.ConfigPanel.java
/** * Create the panel./*w ww .j a va 2 s . c o 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:at.ac.tuwien.auto.iotsys.gateway.connectors.bacnet.BacnetDeviceLoaderImpl.java
@Override public void setConfiguration(XMLConfiguration devicesConfiguration) { this.devicesConfig = devicesConfiguration; if (devicesConfiguration == null) { try {/* w ww . j a v a2 s .c om*/ devicesConfig = new XMLConfiguration(DEVICE_CONFIGURATION_LOCATION); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage(), e); } } }