Search in sources :

Example 1 with POIXMLDocumentPart

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

the class XDGFPageContents method onDocumentRead.

@Override
protected void onDocumentRead() {
    try {
        try {
            _pageContents = PageContentsDocument.Factory.parse(getPackagePart().getInputStream()).getPageContents();
        } catch (XmlException e) {
            throw new POIXMLException(e);
        } catch (IOException e) {
            throw new POIXMLException(e);
        }
        for (POIXMLDocumentPart part : getRelations()) {
            if (!(part instanceof XDGFMasterContents))
                continue;
            //throw new POIXMLException("Unexpected page relation: " + part);
            XDGFMaster master = ((XDGFMasterContents) part).getMaster();
            _masters.put(master.getID(), master);
        }
        super.onDocumentRead();
        for (XDGFShape shape : _shapes.values()) {
            if (shape.isTopmost())
                shape.setupMaster(this, null);
        }
    } 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)

Example 2 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 3 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 4 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 5 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)

Aggregations

POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)43 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 HashMap (java.util.HashMap)4 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)4 OutputStream (java.io.OutputStream)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