List of usage examples for java.util Properties loadFromXML
public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException
From source file:ar.com.zauber.commons.web.proxy.impl.dao.properties.provider.FilesystemPropertiesProvider.java
/** @see PropertiesProvider#getProperties() */ public Properties getProperties() { try {//from w ww.j a v a 2 s .c o m final Properties properties = new Properties(); final InputStream is = new FileInputStream(file); try { properties.loadFromXML(is); return properties; } finally { is.close(); } } catch (final IOException e) { throw new UnhandledException(e); } }
From source file:org.apache.nifi.util.FlowFileUnpackagerV1.java
protected Map<String, String> getAttributes(final TarArchiveInputStream stream) throws IOException { final Properties props = new Properties(); props.loadFromXML(new NonCloseableInputStream(stream)); final Map<String, String> result = new HashMap<>(); for (final Entry<Object, Object> entry : props.entrySet()) { final Object keyObject = entry.getKey(); final Object valueObject = entry.getValue(); if (!(keyObject instanceof String)) { throw new IOException("Flow file attributes object contains key of type " + keyObject.getClass().getCanonicalName() + " but expected java.lang.String"); } else if (!(keyObject instanceof String)) { throw new IOException("Flow file attributes object contains value of type " + keyObject.getClass().getCanonicalName() + " but expected java.lang.String"); }//from www . j a v a 2 s .c o m final String key = (String) keyObject; final String value = (String) valueObject; result.put(key, value); } return result; }
From source file:org.apache.syncope.core.init.ContentLoader.java
@Transactional public void load() { // 1. Check wether we are allowed to load default content into the DB final List<SyncopeConf> res = confDAO.findAll(); if (res == null || res.size() > 0) { LOG.info("Data found in the database, leaving untouched"); return;//w w w .j a va2 s.c om } LOG.info("Empty database found, loading default content"); // 2. Create views LOG.debug("Creating views"); try { InputStream viewsStream = getClass().getResourceAsStream("/views.xml"); Properties views = new Properties(); views.loadFromXML(viewsStream); for (String idx : views.stringPropertyNames()) { LOG.debug("Creating view {}", views.get(idx).toString()); final String updateViews = views.get(idx).toString().replaceAll("\\n", " "); entityManager.createNativeQuery(updateViews).executeUpdate(); } LOG.debug("Views created, go for indexes"); } catch (Exception e) { LOG.error("While creating views", e); } // 3. Create indexes LOG.debug("Creating indexes"); try { InputStream indexesStream = getClass().getResourceAsStream("/indexes.xml"); Properties indexes = new Properties(); indexes.loadFromXML(indexesStream); for (String idx : indexes.stringPropertyNames()) { LOG.debug("Creating index {}", indexes.get(idx).toString()); final String updateIndexed = indexes.get(idx).toString(); entityManager.createNativeQuery(updateIndexed).executeUpdate(); } LOG.debug("Indexes created, go for default content"); } catch (Exception e) { LOG.error("While creating indexes", e); } // noop workflow // entityManager.createNativeQuery("DELETE FROM ACT_GE_PROPERTY").executeUpdate(); // 4. Load default content SAXParserFactory factory = SAXParserFactory.newInstance(); try { SAXParser parser = factory.newSAXParser(); parser.parse(getClass().getResourceAsStream("/content.xml"), importExport); LOG.debug("Default content successfully loaded"); } catch (Exception e) { LOG.error("While loading default content", e); } }
From source file:org.alfresco.extension.bulkfilesystemimport.metadataloaders.XmlPropertiesFileMetadataLoader.java
/** * @see org.alfresco.extension.bulkfilesystemimport.metadataloaders.AbstractMapBasedMetadataLoader#loadMetadataFromFile(java.io.File) *///from ww w . j a v a 2s . com @Override protected Map<String, Serializable> loadMetadataFromFile(File metadataFile) { Map<String, Serializable> result = null; InputStream metadataInputStream = null; try { Properties props = new Properties(); metadataInputStream = new BufferedInputStream(new FileInputStream(metadataFile)); props.loadFromXML(metadataInputStream); result = new HashMap<String, Serializable>((Map) props); } catch (final IOException ioe) { if (log.isWarnEnabled()) log.warn("Metadata file '" + AbstractBulkFilesystemImporter.getFileName(metadataFile) + "' could not be read.", ioe); } finally { IOUtils.closeQuietly(metadataInputStream); // Note: this shouldn't normally be needed as loadFromXML closes the stream passed to it } return (result); }
From source file:org.pentaho.metadata.registry.SimpleFileRegistry.java
/** * @see org.pentaho.metadata.registry.SimpleRegistry#load() *///ww w . j a v a2 s .com @Override protected void load() throws InvalidPropertiesFormatException, IOException { // empty the registry clear(); File file = new File(filePath); if (file.exists()) { InputStream in = new FileInputStream(file); Properties props = new Properties(); props.loadFromXML(in); int idx = 0; List<Link> links = new ArrayList<Link>(); while (true) { String sub = (String) props.get("link-" + idx + "-subId"); String subType = (String) props.get("link-" + idx + "-subType"); String obj = (String) props.get("link-" + idx + "-objId"); String objType = (String) props.get("link-" + idx + "-objType"); String verb = (String) props.get("link-" + idx + "-verb"); if (sub != null && obj != null && verb != null) { Link link = new Link(sub, subType, verb, obj, objType); links.add(link); idx++; } else { break; } } setLinks(links); idx = 0; while (true) { String id = (String) props.get("entity-" + idx + "-id"); String title = (String) props.get("entity-" + idx + "-title"); String typeId = (String) props.get("entity-" + idx + "-type"); if (id != null && typeId != null) { Entity entity = new Entity(id, title, typeId); addEntity(entity); int idx2 = 0; while (true) { String key = (String) props.get("entity-" + idx + "-attrkey-" + idx2); String value = (String) props.get("entity-" + idx + "-attrvalue-" + idx2); if (key != null && value != null) { entity.setAttribute(key, StringEscapeUtils.unescapeJava(value)); idx2++; } else { break; } } idx++; } else { break; } } } }
From source file:org.alfresco.extension.bulkimport.source.fs.XmlPropertiesFileMetadataLoader.java
/** * @see org.alfresco.extension.bulkimport.source.fs.AbstractMapBasedMetadataLoader#loadMetadataFromFile(java.io.File) *//*from ww w. j a v a 2 s .c o m*/ @Override protected Map<String, Serializable> loadMetadataFromFile(final File metadataFile) { Map<String, Serializable> result = null; InputStream metadataInputStream = null; try { Properties props = new Properties(); metadataInputStream = new BufferedInputStream(new FileInputStream(metadataFile)); props.loadFromXML(metadataInputStream); @SuppressWarnings({ "rawtypes", "unchecked" }) Map<String, Serializable> properties = (Map) props; result = new HashMap<>(properties); } catch (final IOException ioe) { if (warn(log)) warn(log, "Metadata file '" + getFileName(metadataFile) + "' could not be read.", ioe); } finally { IOUtils.closeQuietly(metadataInputStream); // Note: this shouldn't normally be needed as loadFromXML closes the stream passed to it } return (result); }
From source file:org.apache.torque.generator.configuration.option.XmlOptionConfiguration.java
/** * Reads the options from the XML file given in the path and * returns them.//from w w w. j a va 2 s.c o m * * @param configurationProvider the provider to access configuration files, * not null. * * @return the options contained in the file, not null. * * @throws ConfigurationException if the file cannot be accessed or parsed. */ public Collection<Option> getOptions(ConfigurationProvider configurationProvider) throws ConfigurationException { Properties properties = new Properties(); InputStream optionsInputStream = null; try { optionsInputStream = configurationProvider.getOptionsInputStream(getPath()); properties.loadFromXML(optionsInputStream); } catch (IOException e) { throw new ConfigurationException("Error reading options file " + getPath(), e); } catch (RuntimeException e) { throw new ConfigurationException("Error reading options file " + getPath(), e); } finally { if (optionsInputStream != null) { try { optionsInputStream.close(); } catch (IOException e) { log.warn("Could not close OptionsInputStream " + optionsInputStream, e); } } } return toOptions(properties); }
From source file:AuthenticationController.java
@RequestMapping("/authentication") public @ResponseBody Authentication authentication( @RequestParam(value = "username", required = true, defaultValue = "") String username, @RequestParam(value = "password", required = true, defaultValue = "") String password) throws JSONException, FileNotFoundException, UnsupportedEncodingException, IOException { Properties props = new Properties(); FileInputStream fis = new FileInputStream("properties.xml"); // loading properites from properties file props.loadFromXML(fis); String server_ip = props.getProperty("server_ip"); String ZABBIX_API_URL = "http://" + server_ip + "/api_jsonrpc.php"; // 1.2.3.4 is your zabbix_server_ip HttpClient client = new HttpClient(); PutMethod putMethod = new PutMethod(ZABBIX_API_URL); putMethod.setRequestHeader("Content-Type", "application/json-rpc"); // content-type is controlled in api_jsonrpc.php, so set it like this // create json object for apiinfo.version JSONObject jsonObj = new JSONObject( "{\"jsonrpc\":\"2.0\",\"method\":\"user.authenticate\",\"params\":{\"user\":\"" + username + "\",\"password\":\"" + password + "\"},\"auth\": null,\"id\":0}"); putMethod.setRequestBody(jsonObj.toString()); // put the json object as input stream into request body String loginResponse = ""; try {// www . j a v a 2 s . c om client.executeMethod(putMethod); // send to request to the zabbix api loginResponse = putMethod.getResponseBodyAsString(); // read the result of the response // Work with the data using methods like... JSONObject obj = new JSONObject(loginResponse); String result = obj.getString("result"); System.out.println(result); return new Authentication(String.format(result)); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return new Authentication(); }
From source file:org.syncope.core.init.ContentLoader.java
@Transactional public void load() { // 0. DB connection, to be used below Connection conn = DataSourceUtils.getConnection(dataSource); // 1. Check wether we are allowed to load default content into the DB Statement statement = null;//w ww.j ava 2 s.c o m ResultSet resultSet = null; boolean existingData = false; try { statement = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); resultSet = statement.executeQuery("SELECT * FROM " + SyncopeConf.class.getSimpleName()); resultSet.last(); existingData = resultSet.getRow() > 0; } catch (SQLException e) { LOG.error("Could not access to table " + SyncopeConf.class.getSimpleName(), e); // Setting this to true make nothing to be done below existingData = true; } finally { try { if (resultSet != null) { resultSet.close(); } } catch (SQLException e) { LOG.error("While closing SQL result set", e); } try { if (statement != null) { statement.close(); } } catch (SQLException e) { LOG.error("While closing SQL statement", e); } } if (existingData) { LOG.info("Data found in the database, leaving untouched"); return; } LOG.info("Empty database found, loading default content"); // 2. Create views LOG.debug("Creating views"); try { InputStream viewsStream = getClass().getResourceAsStream("/views.xml"); Properties views = new Properties(); views.loadFromXML(viewsStream); for (String idx : views.stringPropertyNames()) { LOG.debug("Creating view {}", views.get(idx).toString()); try { statement = conn.createStatement(); statement.executeUpdate(views.get(idx).toString().replaceAll("\\n", " ")); statement.close(); } catch (SQLException e) { LOG.error("Could not create view ", e); } } LOG.debug("Views created, go for indexes"); } catch (Throwable t) { LOG.error("While creating views", t); } // 3. Create indexes LOG.debug("Creating indexes"); try { InputStream indexesStream = getClass().getResourceAsStream("/indexes.xml"); Properties indexes = new Properties(); indexes.loadFromXML(indexesStream); for (String idx : indexes.stringPropertyNames()) { LOG.debug("Creating index {}", indexes.get(idx).toString()); try { statement = conn.createStatement(); statement.executeUpdate(indexes.get(idx).toString()); statement.close(); } catch (SQLException e) { LOG.error("Could not create index ", e); } } LOG.debug("Indexes created, go for default content"); } catch (Throwable t) { LOG.error("While creating indexes", t); } finally { DataSourceUtils.releaseConnection(conn, dataSource); } try { conn.close(); } catch (SQLException e) { LOG.error("While closing SQL connection", e); } // 4. Load default content SAXParserFactory factory = SAXParserFactory.newInstance(); try { SAXParser parser = factory.newSAXParser(); parser.parse(getClass().getResourceAsStream("/content.xml"), importExport); LOG.debug("Default content successfully loaded"); } catch (Throwable t) { LOG.error("While loading default content", t); } }
From source file:com.opensource.frameworks.processframework.utils.DefaultPropertiesPersister.java
public void loadFromXml(Properties props, InputStream is) throws IOException { try {//w w w .j a v a 2s . c o m props.loadFromXML(is); } catch (NoSuchMethodError err) { throw new IOException("Cannot load properties XML file - not running on JDK 1.5+: " + err.getMessage()); } }