Example usage for org.apache.poi.hpsf SummaryInformation wasNull

List of usage examples for org.apache.poi.hpsf SummaryInformation wasNull

Introduction

In this page you can find the example usage for org.apache.poi.hpsf SummaryInformation wasNull.

Prototype

public boolean wasNull() throws NoSingleSectionException 

Source Link

Document

Checks whether the property which the last call to #getPropertyIntValue or #getProperty tried to access was available or not.

Usage

From source file:com.pnf.plugin.ole.parser.StreamReader.java

License:Apache License

private List<INode> readSummaryInfoStream(ByteBuffer stream) {
    List<INode> roots = new LinkedList<>();
    String propType = "Property";

    try {/*from   w  ww  .j  a  v  a2  s  . c om*/
        SummaryInformation sInfo = new SummaryInformation(new PropertySet(stream.array()));

        StreamEntry cInfo = new StreamEntry("Creation Information");
        cInfo.addChild(new StreamEntry("Application Name", propType, sInfo.getApplicationName()));
        cInfo.addChild(new StreamEntry("Creation", "Time",
                sInfo.getCreateDateTime() != null ? sInfo.getCreateDateTime().toString() : null));
        cInfo.addChild(new StreamEntry("Author", propType, sInfo.getAuthor()));
        cInfo.addChild(new StreamEntry("Last Author", propType, sInfo.getLastAuthor()));
        cInfo.addChild(new StreamEntry("Template", propType, sInfo.getTemplate()));
        roots.add(cInfo);

        propType = "Time";
        StreamEntry timeInfo = new StreamEntry("Times");
        timeInfo.addChild(new StreamEntry("Total Edit Time", propType, String.valueOf(sInfo.getEditTime())));
        timeInfo.addChild(new StreamEntry("Last Saved", propType,
                sInfo.getLastSaveDateTime() != null ? sInfo.getLastSaveDateTime().toString() : null));
        timeInfo.addChild(new StreamEntry("Last Printed", propType,
                sInfo.getLastPrinted() != null ? sInfo.getLastPrinted().toString() : null));
        roots.add(timeInfo);

        propType = "Misc";
        StreamEntry misc = new StreamEntry("Miscellaneous");
        misc.addChild(new StreamEntry("OS Version", "int", String.valueOf(sInfo.getOSVersion())));
        misc.addChild(new StreamEntry("Revision Number", "int", sInfo.getRevNumber()));
        misc.addChild(new StreamEntry("Page Count", "int", String.valueOf(sInfo.getPageCount())));
        misc.addChild(new StreamEntry("Word Count", "int", String.valueOf(sInfo.getWordCount())));

        int secVal = sInfo.getSecurity();
        String security = null;

        if (!sInfo.wasNull()) { // Set description according to POI documentation
            switch (secVal) {
            case 0:
                security = "No security";
                break;
            case 1:
                security = "Password protected";
                break;
            case 2:
                security = "Read-only recommended";
                break;
            case 4:
                security = "Read-only enforced";
                break;
            case 8:
                security = "Locked for annotations";
                break;
            default:
                break;
            }

            security += " (code " + secVal + ")";
        } else {
            security = "Field not set";
        }

        misc.addChild(new StreamEntry("Document Security", "int", security));
        misc.addChild(new StreamEntry("Subject", propType, sInfo.getSubject()));
        misc.addChild(new StreamEntry("Keywords", propType, sInfo.getKeywords()));
        roots.add(misc);
    } catch (Throwable t) {
        addMessage("Attempted to read " + SUMM_INFO + " stream but no property sets were found.", null,
                Message.CORRUPT);
    }

    return roots;
}