Package org.apache.poi.hslf.record

Examples of org.apache.poi.hslf.record.Record


  public void testAddSlideToExisting2() throws Exception {
        //grab UserEditAtom
        UserEditAtom usredit = null;
        Record[] _records = hss_two.getRecords();
        for (int i = 0; i < _records.length; i++) {
            Record record = _records[i];
            if(_records[i].getRecordType() == RecordTypes.UserEditAtom.typeID) {
                usredit = (UserEditAtom)_records[i];
            }
       }
       assertNotNull(usredit);
View Full Code Here


      buf.append(printEscherContainerRecord( (EscherContainerRecord)er ));
    } else if (er instanceof EscherTextboxRecord) {
      buf.append("EscherTextboxRecord:" + nl);

      EscherTextboxWrapper etw = new EscherTextboxWrapper((EscherTextboxRecord)er);
      Record children[] = etw.getChildRecords();
      for (int j=0; j<children.length; j++) {
        if (children[j] instanceof StyleTextPropAtom) {

          // need preceding Text[Chars|Bytes]Atom to initialize the data structure
          if (j > 0 && (children[j-1] instanceof TextCharsAtom ||
View Full Code Here

  int indent = depth;
  String ind = "";
  for(int i=0; i<indent; i++) { ind += " "; }

  for(int i=0; i<records.length; i++) {
    Record r = records[i];
    if (r == null) {
      System.out.println(ind + "At position " + pos + " (" + makeHex(pos,6) + "):");
      System.out.println(ind + "Warning! Null record found.");
      continue;
    }

    // Figure out how big it is
    int len = getDiskLen(r);

    // Grab the type as hex
    String hexType = makeHex((int)r.getRecordType(),4);
    String rHexType = reverseHex(hexType);

    // Grab the hslf.record type
    Class c = r.getClass();
    String cname = c.toString();
    if(cname.startsWith("class ")) {
      cname = cname.substring(6);
    }
    if(cname.startsWith("org.apache.poi.hslf.record.")) {
      cname = cname.substring(27);
    }

    // Display the record
    System.out.println(ind + "At position " + pos + " (" + makeHex(pos,6) + "):");
    System.out.println(ind + " Record is of type " + cname);
    System.out.println(ind + " Type is " + r.getRecordType() + " (" + hexType + " -> " + rHexType + " )");
    System.out.println(ind + " Len is " + (len-8) + " (" + makeHex((len-8),8) + "), on disk len is " + len );

    // print additional information for drawings and atoms
    if (optEscher && cname.equals("PPDrawing")) {
      DefaultEscherRecordFactory factory = new DefaultEscherRecordFactory();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      r.writeOut(baos);
      byte[] b = baos.toByteArray();

      EscherRecord er = factory.createRecord(b, 0);
      er.fillFields(b, 0, factory);

      System.out.println( printEscherRecord( er ) );

    } else if(optVerbose && r.getChildRecords() == null) {
      String recData = getPrintableRecordContents(r);
      System.out.println(ind + recData );
    }

    System.out.println();

    // If it has children, show them
    if(r.getChildRecords() != null) {
      walkTree((depth+3),pos+8,r.getChildRecords());
    }

    // Wind on the position marker
    pos += len;
  }
View Full Code Here

      buf.append(printEscherContainerRecord( (EscherContainerRecord)er ));
    } else if (er instanceof EscherTextboxRecord) {
      buf.append("EscherTextboxRecord:" + nl);

      EscherTextboxWrapper etw = new EscherTextboxWrapper((EscherTextboxRecord)er);
      Record children[] = etw.getChildRecords();
      for (int j=0; j<children.length; j++) {
        if (children[j] instanceof StyleTextPropAtom) {

          // need preceding Text[Chars|Bytes]Atom to initialize the data structure
          if (j > 0 && (children[j-1] instanceof TextCharsAtom ||
View Full Code Here

  int indent = depth;
  String ind = "";
  for(int i=0; i<indent; i++) { ind += " "; }

  for(int i=0; i<records.length; i++) {
    Record r = records[i];
    if (r == null) {
      System.out.println(ind + "At position " + pos + " (" + makeHex(pos,6) + "):");
      System.out.println(ind + "Warning! Null record found.");
      continue;
    }

    // Figure out how big it is
    int len = getDiskLen(r);

    // Grab the type as hex
    String hexType = makeHex((int)r.getRecordType(),4);
    String rHexType = reverseHex(hexType);

    // Grab the hslf.record type
    Class c = r.getClass();
    String cname = c.toString();
    if(cname.startsWith("class ")) {
      cname = cname.substring(6);
    }
    if(cname.startsWith("org.apache.poi.hslf.record.")) {
      cname = cname.substring(27);
    }

    // Display the record
    System.out.println(ind + "At position " + pos + " (" + makeHex(pos,6) + "):");
    System.out.println(ind + " Record is of type " + cname);
    System.out.println(ind + " Type is " + r.getRecordType() + " (" + hexType + " -> " + rHexType + " )");
    System.out.println(ind + " Len is " + (len-8) + " (" + makeHex((len-8),8) + "), on disk len is " + len );

    // print additional information for drawings and atoms
    if (optEscher && cname.equals("PPDrawing")) {
      DefaultEscherRecordFactory factory = new DefaultEscherRecordFactory();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      r.writeOut(baos);
      byte[] b = baos.toByteArray();

      EscherRecord er = factory.createRecord(b, 0);
      er.fillFields(b, 0, factory);

      System.out.println( printEscherRecord( er ) );

    } else if(optVerbose && r.getChildRecords() == null) {
      String recData = getPrintableRecordContents(r);
      System.out.println(ind + recData );
    }

    System.out.println();

    // If it has children, show them
    if(r.getChildRecords() != null) {
      walkTree((depth+3),pos+8,r.getChildRecords());
    }

    // Wind on the position marker
    pos += len;
  }
View Full Code Here

        throw new CorruptPowerPointFileException("The CurrentUserAtom claims that the offset of last edit details are past the end of the file");
      }

      // Grab the details of the UserEditAtom there
      // If the record's messed up, we could AIOOB
      Record r = null;
      try {
        r = Record.buildRecordAtOffset(
            hss.getUnderlyingBytes(),
            (int)cua.getCurrentEditOffset()
        );
      } catch(ArrayIndexOutOfBoundsException e) {}
      if(r == null) { return null; }
      if(! (r instanceof UserEditAtom)) { return null; }
      UserEditAtom uea = (UserEditAtom)r;

      // Now get the PersistPtrHolder
      Record r2 = Record.buildRecordAtOffset(
          hss.getUnderlyingBytes(),
          uea.getPersistPointersOffset()
      );
      if(! (r2 instanceof PersistPtrHolder)) { return null; }
      PersistPtrHolder pph = (PersistPtrHolder)r2;

      // Now get the last record
      int[] slideIds = pph.getKnownSlideIDs();
      int maxSlideId = -1;
      for(int i=0; i<slideIds.length; i++) {
        if(slideIds[i] > maxSlideId) { maxSlideId = slideIds[i]; }
      }
      if(maxSlideId == -1) { return null; }

      int offset = (
          (Integer)pph.getSlideLocationsLookup().get(
              new Integer(maxSlideId)
          ) ).intValue();
      Record r3 = Record.buildRecordAtOffset(
          hss.getUnderlyingBytes(),
          offset
      );

      // If we have a DocumentEncryptionAtom, it'll be this one
View Full Code Here

   *            the refID
   */
  private Record getCoreRecordForRefID(int refID) {
    Integer coreRecordId = _sheetIdToCoreRecordsLookup.get(refID);
    if (coreRecordId != null) {
      Record r = _mostRecentCoreRecords[coreRecordId];
      return r;
    }
    logger.log(POILogger.ERROR,
        "We tried to look up a reference to a core record, but there was no core ID for reference ID "
            + refID);
View Full Code Here

      ArrayList<SlideMaster> mmr = new ArrayList<SlideMaster>();
      ArrayList<TitleMaster> tmr = new ArrayList<TitleMaster>();

      for (SlideAtomsSet sas : masterSets) {
        Record r = getCoreRecordForSAS(sas);
        int sheetNo = sas.getSlidePersistAtom().getSlideIdentifier();
        if (r instanceof org.apache.poi.hslf.record.Slide) {
          TitleMaster master = new TitleMaster((org.apache.poi.hslf.record.Slide) r,
              sheetNo);
          master.setSlideShow(this);
          tmr.add(master);
        } else if (r instanceof org.apache.poi.hslf.record.MainMaster) {
          SlideMaster master = new SlideMaster((org.apache.poi.hslf.record.MainMaster) r,
              sheetNo);
          master.setSlideShow(this);
          mmr.add(master);
        }
      }

      _masters = mmr.toArray(new SlideMaster[mmr.size()]);
      _titleMasters = tmr.toArray(new TitleMaster[tmr.size()]);
    }

    // Having sorted out the masters, that leaves the notes and slides

    // Start by finding the notes records to go with the entries in
    // notesSLWT
    org.apache.poi.hslf.record.Notes[] notesRecords;
    SlideAtomsSet[] notesSets = new SlideAtomsSet[0];
    Map<Integer,Integer> slideIdToNotes = new HashMap<Integer,Integer>();
    if (notesSLWT == null) {
      // None
      notesRecords = new org.apache.poi.hslf.record.Notes[0];
    } else {
      // Match up the records and the SlideAtomSets
      notesSets = notesSLWT.getSlideAtomsSets();
      List<org.apache.poi.hslf.record.Notes> notesRecordsL =
         new ArrayList<org.apache.poi.hslf.record.Notes>();
      for (int i = 0; i < notesSets.length; i++) {
        // Get the right core record
        Record r = getCoreRecordForSAS(notesSets[i]);

        // Ensure it really is a notes record
        if (r == null || r instanceof org.apache.poi.hslf.record.Notes) {
            if (r == null) {
                      logger.log(POILogger.WARN, "A Notes SlideAtomSet at " + i
                              + " said its record was at refID "
                              + notesSets[i].getSlidePersistAtom().getRefID()
                              + ", but that record didn't exist - record ignored.");
            }
            // we need to add also null-records, otherwise the index references to other existing
            // don't work anymore
          org.apache.poi.hslf.record.Notes notesRecord = (org.apache.poi.hslf.record.Notes) r;
          notesRecordsL.add(notesRecord);

          // Record the match between slide id and these notes
          SlidePersistAtom spa = notesSets[i].getSlidePersistAtom();
          int slideId = spa.getSlideIdentifier();
          slideIdToNotes.put(slideId, i);
        } else {
          logger.log(POILogger.ERROR, "A Notes SlideAtomSet at " + i
              + " said its record was at refID "
              + notesSets[i].getSlidePersistAtom().getRefID()
              + ", but that was actually a " + r);
        }
      }
      notesRecords = new org.apache.poi.hslf.record.Notes[notesRecordsL.size()];
      notesRecords = notesRecordsL.toArray(notesRecords);
    }

    // Now, do the same thing for our slides
    org.apache.poi.hslf.record.Slide[] slidesRecords;
    SlideAtomsSet[] slidesSets = new SlideAtomsSet[0];
    if (slidesSLWT == null) {
      // None
      slidesRecords = new org.apache.poi.hslf.record.Slide[0];
    } else {
      // Match up the records and the SlideAtomSets
      slidesSets = slidesSLWT.getSlideAtomsSets();
      slidesRecords = new org.apache.poi.hslf.record.Slide[slidesSets.length];
      for (int i = 0; i < slidesSets.length; i++) {
        // Get the right core record
        Record r = getCoreRecordForSAS(slidesSets[i]);

        // Ensure it really is a slide record
        if (r instanceof org.apache.poi.hslf.record.Slide) {
          slidesRecords[i] = (org.apache.poi.hslf.record.Slide) r;
        } else {
View Full Code Here

        }
       
    ExEmbed exEmbed = new ExEmbed();
        // remove unneccessary infos, so we don't need to specify the type
        // of the ole object multiple times
        Record children[] = exEmbed.getChildRecords();
        exEmbed.removeChild(children[2]);
        exEmbed.removeChild(children[3]);
        exEmbed.removeChild(children[4]);

        ExEmbedAtom eeEmbed = exEmbed.getExEmbedAtom();
View Full Code Here

    byte[] s_slwt = writeRecord(s_SLWT);

    // Check the records are the same
    assertEquals(refSLWT.getChildRecords().length, s_SLWT.getChildRecords().length);
    for(int i=0; i<refSLWT.getChildRecords().length; i++) {
      Record ref_r = refSLWT.getChildRecords()[i];
      Record s_r = s_SLWT.getChildRecords()[i];

      byte[] r_rb = writeRecord(ref_r);
      byte[] s_rb = writeRecord(s_r);
      assertEquals(r_rb.length, s_rb.length);
      for(int j=0; j<r_rb.length; j++) {
View Full Code Here

TOP

Related Classes of org.apache.poi.hslf.record.Record

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.