Package org.springframework.core.io

Examples of org.springframework.core.io.Resource


    }

    private HttpServletRequest getRequest()
            throws IOException
    {
        Resource resource = new ClassPathResource("/org/codehaus/xfire/spring/echoRequest.xml");
        byte[] bytes = FileCopyUtils.copyToByteArray(resource.getInputStream());
        MockHttpServletRequest request = new MockHttpServletRequest("POST", "/Echo");
        request.setContentType("text/xml");
        request.setContent(bytes);
        return request;
    }
View Full Code Here


      if (href.startsWith("/")) {
        path = href.substring(1);
      }
      InputStream is = null;
      try {
        Resource resource = appContext.getResource(path);
        if (resource != null && resource.exists()) {
          is = resource.getInputStream();
        } else {
          // conveniencecheck so clients can use same url client- as
          // serverside
          resource = appContext.getResource("images/" + path);
          if (resource != null && resource.exists()) {
            is = resource.getInputStream();
          } else {
            is = ClassLoader.getSystemResourceAsStream(href);
          }
        }
        if (is == null) {
View Full Code Here

      throws LayerException {
    NamedStyleInfo namedStyle = vectorLayerRasterizingInfo.getStyle();
    String location = namedStyle.getSldLocation();
    Style[] styles = styleMap.get(location);
    if (styles == null) {
      Resource sld = applicationContext.getResource(location);
      SLDParser parser = new SLDParser(styleFactory);
      // external graphics will be resolved with respect to the SLD URL !
      try {
        parser.setInput(sld.getURL());
        styles = parser.readXML();
        // apply missing titles (needed for legend)
        String styleName = (namedStyle.getSldStyleName() != null ?
            namedStyle.getSldStyleName() : layer.getId());
        for (Style style : styles) {
View Full Code Here

    return styleBuilder.createFill(styleBuilder.literalExpression(featureStyle.getFillColor()),
        styleBuilder.literalExpression(featureStyle.getFillOpacity()));
  }

  private URL getURL(String resourceLocation) {
    Resource resource = applicationContext.getResource(resourceLocation);
    if (resource.exists()) {
      try {
        return resource.getURL();
      } catch (IOException e) {
        log.warn("missing resource {}", resourceLocation);
      }
    } else {
      log.warn("missing resource {}", resourceLocation);
View Full Code Here

      }
      // apply defaults to all styles
      for (NamedStyleInfo namedStyle : info.getNamedStyleInfos()) {
        // check sld location
        if (namedStyle.getSldLocation() != null) {
          Resource resource = applicationContext.getResource(namedStyle.getSldLocation());
          IBindingFactory bindingFactory;
          try {
            bindingFactory = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class);
            IUnmarshallingContext unmarshallingContext = bindingFactory.createUnmarshallingContext();
            StyledLayerDescriptorInfo sld = (StyledLayerDescriptorInfo) unmarshallingContext
                .unmarshalDocument(new InputStreamReader(resource.getInputStream()));
            namedStyle.setStyledLayerInfo(sld);
          } catch (JiBXException e) {
            throw new LayerException(e, ExceptionCode.INVALID_SLD, namedStyle.getSldLocation(),
                layer.getId());
          } catch (IOException e) {
View Full Code Here


  private static void addHibernateFilesMatching(final String resourcePath, List<String> filesAlreadyAdded, List<String> ignoredFiles) {
    Resource[] ress = CoreSpringFactory.getResources(resourcePath);
    for (int i = 0; i < ress.length; i++) {
      Resource res = ress[i];
      InputStream is;
      String fileName = res.getFilename();
      if (ignoredFiles.contains(fileName)) {
        // then ignore it - dont log either
        continue;
      }
      if (!filesAlreadyAdded.contains(fileName)) {
        filesAlreadyAdded.add(fileName);
        try {
          log.info("Start adding hibernate mapping (xml mapping stream): "+ res.getDescription());
          is = res.getInputStream();
          cf.addInputStream(is);
          log.info("Loaded hibernate mapping (xml mapping stream): "+ res.getDescription());
        } catch (IOException e) {
          throw new AssertException("i/o error while getting inputstream of resource:"+ res.getDescription());
        }
      } else {
        log.warn("Douplicate hibernate mapping file::" + fileName+ " found on classpath, skipping " + res.toString());
      }
    }
  }
View Full Code Here

        if (null == cfgFiles) {
            cfgFiles = new String[] {Configurer.DEFAULT_USER_CFG_FILE};
            usingDefault = true;
        }
        for (String cfgFile : cfgFiles) {
            final Resource cpr = findResource(cfgFile);
            boolean exists = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
                public Boolean run() {
                    return cpr != null && cpr.exists();
                }
               
            });
            if (exists) {
                resources.add(cpr);
View Full Code Here

   
    public static Resource findResource(final String cfgFile) {
        try {
            return AccessController.doPrivileged(new PrivilegedAction<Resource>() {
                public Resource run() {
                    Resource cpr = new ClassPathResource(cfgFile);
                    if (cpr.exists()) {
                        return cpr;
                    }
                    try {
                        //see if it's a URL
                        URL url = new URL(cfgFile);
                        cpr = new UrlResource(url);
                        if (cpr.exists()) {
                            return cpr;
                        }
                    } catch (MalformedURLException e) {
                        //ignore
                    }
                    //try loading it our way
                    URL url = ClassLoaderUtils.getResource(cfgFile, BusApplicationContext.class);
                    if (url != null) {
                        cpr = new UrlResource(url);
                        if (cpr.exists()) {
                            return cpr;
                        }
                    }
                    cpr = new FileSystemResource(cfgFile);
                    if (cpr.exists()) {
                        return cpr;
                    }
                    return null;
                }
            });
View Full Code Here

                                                   String location) {
        XmlWebApplicationContext ctx2 = new XmlWebApplicationContext();
        createdContext = ctx2;
       
        ctx2.setServletConfig(servletConfig);
        Resource r = ctx2.getResource(location);
        try {
            InputStream in = r.getInputStream();
            in.close();
        } catch (IOException e) {
            //ignore
            r = ctx2.getResource("classpath:" + location);
            try {
                r.getInputStream().close();
            } catch (IOException e2) {
                //ignore
                r = null;
            }
        }
        try {
            if (r != null) {
                location = r.getURL().toExternalForm();
            }
        } catch (IOException e) {
            //ignore
        }       
        if (ctx != null) {
View Full Code Here

     * @return Absolute filename of the temp file
     * @throws Exception
     */
    public static File copyResourceToLocalFile(String sourceResource, String destFileName) throws Exception {
        try {
            Resource keystoreFile = new ClassPathResource(sourceResource);
            InputStream in = keystoreFile.getInputStream();

            File outKeyStoreFile = new File(destFileName);
            FileOutputStream fop = new FileOutputStream(outKeyStoreFile);
            byte[] buf = new byte[512];
            int num;
View Full Code Here

TOP

Related Classes of org.springframework.core.io.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.