当前位置: 首页>>代码示例>>Java>>正文


Java SAXHelper.newXMLReader方法代码示例

本文整理汇总了Java中org.apache.poi.util.SAXHelper.newXMLReader方法的典型用法代码示例。如果您正苦于以下问题:Java SAXHelper.newXMLReader方法的具体用法?Java SAXHelper.newXMLReader怎么用?Java SAXHelper.newXMLReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.util.SAXHelper的用法示例。


在下文中一共展示了SAXHelper.newXMLReader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processSheet

import org.apache.poi.util.SAXHelper; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> List<T> processSheet(StylesTable styles, ReadOnlySharedStringsTable readOnlySharedStringsTable,
                                 Class<T> type, InputStream sheetInputStream) {

    DataFormatter formatter = new DataFormatter();
    InputSource sheetSource = new InputSource(sheetInputStream);
    try {
        XMLReader sheetParser = SAXHelper.newXMLReader();
        PoijiHandler poijiHandler = new PoijiHandler(type, options);
        ContentHandler contentHandler =
                new XSSFSheetXMLHandler(styles, null, readOnlySharedStringsTable, poijiHandler, formatter, false);
        sheetParser.setContentHandler(contentHandler);
        sheetParser.parse(sheetSource);
        return poijiHandler.getDataset();
    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new PoijiException("Problem occurred while reading data", e);
    }
}
 
开发者ID:ozlerhakan,项目名称:poiji,代码行数:19,代码来源:XSSFUnmarshaller.java

示例2: determineTypesInXMLFile

import org.apache.poi.util.SAXHelper; //导入方法依赖的package包/类
private void determineTypesInXMLFile(ZipFullEntry entry) {
    if (entry.getSize() > 0) {
        try {
            XMLReader reader = SAXHelper.newXMLReader();
            jcrContentHandler.setLocation(entry.getName()
                    .replaceAll(Pattern.quote("/.content.xml"), "")
                    .replaceAll("jcr_root", ""));
            reader.setContentHandler(jcrContentHandler);
            reader.parse(new InputSource(entry.getInputStream()));
            jcrContentHandler.getTypesFound().forEach((type, paths) -> {
                paths.forEach(path -> trackFilesByType(type, entry.getName() + "/" + path));
            });
        } catch (SAXException | ParserConfigurationException | IOException ex) {
            Logger.getLogger(PackageContents.class.getName()).log(
                    Level.SEVERE,
                    "Error parsing entry " + entry.getName()
                    + " in archive " + packageFile.getName(), ex);
        }
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:aem-epic-tool,代码行数:21,代码来源:PackageContents.java

示例3: processSheet

import org.apache.poi.util.SAXHelper; //导入方法依赖的package包/类
/**
 * Parses and shows the content of one sheet using the specified styles and
 * shared-strings tables.
 *
 * @param styles
 * @param strings
 * @param sheetInputStream
 */
public void processSheet(StylesTable styles, ReadOnlySharedStringsTable strings, SheetContentsHandler sheetHandler,
                         InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException {
    DataFormatter formatter = new DataFormatter();
    InputSource sheetSource = new InputSource(sheetInputStream);
    try {
        XMLReader sheetParser = SAXHelper.newXMLReader();
        ContentHandler handler = new XSSFSheetXMLHandler(styles, null, strings, sheetHandler, formatter, false);
        sheetParser.setContentHandler(handler);
        sheetParser.parse(sheetSource);
    } catch (ParserConfigurationException e) {
        throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:22,代码来源:XLSX2CSV.java

示例4: processSheet

import org.apache.poi.util.SAXHelper; //导入方法依赖的package包/类
/**
 * Parses and shows the content of one sheet using the specified styles and
 * shared-strings tables.
 *
 * @param styles
 * @param strings
 * @param sheetInputStream
 */
public void processSheet(StylesTable styles, ReadOnlySharedStringsTable strings, SheetContentsHandler sheetHandler,
		InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException {
	DataFormatter formatter = new DataFormatter();
	InputSource sheetSource = new InputSource(sheetInputStream);
	try {
		XMLReader sheetParser = SAXHelper.newXMLReader();
		ContentHandler handler = new XSSFSheetXMLHandler(styles, null, strings, sheetHandler, formatter, false);
		sheetParser.setContentHandler(handler);
		sheetParser.parse(sheetSource);
	} catch (ParserConfigurationException e) {
		throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
	}
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:22,代码来源:XLSX2CSV.java

示例5: readFrom

import org.apache.poi.util.SAXHelper; //导入方法依赖的package包/类
/**
 * Read this shared strings table from an XML file.
 * 
 * @param is
 *            The input stream containing the XML document.
 * @throws IOException
 *             if an error occurs while reading.
 * @throws SAXException
 */
public void readFrom(InputStream is) throws IOException, SAXException {
	if (is.available() > 0) {
		InputSource sheetSource = new InputSource(is);
		try {
			XMLReader sheetParser = SAXHelper.newXMLReader();
			sheetParser.setContentHandler(this);
			sheetParser.parse(sheetSource);
		} catch (ParserConfigurationException e) {
			throw new RuntimeException("SAX parser appears to be broken - "
					+ e.getMessage());
		}
	}
}
 
开发者ID:bingyulei007,项目名称:bingexcel,代码行数:23,代码来源:ExcelReadOnlySharedStringsTable.java

示例6: process

import org.apache.poi.util.SAXHelper; //导入方法依赖的package包/类
/**
 * Reads a list of POJOs from the given excel file.
 *
 * @param file Excel file to read from
 * @param sheetName The sheet to extract from in the workbook
 * @param reader The reader class to use to load the file from the sheet
 */
public static void process(File file, String sheetName, ZeroCellReader reader) {
    try (FileInputStream fis = new FileInputStream(file);
         OPCPackage opcPackage = OPCPackage.open(fis)) {

        DataFormatter dataFormatter = new DataFormatter();
        ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(opcPackage);
        XSSFReader xssfReader = new XSSFReader(opcPackage);
        StylesTable stylesTable = xssfReader.getStylesTable();
        InputStream sheetInputStream = null;
        XSSFReader.SheetIterator sheets = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
        while (sheets.hasNext()) {
            sheetInputStream = sheets.next();
            if (sheets.getSheetName().equalsIgnoreCase(sheetName)) {
                break;
            } else {
                sheetInputStream = null;
            }
        }

        if (Objects.isNull(sheetInputStream)) {
            throw new SheetNotFoundException(sheetName);
        }

        XMLReader xmlReader = SAXHelper.newXMLReader();
        xmlReader.setContentHandler(new XSSFSheetXMLHandler(stylesTable, strings, reader, dataFormatter, false));
        xmlReader.parse(new InputSource(sheetInputStream));
        sheetInputStream.close();
        xmlReader = null;
        sheetInputStream = null;
        stylesTable = null;
        strings = null;
        xssfReader = null;
    } catch(org.apache.poi.openxml4j.exceptions.InvalidFormatException | NotOfficeXmlFileException ife) {
        throw new ZeroCellException("Cannot load file. The file must be an Excel 2007+ Workbook (.xlsx)");
    } catch(SheetNotFoundException ex) {
        throw new ZeroCellException(ex.getMessage());
    } catch (ZeroCellException ze) {
        throw ze; // Rethrow the Exception
    } catch (Exception e) {
        throw new ZeroCellException("Failed to process file", e);
    }
}
 
开发者ID:creditdatamw,项目名称:zerocell,代码行数:50,代码来源:ReaderUtil.java


注:本文中的org.apache.poi.util.SAXHelper.newXMLReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。