List of usage examples for org.springframework.core.io DefaultResourceLoader getResource
@Override
public Resource getResource(String location)
From source file:olympus.portal.security.WebSecurityConfig.java
@Bean public KeyManager keyManager() { DefaultResourceLoader loader = new DefaultResourceLoader(); Resource storeFile = loader.getResource("classpath:/security/samlKeystore.jks"); String storePass = "nalle123"; Map<String, String> passwords = new HashMap<String, String>(); passwords.put("apollo", "nalle123"); String defaultKey = "apollo"; return new JKSKeyManager(storeFile, storePass, passwords, defaultKey); }
From source file:org.alfresco.repo.content.transform.OOoContentTransformerHelper.java
public void afterPropertiesSet() throws Exception { // load the document conversion configuration if (documentFormatsConfiguration != null) { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); try {//from ww w . java 2s .c o m InputStream is = resourceLoader.getResource(this.documentFormatsConfiguration).getInputStream(); formatRegistry = new XmlDocumentFormatRegistry(is); // We do not need to explicitly close this InputStream as it is closed for us within the XmlDocumentFormatRegistry } catch (IOException e) { throw new AlfrescoRuntimeException( "Unable to load document formats configuration file: " + this.documentFormatsConfiguration); } } else { formatRegistry = new XmlDocumentFormatRegistry(); } }
From source file:org.eclipse.gemini.blueprint.test.FilteringProbeBuilder.java
private void appendManifest(TinyBundle bundle) throws IOException { DefaultResourceLoader loader = new DefaultResourceLoader(); Manifest manifest = new Manifest(loader.getResource(manifestLocation).getInputStream()); Attributes attr = manifest.getMainAttributes(); for (Object key : attr.keySet()) { String k = key.toString(); String v = attr.getValue(k); // append optional import for org.ops4j.pax.exam if (k.equalsIgnoreCase(Constants.IMPORT_PACKAGE)) { if (StringUtils.hasText(v)) { v = v + ","; }// w ww.j av a 2s . co m } v = v + "org.ops4j.pax.exam;resolution:=optional"; bundle.set(k, v); } }
From source file:org.kuali.coeus.s2sgen.impl.print.FormPrintServiceImpl.java
/** * //from www . jav a 2s .co 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/*from w ww .ja v a2 s. c o m*/ * 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);//from w w w . j a va 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();//from w ww. j a v a 2 s. c o m DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(in); return doc; }
From source file:org.kuali.kfs.sys.web.servlet.KfsDWRServlet.java
protected DwrXmlConfigurator generateConfigurator(DefaultResourceLoader resourceLoader, String scriptConfigurationFilePath) throws ServletException { try {//w w w . j a v a 2 s. co m InputStream is = resourceLoader.getResource(scriptConfigurationFilePath).getInputStream(); DwrXmlConfigurator dwrXmlConfigurator = new DwrXmlConfigurator(); dwrXmlConfigurator.setInputStream(is); return dwrXmlConfigurator; } catch (Exception e) { throw new ServletException(e); } }
From source file:org.kuali.kra.infrastructure.TestUtilities.java
License:asdf
public static String getContentsAsString(String fileLoc) throws Exception { DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); String data = ""; BufferedReader reader = null; try {//w w w .ja v a 2s . c o m reader = new BufferedReader( new InputStreamReader(resourceLoader.getResource(fileLoc).getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { data += line + "\r\n "; } } finally { if (reader != null) { try { reader.close(); } catch (Exception e) { LOG.error(e); } } } return data; }