Search in sources :

Example 1 with GenericPropertyNode

use of org.apache.poi.hwpf.model.GenericPropertyNode in project poi by apache.

the class HWPFLister method dumpPapx.

public void dumpPapx(boolean withProperties, boolean withSprms) throws Exception {
    if (_doc instanceof HWPFDocument) {
        System.out.println("binary PAP pages ");
        HWPFDocument doc = (HWPFDocument) _doc;
        byte[] mainStream = _doc.getMainStream();
        PlexOfCps binTable = new PlexOfCps(doc.getTableStream(), doc.getFileInformationBlock().getFcPlcfbtePapx(), doc.getFileInformationBlock().getLcbPlcfbtePapx(), 4);
        List<PAPX> papxs = new ArrayList<PAPX>();
        int length = binTable.length();
        for (int x = 0; x < length; x++) {
            GenericPropertyNode node = binTable.getProperty(x);
            int pageNum = LittleEndian.getInt(node.getBytes());
            int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum;
            PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(mainStream, doc.getDataStream(), pageOffset, doc.getTextTable());
            System.out.println("* PFKP: " + pfkp);
            for (PAPX papx : pfkp.getPAPXs()) {
                System.out.println("** " + papx);
                papxs.add(papx);
                if (papx != null && withSprms) {
                    SprmIterator sprmIt = new SprmIterator(papx.getGrpprl(), 2);
                    dumpSprms(sprmIt, "*** ");
                }
            }
        }
        Collections.sort(papxs);
        System.out.println("* Sorted by END");
        for (PAPX papx : papxs) {
            System.out.println("** " + papx);
            if (papx != null && withSprms) {
                SprmIterator sprmIt = new SprmIterator(papx.getGrpprl(), 2);
                dumpSprms(sprmIt, "*** ");
            }
        }
    }
    for (PAPX papx : _doc.getParagraphTable().getParagraphs()) {
        System.out.println(papx);
        if (withProperties) {
            Paragraph paragraph = Paragraph.newParagraph(_doc.getOverallRange(), papx);
            System.out.println(paragraph.getProps());
        }
        SprmIterator sprmIt = new SprmIterator(papx.getGrpprl(), 2);
        dumpSprms(sprmIt, "\t");
    }
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) SprmIterator(org.apache.poi.hwpf.sprm.SprmIterator) PlexOfCps(org.apache.poi.hwpf.model.PlexOfCps) ArrayList(java.util.ArrayList) PAPFormattedDiskPage(org.apache.poi.hwpf.model.PAPFormattedDiskPage) PAPX(org.apache.poi.hwpf.model.PAPX) GenericPropertyNode(org.apache.poi.hwpf.model.GenericPropertyNode) Paragraph(org.apache.poi.hwpf.usermodel.Paragraph)

Example 2 with GenericPropertyNode

use of org.apache.poi.hwpf.model.GenericPropertyNode in project poi by apache.

the class HeaderStories method getSubrangeAt.

private Range getSubrangeAt(int plcfHddIndex) {
    if (plcfHdd == null)
        return null;
    GenericPropertyNode prop = plcfHdd.getProperty(plcfHddIndex);
    if (prop.getStart() == prop.getEnd()) {
        // Empty story
        return null;
    }
    if (prop.getEnd() < prop.getStart()) {
        // Broken properties?
        return null;
    }
    final int headersLength = headerStories.getEndOffset() - headerStories.getStartOffset();
    int start = Math.min(prop.getStart(), headersLength);
    int end = Math.min(prop.getEnd(), headersLength);
    return new Range(headerStories.getStartOffset() + start, headerStories.getStartOffset() + end, headerStories);
}
Also used : GenericPropertyNode(org.apache.poi.hwpf.model.GenericPropertyNode)

Example 3 with GenericPropertyNode

use of org.apache.poi.hwpf.model.GenericPropertyNode in project poi by apache.

the class HeaderStories method getAt.

/**
	 * Get the string that's pointed to by the
	 *  given plcfHdd index
	 * @deprecated 3.8 beta 4
	 */
@Deprecated
private String getAt(int plcfHddIndex) {
    if (plcfHdd == null)
        return null;
    GenericPropertyNode prop = plcfHdd.getProperty(plcfHddIndex);
    if (prop.getStart() == prop.getEnd()) {
        // Empty story
        return "";
    }
    if (prop.getEnd() < prop.getStart()) {
        // Broken properties?
        return "";
    }
    // Ensure we're getting a sensible length
    String rawText = headerStories.text();
    int start = Math.min(prop.getStart(), rawText.length());
    int end = Math.min(prop.getEnd(), rawText.length());
    // Grab the contents
    String text = rawText.substring(start, end);
    // Strip off fields and macros if requested
    if (stripFields) {
        return Range.stripFields(text);
    }
    //  which is more what you'd expect
    if (text.equals("\r\r")) {
        return "";
    }
    return text;
}
Also used : GenericPropertyNode(org.apache.poi.hwpf.model.GenericPropertyNode)

Example 4 with GenericPropertyNode

use of org.apache.poi.hwpf.model.GenericPropertyNode in project poi by apache.

the class BookmarksImpl method updateSortedDescriptors.

private void updateSortedDescriptors() {
    if (sortedDescriptors != null)
        return;
    Map<Integer, List<GenericPropertyNode>> result = new HashMap<Integer, List<GenericPropertyNode>>();
    for (int b = 0; b < bookmarksTables.getDescriptorsFirstCount(); b++) {
        GenericPropertyNode property = bookmarksTables.getDescriptorFirst(b);
        Integer positionKey = Integer.valueOf(property.getStart());
        List<GenericPropertyNode> atPositionList = result.get(positionKey);
        if (atPositionList == null) {
            atPositionList = new LinkedList<GenericPropertyNode>();
            result.put(positionKey, atPositionList);
        }
        atPositionList.add(property);
    }
    int counter = 0;
    int[] indices = new int[result.size()];
    for (Map.Entry<Integer, List<GenericPropertyNode>> entry : result.entrySet()) {
        indices[counter++] = entry.getKey().intValue();
        List<GenericPropertyNode> updated = new ArrayList<GenericPropertyNode>(entry.getValue());
        Collections.sort(updated, PropertyNode.EndComparator.instance);
        entry.setValue(updated);
    }
    Arrays.sort(indices);
    this.sortedDescriptors = result;
    this.sortedStartPositions = indices;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) GenericPropertyNode(org.apache.poi.hwpf.model.GenericPropertyNode) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with GenericPropertyNode

use of org.apache.poi.hwpf.model.GenericPropertyNode in project poi by apache.

the class BookmarksImpl method getBookmarksAt.

public List<Bookmark> getBookmarksAt(int startCp) {
    updateSortedDescriptors();
    List<GenericPropertyNode> nodes = sortedDescriptors.get(Integer.valueOf(startCp));
    if (nodes == null || nodes.isEmpty())
        return Collections.emptyList();
    List<Bookmark> result = new ArrayList<Bookmark>(nodes.size());
    for (GenericPropertyNode node : nodes) {
        result.add(getBookmark(node));
    }
    return Collections.unmodifiableList(result);
}
Also used : ArrayList(java.util.ArrayList) GenericPropertyNode(org.apache.poi.hwpf.model.GenericPropertyNode)

Aggregations

GenericPropertyNode (org.apache.poi.hwpf.model.GenericPropertyNode)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)1 PAPFormattedDiskPage (org.apache.poi.hwpf.model.PAPFormattedDiskPage)1 PAPX (org.apache.poi.hwpf.model.PAPX)1 PlexOfCps (org.apache.poi.hwpf.model.PlexOfCps)1 SprmIterator (org.apache.poi.hwpf.sprm.SprmIterator)1 Paragraph (org.apache.poi.hwpf.usermodel.Paragraph)1