List of usage examples for org.springframework.core.io DefaultResourceLoader DefaultResourceLoader
public DefaultResourceLoader(@Nullable ClassLoader classLoader)
From source file:$.PropertyLoadingFactoryBean.java
private static void loadProperties(Properties props, String propertyFileName) { entering();//from w w w. ja v a 2s .com debug("Loading %s", propertyFileName); InputStream propertyFileInputStream = null; try { try { propertyFileInputStream = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader()) .getResource(propertyFileName).getInputStream(); props.load(propertyFileInputStream); } finally { if (propertyFileInputStream != null) { propertyFileInputStream.close(); } } } catch (FileNotFoundException fnfe) { try { try { propertyFileInputStream = new FileInputStream(propertyFileName); props.load(propertyFileInputStream); } finally { if (propertyFileInputStream != null) { propertyFileInputStream.close(); } } } catch (Exception e) { warn("Could not load property file %s", propertyFileName); throwing(e); } } catch (IOException e) { warn("PropertyLoadingFactoryBean unable to load property file: %s", propertyFileName); } finally { exiting(); } }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.stylesheet.StylesheetValidationTest.java
private Resource getXsltStylesheet(Class<? extends S2SFormGenerator> generatorClass) { try {//from w ww . j a va2s . c o m final Field stylesheet = generatorClass.getDeclaredField("stylesheet"); stylesheet.setAccessible(true); final Value value = stylesheet.getAnnotation(Value.class); final ResourceLoader resourceLoader = new DefaultResourceLoader(this.getClass().getClassLoader()); return resourceLoader.getResource(value.value()); } catch (NoSuchFieldException e) { throw new RuntimeException(generatorClass.getName() + " cannot find stylesheet", e); } }
From source file:com.silverpeas.jcrutil.BetterRepositoryFactoryBean.java
/** * Load all the configuration properties * * @return//from www . j ava 2 s. c o m */ protected Properties loadConfigurationKeys() { Iterator<String> iter = configurationProperties.iterator(); Properties props; if (isUseSystemProperties()) { props = new Properties(System.getProperties()); } else { props = new Properties(); } ResourceLoader loader = new DefaultResourceLoader(this.getClass().getClassLoader()); String location = ""; while (iter.hasNext()) { try { location = iter.next(); props.load(loader.getResource(location).getInputStream()); } catch (IOException e) { log.info("Error loading resource " + location, e); } } return props; }
From source file:de.hybris.platform.btgcockpit.service.BTGCockpitServiceTest.java
public void initApplicationContext() { final GenericApplicationContext context = new GenericApplicationContext(); context.setResourceLoader(new DefaultResourceLoader(Registry.class.getClassLoader())); context.setClassLoader(Registry.class.getClassLoader()); context.getBeanFactory().setBeanClassLoader(Registry.class.getClassLoader()); context.setParent(Registry.getGlobalApplicationContext()); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context); xmlReader.setDocumentReaderClass(ScopeTenantIgnoreDocReader.class); xmlReader.setBeanClassLoader(Registry.class.getClassLoader()); xmlReader.loadBeanDefinitions(getSpringConfigurationLocations()); context.refresh();/*from w ww .j av a2s .co m*/ final AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory(); beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true); this.applicationContex = context; }
From source file:org.alfresco.repo.importer.ImporterBootstrap.java
/** * Get a Reader onto an XML view// ww w . j a v a 2 s . c om * * @param view the view location * @param encoding the encoding of the view * @return the reader */ private Reader getReader(String view, String encoding) { // Get Input Stream ResourceLoader resourceLoader = new DefaultResourceLoader(getClass().getClassLoader()); Resource viewResource = resourceLoader.getResource(view); if (viewResource == null) { throw new ImporterException("Could not find view file " + view); } // Wrap in buffered reader try { InputStream viewStream = viewResource.getInputStream(); InputStreamReader inputReader = (encoding == null) ? new InputStreamReader(viewStream) : new InputStreamReader(viewStream, encoding); BufferedReader reader = new BufferedReader(inputReader); return reader; } catch (UnsupportedEncodingException e) { throw new ImporterException( "Could not create reader for view " + view + " as encoding " + encoding + " is not supported"); } catch (IOException e) { throw new ImporterException("Could not open resource for view " + view); } }
From source file:org.kuali.coeus.s2sgen.impl.print.FormPrintServiceImpl.java
/** * //from w ww. j a va2 s. c o m * This method is to write the submitted application data to a pdfStream * * @param pdDoc * Proposal Development Document. * @return ByteArrayOutputStream[] of the submitted application data. * @throws S2SException */ protected PrintableResult getSubmittedPDFStream(ProposalDevelopmentDocumentContract pdDoc) throws S2SException { GrantApplicationDocument submittedDocument; String frmXpath = null; String frmAttXpath = null; try { S2sAppSubmissionContract s2sAppSubmission = getLatestS2SAppSubmission(pdDoc); String submittedApplicationXml = findSubmittedXml(s2sAppSubmission); String submittedApplication = s2SDateTimeService.removeTimezoneFactor(submittedApplicationXml); submittedDocument = GrantApplicationDocument.Factory.parse(submittedApplication); } catch (XmlException e) { LOG.error(e.getMessage(), e); throw new S2SException(e); } FormMappingInfo info = null; DevelopmentProposalContract developmentProposal = pdDoc.getDevelopmentProposal(); List<String> sortedNameSpaces = getSortedNameSpaces(developmentProposal.getProposalNumber(), developmentProposal.getS2sOppForms()); boolean formEntryFlag = true; List<S2SPrintable> formPrintables = new ArrayList<>(); for (String namespace : sortedNameSpaces) { XmlObject formFragment = null; info = formMappingService.getFormInfo(namespace); if (info == null) continue; formFragment = getFormObject(submittedDocument, info); frmXpath = "//*[namespace-uri(.) = '" + namespace + "']"; frmAttXpath = "//*[namespace-uri(.) = '" + namespace + "']//*[local-name(.) = 'FileLocation' and namespace-uri(.) = 'http://apply.grants.gov/system/Attachments-V1.0']"; byte[] formXmlBytes = formFragment.xmlText().getBytes(); GenericPrintable formPrintable = new GenericPrintable(); ArrayList<Source> templates = new ArrayList<Source>(); DefaultResourceLoader resourceLoader = new DefaultResourceLoader( ClassLoaderUtils.getDefaultClassLoader()); Resource resource = resourceLoader.getResource(info.getStyleSheet()); Source xsltSource = null; try { xsltSource = new StreamSource(resource.getInputStream()); } catch (IOException e) { throw new S2SException(e); } templates.add(xsltSource); formPrintable.setXSLTemplates(templates); // Linkedhashmap is used to preserve the order of entry. Map<String, byte[]> formXmlDataMap = new LinkedHashMap<String, byte[]>(); formXmlDataMap.put(info.getFormName(), formXmlBytes); formPrintable.setStreamMap(formXmlDataMap); S2sApplicationContract s2sApplciation = s2sApplicationService .findS2sApplicationByProposalNumber(pdDoc.getDevelopmentProposal().getProposalNumber()); List<? extends S2sAppAttachmentsContract> attachmentList = s2sApplciation.getS2sAppAttachmentList(); Map<String, byte[]> formAttachments = new LinkedHashMap<String, byte[]>(); try { XPathExecutor executer = new XPathExecutor(formFragment.toString()); org.w3c.dom.Node d = executer.getNode(frmXpath); org.w3c.dom.NodeList attList = XPathAPI.selectNodeList(d, frmAttXpath); int attLen = attList.getLength(); for (int i = 0; i < attLen; i++) { org.w3c.dom.Node attNode = attList.item(i); String contentId = ((Element) attNode) .getAttributeNS("http://apply.grants.gov/system/Attachments-V1.0", "href"); if (attachmentList != null && !attachmentList.isEmpty()) { for (S2sAppAttachmentsContract attAppAttachments : attachmentList) { if (attAppAttachments.getContentId().equals(contentId)) { try (ByteArrayOutputStream attStream = new ByteArrayOutputStream()) { attStream.write(getAttContent(pdDoc, attAppAttachments.getContentId())); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new S2SException(e); } StringBuilder attachment = new StringBuilder(); attachment.append(" ATT : "); attachment.append(attAppAttachments.getContentId()); formAttachments.put(attachment.toString(), getAttContent(pdDoc, attAppAttachments.getContentId())); } } } } } catch (Exception e) { LOG.error(e.getMessage(), e); } try { if (developmentProposal.getGrantsGovSelectFlag()) { List<AttachmentData> attachmentLists = new ArrayList<AttachmentData>(); saveGrantsGovXml(pdDoc, formEntryFlag, formFragment, attachmentLists, attachmentList); formEntryFlag = false; } } catch (Exception e) { LOG.error(e.getMessage(), e); } formPrintable.setAttachments(formAttachments); formPrintables.add(formPrintable); } PrintableResult result = new PrintableResult(); result.printables = formPrintables; return result; }
From source file:org.kuali.coeus.s2sgen.impl.print.FormPrintServiceImpl.java
/** * This method is used to generate byte stream of forms * * @param pdDoc/*w w w . j a va 2s. com*/ * ProposalDevelopmentDocumentContract * @return ByteArrayOutputStream[] PDF byte Array * @throws S2SException */ protected PrintableResult getPDFStream(ProposalDevelopmentDocumentContract pdDoc) throws S2SException { List<AuditError> errors = new ArrayList<AuditError>(); DevelopmentProposalContract developmentProposal = pdDoc.getDevelopmentProposal(); String proposalNumber = developmentProposal.getProposalNumber(); List<String> sortedNameSpaces = getSortedNameSpaces(proposalNumber, developmentProposal.getS2sOppForms()); List<S2SPrintable> formPrintables = new ArrayList<>(); boolean formEntryFlag = true; getNarrativeService().deleteSystemGeneratedNarratives(pdDoc.getDevelopmentProposal().getNarratives()); Forms forms = Forms.Factory.newInstance(); for (String namespace : sortedNameSpaces) { FormMappingInfo info = formMappingService.getFormInfo(namespace, proposalNumber); if (info == null) continue; S2SFormGenerator s2sFormGenerator = s2SFormGeneratorService.getS2SGenerator(proposalNumber, info.getNameSpace()); errors.addAll(s2sFormGenerator.getAuditErrors()); XmlObject formObject = s2sFormGenerator.getFormObject(pdDoc); if (s2SValidatorService.validate(formObject, errors) && errors.isEmpty()) { String applicationXml = formObject.xmlText(s2SFormGeneratorService.getXmlOptionsPrefixes()); String filteredApplicationXml = s2SDateTimeService.removeTimezoneFactor(applicationXml); byte[] formXmlBytes = filteredApplicationXml.getBytes(); GenericPrintable formPrintable = new GenericPrintable(); // Linkedhashmap is used to preserve the order of entry. Map<String, byte[]> formXmlDataMap = new LinkedHashMap<String, byte[]>(); formXmlDataMap.put(info.getFormName(), formXmlBytes); formPrintable.setStreamMap(formXmlDataMap); ArrayList<Source> templates = new ArrayList<Source>(); DefaultResourceLoader resourceLoader = new DefaultResourceLoader( ClassLoaderUtils.getDefaultClassLoader()); Resource resource = resourceLoader.getResource(info.getStyleSheet()); Source xsltSource = null; try { xsltSource = new StreamSource(resource.getInputStream()); } catch (IOException e) { throw new S2SException(e); } templates.add(xsltSource); formPrintable.setXSLTemplates(templates); List<AttachmentData> attachmentList = s2sFormGenerator.getAttachments(); try { if (developmentProposal.getGrantsGovSelectFlag()) { List<S2sAppAttachmentsContract> attachmentLists = new ArrayList<S2sAppAttachmentsContract>(); setFormObject(forms, formObject); saveGrantsGovXml(pdDoc, formEntryFlag, forms, attachmentList, attachmentLists); formEntryFlag = false; } } catch (Exception e) { LOG.error(e.getMessage(), e); } Map<String, byte[]> formAttachments = new LinkedHashMap<String, byte[]>(); if (attachmentList != null && !attachmentList.isEmpty()) { for (AttachmentData attachmentData : attachmentList) { if (!isPdfType(attachmentData.getContent())) continue; StringBuilder attachment = new StringBuilder(); attachment.append(" ATT : "); attachment.append(attachmentData.getContentId()); formAttachments.put(attachment.toString(), attachmentData.getContent()); } } if (formAttachments.size() > 0) { formPrintable.setAttachments(formAttachments); } formPrintables.add(formPrintable); } } final PrintableResult result = new PrintableResult(); result.errors = errors; result.printables = formPrintables; return result; }
From source file:org.kuali.kfs.sys.context.CheckModularization.java
protected Document generateDwrConfigDocument(String fileName) throws Exception { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader()); InputStream in = resourceLoader.getResource(fileName).getInputStream(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(true);/* w w w . j a v a 2 s .c o m*/ DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver(new DTDEntityResolver()); db.setErrorHandler(new LogErrorHandler()); Document doc = db.parse(in); return doc; }
From source file:org.kuali.kfs.sys.context.CheckModularization.java
public Document getDesignXmlDocument() throws Exception { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(ClassLoaderUtils.getDefaultClassLoader()); InputStream in = resourceLoader.getResource(DefaultResourceLoader.CLASSPATH_URL_PREFIX + "design.xml") .getInputStream();/*w ww . j a va 2 s. c o m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(in); return doc; }