예제 #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;
  }
예제 #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);
    }
  }
예제 #3
0
  /** @param newIndex 0-based index of the slide */
  @SuppressWarnings("deprecation")
  public void setSlideOrder(XSLFSlide slide, int newIndex) {
    int oldIndex = _slides.indexOf(slide);
    if (oldIndex == -1) throw new IllegalArgumentException("Slide not found");
    if (oldIndex == newIndex) return;

    // fix the usermodel container
    _slides.add(newIndex, _slides.remove(oldIndex));

    // fix ordering in the low-level xml
    CTSlideIdList sldIdLst = _presentation.getSldIdLst();
    CTSlideIdListEntry[] entries = sldIdLst.getSldIdArray();
    CTSlideIdListEntry oldEntry = entries[oldIndex];
    if (oldIndex < newIndex) {
      System.arraycopy(entries, oldIndex + 1, entries, oldIndex, newIndex - oldIndex);
    } else {
      System.arraycopy(entries, newIndex, entries, newIndex + 1, oldIndex - newIndex);
    }
    entries[newIndex] = oldEntry;
    sldIdLst.setSldIdArray(entries);
  }
예제 #4
0
 public XSLFSlide removeSlide(int index) {
   XSLFSlide slide = _slides.remove(index);
   removeRelation(slide);
   _presentation.getSldIdLst().removeSldId(index);
   return slide;
 }