Exemplo n.º 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;
  }
Exemplo n.º 2
0
  /** Create a blank slide. */
  public XSLFSlide createSlide() {
    String masterId = _presentation.getSldMasterIdLst().getSldMasterIdArray(0).getId2();
    XSLFSlideMaster master = _masters.get(masterId);

    XSLFSlideLayout layout = master.getLayout(SlideLayout.BLANK);
    if (layout == null) throw new IllegalArgumentException("Blank layout was not found");

    return createSlide(layout);
  }
Exemplo n.º 3
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);
    }
  }
Exemplo n.º 4
0
  @Override
  protected void commit() throws IOException {
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    Map<String, String> map = new HashMap<String, String>();
    map.put(STRelationshipId.type.getName().getNamespaceURI(), "r");
    xmlOptions.setSaveSuggestedPrefixes(map);

    PackagePart part = getPackagePart();
    OutputStream out = part.getOutputStream();
    _presentation.save(out, xmlOptions);
    out.close();
  }
Exemplo n.º 5
0
 CTTextParagraphProperties getDefaultParagraphStyle(int level) {
   XmlObject[] o =
       _presentation.selectPath(
           "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' "
               + "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' "
               + ".//p:defaultTextStyle/a:lvl"
               + (level + 1)
               + "pPr");
   if (o.length == 1) {
     return (CTTextParagraphProperties) o[0];
   }
   return null;
 }
Exemplo n.º 6
0
  /** Create a notes master. */
  public void createNotesMaster() {

    _notesMaster =
        (XSLFNotesMaster)
            createRelationship(XSLFRelation.NOTES_MASTER, XSLFFactory.getInstance(), 1);

    CTNotesMasterIdList notesMasterIdList = _presentation.addNewNotesMasterIdLst();
    CTNotesMasterIdListEntry notesMasterId = notesMasterIdList.addNewNotesMasterId();
    notesMasterId.setId(_notesMaster.getPackageRelationship().getId());

    Integer themeIndex = 1;
    List<Integer> themeIndexList = new ArrayList<Integer>();
    for (POIXMLDocumentPart p : getRelations()) {
      if (p instanceof XSLFTheme) {
        themeIndexList.add(XSLFRelation.THEME.getFileNameIndex(p));
      }
    }

    if (!themeIndexList.isEmpty()) {
      Boolean found = false;
      for (Integer i = 1; i <= themeIndexList.size(); i++) {
        if (!themeIndexList.contains(i)) {
          found = true;
          themeIndex = i;
        }
      }
      if (!found) {
        themeIndex = themeIndexList.size() + 1;
      }
    }

    XSLFTheme theme =
        (XSLFTheme) createRelationship(XSLFRelation.THEME, XSLFFactory.getInstance(), themeIndex);
    theme.importTheme(getSlides()[0].getTheme());

    _notesMaster.addRelation(theme.getPackageRelationship().getId(), theme);
    PackagePartName themePackagePartName = theme.getPackagePart().getPartName();
    _notesMaster
        .getPackagePart()
        .addRelationship(
            themePackagePartName,
            TargetMode.INTERNAL,
            theme.getPackageRelationship().getRelationshipType());
  }
Exemplo n.º 7
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);
  }
Exemplo n.º 8
0
 /**
  * Sets the page size to the given <code>Dimension</code> object.
  *
  * @param pgSize page size
  */
 public void setPageSize(Dimension pgSize) {
   CTSlideSize sz = CTSlideSize.Factory.newInstance();
   sz.setCx(Units.toEMU(pgSize.getWidth()));
   sz.setCy(Units.toEMU(pgSize.getHeight()));
   _presentation.setSldSz(sz);
 }
Exemplo n.º 9
0
 /**
  * Returns the current page size
  *
  * @return the page size
  */
 public Dimension getPageSize() {
   CTSlideSize sz = _presentation.getSldSz();
   int cx = sz.getCx();
   int cy = sz.getCy();
   return new Dimension((int) Units.toPoints(cx), (int) Units.toPoints(cy));
 }
Exemplo n.º 10
0
 public XSLFSlide removeSlide(int index) {
   XSLFSlide slide = _slides.remove(index);
   removeRelation(slide);
   _presentation.getSldIdLst().removeSldId(index);
   return slide;
 }