List of usage examples for java.util Properties loadFromXML
public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException
From source file:org.jlibrary.core.jcr.security.test.PropertiesTestSynchronizer.java
public Group[] getGroupsToSynchronize() throws SecurityException { List groups = new ArrayList(); try {/* www. j a va2 s . c om*/ Properties userProperties = new Properties(); InputStream stream = null; try { stream = ResourceLoader.getResourceAsStream("org/jlibrary/core/jcr/security/test/groups.xml"); userProperties.loadFromXML(stream); } finally { if (stream != null) { stream.close(); } } Iterator it = userProperties.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); String value = (String) entry.getValue(); String[] attributes = StringUtils.split(value, ","); Group group = new Group(); group.setName(attributes[0]); group.setDescription(attributes[1]); groups.add(group); } } catch (Exception e) { logger.error(e.getMessage(), e); throw new SecurityException(e); } return (Group[]) groups.toArray(new Group[] {}); }
From source file:org.jlibrary.core.jcr.security.test.PropertiesTestSynchronizer.java
public User[] getUsersToSynchronize() throws SecurityException { List users = new ArrayList(); try {//w ww . ja v a 2s. com Properties userProperties = new Properties(); InputStream stream = null; try { stream = ResourceLoader.getResourceAsStream("org/jlibrary/core/jcr/security/test/users.xml"); userProperties.loadFromXML(stream); } finally { if (stream != null) { stream.close(); } } Iterator it = userProperties.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); String value = (String) entry.getValue(); String[] attributes = StringUtils.split(value, ","); User user = new User(); user.setName(attributes[0]); user.setFirstName(attributes[1]); user.setLastName(attributes[2]); user.setEmail(attributes[3]); user.setAdmin(Boolean.valueOf(attributes[4]).booleanValue()); users.add(user); } } catch (Exception e) { logger.error(e.getMessage(), e); throw new SecurityException(e); } return (User[]) users.toArray(new User[] {}); }
From source file:BckgrndServiceThreads.fileListingTH.java
@Override public void run() { Properties server_config = new Properties(); try {// ww w .jav a2 s .c o m server_config.loadFromXML(new FileInputStream("Config\\ServerConfig.xml")); l_downloadPath = server_config.getProperty("localDownloadPath"); } catch (Exception ex) { System.out.println("Error loading configuration"); } try { serInstance_Index = getRecentIndex(); } catch (Exception e) { try { serInstance_Index = new playListDB(); //Saving Initial Settings setRecentIndex(serInstance_Index); serInstance_Index.maxIndex = 0; System.out.println("Created a new play list DB"); } catch (Exception ex) { System.out.println("Attempting to create a new play list DB"); ex.printStackTrace(); } //.. //System.out.println("Attempting to read from the player DB"); // e.printStackTrace(); } if (0 < serInstance_Index.maxIndex) { System.out.println("if block executed"); loadAndPlayMedia(); } else { System.out.println("else block executed"); // Get file list from server downloadUpdatedMedia(); //call this throught event dispatcher SwingUtilities.invokeLater(new Runnable() { @Override public void run() { loadAndPlayMedia(); } }); } }
From source file:org.apache.nutch.searcher.custom.CustomFieldQueryFilter.java
public void setConf(Configuration conf) { try {/*from ww w. j a v a 2 s .com*/ this.conf = conf; FileSystem fs = FileSystem.get(conf); String configFile = conf.get("custom.fields.config", "custom-fields.xml"); LOG.info("Reading configuration field configuration from " + configFile); Properties customFieldProps = new Properties(); InputStream fis = CustomFields.class.getClassLoader().getResourceAsStream(configFile); if (fis == null) { throw new IOException("Was unable to open " + configFile); } customFieldProps.loadFromXML(fis); Enumeration keys = customFieldProps.keys(); while (keys.hasMoreElements()) { String prop = (String) keys.nextElement(); if (prop.endsWith(".name")) { String propName = prop.substring(0, prop.length() - 5); String name = customFieldProps.getProperty(prop); fieldNames.add(name); String boostKey = propName + ".boost"; if (customFieldProps.containsKey(boostKey)) { float boost = Float.parseFloat(customFieldProps.getProperty(boostKey)); boosts.put(name, boost); } } } } catch (Exception e) { LOG.error("Error loading custom field properties:\n" + StringUtils.stringifyException(e)); } }
From source file:CPUController.java
@RequestMapping("/cpu") public @ResponseBody CPU cpu( @RequestParam(value = "authentication", required = false, defaultValue = "Error") String authentication, @RequestParam(value = "hostid", required = false, defaultValue = "") String hostid, @RequestParam(value = "metricType", required = false, defaultValue = "") String name) throws 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 JSONParser parser = new JSONParser(); 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(); jsonObj.put("jsonrpc", "2.0"); jsonObj.put("method", "item.get"); JSONObject params = new JSONObject(); params.put("output", "extend"); params.put("hostid", hostid); JSONObject search = new JSONObject(); search.put("key_", "cpu"); params.put("search", search); params.put("sortfield", "name"); jsonObj.put("params", params); jsonObj.put("auth", authentication);// todo jsonObj.put("id", new Integer(1)); putMethod.setRequestBody(jsonObj.toString()); // put the json object as input stream into request body String loginResponse = ""; String cpu = ""; String clock = ""; String metricType = ""; try {// w w w . j a v a 2s .c om client.executeMethod(putMethod); // send to request to the zabbix api loginResponse = putMethod.getResponseBodyAsString(); // read the result of the response Object obj = parser.parse(loginResponse); JSONObject obj2 = (JSONObject) obj; String jsonrpc = (String) obj2.get("jsonrpc"); JSONArray array = (JSONArray) obj2.get("result"); // System.out.println(array); for (int i = 0; i < array.size(); i++) { JSONObject tobj = (JSONObject) array.get(i); String key = (String) tobj.get("key_"); if (!tobj.get("hostid").equals(hostid)) continue; if (name.equals("idle") && key.contains("idle")) { cpu = (String) tobj.get("lastvalue"); clock = (String) tobj.get("lastclock"); metricType = "cpu idle time"; } else if (name.equals("iowait") && key.contains("iowait")) { cpu = (String) tobj.get("lastvalue"); clock = (String) tobj.get("lastclock"); metricType = "cpu iowait time"; } else if (name.equals("nice") && key.contains("nice")) { cpu = (String) tobj.get("lastvalue"); clock = (String) tobj.get("lastclock"); metricType = "cpu nice time"; } else if (name.equals("system") && key.contains("system")) { cpu = (String) tobj.get("lastvalue"); clock = (String) tobj.get("lastclock"); metricType = "cpu system time"; } else if (name.equals("user") && key.contains("user")) { cpu = (String) tobj.get("lastvalue"); clock = (String) tobj.get("lastclock"); metricType = "cpu user time"; } else if (name.equals("load") && key.contains("load")) { cpu = (String) tobj.get("lastvalue"); clock = (String) tobj.get("lastclock"); metricType = "processor load"; } else if (name.equals("usage") && key.contains("usage")) { cpu = (String) tobj.get("lastvalue"); clock = (String) tobj.get("lastclock"); metricType = "system cpu usage average"; } } } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException pe) { System.out.println("Error"); } if (cpu.equals("")) { return new CPU( "Error: Please provide the appropriate input parameters of the metric you are looking for its corresponding monitoring data:"); } return new CPU(hostid, metricType, cpu, clock); }
From source file:com.idevity.card.read.ShowCard.java
/** * Method onCreateView.// w w w .j a va 2 s .co m * * @param inflater * LayoutInflater * @param container * ViewGroup * @param savedInstanceState * Bundle * @return View */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Globals g = Globals.getInstance(); View cardLayout = inflater.inflate(R.layout.activity_show_card, container, false); Date now = Calendar.getInstance().getTime(); byte[] _data = g.getCard(); CardData80073 carddata = new CardData80073(_data); PIVCardHolderUniqueID chuid = null; PIVDataTempl chuidInDataTempl = carddata.getPIVCardHolderUniqueID(); if (chuidInDataTempl != null) { byte[] chuidData = chuidInDataTempl.getData(); if (chuidData == null) { chuidData = chuidInDataTempl.getEncoded(); } chuid = new PIVCardHolderUniqueID(chuidData); } FASCN fascn = null; try { fascn = chuid.getFASCN(); } catch (Throwable e) { Log.e(TAG, "Error: " + e.getMessage()); } String ac = new String(); String sc = new String(); String cn = new String(); String pi = new String(); String oc = new String(); String oi = new String(); String poa = new String(); String expiryDate = new String(); String guid = new String(); String agencyname = new String(); String orgname = new String(); Date expires = now; if (fascn != null) { ac = fascn.getAgencyCode(); sc = fascn.getSystemCode(); cn = fascn.getCredentialNumber(); pi = fascn.getPersonIdentifier(); oc = fascn.getOrganizationalCategory(); oi = fascn.getOrganizationalIdentifier(); poa = fascn.getAssociationCategory(); expiryDate = chuid.getExpirationDate().toString(); expires = chuid.getExpirationDate(); guid = chuid.getGUID().toString(); // agencyname // orgname } ImageView sigthumbs = (ImageView) cardLayout.findViewById(R.id.validityIndicator1); TextView sigtext = (TextView) cardLayout.findViewById(R.id.validityLabel); TextView vtText = (TextView) cardLayout.findViewById(R.id.expirydateLabel); if (expires.after(now)) { sigthumbs.setImageResource(R.drawable.cert_good); } else { sigthumbs.setImageResource(R.drawable.cert_bad); sigtext.setTextColor(getResources().getColor(R.color.idredmain)); vtText.setTextColor(getResources().getColor(R.color.idredmain)); } // set agency code default TextView editAgencyCode = (TextView) cardLayout.findViewById(R.id.agencyCode); editAgencyCode.setText(ac); // set system code default TextView editSystemCode = (TextView) cardLayout.findViewById(R.id.systemCode); editSystemCode.setText(sc); // set credential number default TextView editCredNumber = (TextView) cardLayout.findViewById(R.id.credNumber); editCredNumber.setText(cn); // set pi number default TextView editPersonId = (TextView) cardLayout.findViewById(R.id.personId); editPersonId.setText(pi); // set org category String organizationalCategory = oc; if (organizationalCategory.equalsIgnoreCase("1")) { oc = "Federal"; } else if (organizationalCategory.equalsIgnoreCase("2")) { oc = "State"; } else if (organizationalCategory.equalsIgnoreCase("3")) { oc = "Commercial"; } else if (organizationalCategory.equalsIgnoreCase("4")) { oc = "International"; } else { // Default is "Federal" oc = "Federal"; } TextView editOrgCat = (TextView) cardLayout.findViewById(R.id.orgCategory); editOrgCat.setText(oc); // set poa code String associationCategory = poa; if (associationCategory.equalsIgnoreCase("1")) { poa = "Employee"; } else if (associationCategory.equalsIgnoreCase("2")) { poa = "Civil"; } else if (associationCategory.equalsIgnoreCase("3")) { poa = "Executive"; } else if (associationCategory.equalsIgnoreCase("4")) { poa = "Uniformed"; } else if (associationCategory.equalsIgnoreCase("5")) { poa = "Contractor"; } else if (associationCategory.equalsIgnoreCase("6")) { poa = "Affiliate"; } else if (associationCategory.equalsIgnoreCase("7")) { poa = "Beneficiary"; } else { // Default is "Employee" poa = "None Specified"; } TextView editPoaCode = (TextView) cardLayout.findViewById(R.id.poaCode); editPoaCode.setText(poa); // set ord id TextView editOrgid = (TextView) cardLayout.findViewById(R.id.orgId); editOrgid.setText(oi); // set expiry date TextView editExpiry = (TextView) cardLayout.findViewById(R.id.expiryDate); editExpiry.setText(expiryDate); // set guid TextView editGuid = (TextView) cardLayout.findViewById(R.id.globadId); editGuid.setText(guid); Resources res = getResources(); InputStream is = res.openRawResource(R.raw.sp80087); Properties codes = new Properties(); try { codes.loadFromXML(is); } catch (InvalidPropertiesFormatException e) { Log.e(TAG, "Error: " + e.getMessage()); } catch (IOException e) { Log.e(TAG, "Error: " + e.getMessage()); } if (codes.getProperty(ac) == null) { agencyname = "Unknown Agency"; } else { agencyname = codes.getProperty(ac); } /* * set issuing agency from XML data */ TextView editAgencyname = (TextView) cardLayout.findViewById(R.id.issuingAgency); editAgencyname.setText(agencyname); if (codes.getProperty(oi) == null) { orgname = "Unknown Organization"; } else { orgname = codes.getProperty(oi); } /* * set organization name from XML data */ TextView editOrgname = (TextView) cardLayout.findViewById(R.id.issuingOrg); editOrgname.setText(orgname); return cardLayout; }
From source file:eu.europa.ejusticeportal.dss.demo.web.portal.PortalFacadeImpl.java
@Override public Map<String, String> getLocalisedMessages(HttpServletRequest request, List<String> codes) { HashMap<String, String> map = new HashMap<String, String>(); Properties p = new Properties(); InputStream is = PortalFacadeImpl.class.getClassLoader().getResourceAsStream("i18n/messages_en.xml"); try {/*from w w w .j av a 2 s . co m*/ p.loadFromXML(is); for (Object o : p.keySet()) { map.put((String) o, messageSource.getMessage((String) o, null, request.getLocale())); } } catch (Exception e) { LOG.error("Error getting messages", e); } return map; }
From source file:org.jspringbot.keyword.config.ConfigHelper.java
private void addProperties(String domain, File file) throws IOException { String filename = file.getName(); Properties properties = new Properties(); if (StringUtils.endsWith(filename, ".properties")) { properties.load(new FileReader(file)); } else if (StringUtils.endsWith(filename, ".xml")) { properties.loadFromXML(new FileInputStream(file)); }//from ww w.j av a2 s . c o m domainProperties.put(domain, properties); }
From source file:com.adaptris.core.services.metadata.WriteMetadataToFilesystemTest.java
private Properties readProperties(File filename, boolean xml) throws IOException { Properties p = new Properties(); InputStream in = null;// ww w . j ava 2 s .co m try { in = new FileInputStream(filename); if (xml) { p.loadFromXML(in); } else { p.load(in); } } finally { IOUtils.closeQuietly(in); } return p; }
From source file:com.webpagebytes.cms.local.WPBLocalFileStorage.java
private Properties getFileProperties(String filePath) throws IOException { Properties props = new Properties(); FileInputStream fis = null;//w w w . ja v a 2 s . c om fis = new FileInputStream(filePath); props.loadFromXML(fis); return props; }