List of usage examples for java.util Properties get
@Override
public Object get(Object key)
From source file:org.eclipse.gemini.blueprint.test.AbstractDependencyManagerTests.java
/** * Returns the bundles that have to be installed as part of the test setup. * This method is preferred as the bundles are by their names rather then as * {@link Resource}s. It allows for a <em>declarative</em> approach for * specifying bundles as opposed to {@link #getTestBundles()} which provides * a programmatic one./* w w w . j a v a2 s . c om*/ * * <p/>This implementation reads a predefined properties file to determine * the bundles needed. If the configuration needs to be changed, consider * changing the configuration location. * * @return an array of testing framework bundle identifiers * @see #getTestingFrameworkBundlesConfiguration() * @see #locateBundle(String) * */ protected String[] getTestFrameworkBundlesNames() { // load properties file Properties props = PropertiesUtil.loadAndExpand(getTestingFrameworkBundlesConfiguration()); if (props == null) throw new IllegalArgumentException( "cannot load default configuration from " + getTestingFrameworkBundlesConfiguration()); boolean trace = logger.isTraceEnabled(); if (trace) logger.trace("Loaded properties " + props); // pass properties to test instance running inside OSGi space System.getProperties().put(GEMINI_BLUEPRINT_VERSION_PROP_KEY, props.get(GEMINI_BLUEPRINT_VERSION_PROP_KEY)); System.getProperties().put(SPRING_VERSION_PROP_KEY, props.get(SPRING_VERSION_PROP_KEY)); Properties excluded = PropertiesUtil.filterKeysStartingWith(props, IGNORE); if (trace) { logger.trace("Excluded ignored properties " + excluded); } String[] bundles = props.keySet().toArray(new String[props.size()]); // sort the array (as the Properties file doesn't respect the order) //bundles = StringUtils.sortStringArray(bundles); if (logger.isDebugEnabled()) logger.debug("Default framework bundles :" + ObjectUtils.nullSafeToString(bundles)); return bundles; }
From source file:com.krawler.esp.utils.ConfigReader.java
/** Writes non-default properties in this configuration. */ public void write(OutputStream out) throws IOException { Properties properties = getProps(); try {/*w w w. jav a 2s .c om*/ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element conf = doc.createElement("krawler-conf"); doc.appendChild(conf); conf.appendChild(doc.createTextNode("\n")); for (Enumeration e = properties.keys(); e.hasMoreElements();) { String name = (String) e.nextElement(); String value = (String) properties.get(name); Element propNode = doc.createElement("property"); conf.appendChild(propNode); Element nameNode = doc.createElement("name"); nameNode.appendChild(doc.createTextNode(name)); propNode.appendChild(nameNode); Element valueNode = doc.createElement("value"); valueNode.appendChild(doc.createTextNode(value)); propNode.appendChild(valueNode); conf.appendChild(doc.createTextNode("\n")); } DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(out); TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = transFactory.newTransformer(); transformer.transform(source, result); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory.java
/** * Gets the custom retry policy.// w w w . ja v a 2 s . c o m * * @param props * the props * @return the custom retry policy * @throws ClassNotFoundException * @throws IllegalAccessException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws Exception * the exception */ private com.datastax.driver.core.policies.RetryPolicy getCustomRetryPolicy(Properties props) { String customRetryPolicy = (String) props.get(CUSTOM_RETRY_POLICY); Class<?> clazz = null; Method getter = null; try { clazz = Class.forName(customRetryPolicy); com.datastax.driver.core.policies.RetryPolicy retryPolicy = (com.datastax.driver.core.policies.RetryPolicy) KunderaCoreUtils .createNewInstance(clazz); if (retryPolicy != null) { return retryPolicy; } getter = clazz.getDeclaredMethod(GET_INSTANCE); return (com.datastax.driver.core.policies.RetryPolicy) getter.invoke(null, (Object[]) null); } catch (ClassNotFoundException e) { logger.error(e.getMessage()); throw new KunderaException("Please make sure class " + customRetryPolicy + " set in property file exists in classpath " + e.getMessage()); } catch (IllegalAccessException e) { logger.error(e.getMessage()); throw new KunderaException("Method " + getter.getName() + " must be declared public " + e.getMessage()); } catch (NoSuchMethodException e) { logger.error(e.getMessage()); throw new KunderaException( "Please make sure getter method of " + clazz.getSimpleName() + " is named \"getInstance()\""); } catch (InvocationTargetException e) { logger.error(e.getMessage()); throw new KunderaException("Error while executing \"getInstance()\" method of Class " + clazz.getSimpleName() + ": " + e.getMessage()); } }
From source file:com.zotoh.maedr.etc.CmdApps.java
protected void eval(String[] args) throws Exception { if (args == null || args.length < 2 || !"create".equals(args[0])) { throw new CmdHelpError(); }/*from w w w . j a va 2 s .c o m*/ boolean webapp = "/webapp".equals(args.length > 2 ? args[2] : ""); String app = args[1]; File base = getCwd(); CmdLineSequence s = constructInput(app); Properties props = new Properties(); props.put("name", app); s.start(props); if (s.isCanceled()) { return; } props.put("delegate", "DelegateImpl"); props.put("processor", "FlowImpl"); // props.put("task", "Task10001"); props.put("apptype", webapp ? APPTYPE_WEB : APPTYPE_SVR); System.out.println("\n\n"); System.out.format("%-20s%s\n", "Application name:", props.get("name")); System.out.format("%-20s%s\n", "Package name:", props.get("package")); System.out.format("%-20s%s\n", "Database:", ((Boolean) props.get("storage")) ? "yes" : "no"); System.out.format("%-20s%s\n", "Language Choice:", props.get("lang")); System.out.println("\n"); File appdir = create0(false, base, props.getProperty("name")); create1(appdir, "", props); create2(appdir, "", props); create3(appdir, props); create4(appdir, props); create5(appdir, props); create6(appdir); if (webapp) { create7(appdir, props); } create8(appdir, props); System.out.println("\n"); System.out.println("Application was created successfully."); System.out.println("\n"); }
From source file:com.urbancode.ud.client.ResourceClient.java
public void applyTemplate(String resourceParam, String resourceTemplateId, Properties properties) throws JSONException, IOException { JSONObject json = new JSONObject(); json.put("resourceTemplateId", resourceTemplateId); json.put("targetResourceId", resourceParam); for (Object key : properties.keySet()) { String propertyKey = "p_" + (String) key; json.put(propertyKey, properties.get(key)); }// ww w . ja va 2 s . c o m HttpPut method = new HttpPut(url + "/rest/resource/resource/applyTemplate"); method.setEntity(getStringEntity(json)); invokeMethod(method); }
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceObjectProviderBase.java
/** * Copy all properties that not already exist in target from source. */// w w w .j av a 2 s . co m private void mergeProperties(Properties aTarget, Properties aSource) { for (Object key : aSource.keySet()) { if (!aTarget.containsKey(key)) { aTarget.put(key, aSource.get(key)); } } }
From source file:com.yoncabt.ebr.executor.jasper.JasperReport.java
@Override public void exportTo(ReportRequest request, ReportOutputFormat outputFormat, EBRConnection connection, ReportDefinition reportDefinition) throws ReportException, IOException { Map<String, Object> params = request.getReportParams(); String locale = request.getLocale(); String uuid = request.getUuid(); // nce genel parametreleri dolduralm. logo_path falan gibi EBRConf.INSTANCE.getMap().entrySet().stream().forEach((es) -> { String key = es.getKey(); if (key.startsWith("report.jrproperties.")) { key = key.substring("report.jrproperties.".length()); String value = es.getValue(); DefaultJasperReportsContext.getInstance().setProperty(key, value); }/*from w ww . jav a 2 s . c o m*/ if (key.startsWith("report.params.")) { key = key.substring("report.params.".length()); String value = es.getValue(); params.put(key, value); } }); params.put("__extension", outputFormat.name()); params.put("__start_time", System.currentTimeMillis()); params.put(JRParameter.REPORT_LOCALE, LocaleUtils.toLocale(locale)); File jrxmlFile = reportDefinition.getFile(); //alttaki satr tehlikeli olabilir mi ? String resourceFileName = "messages_" + locale + ".properties"; try { File resourceFile = new File(jrxmlFile.getParentFile(), resourceFileName); Properties properties = new Properties(); try (FileInputStream fis = new FileInputStream(resourceFile)) { properties.load(fis); } ResourceBundle rb = new ResourceBundle() { @Override protected Object handleGetObject(String key) { return properties.get(key); } @Override public Enumeration<String> getKeys() { return (Enumeration<String>) ((Enumeration<?>) properties.keys()); } }; // FIXME yerelletime dosyalar buradan okunacak params.put(JRParameter.REPORT_RESOURCE_BUNDLE, rb); } catch (FileNotFoundException e) { logManager.info(resourceFileName + " file does not found!"); } String virtDir = EBRConf.INSTANCE.getValue(EBRParams.REPORTS_VIRTUALIZER_DIRECTORY, "/tmp/ebr/virtualizer"); int maxSize = EBRConf.INSTANCE.getValue(EBRParams.REPORTS_VIRTUALIZER_MAXSIZE, Integer.MAX_VALUE); JRAbstractLRUVirtualizer virtualizer = new JRFileVirtualizer(maxSize, virtDir); params.put(JRParameter.REPORT_VIRTUALIZER, virtualizer); net.sf.jasperreports.engine.JasperReport jasperReport; try { jasperReport = (net.sf.jasperreports.engine.JasperReport) JRLoader .loadObject(com.yoncabt.ebr.executor.jasper.JasperReport.compileIfRequired(jrxmlFile)); } catch (JRException ex) { throw new ReportException(ex); } for (JRParameter param : jasperReport.getParameters()) { Object val = params.get(param.getName()); if (val == null) { continue; } params.put(param.getName(), Convert.to(val, param.getValueClass())); } reportLogger.logReport(request, outputFormat, new ByteArrayInputStream(new byte[0])); JasperPrint jasperPrint; try { jasperPrint = JasperFillManager.fillReport(jasperReport, /*jasper parametreleri deitiriyor*/ new HashMap<>(params), connection); } catch (JRException ex) { throw new ReportException(ex); } File outBase = new File(EBRConf.INSTANCE.getValue(EBRParams.REPORTS_OUT_PATH, "/usr/local/reports/out")); outBase.mkdirs(); File exportReportFile = new File(outBase, uuid + "." + outputFormat.name()); Exporter exporter; ExporterOutput output; switch (outputFormat) { case pdf: exporter = new JRPdfExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case html: exporter = new HtmlExporter(); output = new SimpleHtmlExporterOutput(exportReportFile); break; case xls: exporter = new JRXlsExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case xlsx: exporter = new JRXlsxExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case rtf: exporter = new JRRtfExporter(); output = new SimpleWriterExporterOutput(exportReportFile); break; case csv: exporter = new JRCsvExporter(); output = new SimpleWriterExporterOutput(exportReportFile); break; case xml: exporter = new JRXmlExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case docx: exporter = new JRDocxExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case odt: exporter = new JROdtExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case ods: exporter = new JROdsExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case jprint: case txt: exporter = new JRTextExporter(); output = new SimpleWriterExporterOutput(exportReportFile); putTextParams((JRTextExporter) exporter, params, reportDefinition.getTextTemplate()); break; default: throw new AssertionError(outputFormat.toString() + " not supported"); } exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(output); try { exporter.exportReport(); } catch (JRException ex) { throw new ReportException(ex); } if (outputFormat.isText() && !"utf-8".equals(reportDefinition.getTextEncoding())) { String reportData = FileUtils.readFileToString(exportReportFile, "utf-8"); if ("ascii".equals(reportDefinition.getTextEncoding())) { FileUtils.write(exportReportFile, ASCIIFier.ascii(reportData)); } else { FileUtils.write(exportReportFile, reportData, reportDefinition.getTextEncoding()); } } try (FileInputStream fis = new FileInputStream(exportReportFile)) { reportLogger.logReport(request, outputFormat, fis); } exportReportFile.delete(); }
From source file:com.bluexml.side.Framework.alfresco.signature.integration.SignatureHelper.java
/** This function sign all the pdf describe by myFileToSign and all pdf linked to file into myFileToSign (test.doc is into myFileToSign, if test.pdf exist it will be sign). * This pdf need to be child of parapheur or document. * WARNING exception are passed to the action by reference because serviceRegistry.getActionService().executeAction() doesn't throw exception. * @param props all the properties needed to sign * @param entree the folder where are the files to sign. * @param myFileToSign the list of file(s) to diffuse. * @param destination The folder where the signed file are created. If null signed file are brother of the original file. * @return exception if there are/* w w w .j a v a 2 s . com*/ **/ public ArrayList<String> execute(Properties props, NodeRef entree, List<AssociationRef> myFileToSign, NodeRef destination) { ArrayList<String> exception = new ArrayList<String>(); NodeRef key = null; Map<String, Serializable> params = null; //Get the keystore. List<NodeRef> assocTarget = null; NodeRef root = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); assocTarget = serviceRegistry.getSearchService() .query(root.getStoreRef(), SearchService.LANGUAGE_LUCENE, "PATH:\"" + props.get("Service.signature.keystore.path") + "cm:" + props.get("Service.signature.keystore.name") + "\"") .getNodeRefs(); if (assocTarget.size() > 0) { key = assocTarget.get(0); } else { logger.error("Keystore not found at " + props.get("Service.signature.keystore.path") + props.get("Service.signature.keystore.name")); exception.add("Keystore not found at " + props.get("Service.signature.keystore.path") + props.get("Service.signature.keystore.name")); return exception; } //test if properties are correct. exception = testinit(props, entree); if (!exception.isEmpty()) { return exception; } else { //Initialize parameters. params = initParams(props, key, exception); } /* Parse myFileToSign, if it is a pdf => sign it * if not test if a pdf file exist with the same cm:name less the extension. */ for (AssociationRef child : myFileToSign) { ContentReader myReader = serviceRegistry.getContentService().getReader(child.getTargetRef(), ContentModel.PROP_CONTENT); if (myReader.getMimetype().equals("application/pdf")) { logger.debug("Start signature of document " + nodeService.getProperty(child.getTargetRef(), ContentModel.PROP_NAME)); //Create Sign pdf action. if (destination != null && nodeService.exists(destination)) { params.put("destination-folder", destination); } else { params.put("destination-folder", nodeService.getPrimaryParent(child.getTargetRef()).getParentRef()); } Action signPDF = serviceRegistry.getActionService().createAction("pdf-signature", params); serviceRegistry.getActionService().executeAction(signPDF, child.getTargetRef()); } else { //Get Name without extension String name = (String) nodeService.getProperty(child.getTargetRef(), ContentModel.PROP_NAME); String[] splitedName = name.split("\\."); name = getNameWithoutExtension(splitedName); //Get all files under parapheurDocuments List<ChildAssociationRef> myFiles = nodeService.getChildAssocs(entree); for (ChildAssociationRef mychild : myFiles) { if (nodeService.getType(mychild.getChildRef()) == ContentModel.TYPE_CONTENT) { // Test if names matche if (nodeService.getProperty(mychild.getChildRef(), ContentModel.PROP_NAME) .equals(name + ".pdf")) { logger.debug("Start signature of document " + nodeService.getProperty(mychild.getChildRef(), ContentModel.PROP_NAME)); if (destination != null && nodeService.exists(destination)) { params.put("destination-folder", destination); } else { params.put("destination-folder", nodeService.getPrimaryParent(mychild.getParentRef())); } Action signPDF = serviceRegistry.getActionService().createAction("pdf-signature", params); serviceRegistry.getActionService().executeAction(signPDF, mychild.getChildRef()); break; } } else if (nodeService.getType(mychild.getChildRef()) == ContentModel.TYPE_FOLDER) { if (searchFilesIntoFolders(mychild.getChildRef(), name + ".pdf", params, destination)) { break; } } } } } return exception; }
From source file:pl.project13.maven.git.GitCommitIdMojoIntegrationTest.java
@Test @Parameters(method = "useNativeGit") public void testDetectCleanWorkingDirectory(boolean useNativeGit) throws Exception { // given/*from w ww . java 2 s . co m*/ mavenSandbox.withParentProject("my-pom-project", "pom").withChildProject("my-jar-module", "jar") .withGitRepoInChild(AvailableGitTestRepo.GIT_WITH_NO_CHANGES).create(); MavenProject targetProject = mavenSandbox.getChildProject(); setProjectToExecuteMojoIn(targetProject); GitDescribeConfig gitDescribeConfig = createGitDescribeConfig(true, 7); String dirtySuffix = "-dirtyTest"; gitDescribeConfig.setDirty(dirtySuffix); alterMojoSettings("gitDescribe", gitDescribeConfig); alterMojoSettings("useNativeGit", useNativeGit); alterMojoSettings("commitIdGenerationMode", "flat"); // when mojo.execute(); // then Properties properties = targetProject.getProperties(); assertThat(properties.get("git.dirty")).isEqualTo("false"); assertThat(properties).includes(entry("git.commit.id.describe", "85c2888")); // assert no dirtySuffix at the end! }
From source file:com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory.java
/** * Gets the policy.//from ww w .j av a 2s.c o m * * @param policy * the policy * @param props * the props * @return the policy * @throws Exception * the exception */ private com.datastax.driver.core.policies.RetryPolicy getPolicy(RetryPolicy policy, Properties props) { com.datastax.driver.core.policies.RetryPolicy retryPolicy = null; String isLoggingRetry = (String) props.get("isLoggingRetry"); switch (policy) { case DowngradingConsistencyRetryPolicy: retryPolicy = DowngradingConsistencyRetryPolicy.INSTANCE; break; case FallthroughRetryPolicy: retryPolicy = FallthroughRetryPolicy.INSTANCE; break; case Custom: retryPolicy = getCustomRetryPolicy(props); break; default: break; } if (retryPolicy != null && Boolean.valueOf(isLoggingRetry)) { retryPolicy = new LoggingRetryPolicy(retryPolicy); } return retryPolicy; }