Search in sources :

Example 1 with CString

use of org.apache.poi.hslf.record.CString in project poi by apache.

the class QuickButCruddyTextExtractor method findTextRecords.

/**
	 * For the given position, look if the record is a text record, and wind
	 *  on after.
	 * If it is a text record, grabs out the text. Whatever happens, returns
	 *  the position of the next record, or -1 if no more.
	 */
public int findTextRecords(int startPos, List<String> textV) {
    // Grab the length, and the first option byte
    // Note that the length doesn't include the 8 byte atom header
    int len = (int) LittleEndian.getUInt(pptContents, startPos + 4);
    byte opt = pptContents[startPos];
    // If it's a container, step into it and return
    // (If it's a container, option byte 1 BINARY_AND 0x0f will be 0x0f)
    int container = opt & 0x0f;
    if (container == 0x0f) {
        return (startPos + 8);
    }
    // Otherwise, check the type to see if it's text
    int type = LittleEndian.getUShort(pptContents, startPos + 2);
    // TextBytesAtom
    if (type == RecordTypes.TextBytesAtom.typeID) {
        TextBytesAtom tba = (TextBytesAtom) Record.createRecordForType(type, pptContents, startPos, len + 8);
        String text = HSLFTextParagraph.toExternalString(tba.getText(), -1);
        textV.add(text);
    }
    // TextCharsAtom
    if (type == RecordTypes.TextCharsAtom.typeID) {
        TextCharsAtom tca = (TextCharsAtom) Record.createRecordForType(type, pptContents, startPos, len + 8);
        String text = HSLFTextParagraph.toExternalString(tca.getText(), -1);
        textV.add(text);
    }
    // CString (doesn't go via a TextRun)
    if (type == RecordTypes.CString.typeID) {
        CString cs = (CString) Record.createRecordForType(type, pptContents, startPos, len + 8);
        String text = cs.getText();
        // Ignore the ones we know to be rubbish
        if (text.equals("___PPT10")) {
        } else if (text.equals("Default Design")) {
        } else {
            textV.add(text);
        }
    }
    // Wind on by the atom length, and check we're not at the end
    int newPos = (startPos + 8 + len);
    if (newPos > (pptContents.length - 8)) {
        newPos = -1;
    }
    return newPos;
}
Also used : TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) CString(org.apache.poi.hslf.record.CString) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) CString(org.apache.poi.hslf.record.CString)

Example 2 with CString

use of org.apache.poi.hslf.record.CString in project poi by apache.

the class HeadersFooters method getPlaceholderText.

private String getPlaceholderText(Placeholder ph, CString cs) {
    String text;
    if (_ppt2007) {
        HSLFSimpleShape ss = _sheet.getPlaceholder(ph);
        text = (ss instanceof HSLFTextShape) ? ((HSLFTextShape) ss).getText() : null;
        // default text in master placeholders is not visible
        if ("*".equals(text)) {
            text = null;
        }
    } else {
        text = (cs == null) ? null : cs.getText();
    }
    return text;
}
Also used : HSLFTextShape(org.apache.poi.hslf.usermodel.HSLFTextShape) HSLFSimpleShape(org.apache.poi.hslf.usermodel.HSLFSimpleShape) CString(org.apache.poi.hslf.record.CString)

Example 3 with CString

use of org.apache.poi.hslf.record.CString in project poi by apache.

the class HeadersFooters method setHeaderText.

/**
     * Sets headers's text
     *
     * @param text headers's text
     */
public void setHeaderText(String text) {
    setHeaderVisible(true);
    CString cs = _container.getHeaderAtom();
    if (cs == null) {
        cs = _container.addHeaderAtom();
    }
    cs.setText(text);
}
Also used : CString(org.apache.poi.hslf.record.CString)

Example 4 with CString

use of org.apache.poi.hslf.record.CString in project poi by apache.

the class HSLFSheet method getProgrammableTag.

/**
     * Return programmable tag associated with this sheet, e.g. <code>___PPT12</code>.
     *
     * @return programmable tag associated with this sheet.
     */
public String getProgrammableTag() {
    String tag = null;
    RecordContainer progTags = (RecordContainer) getSheetContainer().findFirstOfType(RecordTypes.ProgTags.typeID);
    if (progTags != null) {
        RecordContainer progBinaryTag = (RecordContainer) progTags.findFirstOfType(RecordTypes.ProgBinaryTag.typeID);
        if (progBinaryTag != null) {
            CString binaryTag = (CString) progBinaryTag.findFirstOfType(RecordTypes.CString.typeID);
            if (binaryTag != null) {
                tag = binaryTag.getText();
            }
        }
    }
    return tag;
}
Also used : RecordContainer(org.apache.poi.hslf.record.RecordContainer) CString(org.apache.poi.hslf.record.CString) CString(org.apache.poi.hslf.record.CString)

Example 5 with CString

use of org.apache.poi.hslf.record.CString in project poi by apache.

the class HeadersFooters method setDateTimeText.

/**
     * Sets custom user date to be displayed instead of today's date.
     *
     * @param text custom user date
     */
public void setDateTimeText(String text) {
    setUserDateVisible(true);
    setDateTimeVisible(true);
    CString cs = _container.getUserDateAtom();
    if (cs == null) {
        cs = _container.addUserDateAtom();
    }
    cs.setText(text);
}
Also used : CString(org.apache.poi.hslf.record.CString)

Aggregations

CString (org.apache.poi.hslf.record.CString)6 RecordContainer (org.apache.poi.hslf.record.RecordContainer)1 TextBytesAtom (org.apache.poi.hslf.record.TextBytesAtom)1 TextCharsAtom (org.apache.poi.hslf.record.TextCharsAtom)1 HSLFSimpleShape (org.apache.poi.hslf.usermodel.HSLFSimpleShape)1 HSLFTextShape (org.apache.poi.hslf.usermodel.HSLFTextShape)1