Search in sources :

Example 1 with MasterType

use of com.microsoft.schemas.office.visio.x2012.main.MasterType in project poi by apache.

the class XDGFMasters method onDocumentRead.

@Override
protected void onDocumentRead() {
    try {
        try {
            _mastersObject = MastersDocument.Factory.parse(getPackagePart().getInputStream()).getMasters();
        } catch (XmlException e) {
            throw new POIXMLException(e);
        } catch (IOException e) {
            throw new POIXMLException(e);
        }
        Map<String, MasterType> masterSettings = new HashMap<String, MasterType>();
        for (MasterType master : _mastersObject.getMasterArray()) {
            masterSettings.put(master.getRel().getId(), master);
        }
        // create the masters
        for (RelationPart rp : getRelationParts()) {
            POIXMLDocumentPart part = rp.getDocumentPart();
            String relId = rp.getRelationship().getId();
            MasterType settings = masterSettings.get(relId);
            if (settings == null) {
                throw new POIXMLException("Master relationship for " + relId + " not found");
            }
            if (!(part instanceof XDGFMasterContents)) {
                throw new POIXMLException("Unexpected masters relationship for " + relId + ": " + part);
            }
            XDGFMasterContents contents = (XDGFMasterContents) part;
            contents.onDocumentRead();
            XDGFMaster master = new XDGFMaster(settings, contents, _document);
            _masters.put(master.getID(), master);
        }
    } catch (POIXMLException e) {
        throw XDGFException.wrap(this, e);
    }
}
Also used : HashMap(java.util.HashMap) XmlException(org.apache.xmlbeans.XmlException) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) POIXMLException(org.apache.poi.POIXMLException) IOException(java.io.IOException) MasterType(com.microsoft.schemas.office.visio.x2012.main.MasterType)

Aggregations

MasterType (com.microsoft.schemas.office.visio.x2012.main.MasterType)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)1 POIXMLException (org.apache.poi.POIXMLException)1 XmlException (org.apache.xmlbeans.XmlException)1