List of usage examples for com.vaadin.server ClassResource getStream
@Override
public DownloadStream getStream()
From source file:annis.gui.flatquerybuilder.ReducingStringComparator.java
License:Apache License
private void readMappings() { ALLOGRAPHS = new HashMap<>(); ClassResource cr = new ClassResource(ReducingStringComparator.class, MAPPING_FILE); try {/*from w w w .j a v a 2 s . c o m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document mappingD = db.parse(cr.getStream().getStream()); NodeList mappings = mappingD.getElementsByTagName("mapping"); for (int i = 0; i < mappings.getLength(); i++) { Element mapping = (Element) mappings.item(i); String mappingName = mapping.getAttribute("name"); HashMap mappingMap = initAlphabet(); NodeList variants = mapping.getElementsByTagName("variant"); for (int j = 0; j < variants.getLength(); j++) { Element var = (Element) variants.item(j); char varvalue = var.getAttribute("value").charAt(0); Element character = (Element) var.getParentNode(); char charactervalue = character.getAttribute("value").charAt(0); mappingMap.put(varvalue, charactervalue); } ALLOGRAPHS.put(mappingName, mappingMap); } } catch (SAXException e) { e = null; Notification.show(READING_ERROR_MESSAGE); } catch (IOException e) { e = null; Notification.show(READING_ERROR_MESSAGE); } catch (ParserConfigurationException e) { e = null; Notification.show(READING_ERROR_MESSAGE); } }
From source file:annis.libgui.AnnisBaseUI.java
License:Apache License
protected final void initLogging() { try {//w w w . j a v a2 s . c o m List<File> logbackFiles = getAllConfigLocations("gui-logback.xml"); InputStream inStream = null; if (!logbackFiles.isEmpty()) { try { inStream = new FileInputStream(logbackFiles.get(logbackFiles.size() - 1)); } catch (FileNotFoundException ex) { // well no logging no error... } } if (inStream == null) { ClassResource res = new ClassResource(AnnisBaseUI.class, "logback.xml"); inStream = res.getStream().getStream(); } if (inStream != null) { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator jc = new JoranConfigurator(); jc.setContext(context); context.reset(); context.putProperty("webappHome", VaadinService.getCurrent().getBaseDirectory().getAbsolutePath()); // load config file jc.doConfigure(inStream); } } catch (JoranException ex) { log.error("init logging failed", ex); } }
From source file:com.foc.desc.parsers.xml.FocDescDeclaration_XMLBased.java
License:Apache License
private XMLFocDesc parse() { XMLFocDesc xmlFocDesc = null;//ww w . j av a2s. c om try { ClassResource resource = null; InputStream inputStream = null; resource = new ClassResource(xmlFileName); inputStream = resource.getStream().getStream(); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); XMLFocDescParser focDescParser = new XMLFocDescParser(this); saxParser.parse(inputStream, focDescParser); xmlFocDesc = focDescParser.getXmlFocDesc(); } catch (Exception e) { Globals.logString("Could not load file : " + xmlFileName); Globals.logException(e); } return xmlFocDesc; }
From source file:com.foc.focDataSourceDB.FocDataSource_DB.java
License:Apache License
@Override public boolean command_executeRequestForModulesSP(String spFileName) { try {/* w ww. java 2 s. c om*/ Globals.logString("SP Re-Generation : " + spFileName); ClassResource resource = new ClassResource(spFileName); InputStream inputStream = resource.getStream().getStream(); InputStreamReader isReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(isReader); Connection connection = getDBManagerServer() != null ? getDBManagerServer().getConnection() : null; if (connection != null) { Statement sqlStatement = connection.createStatement(); if (sqlStatement != null) { String line = null; StringBuilder stringBuilder = null; while ((line = bufferedReader.readLine()) != null) { line = line.trim(); if (!Utils.isStringEmpty(line)) { if (stringBuilder != null && (line.contains(SP_DELIMITER) || line.contains(SP_DELIMITER.toLowerCase()))) { String query = stringBuilder.toString().replaceAll("//", ""); sqlStatement.addBatch(query); stringBuilder = null; } else { if (stringBuilder == null) { stringBuilder = new StringBuilder(); } if (stringBuilder.length() != 0) stringBuilder.append("\n"); stringBuilder.append(line); } } } sqlStatement.executeBatch(); } } inputStream.close(); inputStream = null; isReader.close(); isReader = null; bufferedReader.close(); bufferedReader = null; Globals.logString("SP Re-Generation : Successful"); } catch (Exception ex) { Globals.logString("SP Re-Generation : Failed"); Globals.logException(ex); } return false; }
From source file:com.foc.helpBook.FocHelpPage.java
License:Apache License
private InputStream getXMLStream() { InputStream inputStream = null; ClassResource resource = null; try {/* w ww . j a v a2 s . c o m*/ if (fileName != null && !fileName.isEmpty()) { resource = new ClassResource(fileName); inputStream = resource.getStream().getStream(); } } catch (Exception e) { Globals.logString("Could not load file : " + fileName); Globals.logException(e); } if (inputStream == null) { Globals.showNotification("Could not load help page " + fileName, " for page code" + pageCode, IFocEnvironment.TYPE_ERROR_MESSAGE); } return inputStream; }
From source file:com.foc.msword.WordTemplateFillerResource.java
License:Apache License
@Override public DownloadStream getStream() { DownloadStream downloadStream = null; try {/*from ww w. j ava 2 s . c om*/ ClassResource resource = null; InputStream inputStream = null; resource = new ClassResource(tempateFileName); inputStream = resource.getStream().getStream(); ExtendedWordDocument xWord = new ExtendedWordDocument(inputStream); if (xWord != null) { fill(xWord); ByteArrayOutputStream baos = new ByteArrayOutputStream(); xWord.write(baos); bais = new ByteArrayInputStream(baos.toByteArray()); } xWord.dispose(); } catch (Exception e) { Globals.logException(e); } if (bais != null) { String fileName2 = downloadFileName; if (!fileName2.endsWith(".doc") && !fileName2.endsWith(".docx")) { fileName2 += ".docx"; } downloadStream = new DownloadStream(bais, "application/x-unknown", fileName2); downloadStream.setParameter("Content-Disposition", "attachment; filename=" + fileName2); downloadStream.setCacheTime(0); } return downloadStream; }
From source file:com.foc.web.server.xmlViewDictionary.XMLView.java
License:Apache License
private InputStream getXMLStream(boolean help) { InputStream inputStream = null; if (getXmlviewDefinition() != null) { if (!help) { XMLViewDefinition xmlViewDef = getXmlviewDefinition(); String xml = xmlViewDef.getXML(); try { Globals.logString("XML before new ByteArray=" + xml); inputStream = new ByteArrayInputStream(xml.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { Globals.logException(e); }//from w w w . j a va2s .co m if (inputStream == null) { Globals.showNotification("Could not load XML from table", "View key : " + getXmlViewKey().getStringKey(), FocWebEnvironment.TYPE_ERROR_MESSAGE); } } } else { ClassResource resource = null; try { String fileName = help ? getXmlFileName_ForHelp() : getXmlFileName(); if (fileName != null && !fileName.isEmpty()) { resource = new ClassResource(fileName); inputStream = resource.getStream().getStream(); } } catch (Exception e) { Globals.logString("Could not load file : " + getXmlFileName()); Globals.logException(e); if (ConfigInfo.isForDevelopment()) { Globals.logString("Developer? Will Attempt creating the file : " + getXmlFileName()); String fullFileName = getFullFileName(); File file = new File(fullFileName); if (!file.exists()) { try { file.createNewFile(); resource = new ClassResource(getXmlFileName()); inputStream = resource.getStream().getStream(); } catch (IOException eForFileCreation) { Globals.logException(eForFileCreation); } } } } if (inputStream == null) { Globals.showNotification("Could not load XML from file", "View key : " + getXmlViewKey().getStringKey() + "\nFile : " + getXmlFileName(), IFocEnvironment.TYPE_ERROR_MESSAGE); Globals.logString("!!!! ERROR : Could Not Load file : " + getXmlFileName()); } } return inputStream; }
From source file:com.foc.web.unitTesting.FocUnitTestingSuite.java
License:Apache License
private void parseXML_IfNeeded() throws Exception { try {/* w w w. j a v a 2s. c o m*/ if (!isParsingDone()) { setParsingDone(true); String fileName = getFileName(); ClassResource resource = null; InputStream inputStream = null; try { resource = new ClassResource(fileName); inputStream = resource.getStream().getStream(); } catch (Exception e) { FocLogger.getInstance().addError("Could not load file : " + fileName); FocLogger.getInstance().addError(e.getMessage()); Globals.logString("Could not load file : " + fileName); Globals.logException(e); } if (inputStream == null) { FocLogger.getInstance() .addError("Input stream is null. Could not load file: " + fileName + "."); } SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); saxParser.parse(inputStream, new FocXMLUnitHandler()); } } catch (Exception e) { Globals.logException(e); FocLogger.getInstance().addError(e.getMessage()); } }