Beispiel #1
0
  /**
   * Create a slide and initialize it from the specified layout.
   *
   * @param layout
   * @return created slide
   */
  @SuppressWarnings("deprecation")
  public XSLFSlide createSlide(XSLFSlideLayout layout) {
    int slideNumber = 256, cnt = 1;
    CTSlideIdList slideList;
    if (!_presentation.isSetSldIdLst()) slideList = _presentation.addNewSldIdLst();
    else {
      slideList = _presentation.getSldIdLst();
      for (CTSlideIdListEntry slideId : slideList.getSldIdArray()) {
        slideNumber = (int) Math.max(slideId.getId() + 1, slideNumber);
        cnt++;
      }
    }

    XSLFSlide slide =
        (XSLFSlide) createRelationship(XSLFRelation.SLIDE, XSLFFactory.getInstance(), cnt);

    CTSlideIdListEntry slideId = slideList.addNewSldId();
    slideId.setId(slideNumber);
    slideId.setId2(slide.getPackageRelationship().getId());

    layout.copyLayout(slide);
    slide.addRelation(layout.getPackageRelationship().getId(), layout);

    PackagePartName ppName = layout.getPackagePart().getPartName();
    slide
        .getPackagePart()
        .addRelationship(
            ppName, TargetMode.INTERNAL, layout.getPackageRelationship().getRelationshipType());

    _slides.add(slide);
    return slide;
  }
Beispiel #2
0
  @Override
  @SuppressWarnings("deprecation")
  protected void onDocumentRead() throws IOException {
    try {
      PresentationDocument doc = PresentationDocument.Factory.parse(getCorePart().getInputStream());
      _presentation = doc.getPresentation();
      Map<String, XSLFSlide> shIdMap = new HashMap<String, XSLFSlide>();

      _masters = new HashMap<String, XSLFSlideMaster>();
      for (POIXMLDocumentPart p : getRelations()) {
        if (p instanceof XSLFSlide) {
          shIdMap.put(p.getPackageRelationship().getId(), (XSLFSlide) p);
        } else if (p instanceof XSLFSlideMaster) {
          XSLFSlideMaster master = (XSLFSlideMaster) p;
          _masters.put(p.getPackageRelationship().getId(), master);
        } else if (p instanceof XSLFTableStyles) {
          _tableStyles = (XSLFTableStyles) p;
        } else if (p instanceof XSLFNotesMaster) {
          _notesMaster = (XSLFNotesMaster) p;
        } else if (p instanceof XSLFCommentAuthors) {
          _commentAuthors = (XSLFCommentAuthors) p;
        }
      }

      _slides = new ArrayList<XSLFSlide>();
      if (_presentation.isSetSldIdLst()) {
        for (CTSlideIdListEntry slId : _presentation.getSldIdLst().getSldIdArray()) {
          XSLFSlide sh = shIdMap.get(slId.getId2());
          if (sh == null) {
            _logger.log(
                POILogger.WARN,
                "Slide with r:id "
                    + slId.getId()
                    + " was defined, but didn't exist in package, skipping");
            continue;
          }
          _slides.add(sh);
        }
      }
    } catch (XmlException e) {
      throw new POIXMLException(e);
    }
  }