List of usage examples for org.apache.commons.configuration XMLConfiguration load
private void load(InputSource source) throws ConfigurationException
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests the isEmpty() method for an empty configuration that was reloaded. *//*from w w w . j a v a2 s . c om*/ @Test public void testEmptyReload() throws ConfigurationException { XMLConfiguration config = new XMLConfiguration(); assertTrue("Newly created configuration not empty", config.isEmpty()); config.save(testSaveConf); config.load(testSaveConf); assertTrue("Reloaded configuration not empty", config.isEmpty()); }
From source file:com.flexoodb.common.FlexUtils.java
/** * retrieves all possible elements and values of an XML file (string). * * @param content the XML whose elements will be obtained. * @return a Hashtable containing the element name (as key) and Element object containign the type (ie class and the value). * @see Hashtable/*from w w w . j av a2 s . c o m*/ * @see Element */ public Hashtable<String, Element> getAvailableValues(String content) throws Exception { Hashtable<String, Element> h = new Hashtable<String, Element>(); XMLConfiguration x = new XMLConfiguration(); x.setDelimiterParsingDisabled(true); x.load(new ByteArrayInputStream(content.getBytes())); Iterator it = x.getKeys(); String method = null; String type = null; boolean hasmethod = false; while (it.hasNext()) { String s = (String) it.next(); // make sure they have the same type? if (s.contains("[@")) { type = x.getString(s); if (!hasmethod) // then must be empty { h.put(s.substring(0, s.indexOf("[")), new Element(type, "")); type = null; method = null; } } else { hasmethod = true; method = s; } if (type != null && method != null) { if (type.endsWith("Date")) { h.put(method, new Element(type, (new SimpleDateFormat(_dateformat)).parse(x.getString(method)))); } else if (type.endsWith("byte[]")) { h.put(method, new Element(type, (byte[]) Base64.decodeBase64(x.getString(method).getBytes()))); } else if (type.endsWith("Serializable")) { h.put(method, new Element(type, (Serializable) getObject(Base64.decodeBase64(x.getString(method).getBytes())))); } else { h.put(method, new Element(type, x.getString(method))); } type = null; method = null; hasmethod = false; } } return h; }
From source file:com.flexoodb.common.FlexUtils.java
/** * use this method to instantiate a JAXB object encapsulated in a FlexContainer, given an XML document and the reference class. * * @param xml string contents containing the elements and values for the object. * @param c the reference class that wil be used for instantiation. * @return the instantiated and value-populated object. * @see Hashtable/*from w w w. j a va2 s . co m*/ * @see Element */ public Object getJAXBObject(String xml, Class c) throws Exception { Object obj = c.newInstance(); Object fc = new FlexContainer(obj); XMLConfiguration x = new XMLConfiguration(); x.setDelimiterParsingDisabled(true); x.load(new ByteArrayInputStream(xml.getBytes())); Iterator it = x.getKeys(); //Method[] m = c.getMethods(); Vector ve = retrieveMethods(obj.getClass(), null); Method[] m = new Method[ve.size()]; ve.toArray(m); String method = null; String type = null; boolean hasmethod = false; while (it.hasNext()) { String s = (String) it.next(); // make sure they have the same type? if (s.contains("[@")) { type = x.getString(s); if (method != null) { hasmethod = true; } } else { method = s; } if (hasmethod && type != null && method != null) { // check if class has the method. for (int i = 0; i < m.length; i++) { if (m[i].getName().toLowerCase().equals("set" + method)) { Object[] o = new Object[1]; Class ct = null; if (type.endsWith("String")) { ct = String.class; o[0] = x.getString(method); } else if (type.endsWith("Date")) { ct = Date.class; // assume use default java date format //o[0] = (new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy")).parse(x.getString(method)); o[0] = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(x.getString(method)); } else if (type.endsWith("BigInteger")) { ct = BigInteger.class; o[0] = new BigInteger(x.getString(method)); } else if (type.endsWith("BigDecimal")) { ct = BigDecimal.class; o[0] = new BigDecimal(x.getString(method)); } else if (type.endsWith(".Integer")) { ct = Integer.class; o[0] = x.getInt(method); } else if (type.endsWith("Long")) { ct = Long.class; o[0] = x.getLong(method); } else if (type.endsWith("Double")) { ct = Double.class; o[0] = x.getDouble(method); } else if (type.endsWith("Float")) { ct = Float.class; o[0] = x.getFloat(method); } else if (type.endsWith("Short")) { ct = Short.class; o[0] = x.getShort(method); } else if (type.endsWith("boolean")) { ct = boolean.class; o[0] = x.getBoolean(method); } else if (type.endsWith("Boolean")) { ct = Boolean.class; o[0] = x.getBoolean(method); } else if (type.endsWith("byte[]")) { ct = byte[].class; o[0] = Base64.decodeBase64(x.getString(method).getBytes()); } else if (type.endsWith("Serializable")) { ct = Serializable.class; o[0] = getObject(Base64.decodeBase64(x.getString(method).getBytes())); } else { throw new Exception("Unknown type:" + type + " for element:" + method); } Class[] c2 = new Class[1]; c2[0] = ct; //Method met = c.getMethod("set"+method,c2); Method met = c.getMethod(m[i].getName(), c2); met.invoke(obj, o); break; } } type = null; method = null; hasmethod = false; } } return obj; }
From source file:com.flexoodb.common.FlexUtils.java
/** * use this method to instantiate an object given an XML document and the reference class. * * @param xml string contents containing the elements and values for the object. * @param c the reference class that wil be used for instantiation. * @return the instantiated and value-populated object. * @see Hashtable//from w w w . j av a2 s.c o m * @see Element */ public Object getObject(String xml, Class c) throws Exception { Object obj = c.newInstance(); XMLConfiguration x = new XMLConfiguration(); x.setDelimiterParsingDisabled(true); x.load(new ByteArrayInputStream(xml.getBytes())); Iterator it = x.getKeys(); //Method[] m = c.getMethods(); Vector ve = retrieveMethods(obj.getClass(), null); Method[] m = new Method[ve.size()]; ve.toArray(m); String method = null; String type = null; boolean hasmethod = false; while (it.hasNext()) { String s = (String) it.next(); // make sure they have the same type? if (s.contains("[@")) { type = x.getString(s); if (method != null) { hasmethod = true; } } else { method = s; } if (hasmethod && type != null && method != null) { // check if class has the method. for (int i = 0; i < m.length; i++) { if (m[i].getName().toLowerCase().equals("set" + method)) { Object[] o = new Object[1]; Class ct = null; if (type.endsWith("String")) { ct = String.class; o[0] = x.getString(method); } else if (type.endsWith("XMLGregorianCalendar") || type.equalsIgnoreCase("timestamp")) { // dirty 'temporary' workaround // 2009-01-01T10:00:00.000+08:00 Date d = null; try { d = new Date(Long.parseLong(x.getString(method))); } catch (Exception a) { try { d = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S")) .parse(x.getString(method)); } catch (Exception e) { try { d = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")) .parse(x.getString(method)); } catch (Exception f) { try // must be a date only { d = (new SimpleDateFormat("yyyy-MM-dd")).parse(x.getString(method)); } catch (Exception g) // ok must be a time? { d = (new SimpleDateFormat("HH:mm:ss")).parse(x.getString(method)); } } } } GregorianCalendar gc = new GregorianCalendar(); gc.setTime(d); XMLGregorianCalendar cal = ((new com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl()) .newXMLGregorianCalendar(gc)); ct = XMLGregorianCalendar.class; o[0] = cal; } else if (type.endsWith("Date")) { ct = Date.class; // assume use default java date format //o[0] = (new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy")).parse(x.getString(method)); try { o[0] = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).parse(x.getString(method)); } catch (Exception e) { //if not must be in long version //o[0] = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date(Long.parseLong(x.getString(method)))); o[0] = new Date(Long.parseLong(x.getString(method))); } } else if (type.endsWith("BigInteger")) { ct = BigInteger.class; o[0] = new BigInteger(x.getString(method)); } else if (type.endsWith("BigDecimal")) { ct = BigDecimal.class; o[0] = new BigDecimal(x.getString(method)); } else if (type.endsWith(".Integer") || type.equals("Integer") || type.equalsIgnoreCase("int unsigned") || type.equalsIgnoreCase("tinyint")) { ct = Integer.class; o[0] = x.getInt(method); } else if (type.endsWith("Long")) { ct = Long.class; o[0] = x.getLong(method); } else if (type.endsWith("Double")) { ct = Double.class; o[0] = x.getDouble(method); } else if (type.endsWith("Float")) { ct = Float.class; o[0] = x.getFloat(method); } else if (type.endsWith("Short")) { ct = Short.class; o[0] = x.getShort(method); } else if (type.endsWith("boolean")) { ct = boolean.class; o[0] = x.getBoolean(method); } else if (type.endsWith("Boolean")) { ct = Boolean.class; o[0] = x.getBoolean(method); } else if (type.endsWith("byte[]")) { ct = byte[].class; o[0] = x.getString(method).getBytes(); } else if (type.endsWith("Serializable")) { ct = Serializable.class; o[0] = x.getString(method).getBytes(); } else { throw new Exception("Unknown type:" + type + " for element:" + method); } Class[] c2 = new Class[1]; c2[0] = ct; //Method met = c.getMethod("set"+method,c2); Method met = c.getMethod(m[i].getName(), c2); met.invoke(obj, o); break; } } type = null; method = null; hasmethod = false; } } return obj; }
From source file:ching.icecreaming.action.ViewAction.java
@Action(value = "view", results = { @Result(name = "login", location = "edit.jsp"), @Result(name = "input", location = "view.jsp"), @Result(name = "success", location = "view.jsp"), @Result(name = "error", location = "error.jsp") }) public String execute() throws Exception { Enumeration enumerator = null; String[] array1 = null, array2 = null; int int1 = -1, int2 = -1, int3 = -1; InputStream inputStream1 = null; OutputStream outputStream1 = null; java.io.File file1 = null, file2 = null, dir1 = null; List<File> files = null; HttpHost httpHost1 = null;/*from w ww.ja v a2 s .co m*/ HttpGet httpGet1 = null, httpGet2 = null; HttpPut httpPut1 = null; URI uri1 = null; URL url1 = null; DefaultHttpClient httpClient1 = null; URIBuilder uriBuilder1 = null, uriBuilder2 = null; HttpResponse httpResponse1 = null, httpResponse2 = null; HttpEntity httpEntity1 = null, httpEntity2 = null; List<NameValuePair> nameValuePair1 = null; String string1 = null, string2 = null, string3 = null, string4 = null, return1 = LOGIN; XMLConfiguration xmlConfiguration = null; List<HierarchicalConfiguration> list1 = null, list2 = null; HierarchicalConfiguration hierarchicalConfiguration2 = null; DataModel1 dataModel1 = null; DataModel2 dataModel2 = null; List<DataModel1> listObject1 = null, listObject3 = null; org.joda.time.DateTime dateTime1 = null, dateTime2 = null; org.joda.time.Period period1 = null; PeriodFormatter periodFormatter1 = new PeriodFormatterBuilder().appendYears() .appendSuffix(String.format(" %s", getText("year")), String.format(" %s", getText("years"))) .appendSeparator(" ").appendMonths() .appendSuffix(String.format(" %s", getText("month")), String.format(" %s", getText("months"))) .appendSeparator(" ").appendWeeks() .appendSuffix(String.format(" %s", getText("week")), String.format(" %s", getText("weeks"))) .appendSeparator(" ").appendDays() .appendSuffix(String.format(" %s", getText("day")), String.format(" %s", getText("days"))) .appendSeparator(" ").appendHours() .appendSuffix(String.format(" %s", getText("hour")), String.format(" %s", getText("hours"))) .appendSeparator(" ").appendMinutes() .appendSuffix(String.format(" %s", getText("minute")), String.format(" %s", getText("minutes"))) .appendSeparator(" ").appendSeconds().minimumPrintedDigits(2) .appendSuffix(String.format(" %s", getText("second")), String.format(" %s", getText("seconds"))) .printZeroNever().toFormatter(); if (StringUtils.isBlank(urlString) || StringUtils.isBlank(wsType)) { urlString = portletPreferences.getValue("urlString", "/"); wsType = portletPreferences.getValue("wsType", "folder"); } Configuration propertiesConfiguration1 = new PropertiesConfiguration("system.properties"); timeZone1 = portletPreferences.getValue("timeZone", TimeZone.getDefault().getID()); enumerator = portletPreferences.getNames(); if (enumerator.hasMoreElements()) { array1 = portletPreferences.getValues("server", null); if (array1 != null) { if (ArrayUtils.isNotEmpty(array1)) { for (int1 = 0; int1 < array1.length; int1++) { switch (int1) { case 0: sid = array1[int1]; break; case 1: uid = array1[int1]; break; case 2: pid = array1[int1]; break; case 3: alias1 = array1[int1]; break; default: break; } } sid = new String(Base64.decodeBase64(sid.getBytes())); uid = new String(Base64.decodeBase64(uid.getBytes())); pid = new String(Base64.decodeBase64(pid.getBytes())); } return1 = INPUT; } else { return1 = LOGIN; } } else { return1 = LOGIN; } if (StringUtils.equals(urlString, "/")) { if (listObject1 != null) { listObject1.clear(); } if (session.containsKey("breadcrumbs")) { session.remove("breadcrumbs"); } } else { array2 = StringUtils.split(urlString, "/"); listObject1 = (session.containsKey("breadcrumbs")) ? (List<DataModel1>) session.get("breadcrumbs") : new ArrayList<DataModel1>(); int2 = array2.length - listObject1.size(); if (int2 > 0) { listObject1.add(new DataModel1(urlString, label1)); } else { int2 += listObject1.size(); for (int1 = listObject1.size() - 1; int1 >= int2; int1--) { listObject1.remove(int1); } } session.put("breadcrumbs", listObject1); } switch (wsType) { case "folder": break; case "reportUnit": try { dateTime1 = new org.joda.time.DateTime(); return1 = INPUT; httpClient1 = new DefaultHttpClient(); if (StringUtils.equals(button1, getText("Print"))) { nameValuePair1 = new ArrayList<NameValuePair>(); if (listObject2 != null) { if (listObject2.size() > 0) { for (DataModel2 dataObject2 : listObject2) { listObject3 = dataObject2.getOptions(); if (listObject3 == null) { string2 = dataObject2.getValue1(); if (StringUtils.isNotBlank(string2)) nameValuePair1.add(new BasicNameValuePair(dataObject2.getId(), string2)); } else { for (int1 = listObject3.size() - 1; int1 >= 0; int1--) { dataModel1 = (DataModel1) listObject3.get(int1); string2 = dataModel1.getString2(); if (StringUtils.isNotBlank(string2)) nameValuePair1 .add(new BasicNameValuePair(dataObject2.getId(), string2)); } } } } } url1 = new URL(sid); uriBuilder1 = new URIBuilder(sid); uriBuilder1.setUserInfo(uid, pid); if (StringUtils.isBlank(format1)) format1 = "pdf"; uriBuilder1.setPath(url1.getPath() + "/rest_v2/reports" + urlString + "." + format1); if (StringUtils.isNotBlank(locale2)) { nameValuePair1.add(new BasicNameValuePair("userLocale", locale2)); } if (StringUtils.isNotBlank(page1)) { if (NumberUtils.isNumber(page1)) { nameValuePair1.add(new BasicNameValuePair("page", page1)); } } if (nameValuePair1.size() > 0) { uriBuilder1.setQuery(URLEncodedUtils.format(nameValuePair1, "UTF-8")); } uri1 = uriBuilder1.build(); httpGet1 = new HttpGet(uri1); httpResponse1 = httpClient1.execute(httpGet1); int1 = httpResponse1.getStatusLine().getStatusCode(); if (int1 == HttpStatus.SC_OK) { string3 = System.getProperty("java.io.tmpdir") + File.separator + httpServletRequest.getSession().getId(); dir1 = new File(string3); if (!dir1.exists()) { dir1.mkdir(); } httpEntity1 = httpResponse1.getEntity(); file1 = new File(string3, StringUtils.substringAfterLast(urlString, "/") + "." + format1); if (StringUtils.equalsIgnoreCase(format1, "html")) { result1 = EntityUtils.toString(httpEntity1); FileUtils.writeStringToFile(file1, result1); array1 = StringUtils.substringsBetween(result1, "<img src=\"", "\""); if (ArrayUtils.isNotEmpty(array1)) { dir1 = new File( string3 + File.separator + FilenameUtils.getBaseName(file1.getName())); if (dir1.exists()) { FileUtils.deleteDirectory(dir1); } file2 = new File(FilenameUtils.getFullPath(file1.getAbsolutePath()) + FilenameUtils.getBaseName(file1.getName()) + ".zip"); if (file2.exists()) { if (FileUtils.deleteQuietly(file2)) { } } for (int2 = 0; int2 < array1.length; int2++) { try { string2 = url1.getPath() + "/rest_v2/reports" + urlString + "/" + StringUtils.substringAfter(array1[int2], "/"); uriBuilder1.setPath(string2); uri1 = uriBuilder1.build(); httpGet1 = new HttpGet(uri1); httpResponse1 = httpClient1.execute(httpGet1); int1 = httpResponse1.getStatusLine().getStatusCode(); } finally { if (int1 == HttpStatus.SC_OK) { try { string2 = StringUtils.substringBeforeLast(array1[int2], "/"); dir1 = new File(string3 + File.separator + string2); if (!dir1.exists()) { dir1.mkdirs(); } httpEntity1 = httpResponse1.getEntity(); inputStream1 = httpEntity1.getContent(); } finally { string1 = StringUtils.substringAfterLast(array1[int2], "/"); file2 = new File(string3 + File.separator + string2, string1); outputStream1 = new FileOutputStream(file2); IOUtils.copy(inputStream1, outputStream1); } } } } outputStream1 = new FileOutputStream( FilenameUtils.getFullPath(file1.getAbsolutePath()) + FilenameUtils.getBaseName(file1.getName()) + ".zip"); ArchiveOutputStream archiveOutputStream1 = new ArchiveStreamFactory() .createArchiveOutputStream(ArchiveStreamFactory.ZIP, outputStream1); archiveOutputStream1.putArchiveEntry(new ZipArchiveEntry(file1, file1.getName())); IOUtils.copy(new FileInputStream(file1), archiveOutputStream1); archiveOutputStream1.closeArchiveEntry(); dir1 = new File(FilenameUtils.getFullPath(file1.getAbsolutePath()) + FilenameUtils.getBaseName(file1.getName())); files = (List<File>) FileUtils.listFiles(dir1, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File file3 : files) { archiveOutputStream1.putArchiveEntry(new ZipArchiveEntry(file3, StringUtils .substringAfter(file3.getCanonicalPath(), string3 + File.separator))); IOUtils.copy(new FileInputStream(file3), archiveOutputStream1); archiveOutputStream1.closeArchiveEntry(); } archiveOutputStream1.close(); } bugfixGateIn = propertiesConfiguration1.getBoolean("bugfixGateIn", false); string4 = bugfixGateIn ? String.format("<img src=\"%s/namespace1/file-link?sessionId=%s&fileName=", portletRequest.getContextPath(), httpServletRequest.getSession().getId()) : String.format("<img src=\"%s/namespace1/file-link?fileName=", portletRequest.getContextPath()); result1 = StringUtils.replace(result1, "<img src=\"", string4); } else { inputStream1 = httpEntity1.getContent(); outputStream1 = new FileOutputStream(file1); IOUtils.copy(inputStream1, outputStream1); result1 = file1.getAbsolutePath(); } return1 = SUCCESS; } else { addActionError(String.format("%s %d: %s", getText("Error"), int1, getText(Integer.toString(int1)))); } dateTime2 = new org.joda.time.DateTime(); period1 = new Period(dateTime1, dateTime2.plusSeconds(1)); message1 = getText("Execution.time") + ": " + periodFormatter1.print(period1); } else { url1 = new URL(sid); uriBuilder1 = new URIBuilder(sid); uriBuilder1.setUserInfo(uid, pid); uriBuilder1.setPath(url1.getPath() + "/rest_v2/reports" + urlString + "/inputControls"); uri1 = uriBuilder1.build(); httpGet1 = new HttpGet(uri1); httpResponse1 = httpClient1.execute(httpGet1); int1 = httpResponse1.getStatusLine().getStatusCode(); switch (int1) { case HttpStatus.SC_NO_CONTENT: break; case HttpStatus.SC_OK: httpEntity1 = httpResponse1.getEntity(); if (httpEntity1 != null) { inputStream1 = httpEntity1.getContent(); if (inputStream1 != null) { xmlConfiguration = new XMLConfiguration(); xmlConfiguration.load(inputStream1); list1 = xmlConfiguration.configurationsAt("inputControl"); if (list1.size() > 0) { listObject2 = new ArrayList<DataModel2>(); for (HierarchicalConfiguration hierarchicalConfiguration1 : list1) { string2 = hierarchicalConfiguration1.getString("type"); dataModel2 = new DataModel2(); dataModel2.setId(hierarchicalConfiguration1.getString("id")); dataModel2.setLabel1(hierarchicalConfiguration1.getString("label")); dataModel2.setType1(string2); dataModel2.setMandatory(hierarchicalConfiguration1.getBoolean("mandatory")); dataModel2.setReadOnly(hierarchicalConfiguration1.getBoolean("readOnly")); dataModel2.setVisible(hierarchicalConfiguration1.getBoolean("visible")); switch (string2) { case "bool": case "singleValueText": case "singleValueNumber": case "singleValueDate": case "singleValueDatetime": hierarchicalConfiguration2 = hierarchicalConfiguration1 .configurationAt("state"); dataModel2.setValue1(hierarchicalConfiguration2.getString("value")); break; case "singleSelect": case "singleSelectRadio": case "multiSelect": case "multiSelectCheckbox": hierarchicalConfiguration2 = hierarchicalConfiguration1 .configurationAt("state"); list2 = hierarchicalConfiguration2.configurationsAt("options.option"); if (list2.size() > 0) { listObject3 = new ArrayList<DataModel1>(); for (HierarchicalConfiguration hierarchicalConfiguration3 : list2) { dataModel1 = new DataModel1( hierarchicalConfiguration3.getString("label"), hierarchicalConfiguration3.getString("value")); if (hierarchicalConfiguration3.getBoolean("selected")) { dataModel2.setValue1( hierarchicalConfiguration3.getString("value")); } listObject3.add(dataModel1); } dataModel2.setOptions(listObject3); } break; default: break; } listObject2.add(dataModel2); } } } } break; default: addActionError(String.format("%s %d: %s", getText("Error"), int1, getText(Integer.toString(int1)))); break; } if (httpEntity1 != null) { EntityUtils.consume(httpEntity1); } uriBuilder1.setPath(url1.getPath() + "/rest/resource" + urlString); uri1 = uriBuilder1.build(); httpGet1 = new HttpGet(uri1); httpResponse1 = httpClient1.execute(httpGet1); int2 = httpResponse1.getStatusLine().getStatusCode(); if (int2 == HttpStatus.SC_OK) { httpEntity1 = httpResponse1.getEntity(); inputStream1 = httpEntity1.getContent(); xmlConfiguration = new XMLConfiguration(); xmlConfiguration.load(inputStream1); list1 = xmlConfiguration.configurationsAt("resourceDescriptor"); for (HierarchicalConfiguration hierarchicalConfiguration4 : list1) { if (StringUtils.equalsIgnoreCase( StringUtils.trim(hierarchicalConfiguration4.getString("[@wsType]")), "prop")) { if (map1 == null) map1 = new HashMap<String, String>(); string2 = StringUtils.substringBetween( StringUtils.substringAfter( hierarchicalConfiguration4.getString("[@uriString]"), "_files/"), "_", ".properties"); map1.put(string2, StringUtils.isBlank(string2) ? getText("Default") : getText(string2)); } } } if (httpEntity1 != null) { EntityUtils.consume(httpEntity1); } } } catch (IOException | ConfigurationException | URISyntaxException exception1) { exception1.printStackTrace(); addActionError(exception1.getLocalizedMessage()); httpGet1.abort(); return ERROR; } finally { httpClient1.getConnectionManager().shutdown(); IOUtils.closeQuietly(inputStream1); } break; default: addActionError(getText("This.file.type.is.not.supported")); break; } if (return1 != LOGIN) { sid = new String(Base64.encodeBase64(sid.getBytes())); uid = new String(Base64.encodeBase64(uid.getBytes())); pid = new String(Base64.encodeBase64(pid.getBytes())); } return return1; }
From source file:org.accada.hal.impl.sim.BatchSimulator.java
/** * initializes the fields and starts the simulator. * * @throws SimulatorException if the event input file could not be opened. *//*ww w. j a va 2s . c om*/ private void initSimulator() throws SimulatorException { // load properties from config file XMLConfiguration config = new XMLConfiguration(); URL fileurl = ResourceLocator.getURL(configFile, defaultConfigFile, this.getClass()); try { config.load(fileurl); } catch (ConfigurationException ce) { throw new SimulatorException("Can not load config file '" + configFile + "'."); } // get properties String file = config.getString("batchfile"); cycles = config.getLong("iterations"); // find batchfile URL batchfileurl = ResourceLocator.getURL(file, file, this.getClass()); try { eventFile = new File(batchfileurl.toURI()); } catch (URISyntaxException e1) { throw new SimulatorException("Can not creat URI of batchfile '" + file + "'."); } rfidThread = null; threadRunning = false; stopRequested = false; try { // tries to open file FileReader in = new FileReader(eventFile); in.close(); // start simulator thread start(); } catch (IOException e) { throw new SimulatorException("Cannot open event file '" + file + "': " + e); } }
From source file:org.apache.giraph.rexster.io.formats.TestAbstractRexsterInputFormat.java
@Before @SuppressWarnings("unchecked") public void setUp() throws Exception { final XMLConfiguration properties = new XMLConfiguration(); final RexsterApplication application; final List<HierarchicalConfiguration> graphConfigs; final InputStream rexsterConf; final int scriptEngineThreshold; final String scriptEngineInitFile; final List<String> scriptEngineNames; /* prepare all databases */ for (int i = 0; i < DATABASES.length; ++i) { prepareDb(DATABASES[i]);/*from w w w. j ava2 s. co m*/ } /* start the Rexster HTTP server using the prepared rexster configuration */ rexsterConf = this.getClass().getResourceAsStream(REXSTER_CONF); properties.load(rexsterConf); rexsterConf.close(); graphConfigs = properties.configurationsAt(Tokens.REXSTER_GRAPH_PATH); application = new XmlRexsterApplication(graphConfigs); this.server = new HttpRexsterServer(properties); scriptEngineThreshold = properties.getInt("script-engine-reset-threshold", EngineController.RESET_NEVER); scriptEngineInitFile = properties.getString("script-engine-init", ""); /* allow scriptengines to be configured so that folks can drop in different gremlin flavors. */ scriptEngineNames = properties.getList("script-engines"); if (scriptEngineNames == null) { // configure to default with gremlin-groovy EngineController.configure(scriptEngineThreshold, scriptEngineInitFile); } else { EngineController.configure(scriptEngineThreshold, scriptEngineInitFile, new HashSet<String>(scriptEngineNames)); } this.server.start(application); }
From source file:org.apache.giraph.rexster.io.formats.TestRexsterLongDoubleFloatIOFormat.java
/** * Start the Rexster server by preparing the configuration file loaded via * the resources and setting other important parameters. *//*from w ww. j a v a 2 s . co m*/ @SuppressWarnings("unchecked") private static void startRexsterServer() throws Exception { InputStream rexsterConf = TestRexsterLongDoubleFloatIOFormat.class.getResourceAsStream(REXSTER_CONF); XMLConfiguration properties = new XMLConfiguration(); properties.load(rexsterConf); rexsterConf.close(); List<HierarchicalConfiguration> graphConfigs = properties.configurationsAt(Tokens.REXSTER_GRAPH_PATH); RexsterApplication application = new XmlRexsterApplication(graphConfigs); server = new HttpRexsterServer(properties); int scriptEngineThreshold = properties.getInt("script-engine-reset-threshold", EngineController.RESET_NEVER); String scriptEngineInitFile = properties.getString("script-engine-init", ""); /* allow scriptengines to be configured so that folks can drop in different gremlin flavors. */ List<String> scriptEngineNames = properties.getList("script-engines"); if (scriptEngineNames == null) { /* configure to default with gremlin-groovy */ EngineController.configure(scriptEngineThreshold, scriptEngineInitFile); } else { EngineController.configure(scriptEngineThreshold, scriptEngineInitFile, new HashSet<String>(scriptEngineNames)); } server.start(application); }
From source file:org.apache.james.container.spring.lifecycle.ConfigurationProviderImpl.java
/** * Load the xmlConfiguration from the given resource. * /*from www . j a v a2 s .c o m*/ * @param r * @return * @throws ConfigurationException * @throws IOException */ private XMLConfiguration getConfig(Resource r) throws ConfigurationException, IOException { XMLConfiguration config = new XMLConfiguration(); config.setDelimiterParsingDisabled(true); // Don't split attributes which can have bad side-effects with matcher-conditions. // See JAMES-1233 config.setAttributeSplittingDisabled(true); // Use InputStream so we are not bound to File implementations of the // config config.load(r.getInputStream()); return config; }
From source file:org.apache.james.container.spring.lifecycle.osgi.OSGIConfigurationProvider.java
@Override public HierarchicalConfiguration getConfiguration(String beanName) throws ConfigurationException { XMLConfiguration config = new XMLConfiguration(); FileInputStream fis = null;/*from w w w. j ava 2 s. c o m*/ config.setDelimiterParsingDisabled(true); // Don't split attributes which can have bad side-effects with matcher-conditions. // See JAMES-1233 config.setAttributeSplittingDisabled(true); // Use InputStream so we are not bound to File implementations of the // config try { fis = new FileInputStream("/tmp/" + beanName + ".xml"); config.load(fis); } catch (FileNotFoundException e) { throw new ConfigurationException("Bean " + beanName); } finally { if (fis != null) { try { fis.close(); } catch (Exception e) { // Left empty on purpose } } } return config; }