Search in sources :

Example 6 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class XDGFPages method onDocumentRead.

@Override
protected void onDocumentRead() {
    try {
        try {
            _pagesObject = PagesDocument.Factory.parse(getPackagePart().getInputStream()).getPages();
        } catch (XmlException e) {
            throw new POIXMLException(e);
        } catch (IOException e) {
            throw new POIXMLException(e);
        }
        // this iteration is ordered by page number
        for (PageType pageSettings : _pagesObject.getPageArray()) {
            String relId = pageSettings.getRel().getId();
            POIXMLDocumentPart pageContentsPart = getRelationById(relId);
            if (pageContentsPart == null)
                throw new POIXMLException("PageSettings relationship for " + relId + " not found");
            if (!(pageContentsPart instanceof XDGFPageContents))
                throw new POIXMLException("Unexpected pages relationship for " + relId + ": " + pageContentsPart);
            XDGFPageContents contents = (XDGFPageContents) pageContentsPart;
            XDGFPage page = new XDGFPage(pageSettings, contents, _document, this);
            contents.onDocumentRead();
            _pages.add(page);
        }
    } catch (POIXMLException e) {
        throw XDGFException.wrap(this, e);
    }
}
Also used : XmlException(org.apache.xmlbeans.XmlException) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) POIXMLException(org.apache.poi.POIXMLException) IOException(java.io.IOException) PageType(com.microsoft.schemas.office.visio.x2012.main.PageType)

Example 7 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class XSLFSlideMaster method getLayouts.

private Map<String, XSLFSlideLayout> getLayouts() {
    if (_layouts == null) {
        _layouts = new HashMap<String, XSLFSlideLayout>();
        for (POIXMLDocumentPart p : getRelations()) {
            if (p instanceof XSLFSlideLayout) {
                XSLFSlideLayout layout = (XSLFSlideLayout) p;
                _layouts.put(layout.getName().toLowerCase(Locale.ROOT), layout);
            }
        }
    }
    return _layouts;
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart)

Example 8 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class XSSFSheet method getDrawingPatriarch.

/**
     * Return the sheet's existing drawing, or null if there isn't yet one.
     * 
     * Use {@link #createDrawingPatriarch()} to get or create
     *
     * @return a SpreadsheetML drawing
     */
@Override
public XSSFDrawing getDrawingPatriarch() {
    CTDrawing ctDrawing = getCTDrawing();
    if (ctDrawing != null) {
        // Search the referenced drawing in the list of the sheet's relations
        for (RelationPart rp : getRelationParts()) {
            POIXMLDocumentPart p = rp.getDocumentPart();
            if (p instanceof XSSFDrawing) {
                XSSFDrawing dr = (XSSFDrawing) p;
                String drId = rp.getRelationship().getId();
                if (drId.equals(ctDrawing.getId())) {
                    return dr;
                }
                break;
            }
        }
        logger.log(POILogger.ERROR, "Can't find drawing with id=" + ctDrawing.getId() + " in the list of the sheet's relationships");
    }
    return null;
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart)

Example 9 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class XSSFMap method getRelatedSingleXMLCell.

/**
     * @return the list of Single Xml Cells that provide a map rule to this mapping.
     */
public List<XSSFSingleXmlCell> getRelatedSingleXMLCell() {
    List<XSSFSingleXmlCell> relatedSimpleXmlCells = new ArrayList<XSSFSingleXmlCell>();
    int sheetNumber = mapInfo.getWorkbook().getNumberOfSheets();
    for (int i = 0; i < sheetNumber; i++) {
        XSSFSheet sheet = mapInfo.getWorkbook().getSheetAt(i);
        for (POIXMLDocumentPart p : sheet.getRelations()) {
            if (p instanceof SingleXmlCells) {
                SingleXmlCells singleXMLCells = (SingleXmlCells) p;
                for (XSSFSingleXmlCell cell : singleXMLCells.getAllSimpleXmlCell()) {
                    if (cell.getMapId() == ctMap.getID()) {
                        relatedSimpleXmlCells.add(cell);
                    }
                }
            }
        }
    }
    return relatedSimpleXmlCells;
}
Also used : SingleXmlCells(org.apache.poi.xssf.model.SingleXmlCells) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) ArrayList(java.util.ArrayList) XSSFSingleXmlCell(org.apache.poi.xssf.usermodel.helpers.XSSFSingleXmlCell)

Example 10 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class XWPFDocument method onDocumentRead.

@SuppressWarnings("deprecation")
@Override
protected void onDocumentRead() throws IOException {
    try {
        DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
        ctDocument = doc.getDocument();
        initFootnotes();
        // parse the document with cursor and add
        // the XmlObject to its lists
        XmlCursor cursor = ctDocument.getBody().newCursor();
        cursor.selectPath("./*");
        while (cursor.toNextSelection()) {
            XmlObject o = cursor.getObject();
            if (o instanceof CTP) {
                XWPFParagraph p = new XWPFParagraph((CTP) o, this);
                bodyElements.add(p);
                paragraphs.add(p);
            } else if (o instanceof CTTbl) {
                XWPFTable t = new XWPFTable((CTTbl) o, this);
                bodyElements.add(t);
                tables.add(t);
            } else if (o instanceof CTSdtBlock) {
                XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
                bodyElements.add(c);
                contentControls.add(c);
            }
        }
        cursor.dispose();
        // Sort out headers and footers
        if (doc.getDocument().getBody().getSectPr() != null)
            headerFooterPolicy = new XWPFHeaderFooterPolicy(this);
        // Create for each XML-part in the Package a PartClass
        for (RelationPart rp : getRelationParts()) {
            POIXMLDocumentPart p = rp.getDocumentPart();
            String relation = rp.getRelationship().getRelationshipType();
            if (relation.equals(XWPFRelation.STYLES.getRelation())) {
                this.styles = (XWPFStyles) p;
                this.styles.onDocumentRead();
            } else if (relation.equals(XWPFRelation.NUMBERING.getRelation())) {
                this.numbering = (XWPFNumbering) p;
                this.numbering.onDocumentRead();
            } else if (relation.equals(XWPFRelation.FOOTER.getRelation())) {
                XWPFFooter footer = (XWPFFooter) p;
                footers.add(footer);
                footer.onDocumentRead();
            } else if (relation.equals(XWPFRelation.HEADER.getRelation())) {
                XWPFHeader header = (XWPFHeader) p;
                headers.add(header);
                header.onDocumentRead();
            } else if (relation.equals(XWPFRelation.COMMENT.getRelation())) {
                // TODO Create according XWPFComment class, extending POIXMLDocumentPart
                CommentsDocument cmntdoc = CommentsDocument.Factory.parse(p.getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
                for (CTComment ctcomment : cmntdoc.getComments().getCommentArray()) {
                    comments.add(new XWPFComment(ctcomment, this));
                }
            } else if (relation.equals(XWPFRelation.SETTINGS.getRelation())) {
                settings = (XWPFSettings) p;
                settings.onDocumentRead();
            } else if (relation.equals(XWPFRelation.IMAGES.getRelation())) {
                XWPFPictureData picData = (XWPFPictureData) p;
                picData.onDocumentRead();
                registerPackagePictureData(picData);
                pictures.add(picData);
            } else if (relation.equals(XWPFRelation.GLOSSARY_DOCUMENT.getRelation())) {
                // Until we do, we do need to load the glossary child parts of it
                for (POIXMLDocumentPart gp : p.getRelations()) {
                    // Trigger the onDocumentRead for all the child parts
                    // Otherwise we'll hit issues on Styles, Settings etc on save
                    // TODO: Refactor this to not need to access protected method
                    // from other package! Remove the static helper method once fixed!!!
                    POIXMLDocumentPart._invokeOnDocumentRead(gp);
                }
            }
        }
        initHyperlinks();
    } catch (XmlException e) {
        throw new POIXMLException(e);
    }
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) XWPFHeaderFooterPolicy(org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy) POIXMLException(org.apache.poi.POIXMLException) XmlCursor(org.apache.xmlbeans.XmlCursor) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)42 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)16 MapInfo (org.apache.poi.xssf.model.MapInfo)14 XSSFMap (org.apache.poi.xssf.usermodel.XSSFMap)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 POIXMLException (org.apache.poi.POIXMLException)9 XmlException (org.apache.xmlbeans.XmlException)7 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)3 HashMap (java.util.HashMap)3 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)2 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)2 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)2 CellReference (org.apache.poi.ss.util.CellReference)2 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)2 CTAxDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)2 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)2