Java Code Examples for org.springframework.core.io.Resource

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project cas, under directory /cas-server-extension-clearpass/src/main/java/org/jasig/cas/extension/clearpass/integration/uportal/.

Source file: PasswordCachingCasAssertionSecurityContextFactory.java

  21 
vote

public PasswordCachingCasAssertionSecurityContextFactory(){
  final Resource resource=new ClassPathResource(DEFAULT_PORTAL_SECURITY_PROPERTY_FILE,getClass().getClassLoader());
  final Properties securityProperties=new Properties();
  InputStream inputStream=null;
  try {
    inputStream=resource.getInputStream();
    securityProperties.load(inputStream);
    this.clearPassUrl=securityProperties.getProperty(CLEARPASS_CAS_URL_PROPERTY);
  }
 catch (  final Exception e) {
    throw new RuntimeException(e);
  }
 finally {
    if (inputStream != null) {
      try {
        inputStream.close();
      }
 catch (      final IOException e) {
      }
    }
  }
}
 

Example 2

From project Gemini-Blueprint, under directory /core/src/test/java/org/eclipse/gemini/blueprint/context/support/internal/.

Source file: ScopeTests.java

  20 
vote

protected void setUp() throws Exception {
  Resource file=new ClassPathResource("scopes.xml");
  bf=new ScopedXmlFactory(file);
  callback=null;
  tag=null;
}
 

Example 3

From project android-joedayz, under directory /Proyectos/client/src/org/springframework/android/showcase/rest/.

Source file: HttpPostFormDataActivity.java

  19 
vote

@Override protected void onPreExecute(){
  showLoadingProgressDialog();
  Resource resource=new ClassPathResource("res/drawable/spring09_logo.png");
  formData=new LinkedMultiValueMap<String,Object>();
  formData.add("description","Spring logo");
  formData.add("file",resource);
}
 

Example 4

From project grails-searchable, under directory /src/java/grails/plugin/searchable/internal/.

Source file: SearchableUtils.java

  19 
vote

private static Map loadMetadata(){
  Resource r=new ClassPathResource(PROJECT_META_FILE);
  if (r.exists()) {
    return loadMetadata(r);
  }
  String basedir=System.getProperty("base.dir");
  if (basedir != null) {
    r=new FileSystemResource(new File(basedir,PROJECT_META_FILE));
    if (r.exists()) {
      return loadMetadata(r);
    }
  }
  return null;
}
 

Example 5

From project handlebars.java_1, under directory /handlebars-springmvc/src/main/java/com/github/jknack/handlebars/springmvc/.

Source file: SpringTemplateLoader.java

  19 
vote

@Override protected Reader read(final String location) throws IOException {
  Resource resource=loader.getResource(location);
  if (resource.exists()) {
    return new InputStreamReader(resource.getInputStream());
  }
  return null;
}
 

Example 6

From project ANNIS, under directory /annis-service/src/main/java/annis/administration/.

Source file: DefaultAdministrationDao.java

  18 
vote

@Override public boolean executeSqlFromScript(String script,MapSqlParameterSource args){
  File fScript=new File(scriptPath,script);
  if (fScript.canRead() && fScript.isFile()) {
    Resource resource=new FileSystemResource(fScript);
    log.debug("executing SQL script: " + resource.getFilename());
    String sql=readSqlFromResource(resource,args);
    jdbcTemplate.getJdbcOperations().execute(sql);
    return true;
  }
 else {
    log.debug("SQL script " + fScript.getName() + " does not exist");
    return false;
  }
}
 

Example 7

From project bioportal-service, under directory /src/test/java/edu/mayo/cts2/framework/plugin/service/bioportal/service/transform/.

Source file: AssociationTransformTest.java

  18 
vote

@Before public void buildTransform() throws Exception {
  this.associationTransform=new AssociationTransform();
  IdentityConverter idConverter=EasyMock.createMock(IdentityConverter.class);
  UrlConstructor urlConstructor=EasyMock.createNiceMock(UrlConstructor.class);
  EasyMock.expect(idConverter.ontologyIdToCodeSystemName("1104")).andReturn("testCsName").anyTimes();
  EasyMock.expect(idConverter.ontologyVersionIdToCodeSystemVersionName("1104","44450")).andReturn("testCsVersionName").anyTimes();
  EasyMock.expect(idConverter.getCodeSystemAbout("csName","http://purl.bioontology.org/ontology/")).andReturn("http://test.doc.uri").anyTimes();
  EasyMock.expect(idConverter.getCodeSystemAbout("ICD10","http://purl.bioontology.org/ontology/")).andReturn("http://test.doc.uri").anyTimes();
  EasyMock.expect(idConverter.codeSystemVersionNameToVersion("ICD10")).andReturn("ICD10").anyTimes();
  EasyMock.replay(idConverter,urlConstructor);
  this.associationTransform.setIdentityConverter(idConverter);
  this.associationTransform.setUrlConstructor(urlConstructor);
  Resource resource=new ClassPathResource("bioportalXml/entityDescription.xml");
  StringWriter sw=new StringWriter();
  IOUtils.copy(resource.getInputStream(),sw);
  this.xml=sw.toString();
}
 

Example 8

From project CalendarPortlet, under directory /src/test/java/org/jasig/portlet/calendar/processor/.

Source file: ICalendarContentProcessorTest.java

  18 
vote

@Test public void test() throws IOException {
  Resource calendarFile=applicationContext.getResource("classpath:/sampleEvents.ics");
  DateMidnight start=new DateMidnight(2010,1,1,DateTimeZone.UTC);
  Interval interval=new Interval(start,start.plusYears(3));
  InputStream in=calendarFile.getInputStream();
  ByteArrayOutputStream buffer=new ByteArrayOutputStream();
  IOUtils.copyLarge(in,buffer);
  TreeSet<VEvent> events=new TreeSet<VEvent>(new VEventStartComparator());
  net.fortuna.ical4j.model.Calendar c=processor.getIntermediateCalendar(interval,new ByteArrayInputStream(buffer.toByteArray()));
  events.addAll(processor.getEvents(interval,c));
  assertEquals(5,events.size());
  Iterator<VEvent> iterator=events.iterator();
  VEvent event=iterator.next();
  assertEquals("Independence Day",event.getSummary().getValue());
  assertNull(event.getStartDate().getTimeZone());
  event=iterator.next();
  assertEquals("Vikings @ Saints  [NBC]",event.getSummary().getValue());
  DateTime eventStart=new DateTime(event.getStartDate().getDate(),DateTimeZone.UTC);
  assertEquals(0,eventStart.getHourOfDay());
  assertEquals(30,eventStart.getMinuteOfHour());
  event=iterator.next();
  assertEquals("Independence Day",event.getSummary().getValue());
  assertNull(event.getStartDate().getTimeZone());
}
 

Example 9

From project Carolina-Digital-Repository, under directory /solr-ingest/src/main/java/edu/unc/lib/dl/data/ingest/solr/.

Source file: UpdateDocTransformer.java

  18 
vote

/** 
 * Initializes the transformer by retrieving the XSLT document to use and building a transformer from it. 
 * @throws Exception
 */
public void init() throws Exception {
  ApplicationContext ctx=new ClassPathXmlApplicationContext();
  Resource res=ctx.getResource("classpath:/transform/" + xslName);
  Source transformSource=new StreamSource(res.getInputStream());
  TransformerFactory factory=TransformerFactory.newInstance();
  factory.setURIResolver(new URIResolver(){
    public Source resolve(    String href,    String base) throws TransformerException {
      Source result=null;
      if (href.startsWith("/"))       result=new StreamSource(UpdateDocTransformer.class.getResourceAsStream(href));
 else       result=new StreamSource(UpdateDocTransformer.class.getResourceAsStream("/transform/" + href));
      return result;
    }
  }
);
  Templates transformTemplate=factory.newTemplates(transformSource);
  transformer=transformTemplate.newTransformer();
}
 

Example 10

From project droolsjbpm-build-distribution, under directory /drools-osgi-bundles/org.drools.osgi.test/src/test/java/org/drools/osgi/test/utils/.

Source file: EclipseWorkspaceArtifactLocator.java

  18 
vote

/** 
 * Locate an artifact in an Eclipse Workspace
 * @param artifactId - the artifact id of the bundle (required)
 * @param version - the version of the bundle (can be null)
 * @return Resource corresponding to the located Eclipse bundle
 */
private Resource localEclipseWorkspaceArtifact(String artifactId,String version){
  Resource res=m_ArtifactFinder.findArtifact(artifactId,version);
  if (res != null && log.isDebugEnabled()) {
    log.debug("[" + artifactId + "|"+ version+ "] resolved to "+ res.getDescription()+ " as a Eclipse artifact");
  }
  return res;
}
 

Example 11

From project EasySOA, under directory /easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-httpdiscoveryproxy/src/main/java/org/easysoa/cxf/.

Source file: EasySOABusFactory.java

  18 
vote

/** 
 * Does the same thing as in SpringBusFactory.finishCreatingBus(), but calls a custom myFinishCreatingBus() that adds an anti-deadlock wait
 * @param bac
 * @return
 */
public Bus createBus(String cfgFiles[],boolean includeDefaults){
  try {
    String userCfgFile=System.getProperty(Configurer.USER_CFG_FILE_PROPERTY_NAME);
    String sysCfgFileUrl=System.getProperty(Configurer.USER_CFG_FILE_PROPERTY_URL);
    Resource r=BusApplicationContext.findResource(Configurer.DEFAULT_USER_CFG_FILE);
    if (context == null && userCfgFile == null && cfgFiles == null && sysCfgFileUrl == null && (r == null || !r.exists()) && includeDefaults) {
      return new org.apache.cxf.bus.CXFBusFactory().createBus();
    }
    return myFinishCreatingBus(createApplicationContext(cfgFiles,includeDefaults));
  }
 catch (  BeansException ex) {
    LogUtils.log(LOG,Level.WARNING,"APP_CONTEXT_CREATION_FAILED_MSG",ex,(Object[])null);
    throw new RuntimeException(ex);
  }
}
 

Example 12

From project ehour, under directory /eHour-persistence-derby/src/main/java/net/rrm/ehour/persistence/dbvalidator/.

Source file: DerbyDbValidator.java

  18 
vote

/** 
 * Insert data
 * @param platform
 * @param model
 * @throws IOException
 * @throws FileNotFoundException
 * @throws DdlUtilsException
 */
private void insertData(Platform platform,Database model) throws DdlUtilsException, IOException {
  DatabaseDataIO dataIO=new DatabaseDataIO();
  DataReader dataReader=dataIO.getConfiguredDataReader(platform,model);
  dataReader.getSink().start();
  Resource resource=new ClassPathResource(getDmlFilename());
  dataIO.writeDataToDatabase(dataReader,new InputStreamReader(resource.getInputStream()));
  LOGGER.info("Data inserted");
}
 

Example 13

From project ecoadapters, under directory /ecoadapters/src/main/java/com/inadco/ecoadapters/.

Source file: EcoUtil.java

  17 
vote

/** 
 * the part before ? is in spring resource notation
 * @param descriptorUrl the part before ? is in spring resource notation, msg param contains the msg name
 * @return descriptor
 */
public static Descriptor inferDescriptorFromSpringResource(String descriptorUrl) throws IOException, URISyntaxException, DescriptorValidationException {
  int qPos=descriptorUrl.indexOf('?');
  String resourceSpec=qPos < 0 ? descriptorUrl : descriptorUrl.substring(0,qPos);
  String querySpec=qPos < 0 ? "" : descriptorUrl.substring(qPos + 1);
  String msgName=parseQuery(querySpec).getProperty("msg");
  if (msgName == null)   throw new IOException("need to know msg name!");
  Resource springResource=new DefaultResourceLoader().getResource(resourceSpec);
  InputStream is=springResource.getInputStream();
  try {
    Map<String,Descriptor> msgMap=inferDescriptorsFromStream(is);
    return inferDescWithNestedTypes(msgMap,msgName);
  }
  finally {
    is.close();
  }
}
 

Example 14

From project entando-core-engine, under directory /src/main/java/com/agiletec/apsadmin/system/services/shortcut/.

Source file: ShortcutLoader.java

  17 
vote

private void loadShortcutObjects(String locationPattern,ServletContext servletContext) throws Exception {
  Logger log=ApsSystemUtils.getLogger();
  Resource[] resources=ApsWebApplicationUtils.getResources(locationPattern,servletContext);
  ShortcutDefDOM dom=null;
  for (int i=0; i < resources.length; i++) {
    Resource resource=resources[i];
    InputStream is=null;
    try {
      String path=resource.getFilename();
      is=resource.getInputStream();
      String xml=FileTextReader.getText(is);
      dom=new ShortcutDefDOM(xml,path);
      this.getManuSections().putAll(dom.getSectionMenus());
      this.getShortcuts().putAll(dom.getShortcuts());
      log.info("Loaded Shortcut definition by file " + path);
    }
 catch (    Throwable t) {
      ApsSystemUtils.logThrowable(t,this,"loadShortcuts","Error loading Shortcut definition by file " + locationPattern);
    }
 finally {
      if (null != is) {
        is.close();
      }
    }
  }
}
 

Example 15

From project geronimo-xbean, under directory /xbean-spring/src/main/java/org/apache/xbean/spring/context/v2/.

Source file: XBeanBeanDefinitionDocumentReader.java

  17 
vote

/** 
 * Parse an "import" element and load the bean definitions from the given resource into the bean factory.
 */
protected void importBeanDefinitionResource(Element ele){
  String location=ele.getAttribute(RESOURCE_ATTRIBUTE);
  if (!StringUtils.hasText(location)) {
    getReaderContext().error("Resource location must not be empty",ele);
    return;
  }
  location=SystemPropertyUtils.resolvePlaceholders(location);
  if (ResourcePatternUtils.isUrl(location)) {
    int importCount=getReaderContext().getReader().loadBeanDefinitions(location);
    if (logger.isDebugEnabled()) {
      logger.debug("Imported " + importCount + " bean definitions from URL location ["+ location+ "]");
    }
  }
 else {
    try {
      Resource relativeResource=getReaderContext().getResource().createRelative(location);
      int importCount=getReaderContext().getReader().loadBeanDefinitions(relativeResource);
      if (logger.isDebugEnabled()) {
        logger.debug("Imported " + importCount + " bean definitions from relative location ["+ location+ "]");
      }
    }
 catch (    IOException ex) {
      getReaderContext().error("Invalid relative resource location [" + location + "] to import bean definitions from",ele,null,ex);
    }
  }
  getReaderContext().fireImportProcessed(location,extractSource(ele));
}
 

Example 16

From project HBase-Lattice, under directory /hbl/src/main/java/com/inadco/hbl/client/.

Source file: HblQueryClient.java

  17 
vote

private Cube loadCube(String cubeName) throws HblException {
  Deque<Closeable> closeables=new ArrayDeque<Closeable>();
  try {
    try {
      Resource yamlModel=HblAdmin.readModelFromHBase(conf,cubeName,HblAdmin.HBL_DEFAULT_SYSTEM_TABLE);
      InputStream is=yamlModel.getInputStream();
      Validate.notNull(is);
      closeables.addFirst(is);
      yamlModelStr=IOUtil.fromStream(is,"utf-8");
      return YamlModelParser.parseYamlModel(yamlModelStr);
    }
  finally {
      IOUtil.closeAll(closeables);
    }
  }
 catch (  IOException exc) {
    throw new HblException(String.format("Unable to load cube '%s'.",cubeName),exc);
  }
}
 

Example 17

From project Hesperid, under directory /server/src/main/java/ch/astina/hesperid/web/services/dbmigration/impl/.

Source file: ClasspathMigrationResolver.java

  17 
vote

public Set<Migration> resolve(){
  Set<Migration> migrations=new HashSet<Migration>();
  try {
    Enumeration<URL> enumeration=getClass().getClassLoader().getResources(classPath);
    while (enumeration.hasMoreElements()) {
      URL url=enumeration.nextElement();
      if (url.toExternalForm().startsWith("jar:")) {
        String file=url.getFile();
        file=file.substring(0,file.indexOf("!"));
        file=file.substring(file.indexOf(":") + 1);
        InputStream is=new FileInputStream(file);
        ZipInputStream zip=new ZipInputStream(is);
        ZipEntry ze;
        while ((ze=zip.getNextEntry()) != null) {
          if (!ze.isDirectory() && ze.getName().startsWith(classPath) && ze.getName().endsWith(".sql")) {
            Resource r=new UrlResource(getClass().getClassLoader().getResource(ze.getName()));
            String version=versionExtractor.extractVersion(r.getFilename());
            migrations.add(migrationFactory.create(version,r));
          }
        }
      }
 else {
        File file=new File(url.getFile());
        for (        String s : file.list()) {
          Resource r=new UrlResource(getClass().getClassLoader().getResource(classPath + "/" + s));
          String version=versionExtractor.extractVersion(r.getFilename());
          migrations.add(migrationFactory.create(version,r));
        }
      }
    }
  }
 catch (  Exception e) {
    logger.error("Error while resolving migrations",e);
  }
  return migrations;
}
 

Example 18

From project jagger, under directory /chassis/util/src/main/java/com/griddynamics/jagger/util/.

Source file: PropertiesResolverRegistry.java

  17 
vote

public Properties resolve(String propertiesResourceLocation){
  Properties rawProperties=new Properties();
  Properties result=new Properties();
  try {
    Resource resource=context.getResource(propertiesResourceLocation);
    rawProperties.load(resource.getInputStream());
  }
 catch (  IOException e) {
    throw new TechnicalException(e);
  }
  for (  String rawPropertyName : rawProperties.stringPropertyNames()) {
    String rawPropertyValue=rawProperties.getProperty(rawPropertyName);
    result.setProperty(rawPropertyName,resolveProperty(rawPropertyValue));
  }
  return result;
}
 

Example 19

From project banshun, under directory /banshun/core/src/main/java/com/griddynamics/banshun/.

Source file: ContextParentBean.java

  15 
vote

private void initializeChildContexts(){
  for (  String loc : resultConfigLocations) {
    if (ignoredLocations.contains(loc)) {
      continue;
    }
    try {
      Resource[] resources=context.getResources(loc);
      for (      final Resource res : resources) {
        try {
          ConfigurableApplicationContext child=createChildContext(res,context);
          children.add(child);
        }
 catch (        Exception e) {
          log.error(String.format("Failed to process resource [%s] from location [%s] ",res.getURL(),loc),e);
          if (strictErrorHandling) {
            throw new RuntimeException(e);
          }
          nestedContextsExceptions.put(loc,e);
          addToFailedLocations(loc);
          break;
        }
      }
    }
 catch (    IOException e) {
      log.error(String.format("Failed to process configuration from [%s]",loc),e);
      if (strictErrorHandling) {
        throw new RuntimeException(e);
      }
      addToFailedLocations(loc);
    }
  }
}
 

Example 20

From project Blitz, under directory /src/com/laxser/blitz/scanning/context/.

Source file: BlitzAppContext.java

  15 
vote

@Override protected final Resource[] getConfigResources(){
  try {
    return getConfigResourcesThrowsIOException();
  }
 catch (  IOException e) {
    throw new ApplicationContextException("getConfigResources",e);
  }
}
 

Example 21

From project c24-spring, under directory /c24-spring-batch/src/test/java/biz/c24/io/spring/batch/config/.

Source file: C24ItemReaderParserTests.java

  15 
vote

private void validateSource(BufferedReaderSource source,Class<? extends BufferedReaderSource> expectedClass,int expectedSkipLines,Class<? extends Resource> expectedResource,String expectedEncoding){
  assertThat(source,is(expectedClass));
  if (source instanceof FileSource) {
    FileSource fileSource=(FileSource)source;
    assertThat(fileSource.getSkipLines(),is(expectedSkipLines));
    assertThat(fileSource.getResource(),expectedResource != null ? is(expectedResource) : nullValue());
    assertThat(fileSource.getEncoding(),is(expectedEncoding));
  }
 else   if (source instanceof ZipFileSource) {
    ZipFileSource fileSource=(ZipFileSource)source;
    assertThat(fileSource.getSkipLines(),is(expectedSkipLines));
    assertThat(fileSource.getResource(),expectedResource != null ? is(expectedResource) : nullValue());
    assertThat(fileSource.getEncoding(),is(expectedEncoding));
  }
}
 

Example 22

From project common_1, under directory /src/main/java/org/powertac/common/.

Source file: XMLMessageConverter.java

  15 
vote

@SuppressWarnings("rawtypes") private List<Class> findMyTypes(String basePackage) throws IOException, ClassNotFoundException {
  ResourcePatternResolver resourcePatternResolver=new PathMatchingResourcePatternResolver();
  MetadataReaderFactory metadataReaderFactory=new CachingMetadataReaderFactory(resourcePatternResolver);
  List<Class> candidates=new ArrayList<Class>();
  String packageSearchPath=ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(basePackage) + "/"+ "**/*.class";
  Resource[] resources=resourcePatternResolver.getResources(packageSearchPath);
  for (  Resource resource : resources) {
    if (resource.isReadable()) {
      MetadataReader metadataReader=metadataReaderFactory.getMetadataReader(resource);
      candidates.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
    }
  }
  return candidates;
}
 

Example 23

From project constretto-core, under directory /constretto-spring/src/main/java/org/constretto/spring/internal/converter/.

Source file: SpringResourceValueConverter.java

  15 
vote

public List<Resource> fromStrings(String value) throws ConstrettoConversionException {
  List<Resource> resources=new ArrayList<Resource>();
  List<String> strings=gson.fromJson(value,listType);
  for (  String string : strings) {
    resources.add(fromString(string));
  }
  return resources;
}
 

Example 24

From project cxf-dosgi, under directory /systests/common/src/main/java/org/apache/cxf/dosgi/systests/common/.

Source file: AbstractDosgiSystemTest.java

  15 
vote

@Override protected Resource[] getTestBundles(){
  List<String> frameworkBundleNames=new ArrayList<String>();
  for (  Resource r : getTestFrameworkBundles()) {
    frameworkBundleNames.add(r.getFilename());
  }
  try {
    List<Resource> resources=new ArrayList<Resource>();
    for (    File file : getDistributionBundles()) {
      if (!frameworkBundleNames.contains(file.getName())) {
        resources.add(new FileSystemResource(file));
      }
    }
    resources.addAll(Arrays.asList(super.getTestBundles()));
    return resources.toArray(new Resource[resources.size()]);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 25

From project dozer, under directory /core/src/main/java/org/dozer/spring/.

Source file: DozerBeanMapperFactoryBean.java

  15 
vote

public final void afterPropertiesSet() throws Exception {
  this.beanMapper=new DozerBeanMapper();
  if (this.mappingFiles != null) {
    final List<String> mappings=new ArrayList<String>(this.mappingFiles.length);
    for (    Resource mappingFile : this.mappingFiles) {
      mappings.add(mappingFile.getURL().toString());
    }
    this.beanMapper.setMappingFiles(mappings);
  }
  if (this.customConverters != null) {
    this.beanMapper.setCustomConverters(this.customConverters);
  }
  if (this.customConvertersWithId != null) {
    this.beanMapper.setCustomConvertersWithId(customConvertersWithId);
  }
  if (this.eventListeners != null) {
    this.beanMapper.setEventListeners(this.eventListeners);
  }
  if (this.factories != null) {
    this.beanMapper.setFactories(this.factories);
  }
}
 

Example 26

From project excilys-bank, under directory /excilys-bank-dao-impl/src/main/java/com/excilys/ebi/bank/jdbc/.

Source file: SimpleBatchResourceDatabasePopulator.java

  15 
vote

public void populate(Connection connection) throws SQLException {
  for (  Resource script : this.scripts) {
    try {
      executeSqlScript(connection,applyEncodingIfNecessary(script),this.continueOnError,this.ignoreFailedDrops);
    }
 catch (    IOException e) {
      throw new RuntimeException(e);
    }
  }
}
 

Example 27

From project faces, under directory /Proyectos/01-jsf-solution/src/main/java/accounts/testdb/.

Source file: TestDataSourceFactory.java

  15 
vote

private String parseSqlIn(Resource resource) throws IOException {
  InputStream is=null;
  try {
    is=resource.getInputStream();
    BufferedReader reader=new BufferedReader(new InputStreamReader(is));
    StringWriter sw=new StringWriter();
    BufferedWriter writer=new BufferedWriter(sw);
    for (int c=reader.read(); c != -1; c=reader.read()) {
      writer.write(c);
    }
    writer.flush();
    return sw.toString();
  }
  finally {
    if (is != null) {
      is.close();
    }
  }
}
 

Example 28

From project FunctionalTestsPortlet, under directory /src/main/java/org/springframework/portlet/filter/.

Source file: GenericPortletFilterBean.java

  15 
vote

@Override public void init(FilterConfig filterConfig) throws PortletException {
  Assert.notNull(filterConfig,"FilterConfig must not be null");
  if (logger.isDebugEnabled()) {
    logger.debug("Initializing filter '" + filterConfig.getFilterName() + "'");
  }
  this.filterConfig=filterConfig;
  try {
    PropertyValues pvs=new FilterConfigPropertyValues(filterConfig,this.requiredProperties);
    BeanWrapper bw=PropertyAccessorFactory.forBeanPropertyAccess(this);
    ResourceLoader resourceLoader=new PortletContextResourceLoader(filterConfig.getPortletContext());
    bw.registerCustomEditor(Resource.class,new ResourceEditor(resourceLoader));
    initBeanWrapper(bw);
    bw.setPropertyValues(pvs,true);
  }
 catch (  BeansException ex) {
    String msg="Failed to set bean properties on filter '" + filterConfig.getFilterName() + "': "+ ex.getMessage();
    logger.error(msg,ex);
    throw new PortletException(msg,ex);
  }
  initFilterBean();
  if (logger.isDebugEnabled()) {
    logger.debug("Filter '" + filterConfig.getFilterName() + "' configured successfully");
  }
}
 

Example 29

From project grails-data-mapping, under directory /grails-datastore-gemfire/src/main/groovy/org/grails/datastore/mapping/gemfire/.

Source file: GemfireDatastore.java

  15 
vote

public void afterPropertiesSet() throws Exception {
  CacheFactoryBean cacheFactory=new CacheFactoryBean();
  if (connectionDetails != null) {
    if (connectionDetails.containsKey(SETTING_CACHE_XML)) {
      Object entry=connectionDetails.remove(SETTING_CACHE_XML);
      if (entry instanceof Resource) {
        cacheFactory.setCacheXml((Resource)entry);
      }
 else {
        cacheFactory.setCacheXml(new ClassPathResource(entry.toString()));
      }
    }
    if (connectionDetails.containsKey(SETTING_PROPERTIES)) {
      Object entry=connectionDetails.get(SETTING_PROPERTIES);
      if (entry instanceof Properties) {
        cacheFactory.setProperties((Properties)entry);
      }
 else       if (entry instanceof Map) {
        final Properties props=new Properties();
        props.putAll((Map)entry);
        cacheFactory.setProperties(props);
      }
    }
  }
  try {
    if (gemfireCache == null) {
      cacheFactory.afterPropertiesSet();
      gemfireCache=cacheFactory.getObject();
    }
    initializeRegions(gemfireCache,mappingContext);
    initializeConverters(mappingContext);
  }
 catch (  Exception e) {
    throw new DatastoreConfigurationException("Failed to configure Gemfire cache and regions: " + e.getMessage(),e);
  }
}
 

Example 30

From project grails-ide, under directory /org.grails.ide.eclipse.ui/src/org/grails/ide/eclipse/ui/internal/inplace/.

Source file: GrailsCompletionUtils.java

  15 
vote

private void scanForScripts(String pattern,List<String> proposals){
  try {
    Resource[] scripts=RESOLVER.getResources(pattern);
    for (    Resource script : scripts) {
      String scriptName=getScriptName(script.getFilename());
      if (!isFiltered(scriptName)) {
        proposals.add(scriptName);
      }
    }
  }
 catch (  Exception e) {
  }
}
 

Example 31

From project greenhouse, under directory /src/main/java/org/springframework/data/.

Source file: LocalFileStorage.java

  15 
vote

/** 
 * Constructs a local file storage.
 * @param storageUrl the logical URL pointing to the root of this file storage
 * @param storageDirectory the path to the base directory on the filesystem where files physically reside; created if necessary.
 */
public LocalFileStorage(String storageUrl,Resource storageDirectory){
  this.storageUrl=storageUrl;
  try {
    this.storageDirectory=storageDirectory.getFile();
    this.storageDirectory.deleteOnExit();
    this.storageDirectory.createNewFile();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}
 

Example 32

From project griffon, under directory /subprojects/griffon-cli/src/main/groovy/org/codehaus/griffon/cli/.

Source file: GriffonScriptRunner.java

  15 
vote

private int attemptPrecompiledScriptExecute(ScriptAndArgs script,GantBinding binding,Resource[] allScripts){
  out.println("Running pre-compiled script");
  setRunningEnvironment(script.name,script.env);
  Gant gant=createGantInstance(binding);
  String scriptName=script.name;
  binding.setVariable(VAR_SCRIPT_NAME,scriptName);
  binding.setVariable(VAR_SCRIPT_ARGS_MAP,script.options);
  binding.setVariable(VAR_SCRIPT_UNPARSED_ARGS,script.unparsedArgs);
  binding.setVariable(VAR_SYS_PROPERTIES,script.sysProperties);
  try {
    loadScriptClass(gant,scriptName);
  }
 catch (  ScriptNotFoundException e) {
    if (isInteractive) {
      scriptName=fixScriptName(scriptName,allScripts);
      if (scriptName == null) {
        throw e;
      }
      loadScriptClass(gant,scriptName);
      if (Boolean.TRUE.toString().equals(System.getProperty(Environment.DEFAULT))) {
        setRunningEnvironment(scriptName,script.env);
        settings.setDefaultEnv(false);
        System.setProperty(Environment.DEFAULT,Boolean.FALSE.toString());
      }
    }
 else {
      throw e;
    }
  }
  return executeWithGantInstanceNoException(gant,binding);
}
 

Example 33

From project gxa, under directory /atlas-updates/src/main/java/uk/ac/ebi/gxa/db/.

Source file: MigrationFactory.java

  15 
vote

@Override public Migration create(String version,Resource resource){
  final String extension=getExtension(resource.getFilename()).toLowerCase();
  if ("sql".equals(extension)) {
    return new OracleScriptMigration(version,resource);
  }
  return super.create(version,resource);
}