List of usage examples for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy
FileChangedReloadingStrategy
From source file:org.goobi.api.display.helper.ConfigDispayRules.java
/** * reads given xml file into XMLConfiguration. *///from w w w . j a va 2 s. c o m private ConfigDispayRules() { configPfad = ConfigCore.getKitodoConfigDirectory() + "kitodo_metadataDisplayRules.xml"; try { config = new XMLConfiguration(configPfad); config.setReloadingStrategy(new FileChangedReloadingStrategy()); getDisplayItems(); } catch (ConfigurationException e) { /* * no configuration file found, default configuration (textarea) * will be used, nothing to do here */ } }
From source file:org.goobi.api.display.helper.ConfigDisplayRules.java
/** * Reads given xml file into XMLConfiguration. *//* ww w . j a v a 2 s . co m*/ private ConfigDisplayRules() { String configPath = ConfigCore.getKitodoConfigDirectory() + FileNames.METADATA_DISPLAY_RULES_FILE; try { config = new XMLConfiguration(configPath); config.setReloadingStrategy(new FileChangedReloadingStrategy()); getDisplayItems(); } catch (ConfigurationException e) { /* * no configuration file found, default configuration (textarea) will be used, * nothing to do here */ } }
From source file:org.goobi.production.cli.WebInterfaceConfig.java
/** * Get credentials.//from w w w. j ava 2s . c o m * * @param requestIp * String * @param requestPassword * String * @return list of Strings */ public static List<String> getCredentials(String requestIp, String requestPassword) { ArrayList<String> allowed = new ArrayList<>(); try { XMLConfiguration config = new XMLConfiguration( ConfigCore.getKitodoConfigDirectory() + "kitodo_webapi.xml"); config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); int count = config.getMaxIndex("credentials"); for (int i = 0; i <= count; i++) { String ip = config.getString("credentials(" + i + ")[@ip]"); String password = config.getString("credentials(" + i + ")[@password]"); if (requestIp.startsWith(ip) && requestPassword.equals(password)) { int countCommands = config.getMaxIndex("credentials(" + i + ").command"); for (int j = 0; j <= countCommands; j++) { allowed.add(config.getString("credentials(" + i + ").command(" + j + ")[@name]")); } } } } catch (Exception e) { allowed = new ArrayList<>(); } return allowed; }
From source file:org.goobi.production.export.ExportXmlLog.java
private HashMap<String, String> getMetsFieldsFromConfig(boolean useAnchor) { String xmlpath = "mets.property"; if (useAnchor) { xmlpath = "anchor.property"; }/* w ww . j a va 2 s .com*/ HashMap<String, String> fields = new HashMap<>(); try { File file = new File(ConfigCore.getKitodoConfigDirectory() + "kitodo_exportXml.xml"); if (file.exists() && file.canRead()) { XMLConfiguration config = new XMLConfiguration(file); config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); int count = config.getMaxIndex(xmlpath); for (int i = 0; i <= count; i++) { String name = config.getString(xmlpath + "(" + i + ")[@name]"); String value = config.getString(xmlpath + "(" + i + ")[@value]"); fields.put(name, value); } } } catch (Exception e) { fields = new HashMap<>(); } return fields; }
From source file:org.goobi.production.export.ExportXmlLog.java
private HashMap<String, String> getNamespacesFromConfig() { HashMap<String, String> nss = new HashMap<>(); try {//from w w w .ja v a2 s .c om File file = new File(ConfigCore.getKitodoConfigDirectory() + "kitodo_exportXml.xml"); if (file.exists() && file.canRead()) { XMLConfiguration config = new XMLConfiguration(file); config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); int count = config.getMaxIndex("namespace"); for (int i = 0; i <= count; i++) { String name = config.getString("namespace(" + i + ")[@name]"); String value = config.getString("namespace(" + i + ")[@value]"); nss.put(name, value); } } } catch (Exception e) { nss = new HashMap<>(); } return nss; }
From source file:org.goobi.production.importer.GoobiHotfolder.java
/** * Get instances./*w w w . ja v a 2 s . c om*/ * * @return list of GoobiHotfolder objects */ public static List<GoobiHotfolder> getInstances() { logger.trace("config 1"); List<GoobiHotfolder> answer = new ArrayList<>(); logger.trace("config 2"); try { XMLConfiguration config = new XMLConfiguration( ConfigCore.getKitodoConfigDirectory() + "kitodo_hotfolder.xml"); logger.trace("config 3"); config.setListDelimiter('&'); logger.trace("config 4"); config.setReloadingStrategy(new FileChangedReloadingStrategy()); logger.trace("config 5"); int count = config.getMaxIndex("hotfolder"); logger.trace("config 6"); for (int i = 0; i <= count; i++) { logger.trace("config 7"); String name = config.getString("hotfolder(" + i + ")[@name]"); logger.trace("config 8"); URI folder = URI.create(config.getString("hotfolder(" + i + ")[@folder]")); logger.trace("config 9"); Integer template = config.getInt("hotfolder(" + i + ")[@template]"); logger.trace("config 10"); String updateStrategy = config.getString("hotfolder(" + i + ")[@updateStrategy]"); logger.trace("config 11"); String collection = config.getString("hotfolder(" + i + ")[@collection]"); logger.trace("config 12"); if (name == null || name.equals("") || template == null) { logger.trace("config 13"); break; } logger.trace("config 14"); if (updateStrategy == null || updateStrategy.equals("")) { logger.trace("config 15"); updateStrategy = "ignore"; } if (collection.equals("")) { logger.trace("config 16"); collection = null; } logger.trace("config 17"); answer.add(new GoobiHotfolder(name, folder, template, updateStrategy, collection)); } logger.trace("config 18"); } catch (Exception e) { if (logger.isTraceEnabled()) { logger.trace("config 19" + e.getMessage()); } return new ArrayList<>(); } logger.trace("config 20"); return answer; }
From source file:org.goobi.production.properties.PropertyParser.java
/** * Get properties for task.// ww w . ja va 2 s .c o m * * @param mySchritt * Task object * @return list of ProcessProperty objects */ public static ArrayList<ProcessProperty> getPropertiesForStep(Task mySchritt) { Hibernate.initialize(mySchritt.getProcess()); Hibernate.initialize(mySchritt.getProcess().getProject()); String stepTitle = mySchritt.getTitle(); String projectTitle = mySchritt.getProcess().getProject().getTitle(); ArrayList<ProcessProperty> properties = new ArrayList<>(); if (mySchritt.getProcess().isTemplate()) { return properties; } String path = ConfigCore.getKitodoConfigDirectory() + "kitodo_processProperties.xml"; XMLConfiguration config; try { config = new XMLConfiguration(path); } catch (ConfigurationException e) { logger.error(e); config = new XMLConfiguration(); } config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); // run though all properties int countProperties = config.getMaxIndex("property"); for (int i = 0; i <= countProperties; i++) { // general values for property ProcessProperty pp = new ProcessProperty(); pp.setName(config.getString("property(" + i + ")[@name]")); pp.setContainer(config.getInt("property(" + i + ")[@container]")); // projects int count = config.getMaxIndex("property(" + i + ").project"); for (int j = 0; j <= count; j++) { pp.getProjects().add(config.getString("property(" + i + ").project(" + j + ")")); } // project is configured if (pp.getProjects().contains("*") || pp.getProjects().contains(projectTitle)) { // showStep boolean containsCurrentStepTitle = false; count = config.getMaxIndex("property(" + i + ").showStep"); for (int j = 0; j <= count; j++) { ShowStepCondition ssc = new ShowStepCondition(); ssc.setName(config.getString("property(" + i + ").showStep(" + j + ")[@name]")); String access = config.getString("property(" + i + ").showStep(" + j + ")[@access]"); boolean duplicate = config.getBoolean("property(" + i + ").showStep(" + j + ")[@duplicate]", false); ssc.setAccessCondition(AccessCondition.getAccessConditionByName(access)); if (ssc.getName().equals(stepTitle)) { containsCurrentStepTitle = true; pp.setDuplicationAllowed(duplicate); pp.setCurrentStepAccessCondition(AccessCondition.getAccessConditionByName(access)); } pp.getShowStepConditions().add(ssc); } // steptitle is configured if (containsCurrentStepTitle) { // showProcessGroupAccessCondition String groupAccess = config.getString("property(" + i + ").showProcessGroup[@access]"); if (groupAccess != null) { pp.setShowProcessGroupAccessCondition( AccessCondition.getAccessConditionByName(groupAccess)); } else { pp.setShowProcessGroupAccessCondition(AccessCondition.WRITE); } // validation expression pp.setValidation(config.getString("property(" + i + ").validation")); // type pp.setType(Type.getTypeByName(config.getString("property(" + i + ").type"))); // (default) value pp.setValue(config.getString("property(" + i + ").defaultvalue")); // possible values count = config.getMaxIndex("property(" + i + ").value"); for (int j = 0; j <= count; j++) { pp.getPossibleValues().add(config.getString("property(" + i + ").value(" + j + ")")); } properties.add(pp); } } } // add existing 'eigenschaften' to properties from config, so we have // all properties from config and // some of them with already existing 'eigenschaften' ArrayList<ProcessProperty> listClone = new ArrayList<>(properties); List<Property> propertyList = mySchritt.getProcess().getProperties(); for (Property processProperty : propertyList) { for (ProcessProperty pp : listClone) { // TODO added temporarily a fix for NPE. Properties without // title shouldn't exist at all if (processProperty.getTitle() != null) { if (processProperty.getTitle().equals(pp.getName())) { // pp has no pe assigned if (pp.getProzesseigenschaft() == null) { pp.setProzesseigenschaft(processProperty); pp.setValue(processProperty.getValue()); pp.setContainer(processProperty.getContainer()); } else { // clone pp ProcessProperty pnew = pp.getClone(processProperty.getContainer()); pnew.setProzesseigenschaft(processProperty); pnew.setValue(processProperty.getValue()); pnew.setContainer(processProperty.getContainer()); properties.add(pnew); } } } } } return properties; }
From source file:org.goobi.production.properties.PropertyParser.java
/** * Get properties for process.//from ww w . j a v a 2 s. com * * @param process * object * @return ProcessProperty object */ public static ArrayList<ProcessProperty> getPropertiesForProcess(Process process) { Hibernate.initialize(process.getProject()); String projectTitle = process.getProject().getTitle(); ArrayList<ProcessProperty> properties = new ArrayList<>(); if (process.isTemplate()) { List<Property> propertyList = process.getProperties(); for (Property processProperty : propertyList) { ProcessProperty pp = new ProcessProperty(); pp.setName(processProperty.getTitle()); pp.setProzesseigenschaft(processProperty); pp.setType(Type.TEXT); pp.setValue(processProperty.getValue()); pp.setContainer(processProperty.getContainer()); properties.add(pp); } return properties; } String path = ConfigCore.getKitodoConfigDirectory() + "kitodo_processProperties.xml"; XMLConfiguration config; try { config = new XMLConfiguration(path); } catch (ConfigurationException e) { logger.error(e); config = new XMLConfiguration(); } config.setListDelimiter('&'); config.setReloadingStrategy(new FileChangedReloadingStrategy()); // run though all properties int countProperties = config.getMaxIndex("property"); for (int i = 0; i <= countProperties; i++) { // general values for property ProcessProperty pp = new ProcessProperty(); pp.setName(config.getString("property(" + i + ")[@name]")); pp.setContainer(config.getInt("property(" + i + ")[@container]")); // projects int count = config.getMaxIndex("property(" + i + ").project"); for (int j = 0; j <= count; j++) { pp.getProjects().add(config.getString("property(" + i + ").project(" + j + ")")); } // project is configured if (pp.getProjects().contains("*") || pp.getProjects().contains(projectTitle)) { // validation expression pp.setValidation(config.getString("property(" + i + ").validation")); // type pp.setType(Type.getTypeByName(config.getString("property(" + i + ").type"))); // (default) value pp.setValue(config.getString("property(" + i + ").defaultvalue")); // possible values count = config.getMaxIndex("property(" + i + ").value"); for (int j = 0; j <= count; j++) { pp.getPossibleValues().add(config.getString("property(" + i + ").value(" + j + ")")); } if (logger.isDebugEnabled()) { logger.debug( "add property A " + pp.getName() + " - " + pp.getValue() + " - " + pp.getContainer()); } properties.add(pp); } } // add existing 'eigenschaften' to properties from config, so we have // all properties from config and some // of them with already existing 'eigenschaften' List<ProcessProperty> listClone = new ArrayList<>(properties); List<Property> propertyList = process.getProperties(); for (Property processProperty : propertyList) { // TODO added temporarily a fix for NPE. Properties without title // shouldn't exist at all if (processProperty.getTitle() != null) { for (ProcessProperty pp : listClone) { if (processProperty.getTitle().equals(pp.getName())) { // pp has no pe assigned if (pp.getProzesseigenschaft() == null) { pp.setProzesseigenschaft(processProperty); pp.setValue(processProperty.getValue()); pp.setContainer(processProperty.getContainer()); } else { // clone pp ProcessProperty pnew = pp.getClone(processProperty.getContainer()); pnew.setProzesseigenschaft(processProperty); pnew.setValue(processProperty.getValue()); pnew.setContainer(processProperty.getContainer()); if (logger.isDebugEnabled()) { logger.debug("add property B " + pp.getName() + " - " + pp.getValue() + " - " + pp.getContainer()); } properties.add(pnew); } } } } } // add 'eigenschaft' to all ProcessProperties for (ProcessProperty pp : properties) { if (pp.getProzesseigenschaft() != null) { propertyList.remove(pp.getProzesseigenschaft()); } } // create ProcessProperties to remaining 'eigenschaften' if (propertyList.size() > 0) { for (Property processProperty : propertyList) { ProcessProperty pp = new ProcessProperty(); pp.setProzesseigenschaft(processProperty); pp.setName(processProperty.getTitle()); pp.setValue(processProperty.getValue()); pp.setContainer(processProperty.getContainer()); pp.setType(Type.TEXT); if (logger.isDebugEnabled()) { logger.debug( "add property C " + pp.getName() + " - " + pp.getValue() + " - " + pp.getContainer()); } properties.add(pp); } } if (logger.isDebugEnabled()) { logger.debug("all properties are " + properties.size()); } return properties; }
From source file:org.jboss.datavirt.commons.config.ConfigurationFactory.java
/** * Shared method used to locate and load configuration information from a number of * places, aggregated into a single {@link Configuration} instance. * @param configFileOverride/* w w w. j a v a 2 s . com*/ * @param standardConfigFileName * @param refreshDelay * @param defaultConfigPath * @param defaultConfigLoader * @throws ConfigurationException */ public static Configuration createConfig(String configFileOverride, String standardConfigFileName, Long refreshDelay, String defaultConfigPath, Class<?> defaultConfigLoader) { registerGlobalLookups(); try { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemPropertiesConfiguration()); URL url = findConfig(configFileOverride, standardConfigFileName); if (url != null) { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(url); FileChangedReloadingStrategy fileChangedReloadingStrategy = new FileChangedReloadingStrategy(); fileChangedReloadingStrategy.setRefreshDelay(refreshDelay); propertiesConfiguration.setReloadingStrategy(fileChangedReloadingStrategy); config.addConfiguration(propertiesConfiguration); } if (defaultConfigPath != null) { config.addConfiguration( new PropertiesConfiguration(defaultConfigLoader.getResource(defaultConfigPath))); } return config; } catch (ConfigurationException e) { throw new RuntimeException(e); } }
From source file:org.jboss.forge.addon.configuration.ConfigurationFactoryImpl.java
private Configuration getConfiguration(File file) { try {/* ww w. j a va2s. c o m*/ PropertiesConfiguration commonsConfig = new PropertiesConfiguration(file); commonsConfig.setEncoding("UTF-8"); commonsConfig.setReloadingStrategy(new FileChangedReloadingStrategy()); commonsConfig.setAutoSave(true); return new ConfigurationAdapter(commonsConfig); } catch (org.apache.commons.configuration.ConfigurationException e) { throw new ConfigurationException("Error while creating configuration from " + file, e); } }