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");
}
}
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);
}
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;
}
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;
}
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);
}
Aggregations