List of usage examples for org.apache.commons.configuration Configuration isEmpty
boolean isEmpty();
From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java
public static boolean configureOld(File tempDir, Configuration configuration) { logger.info("PackageManager::configure()"); boolean status = true; if (tempDir != null && configuration != null && !configuration.isEmpty()) { VelocityEngine velocityEngine = new VelocityEngine(); Properties vProps = new Properties(); vProps.setProperty("resource.loader", "string"); vProps.setProperty("string.resource.loader.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader"); velocityEngine.init(vProps);/* ww w . ja v a2s .c om*/ Template template = null; VelocityContext velocityContext = JPackageManagerOld.createVelocityContext(configuration); StringResourceRepository stringResourceRepository = StringResourceLoader.getRepository(); String templateContent = null; StringWriter stringWriter = null; long lastModified; Collection<File> patchFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.PATCH_DIR_NAME + "/" + JPackageManagerOld.PATCH_FILES_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (patchFiles != null) { for (File pfile : patchFiles) { logger.debug(" processing patch fileset file: " + pfile.getAbsolutePath()); try { lastModified = pfile.lastModified(); templateContent = FileUtils.readFileToString(pfile); if (templateContent.matches("(\\$)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})")) { System.out.println(" converting $ to #"); } templateContent = templateContent.replaceAll("#", "\\#"); templateContent = templateContent.replaceAll("(\\$)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})", "#$2$3$4$5$6"); stringResourceRepository.putStringResource(JPackageManagerOld.CURRENT_TEMPLATE_NAME, templateContent); stringWriter = new StringWriter(); template = velocityEngine.getTemplate(JPackageManagerOld.CURRENT_TEMPLATE_NAME); template.merge(velocityContext, stringWriter); templateContent = stringWriter.toString(); if (templateContent.matches("(#)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})")) { System.out.println(" converting # back to $"); } templateContent = templateContent.replaceAll("(#)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})", "\\$$2$3$4$5$6"); templateContent = templateContent.replaceAll("\\#", "#"); FileUtils.writeStringToFile(pfile, templateContent); pfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } Collection<File> scriptFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManagerOld.AUTORUN_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (scriptFiles != null) { for (File scriptfile : scriptFiles) { logger.debug(" processing script file: " + scriptfile.getAbsolutePath()); try { lastModified = scriptfile.lastModified(); templateContent = FileUtils.readFileToString(scriptfile); templateContent = templateContent.replaceAll("#", "\\#"); templateContent = templateContent.replaceAll("(\\$)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})", "#$2$3$4$5$6"); stringResourceRepository.putStringResource(JPackageManagerOld.CURRENT_TEMPLATE_NAME, templateContent); stringWriter = new StringWriter(); template = velocityEngine.getTemplate(JPackageManagerOld.CURRENT_TEMPLATE_NAME); template.merge(velocityContext, stringWriter); templateContent = stringWriter.toString(); templateContent = templateContent.replaceAll("(#)(\\{)([^\\}]*)(\\:)([^\\{]*)(\\})", "\\$$2$3$4$5$6"); templateContent = templateContent.replaceAll("\\#", "#"); FileUtils.writeStringToFile(scriptfile, templateContent); scriptfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } } return status; }
From source file:com.virtualparadigm.packman.processor.JPackageManager.java
public static boolean configure(File tempDir, File localConfigurationFile) { logger.info("PackageManager::configure()"); boolean status = true; if (tempDir != null && localConfigurationFile != null) { Configuration configuration = null; try {//w ww .ja v a 2 s . c o m configuration = new PropertiesConfiguration(localConfigurationFile); } catch (ConfigurationException ce) { //dont want to error out completely if config file is not loaded ce.printStackTrace(); } if (configuration != null && !configuration.isEmpty()) { Map<String, String> substitutionContext = JPackageManager.createSubstitutionContext(configuration); StrSubstitutor strSubstitutor = new StrSubstitutor(substitutionContext); String templateContent = null; long lastModified; Collection<File> patchFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManager.PATCH_DIR_NAME + "/" + JPackageManager.PATCH_FILES_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (patchFiles != null) { for (File pfile : patchFiles) { logger.debug(" processing patch fileset file: " + pfile.getAbsolutePath()); try { lastModified = pfile.lastModified(); templateContent = FileUtils.readFileToString(pfile); templateContent = strSubstitutor.replace(templateContent); FileUtils.writeStringToFile(pfile, templateContent); pfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } Collection<File> scriptFiles = FileUtils.listFiles( new File(tempDir.getAbsolutePath() + "/" + JPackageManager.AUTORUN_DIR_NAME), TEMPLATE_SUFFIX_FILE_FILTER, DirectoryFileFilter.DIRECTORY); if (scriptFiles != null) { for (File scriptfile : scriptFiles) { logger.debug(" processing script file: " + scriptfile.getAbsolutePath()); try { lastModified = scriptfile.lastModified(); templateContent = FileUtils.readFileToString(scriptfile); templateContent = strSubstitutor.replace(templateContent); FileUtils.writeStringToFile(scriptfile, templateContent); scriptfile.setLastModified(lastModified); } catch (Exception e) { e.printStackTrace(); } } } } } return status; }
From source file:com.germinus.easyconf.AggregatedProperties.java
public void addBaseFileName(String fileName) { Configuration conf = addPropertiesSource(fileName, baseConf); if ((conf != null) && (!conf.isEmpty())) { baseConfigurationLoaded = true;/* w ww . ja v a 2 s . c o m*/ } }
From source file:ezbake.groups.graph.TitanGraphConfiguration.java
public String getIndex() { Configuration indexSubset = subset(joinProperties(GraphDatabaseConfiguration.STORAGE_NAMESPACE, GraphDatabaseConfiguration.INDEX_NAMESPACE, SEARCH_INDEX)); String index = Titan.Token.STANDARD_INDEX; if (!indexSubset.isEmpty()) { index = SEARCH_INDEX;//from ww w .j a v a 2 s . c o m } return index; }
From source file:cross.ObjectFactory.java
private <T> T configureType(final T t, final Configuration cfg) { if (t instanceof IConfigurable) { if (cfg == null || cfg.isEmpty()) { log.warn("ObjectFactory's configuration is null or empty! Skipping configuration of {}", t.getClass().getName()); return t; }//ww w .j a v a2s. c o m log.debug("Instance of type {} is configurable!", t.getClass().toString()); final Collection<String> requiredKeys = AnnotationInspector.getRequiredConfigKeys(t); log.debug("Required keys for class {}", t.getClass()); log.debug("{}", requiredKeys); log.debug("Configuring with full configuration!"); ((IConfigurable) t).configure(cfg); } return t; }
From source file:com.boozallen.cognition.ingest.storm.bolt.enrich.ElasticSearchJsonBolt.java
void configureTimeSeriesIndex(Configuration timeSeriesIndexNameConfig) { if (!timeSeriesIndexNameConfig.isEmpty()) { timeSeriesIndexFieldName = timeSeriesIndexNameConfig.getString(FIELD_NAME); timeSeriesIndexInputDateFormat = timeSeriesIndexNameConfig.getString(INPUT_DATE_FORMAT); timeSeriesIndexOutputDateFormat = timeSeriesIndexNameConfig.getString(POSTFIX_DATE_FORMAT); }// ww w . j ava 2 s.c om }
From source file:maltcms.ui.fileHandles.properties.tools.SceneExporter.java
/** * Layout: NAME/ NAME.properties NAME-general.properties (optional) * fragmentCommands/ 00_CLASSNAME/ CLASSNAME.properties 01_CLASSNAME/ * CLASSNAME.properties/*ww w. j a v a 2 s . co m*/ * * @param pipeline * @param general */ private void createConfigFiles(List<PipelineElementWidget> pipeline, PipelineGeneralConfigWidget general) { try { //create base config FileObject baseConfigFo = this.file.getFileObject(this.name + ".mpl"); File f = FileUtil.toFile(baseConfigFo); PropertiesConfiguration baseConfig = new PropertiesConfiguration(); File subDir = new File(f.getParent(), "xml"); FileUtil.createFolder(subDir); //retrieve general configuration Configuration generalConfig = general.getProperties(); //only create and link, if non-empty if (!generalConfig.isEmpty()) { ConfigurationUtils.copy(generalConfig, baseConfig); } //String list for pipeline elements List<String> pipelineElements = new LinkedList<>(); File pipelineXml = new File(subDir, this.name + ".xml"); for (PipelineElementWidget pw : pipeline) { //add full class name to pipeline elements pipelineElements.add(pw.getClassName()); //write configuration to that file PropertiesConfiguration pc = new PropertiesConfiguration(); } //set pipeline property baseConfig.setProperty("pipeline", pipelineElements); //set pipeline.properties property String pipelineXmlString = "file:${config.basedir}/xml/bipace.xml"; baseConfig.setProperty("pipeline.xml", pipelineXmlString); FileObject fo = FileUtil.toFileObject(f); try { baseConfig.save(new PrintStream(fo.getOutputStream())); } catch (ConfigurationException ex) { Exceptions.printStackTrace(ex); } } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
From source file:com.norconex.importer.parser.GenericDocumentParserFactory.java
@Override public void loadFromXML(Reader in) throws IOException { try {/*from ww w. j a va 2s .c o m*/ XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in); setIgnoredContentTypesRegex(xml.getString("ignoredContentTypes", getIgnoredContentTypesRegex())); setSplitEmbedded(xml.getBoolean("[@splitEmbedded]", isSplitEmbedded())); Configuration ocrXml = xml.subset("ocr"); OCRConfig ocrConfig = null; if (!ocrXml.isEmpty()) { ocrConfig = new OCRConfig(); ocrConfig.setPath(ocrXml.getString("[@path]")); ocrConfig.setLanguages(ocrXml.getString("languages")); ocrConfig.setContentTypes(ocrXml.getString("contentTypes")); } setOCRConfig(ocrConfig); } catch (ConfigurationException e) { throw new IOException("Cannot load XML.", e); } }
From source file:com.liferay.portal.configuration.easyconf.ClassLoaderAggregateProperties.java
@Override public void addBaseFileName(String fileName) { URL url = _classLoader.getResource(fileName); Configuration configuration = _addPropertiesSource(fileName, url, _baseCompositeConfiguration); if ((configuration != null) && !configuration.isEmpty()) { _baseConfigurationLoaded = true; }//from ww w. ja va 2s. c o m }
From source file:cz.cas.lib.proarc.common.imports.TiffImporter.java
private FileEntry processJp2Copy(FileSet fileSet, File tiff, File tempBatchFolder, String dsId, Configuration processorConfig) throws IOException { if (processorConfig != null && !processorConfig.isEmpty()) { File acFile = new File(tempBatchFolder, fileSet.getName() + '.' + dsId + ".jp2"); String processorType = processorConfig.getString("type"); ExternalProcess process = null;/*w ww. j a v a 2 s. c o m*/ if (KakaduCompress.ID.equals(processorType)) { process = new KakaduCompress(processorConfig, tiff, acFile); } if (process != null) { process.run(); if (!process.isOk()) { throw new IOException(acFile.toString() + "\n" + process.getFullOutput()); } } return new FileEntry(acFile); } return null; }