Examples of OdfDocument


Examples of org.odftoolkit.odfdom.doc.OdfDocument

  @Test
  public void testPackage() {
    File tmpFile1 = ResourceUtilities.newTestOutputFile(TARGET_STEP_1);
    File tmpFile2 = ResourceUtilities.newTestOutputFile(TARGET_STEP_2);
    File tmpFile3 = ResourceUtilities.newTestOutputFile(TARGET_STEP_3);
    OdfDocument doc = null;
    try {
      doc = OdfSpreadsheetDocument.newSpreadsheetDocument();
      doc.save(tmpFile1);
      doc.close();
    } catch (Exception ex) {
      LOG.log(Level.SEVERE, mImagePath, ex);
      Assert.fail();
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

      File resDir = new File(targetDirectory);
      File[] resFiles = resDir.listFiles();
      boolean validTest = true;
      for (File odfFile : resFiles) {
        if (!odfFile.isDirectory() ) { //&& odfFile.getName().startsWith("Odf")
          OdfDocument odfDoc = OdfDocument.loadDocument(odfFile);
          String version = System.getProperty("odfdom.version");
          OdfOfficeMeta meta = odfDoc.getOfficeMetadata();
          meta.setAutomaticUpdate(false);
          meta.setCreator(null);
          meta.setCreationDate(null);
          meta.setDate(null);
          meta.setDescription(null);
          meta.setEditingCycles(null);
          meta.setEditingDuration(null);
          meta.setLanguage(null);
          meta.setPrintDate(null);
          meta.setPrintedBy(null);
          meta.setSubject(null);
          meta.setTitle(null);
          meta.removeUserDefinedDataByName("Info 1");
          meta.removeUserDefinedDataByName("Info 2");
          meta.removeUserDefinedDataByName("Info 3");
          meta.removeUserDefinedDataByName("Info 4");
          String timeStamp = mSimpleDateFormat.format(Calendar.getInstance().getTime());
          if (version != null) {
            if (version.endsWith("SNAPSHOT")) {
              version = version + "(" + timeStamp + ")";
            }
            meta.setGenerator("ODFDOM/" + version);
          } else {
            meta.setGenerator("ODFDOM/SNAPSHOT(" + timeStamp + ")");
            validTest = false;
          }
          LOG.log(Level.INFO, "Updating the resource {0}", odfFile.getPath());
          odfDoc.save(odfFile.getPath());
        }
      }
      Assert.assertTrue("No meta:generator could be set as the System property 'odfdom.version' set by the Maven pom.xml was not found!", validTest);

      //ToDO: Add validation test afterwards..
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

            ImportingJob job, List<JSONObject> fileRecords, String format) {
        JSONObject options = super.createParserUIInitializationData(job, fileRecords, format);

        JSONArray sheetRecords = new JSONArray();
        JSONUtilities.safePut(options, "sheetRecords", sheetRecords);
        OdfDocument odfDoc = null;
        try {
            JSONObject firstFileRecord = fileRecords.get(0);
            File file = ImportingUtilities.getFile(job, firstFileRecord);
            InputStream is = new FileInputStream(file);
            odfDoc = OdfDocument.loadDocument(is);
            List<OdfTable> tables = odfDoc.getTableList();
            int sheetCount = tables.size();

            boolean hasData = false;
            for (int i = 0; i < sheetCount; i++) {
                OdfTable sheet = tables.get(i);
                int rows = sheet.getRowCount();

                JSONObject sheetRecord = new JSONObject();
                JSONUtilities.safePut(sheetRecord, "name", sheet.getTableName());
                JSONUtilities.safePut(sheetRecord, "rows", rows);
                if (hasData) {
                    JSONUtilities.safePut(sheetRecord, "selected", false);
                } else if (rows > 0) {
                    JSONUtilities.safePut(sheetRecord, "selected", true);
                    hasData = true;
                }
                JSONUtilities.append(sheetRecords, sheetRecord);
            }
        } catch (FileNotFoundException e) {
            logger.info("File not found",e);
        } catch (Exception e) {
            // ODF throws *VERY* wide exceptions
            logger.info("Error reading ODF spreadsheet",e);
        } finally {
            if (odfDoc != null) {
                odfDoc.close();
            }
        }
        return options;
    }
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

            InputStream inputStream,
            int limit,
            JSONObject options,
            List<Exception> exceptions
    ) {
        OdfDocument odfDoc;
        try {
            odfDoc = OdfDocument.loadDocument(inputStream);
        } catch (Exception e) { // Ugh! could they throw any wider exception?
            exceptions.add(e);
            return;
        }

        List<OdfTable> tables = odfDoc.getTableList();

        int[] sheets = JSONUtilities.getIntArray(options, "sheets");
        for (int sheetIndex : sheets) {
            final OdfTable table = tables.get(sheetIndex);
            final int lastRow = table.getRowCount();
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

      // loads the image from the URL and inserts the image in the package, adapting the manifest
      pkg.insert(new FileInputStream(TEST_FILE_FOLDER + IMage), "Pictures/myHoliday.jpg", "image/jpeg");
      pkg.save(ResourceUtilities.newTestOutputFile(New_File));

      OdfDocument doc = OdfDocument.loadDocument(TEST_FILE_FOLDER + New_File);
      OdfFileDom contentDom = doc.getContentDom();

      XPath xpath = contentDom.getXPath();
      DrawFrameElement frame = contentDom.newOdfElement(DrawFrameElement.class);
      frame.setSvgHeightAttribute("3in");
      frame.setSvgWidthAttribute("7in");
      DrawImageElement image = contentDom.newOdfElement(DrawImageElement.class);
      image.setXlinkHrefAttribute("Pictures/myHoliday.jpg");
      frame.appendChild(image);

      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      para.appendChild(frame);
      doc.save(TEST_FILE_FOLDER + New_File);
      doc.close();

      //Test if the image has been inserted
      doc = OdfDocument.loadDocument(TEST_FILE_FOLDER + New_File);
      contentDom = doc.getContentDom();
      DrawFrameElement frameobj = (DrawFrameElement) xpath.evaluate("//text:p[1]/draw:frame", contentDom, XPathConstants.NODE);
      Assert.assertEquals("3in", frameobj.getSvgHeightAttribute());
      Assert.assertEquals("7in", frameobj.getSvgWidthAttribute());
      DrawImageElement imageobj = (DrawImageElement) frameobj.getFirstChild();
      Assert.assertEquals("Pictures/myHoliday.jpg", imageobj.getXlinkHrefAttribute());
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

   * @see org.odftoolkit.odfdom.dom.DefaultElementVisitor#visit(org.odftoolkit.odfdom.dom.element.draw.DrawObjectElement)
   */
  @Override
  public void visit(DrawObjectElement element) {
    String embedDocPath = element.getXlinkHrefAttribute();
    OdfDocument embedDoc = ((OdfDocument) (((OdfContentDom) element.getOwnerDocument()).getDocument())).loadSubDocument(embedDocPath);
    if (embedDoc != null) {
      try {
        mTextBuilder.append(OdfEditableTextExtractor.newOdfEditableTextExtractor(embedDoc).getText());
      } catch (Exception e) {
        Logger.getLogger(OdfEditableTextExtractor.class.getName()).log(Level.SEVERE, null, e);
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

   *           is the row index of the last cell in this cell range.
   */
  OdfTableCellRange(OdfTable table, int startColumn, int startRow, int endColumn, int endRow) {
    maOwnerTable = table;

    OdfDocument doc = (OdfDocument) ((OdfFileDom) maOwnerTable.getOdfElement().getOwnerDocument()).getDocument();
    if (doc instanceof OdfSpreadsheetDocument) {
      mbSpreadsheet = true;
    }

    //the first cell is the covered cell, then the cell range should be enlarged
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

   * @see org.odftoolkit.odfdom.dom.DefaultElementVisitor#visit(org.odftoolkit.odfdom.dom.element.draw.DrawObjectElement)
   */
  @Override
  public void visit(DrawObjectElement element) {
    String embedDocPath = element.getXlinkHrefAttribute();
    OdfDocument embedDoc = ((OdfDocument) (((OdfContentDom) element.getOwnerDocument()).getDocument())).loadSubDocument(embedDocPath);
    if (embedDoc != null) {
      try {
        mTextBuilder.append(OdfEditableTextExtractor.newOdfEditableTextExtractor(embedDoc).getText());
      } catch (Exception e) {
        Logger.getLogger(OdfEditableTextExtractor.class.getName()).log(Level.SEVERE, null, e);
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

      File resDir = new File(targetDirectory);
      File[] resFiles = resDir.listFiles();
      boolean validTest = true;
      for (File odfFile : resFiles) {
        if (!odfFile.isDirectory() ) { //&& odfFile.getName().startsWith("Odf")
          OdfDocument odfDoc = OdfDocument.loadDocument(odfFile);
          String version = System.getProperty("odfdom.version");
          OdfOfficeMeta meta = odfDoc.getOfficeMetadata();
          meta.setAutomaticUpdate(false);
          meta.setCreator(null);
          meta.setCreationDate(null);
          meta.setDate(null);
          meta.setDescription(null);
          meta.setEditingCycles(null);
          meta.setEditingDuration(null);
          meta.setLanguage(null);
          meta.setPrintDate(null);
          meta.setPrintedBy(null);
          meta.setSubject(null);
          meta.setTitle(null);
          meta.removeUserDefinedDataByName("Info 1");
          meta.removeUserDefinedDataByName("Info 2");
          meta.removeUserDefinedDataByName("Info 3");
          meta.removeUserDefinedDataByName("Info 4");
          String timeStamp = mSimpleDateFormat.format(Calendar.getInstance().getTime());
          if (version != null) {
            if (version.endsWith("SNAPSHOT")) {
              version = version + "(" + timeStamp + ")";
            }
            meta.setGenerator("ODFDOM/" + version);
          } else {
            meta.setGenerator("ODFDOM/SNAPSHOT(" + timeStamp + ")");
            validTest = false;
          }
          LOG.log(Level.INFO, "Updating the resource {0}", odfFile.getPath());
          odfDoc.save(odfFile.getPath());
        }
      }
      Assert.assertTrue("No meta:generator could be set as the System property 'odfdom.version' set by the Maven pom.xml was not found!", validTest);

      //ToDO: Add validation test afterwards..
View Full Code Here

Examples of org.odftoolkit.odfdom.doc.OdfDocument

  private void repeatedLoading() {
    long t = 0;
    for (int i = 0; i < num; i++) {
      try {
        long t1 = System.currentTimeMillis();
        OdfDocument doc = OdfDocument.loadDocument("src/test/resources/test1.odt");
        OdfContentDom dom1 = doc.getContentDom();
        OdfStylesDom dom2 = doc.getStylesDom();
        long t2 = System.currentTimeMillis() - t1;
        t = t + t2;
        LOG.info("Open in " + t2 + " milliseconds");
        long f1 = Runtime.getRuntime().freeMemory();
        doc.close();
        Runtime.getRuntime().gc();
        long f2 = Runtime.getRuntime().freeMemory();
        LOG.info("Freemem pre-gc: " + f1 + ", post-gc: " + f2 + ", delta: " + (f1 - f2) + ".");
      } catch (Exception ex) {
        Logger.getLogger(LoadMultipleTimes.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.