Package org.odftoolkit.odfdom.pkg

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom


  private static TableTableElement createTable(TableContainer container, int numRows, int numCols,
      int headerRowNumber, int headerColumnNumber, double marginLeft, double marginRight) throws Exception {
    Document document = getOwnerDocument(container);
    OdfElement containerElement = container.getTableContainerElement();
    OdfFileDom dom = (OdfFileDom) containerElement.getOwnerDocument();
    double tableWidth = getTableWidth(container, marginLeft, marginRight);

    boolean isTextDocument = document instanceof TextDocument;

    // check arguments
View Full Code Here


  /**
   * This method is invoked by appendRow. When a table has no row, the first
   * row is a default row.
   */
  private TableTableRowElement createDefaultRow(int columnCount, boolean createRepeatedCell) {
    OdfFileDom dom = (OdfFileDom) mTableElement.getOwnerDocument();
    TableTableRowElement aRow = (TableTableRowElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(
        OdfDocumentNamespace.TABLE, "table-row"));
    if (createRepeatedCell) {
      TableTableCellElement aCell = (TableTableCellElement) OdfXMLFactory.newOdfElement(dom, OdfName.newName(
          OdfDocumentNamespace.TABLE, "table-cell"));
View Full Code Here

  }

  @Test
  public void testAppendRow() {
    OdfFileDom dom;
    try {
      SpreadsheetDocument odsDoc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("TestODSAppendRow.ods"));
      dom = odsDoc.getContentDom();
      NodeList tablelist = dom.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table");
      for (int i = 0; i < tablelist.getLength(); i++) {
        mOdsTable = (TableTableElement) tablelist.item(i);
        testAppendRow(mOdsTable);
      }
      odsDoc.save(ResourceUtilities.newTestOutputFile("TestODSAppendRowOutput.ods"));

      TextDocument odtDoc = TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("TestODTAppendRow.odt"));
      dom = odtDoc.getContentDom();
      tablelist = dom.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table");
      for (int i = 0; i < tablelist.getLength(); i++) {
        mOdtTable = (TableTableElement) tablelist.item(i);
        testAppendRow(mOdtTable);
      }
      odtDoc.save(ResourceUtilities.newTestOutputFile("TestODTAppendRowOutput.odt"));
View Full Code Here

  }

  @Test
  public void testAppendRow() {
    OdfFileDom dom;
    try {
      SpreadsheetDocument odsDoc = SpreadsheetDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("TestODSAppendRow.ods"));
      dom = odsDoc.getContentDom();
      NodeList tablelist = dom.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table");
      for (int i = 0; i < tablelist.getLength(); i++) {
        mOdsTable = (TableTableElement) tablelist.item(i);
        testAppendRow(mOdsTable);
      }
      odsDoc.save(ResourceUtilities.newTestOutputFile("TestODSAppendRowOutput.ods"));

      TextDocument odtDoc = TextDocument.loadDocument(ResourceUtilities
          .getTestResourceAsStream("TestODTAppendRow.odt"));
      dom = odtDoc.getContentDom();
      tablelist = dom.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table");
      for (int i = 0; i < tablelist.getLength(); i++) {
        mOdtTable = (TableTableElement) tablelist.item(i);
        testAppendRow(mOdtTable);
      }
      odtDoc.save(ResourceUtilities.newTestOutputFile("TestODTAppendRowOutput.odt"));
View Full Code Here

      // loads the ODF document from the path
      Document odfDoc = Document.loadDocument(ResourceUtilities
          .getTestResourceAsStream("TestEmpty_OdfTextDocument.odt"));

      // get the ODF content as DOM tree representation
      OdfFileDom odfContent = odfDoc.getContentDom();

      // // W3C XPath initialization ''(JDK5 functionality)'' - XPath is
      // the path within the XML file
      // // (Find XPath examples here:
      // http://www.w3.org/TR/xpath#path-abbrev)
      XPath xpath2 = odfContent.getXPath();

      // receiving the first paragraph "//text:p[1]" ''(JDK5
      // functionality)''
      TextPElement para = (TextPElement) xpath2.evaluate("//text:p[1]", odfContent, XPathConstants.NODE);
View Full Code Here

      Assert.assertTrue(odfDocument.getPackage().contains("content.xml"));
      String baseURI = odfDocument.getBaseURI();
//      Assert.assertEquals(ResourceUtilities.getURI(SOURCE).toString(), baseURI);
      System.out.println("SOURCE URI1:"+ResourceUtilities.getURI(SOURCE).toString());
      System.out.println("SOURCE URI2:"+baseURI);
      OdfFileDom odfContent = odfDocument.getContentDom();
      String odf12 = OfficeVersionAttribute.Value._1_2.toString();
      OfficeDocumentContentElement content = (OfficeDocumentContentElement) odfContent.getDocumentElement();
      String version = content.getOfficeVersionAttribute();
      Assert.assertFalse(version.equals(odf12));

      NodeList lst = odfContent.getElementsByTagNameNS(OdfDocumentNamespace.TEXT.getUri(), "p");
      Node node = lst.item(0);
      String oldText = "Changed!!!";
      node.setTextContent(oldText);

      odfDocument.save(ResourceUtilities.newTestOutputFile(TARGET));
      odfDocument = Document.loadDocument(ResourceUtilities.getAbsolutePath(TARGET));

      odfContent = odfDocument.getContentDom();
      // ToDo: Will be used for issue 60: Load & Save of previous ODF versions (ie. ODF 1.0, ODF 1.1)
      //Assert.assertTrue(odfContent.getRootElement().getOfficeVersionAttribute().equals(odf12));
      lst = odfContent.getElementsByTagNameNS(OdfDocumentNamespace.TEXT.getUri(), "p");
      node = lst.item(0);
      String newText = node.getTextContent();
      Assert.assertTrue(newText.equals(oldText));

      node = lst.item(1);
View Full Code Here

   * @return the slide index in the owner document
   * <p>
   * -1, if the odf element which can represent this slide is not in the document DOM tree
   */
  public int getSlideIndex() {
    OdfFileDom contentDom = (OdfFileDom) maSlideElement.getOwnerDocument();
    NodeList slideNodes = contentDom.getElementsByTagNameNS(OdfDocumentNamespace.DRAW.getUri(), "page");
    for (int i = 0; i < slideNodes.getLength(); i++) {
      DrawPageElement slideEle = (DrawPageElement) slideNodes.item(i);
      if (slideEle == maSlideElement)//should not equals here, see OdfElement.equals(Object obj)
      {
        return i;
View Full Code Here

  public void setSlideName(String name) {
    if (name == null) {
      throw new IllegalArgumentException("slide name is null is not accepted in the presentation document");
    }
    //check if name is unique in this presentation
    OdfFileDom contentDom = (OdfFileDom) maSlideElement.getOwnerDocument();
    NodeList slideNodes = contentDom.getElementsByTagNameNS(OdfDocumentNamespace.DRAW.getUri(), "page");
    for (int i = 0; i < slideNodes.getLength(); i++) {
      DrawPageElement slideEle = (DrawPageElement) slideNodes.item(i);
      OdfSlide slide = OdfSlide.getInstance(slideEle);
      String slideName = slide.getSlideName();
      if (slideName.equals(name)) {
View Full Code Here

  public OdfTextListStyle getListStyle() {
    OdfTextListStyle style = null;

    String listName = getTextStyleNameAttribute();
    if (listName != null && listName.length() > 0) {
      OdfFileDom fileDom = (OdfFileDom) this.ownerDocument;
      OdfOfficeAutomaticStyles autoStyles = fileDom.getAutomaticStyles();
      if (autoStyles != null) {
        style = autoStyles.getListStyle(listName);
      }

      if (style == null) {
        OdfOfficeStyles styles = ((OdfSchemaDocument) fileDom.getDocument()).getDocumentStyles();
        if (styles != null) {
          style = styles.getListStyle(listName);
        }
      }
    } else {
View Full Code Here

   * These elements are built "by hand" rather than
   * @param ch the formatting character to process
   * @param count the number of occurrences of this character
   */
  private void processChar(char ch, int count) {
    OdfFileDom ownerDoc = (OdfFileDom) this.getOwnerDocument();
    switch (ch) {
      case 'G':
        NumberEraElement era =
            new NumberEraElement(ownerDoc);
        era.setNumberStyleAttribute(isLongIf(count > 3));
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.pkg.OdfFileDom

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.