Package org.odftoolkit.odfdom.dom

Examples of org.odftoolkit.odfdom.dom.OdfContentDom


  }

  @Test
  public void testSetDefaultCellStyle() {
    SpreadsheetDocument outputDocument;
    OdfContentDom contentDom; // the document object model for content.xml
    // the office:automatic-styles element in content.xml
    OdfOfficeAutomaticStyles contentAutoStyles;
    OdfStyle style;
    String noaaDateStyleName;
    String noaaTempStyleName;

    try {
      outputDocument = SpreadsheetDocument.newSpreadsheetDocument();
      contentDom = outputDocument.getContentDom();
      contentAutoStyles = contentDom.getOrCreateAutomaticStyles();

      OdfNumberDateStyle dateStyle = new OdfNumberDateStyle(contentDom, "yyyy-MM-dd", "numberDateStyle", null);
      OdfNumberStyle numberStyle = new OdfNumberStyle(contentDom, "#0.00", "numberTemperatureStyle");

      contentAutoStyles.appendChild(dateStyle);
View Full Code Here


            TEST_FILE_EMBEDDED, embDoc.getDocumentPath(), embDoc.getMediaTypeString() });
        pathToEmbeddedObject = embDoc.getDocumentPath();
      }

      Document embDoc = docWithEmbeddedObjects.getEmbeddedDocument(pathToEmbeddedObject);
      OdfContentDom contentDom = embDoc.getContentDom();
      XPath xpath = contentDom.getXPath();
      // Make sure the embedded document is being loaded

      // Add text element
      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      LOG.log(Level.INFO, "First para: {0}", para.getTextContent());
View Full Code Here

      embDoc.insertDocument(TextDocument.newTextDocument(), pathOfSecondInnerDoc);
      OdfFileEntry fileEntry = embDoc.getPackage().getFileEntry(embDoc.getDocumentPath() + pathOfSecondInnerDoc);
      Assert.assertNotNull(fileEntry);

      // get "Object 1/content.xml"
      OdfContentDom contentDom = embDoc.getContentDom();
      XPath xpath = contentDom.getXPath();
      TextPElement lastPara = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom, XPathConstants.NODE);
      addFrameForEmbeddedDoc(contentDom, lastPara, "Object in Object1");
      List<Document> emb_embDocs = embDoc.getEmbeddedDocuments();
      Assert.assertEquals(embDocsNumber + 1, emb_embDocs.size());

      Document emb_embDoc = rootDocument.getEmbeddedDocument(embDoc.getDocumentPath() + pathOfSecondInnerDoc);
      contentDom = emb_embDoc.getContentDom();
      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      OdfTextSpan spanElem = new OdfTextSpan(contentDom);
      spanElem.setTextContent(TEST_SPAN_TEXT);
      para.appendChild(spanElem);

      // embDoc.save(ResourceUtilities.newTestOutputFile("222debug.odt"));
      rootDocument.save(TEST_FILE_EMBEDDED_EMBEDDED);

      Document docWithdoubleEmbeddedDoc = Document.loadDocument(TEST_FILE_EMBEDDED_EMBEDDED);
      Document embeddedDoc = docWithdoubleEmbeddedDoc.getEmbeddedDocument("Object 1");
      Document doubleEmbeddedDoc = embeddedDoc.getEmbeddedDocument("Object in Object1");

      OdfContentDom dEDcontentDom = doubleEmbeddedDoc.getContentDom();
      TextSpanElement spanTest = (TextSpanElement) xpath.evaluate("//text:span[last()]", dEDcontentDom,
          XPathConstants.NODE);
      Assert.assertEquals(spanTest.getTextContent(), TEST_SPAN_TEXT);

    } catch (Exception ex) {
View Full Code Here

    Document docWithEmbeddedObjects;
    try {
      docWithEmbeddedObjects = Document.loadDocument(TEST_FILE_EMBEDDED);
      List<Document> embDocs = docWithEmbeddedObjects.getEmbeddedDocuments();
      Document doc1 = embDocs.get(0);
      OdfContentDom contentDom1 = doc1.getContentDom();
      Document doc2 = doc1.getEmbeddedDocument(".");
      OdfContentDom contentDom2 = doc2.getContentDom();
      Assert.assertEquals(doc2, doc1);
      Assert.assertEquals(contentDom1, contentDom2);
    } catch (Exception ex) {
      Logger.getLogger(DocumentCreationTest.class.getName()).log(Level.SEVERE, null, ex);
      Assert.fail("Failed with " + ex.getClass().getName() + ": '" + ex.getMessage() + "'");
View Full Code Here

      List<Document> embDocs = docWithEmbeddedObjects.getEmbeddedDocuments(Document.OdfMediaType.GRAPHICS);
      // Graphics Doc
      Document doc1 = embDocs.get(0);
      Assert.assertNotNull(doc1);

      OdfContentDom contentDom = doc1.getContentDom();
      XPath xpath = contentDom.getXPath();
      TextPElement para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom, XPathConstants.NODE);
      OdfTextSpan spanElem = new OdfTextSpan(contentDom);
      spanElem.setTextContent(TEST_SPAN_TEXT);
      para.appendChild(spanElem);
      // save the embed document to a stand alone document
      doc1.save(TEST_FILE_SAVE_EMBEDDED_OUT);
      // Load test
      Document loadedDoc = Document.loadDocument(TEST_FILE_SAVE_EMBEDDED_OUT);
      OdfContentDom contentDom2 = loadedDoc.getContentDom();
      OdfTextSpan span = (OdfTextSpan) xpath.evaluate("//text:span[last()]", contentDom2, XPathConstants.NODE);
      Assert.assertEquals(span.getTextContent(), TEST_SPAN_TEXT);
      List<Document> embDocs3 = docWithEmbeddedObjects.getEmbeddedDocuments(Document.OdfMediaType.TEXT);

      // Writer Doc
      Document doc3 = embDocs3.get(0);
      Assert.assertNotNull(doc3);
      OdfContentDom contentDom3 = doc3.getContentDom();
      TextPElement para2 = (TextPElement) xpath.evaluate("//text:p[1]", contentDom3, XPathConstants.NODE);
      addImageToDocument(contentDom3, para2);
      TextPElement para3 = (TextPElement) xpath.evaluate("//text:p[last()]", contentDom3, XPathConstants.NODE);
      addFrameForEmbeddedDoc(contentDom3, para3, "NewEmbedded");
      doc3.insertDocument(TextDocument.newTextDocument(), "/NewEmbedded/");
      Document doc4 = doc3.getEmbeddedDocument("NewEmbedded");
      Assert.assertNotNull(doc4);
      OdfContentDom contentDom4 = doc4.getContentDom();
      para = (TextPElement) xpath.evaluate("//text:p[1]", contentDom4, XPathConstants.NODE);
      spanElem = new OdfTextSpan(contentDom4);
      spanElem.setTextContent(TEST_SPAN_TEXT);
      para.appendChild(spanElem);
      doc3.save(TEST_FILE_SAVE_EMBEDDED_OUT2);
View Full Code Here

    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();
View Full Code Here

   *
   * @param doc
   *            the Document which this OutLineDecorator will be used on.
   */
  public OutLineDecorator(Document doc) {
    OdfContentDom contentDocument;
    try {
      contentDocument = doc.getContentDom();
      styles = contentDocument.getAutomaticStyles();
      OdfOfficeStyles documentStyles = doc.getDocumentStyles();
      listStyle = styles.getListStyle(DEFAULT_NAME);
      // create outline style
      if (listStyle == null) {
        listStyle = styles.newListStyle();
View Full Code Here

    @Test
  @Ignore
  /** Should there be a validation in the future? */
    public void testSetValue() throws Exception {
        OdfTextDocument odt = OdfTextDocument.newTextDocument();
        OdfContentDom dom = odt.getContentDom();
        OdfStyle style1 = new OdfStyle(dom);

        // No exception should be thrown here
        style1.setStyleFamilyAttribute(OdfStyleFamily.Paragraph.toString());
        assertEquals(style1.getStyleFamilyAttribute(), OdfStyleFamily.Paragraph.toString());
View Full Code Here

      return decorator.getListType();
    } else {
      try {
        String textStyleName = listElement.getTextStyleNameAttribute();
        Document doc = (Document) (((OdfFileDom) listElement.getOwnerDocument()).getDocument());
        OdfContentDom contentDocument = doc.getContentDom();
        OdfOfficeAutomaticStyles styles = contentDocument.getAutomaticStyles();
        OdfOfficeStyles documentStyles = doc.getDocumentStyles();
        OdfTextListStyle listStyle = styles.getListStyle(textStyleName);
        if (listStyle == null) {
          listStyle = documentStyles.getListStyle(textStyleName);
        }
View Full Code Here

  private String getFontFamilyNameFromFontName(String aFontName) {
    try {
      // try if the font has been defined.
      Document mDocument = ((Document) ((OdfFileDom) mElement.getOwnerDocument()).getDocument());
      // find <office:font-face-decls> in content dom
      OdfContentDom contentDom = mDocument.getContentDom();
      OfficeFontFaceDeclsElement fontfaceDecls = OdfElement.findFirstChildNode(OfficeFontFaceDeclsElement.class,
          contentDom.getRootElement());
      if (fontfaceDecls == null) {
        // find <office:font-face-decls> in style dom
        OdfStylesDom styleDom = mDocument.getStylesDom();
        fontfaceDecls = OdfElement.findFirstChildNode(OfficeFontFaceDeclsElement.class, styleDom
            .getRootElement());
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.dom.OdfContentDom

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.