List of usage examples for org.apache.commons.configuration Configuration getString
String getString(String key);
From source file:edu.kit.dama.rest.util.auth.AbstractAuthenticator.java
@Override public boolean configure(Configuration pConfig) throws ConfigurationException { //get authenticatorId authenticatorId = pConfig.getString(AUTHENTICATOR_ID_PROPERTY_KEY); if (authenticatorId == null) { throw new ConfigurationException("Failed to configure AbstractAuthenticator. Mandatory property " + AUTHENTICATOR_ID_PROPERTY_KEY + " is missing."); }//from w w w . j ava 2s. co m enableForPattern = pConfig.getString(ENABLE_FOR_PATTERN_PROPERTY_KEY); if (enableForPattern == null) { enableForPattern = ENABLE_FOR_ALL_PATTERN; } else { //check pattern try { Pattern.compile(enableForPattern); } catch (PatternSyntaxException ex) { LOGGER.error("Feiled to compile regex pattern " + enableForPattern, ex); throw new ConfigurationException("Failed to configure AbstractAuthenticator. Value of property " + ENABLE_FOR_PATTERN_PROPERTY_KEY + " is no valid regular expression."); } } return performCustomConfiguration(pConfig); }
From source file:com.appeligo.search.actions.network.RecommendProgramAction.java
private String generateLink(Program program) { Configuration configuration = ConfigUtils.getSystemConfig(); StringBuilder link = new StringBuilder(); String url = configuration.getString("url"); link.append(url);// w w w . ja va 2 s.c o m if (url.endsWith("/")) { link.deleteCharAt(link.length() - 1); } if (showOnly) { link.append(program.getShowWebPath()); } else { link.append(program.getWebPath()); } return link.toString(); }
From source file:gr.abiss.calipso.tiers.controller.AbstractModelWithAttachmentsController.java
@ApiOperation(value = "Add a file uploads to property") @RequestMapping(value = "{subjectId}/uploads/{propertyName}", method = { RequestMethod.POST, RequestMethod.PUT }, consumes = {}) public @ResponseBody BinaryFile addUploadsToProperty(@PathVariable ID subjectId, @PathVariable String propertyName, MultipartHttpServletRequest request, HttpServletResponse response) { LOGGER.info("uploadPost called"); Configuration config = ConfigurationFactory.getConfiguration(); String fileUploadDirectory = config.getString(ConfigurationFactory.FILES_DIR); String baseUrl = config.getString("calipso.baseurl"); Iterator<String> itr = request.getFileNames(); MultipartFile mpf;/* w w w. j ava 2s .co m*/ BinaryFile bf = new BinaryFile(); try { if (itr.hasNext()) { mpf = request.getFile(itr.next()); LOGGER.info("Uploading {}", mpf.getOriginalFilename()); bf.setName(mpf.getOriginalFilename()); bf.setFileNameExtention( mpf.getOriginalFilename().substring(mpf.getOriginalFilename().lastIndexOf(".") + 1)); bf.setContentType(mpf.getContentType()); bf.setSize(mpf.getSize()); // request targets specific path? StringBuffer uploadsPath = new StringBuffer('/') .append(this.service.getDomainClass().getDeclaredField("PATH_FRAGMENT").get(String.class)) .append('/').append(subjectId).append("/uploads/").append(propertyName); bf.setParentPath(uploadsPath.toString()); LOGGER.info("Saving image entity with path: " + bf.getParentPath()); bf = binaryFileService.create(bf); LOGGER.info("file name: {}", bf.getNewFilename()); bf = binaryFileService.findById(bf.getId()); LOGGER.info("file name: {}", bf.getNewFilename()); File storageDirectory = new File(fileUploadDirectory + bf.getParentPath()); if (!storageDirectory.exists()) { storageDirectory.mkdirs(); } LOGGER.info("storageDirectory: {}", storageDirectory.getAbsolutePath()); LOGGER.info("file name: {}", bf.getNewFilename()); File newFile = new File(storageDirectory, bf.getNewFilename()); newFile.createNewFile(); LOGGER.info("newFile path: {}", newFile.getAbsolutePath()); Files.copy(mpf.getInputStream(), newFile.toPath(), StandardCopyOption.REPLACE_EXISTING); BufferedImage thumbnail = Scalr.resize(ImageIO.read(newFile), 290); File thumbnailFile = new File(storageDirectory, bf.getThumbnailFilename()); ImageIO.write(thumbnail, "png", thumbnailFile); bf.setThumbnailSize(thumbnailFile.length()); bf = binaryFileService.update(bf); // attach file // TODO: add/update to collection Field fileField = GenericSpecifications.getField(this.service.getDomainClass(), propertyName); Class clazz = fileField.getType(); if (BinaryFile.class.isAssignableFrom(clazz)) { T target = this.service.findById(subjectId); BeanUtils.setProperty(target, propertyName, bf); this.service.update(target); } bf.setUrl(baseUrl + "/api/rest/" + bf.getParentPath() + "/files/" + bf.getId()); bf.setThumbnailUrl(baseUrl + "/api/rest/" + bf.getParentPath() + "/thumbs/" + bf.getId()); bf.setDeleteUrl(baseUrl + "/api/rest/" + bf.getParentPath() + "/" + bf.getId()); bf.setDeleteType("DELETE"); bf.addInitialPreview("<img src=\"" + bf.getThumbnailUrl() + "\" class=\"file-preview-image\" />"); } } catch (Exception e) { LOGGER.error("Could not upload file(s) ", e); } return bf; }
From source file:es.udc.gii.common.eaf.algorithm.operator.replace.NSGA2ReplaceOperator.java
@Override public void configure(Configuration conf) { super.configure(conf); try {/*from ww w . j a v a 2 s. co m*/ if (conf.containsKey("RemainingFrontSelectionPlugin.Class")) { this.remainingFrontPlugin = (RemainingFrontSelectionPlugin) Class .forName(conf.getString("RemainingFrontSelectionPlugin.Class")).newInstance(); this.remainingFrontPlugin.configure(conf.subset("RemainingFrontSelectionPlugin")); } else { ConfWarning w = new ConfWarning("RemainingFrontSelectionPlugin", this.getClass().getSimpleName()); w.warn(); } } catch (Exception ex) { throw new ConfigurationException(this.getClass(), ex); } }
From source file:TestExtractor.java
@Test public void TestConf() { try {/* w ww . j a v a2 s . c o m*/ Configuration conf = new PropertiesConfiguration( System.getProperty("user.dir") + "/src/test/resources/xwiki.cfg"); int ldapPort = conf.getInt("xwiki.authentication.ldap.port", 389); String tmpldap_server = conf .getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_server"); //String tmpldap_base_DN = conf.getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_base_DN"); String tmpBinDN = conf.getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_bind_DN"); String tmpldap_bind_pass = conf .getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_bind_pass"); String[] ldap_server = StringUtils.split(tmpldap_server, "|"); //String[] ldap_base_DN = StringUtils.split(tmpldap_base_DN,"|"); String[] BinDN = StringUtils.split(tmpBinDN, "|"); String[] ldap_bind_pass = StringUtils.split(tmpldap_bind_pass, "|"); //assertTrue(ldap_server.length == ldap_base_DN.length); assertTrue(BinDN.length == ldap_bind_pass.length); assertTrue(ldap_server.length == ldap_bind_pass.length); assertTrue(ldap_server.length == 6); assertTrue(ldapPort == 389); String className = conf.getString("xwiki.authentication.ldap.ssl.secure_provider", "com.sun.net.ssl.internal.ssl.Provider"); assertEquals(className, "com.sun.net.ssl.internal.ssl.Provider"); assertEquals(conf.getInt("xwiki.authentication.ldap.timeout", 500), 500); assertEquals(conf.getInt("xwiki.authentication.ldap.maxresults", 10), 10); } catch (ConfigurationException ex) { Logger.getLogger(TestExtractor.class.getName()).log(Level.SEVERE, null, ex); fail(ex.getLocalizedMessage()); } }
From source file:de.chdev.artools.loga.controller.ApiController.java
public ApiController(Configuration keywords, MainController mainController) { this.keywords = keywords; this.mainController = mainController; String regexKey;/*from w ww .ja v a 2s . co m*/ // Define API Start Pattern regexKey = keywords.getString("api.start"); patternApiStart = Pattern.compile(regexKey); // Define API Stop Pattern regexKey = keywords.getString("api.stop"); patternApiStop = Pattern.compile(regexKey); }
From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.mutation.de.mutationStrategy.CurrentToRandomMutationStrategy.java
@Override public void configure(Configuration conf) { ConfWarning w = null;/*from w ww . j a va2 s. c om*/ try { super.configure(conf); if (conf.containsKey("K.Class")) { this.K_plugin = (Parameter) Class.forName(conf.getString("K.Class")).newInstance(); this.K_plugin.configure(conf.subset("K")); } else { w = new ConfWarning(this.getClass().getSimpleName() + ".K", this.K_plugin.getClass().getSimpleName()); w.warn(); } if (w != null) { w.warn(); } } catch (Exception ex) { throw new ConfigurationException(this.getClass(), ex); } }
From source file:com.appeligo.amazon.ProgramIndexer.java
public ProgramIndexer() { ConfigurationService.init();/*from www . j ava 2s . c o m*/ Configuration config = ConfigUtils.getAmazonConfig(); indexLocation = new File(config.getString("programIndex")); jdbcDriver = config.getString("jdbc.driver", "com.mysql.jdbc.Driver"); jdbcUrl = config.getString("jdbc.url"); jdbcUsername = config.getString("jdbc.username"); jdbcPassword = config.getString("jdbc.password"); fetchSize = config.getInt("fetchSize", 1000); staleDays = config.getInt("staleDays", 30); }
From source file:com.manydesigns.portofino.stripes.ForbiddenAccessResolution.java
public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception { Subject subject = SecurityUtils.getSubject(); //TODO ElementsActionBeanContext ElementsActionBeanContext context = new ElementsActionBeanContext(); context.setRequest(request);/*w w w. jav a 2 s . c o m*/ String originalPath = context.getActionPath(); UrlBuilder urlBuilder = new UrlBuilder(Locale.getDefault(), originalPath, false); Map<?, ?> parameters = request.getParameterMap(); urlBuilder.addParameters(parameters); String returnUrl = urlBuilder.toString(); boolean ajax = "true".equals(request.getParameter("ajax")); ServletContext servletContext = ElementsThreadLocals.getServletContext(); Configuration configuration = (Configuration) servletContext .getAttribute(BaseModule.PORTOFINO_CONFIGURATION); if (!subject.isAuthenticated() && !ajax) { logger.info("Anonymous user not allowed. Redirecting to login."); String loginPage = configuration.getString(PortofinoProperties.LOGIN_PAGE); RedirectResolution redirectResolution = new RedirectResolution(loginPage, true); redirectResolution.addParameter("returnUrl", returnUrl); redirectResolution.execute(request, response); } else { if (ajax) { logger.debug("AJAX call while user disconnected"); //TODO where to redirect? String loginPage = configuration.getString(PortofinoProperties.LOGIN_PAGE); UrlBuilder loginUrlBuilder = new UrlBuilder(Locale.getDefault(), loginPage, false); response.setStatus(UNAUTHORIZED); new StreamingResolution("text/plain", loginUrlBuilder.toString()).execute(request, response); } else { logger.warn("User not authorized for url {}.", returnUrl); new ErrorResolution(UNAUTHORIZED, errorMessage).execute(request, response); } } }
From source file:com.litt.saap.core.web.listener.InitSystemListener.java
/** * ?.//from w w w . j a v a2 s .com */ public void contextInitialized(ServletContextEvent event) { super.contextInitialized(event); ServletContext application = event.getServletContext(); //HOME? Configuration config = ConfigManager.getInstance().getConfig(); if (config.isEmpty()) { logger.error("???"); throw new java.lang.RuntimeException("???"); } logger.info("?" + config.getString("system.version")); //homePath = props.getProperty("home.path"); String homePath = config.getString("home.path"); CoreConstants.IS_DEBUG = config.getBoolean("debug", false); SaapConstants.HOME_PATH = homePath; //???? logger.info("?" + homePath); File homeFile = new File(homePath); if (!homeFile.exists()) //??? { homeFile.mkdirs(); } //read license. // File licensePath = new File(homePath, "license"); // File licenseFile = new File(licensePath, "license.xml"); // File publicKeyFile = new File(licensePath, "license.key"); // try { // LicenseManager.reload(licenseFile.getPath(), publicKeyFile.getPath()); // } catch (LicenseException e) { // logger.error("Can't read license file.", e); // } String contextPath = application.getContextPath(); //???APPLICATION ISystemInfoService systemInfoService = BeanManager.getBean("systemInfoService", ISystemInfoService.class); SystemInfoVo systemInfoVo = systemInfoService.getSystemInfo(); systemInfoVo.setBaseUrl(config.getString("baseUrl") + contextPath); systemInfoVo.setHomePath(homePath); application.setAttribute(CoreConstants.APP_SYSTEMINFO, systemInfoVo); //servlet? }