Example usage for org.apache.poi.hwpf.model PropertyNode getEnd

List of usage examples for org.apache.poi.hwpf.model PropertyNode getEnd

Introduction

In this page you can find the example usage for org.apache.poi.hwpf.model PropertyNode getEnd.

Prototype

public int getEnd() 

Source Link

Usage

From source file:b01.officeLink.ExtendedWordDocument.java

License:Apache License

public void replace_XXXXX(String oldString, String newString) {
    // hack to get the ending cp of the document, Have to revisit this.
    if (getHwpfDocument() != null && getHwpfDocument().getTextTable() != null) {
        java.util.List text = getHwpfDocument().getTextTable().getTextPieces();
        for (int i = 0; i < text.size(); i++) {
            PropertyNode p = (PropertyNode) text.get(i);
            System.out.println("Property Node " + i + " = " + p);
            System.out.println("Start = " + p.getStart() + " End = " + p.getEnd());
            System.out.println("Class = " + p.getClass().getName());

            if (p instanceof TextPiece) {
                TextPiece tp = (TextPiece) p;
                StringBuffer buffer = tp.getStringBuffer();
                System.out.println("Buffer = " + buffer);

                int start = buffer.indexOf(oldString);
                int end = start + oldString.length();

                //buffer.indexOf(newString);        
                buffer.replace(start, end, newString);
                tp.setEnd(tp.getEnd() + (newString.length() - oldString.length()));
            }//from   ww  w.j  av  a2s. co  m
        }
    }
}