Package org.odftoolkit.odfdom.pkg

Examples of org.odftoolkit.odfdom.pkg.OdfFileDom


      Assert.fail(e.getMessage());
    }
  }

  private void testStyle(OdfStyle testStyle) throws Exception {
    OdfFileDom fileDom = (OdfFileDom) testStyle.getOwnerDocument();
    OdfOfficeAutomaticStyles autoStyles = null;
    if (testStyle.getStyleParentStyleNameAttribute() != null) {
      if (fileDom instanceof OdfContentDom) {
        autoStyles = ((OdfContentDom) fileDom).getAutomaticStyles();
      } else if (fileDom instanceof OdfStylesDom) {
        autoStyles = ((OdfStylesDom) fileDom).getAutomaticStyles();
      }
      OdfStyle parentStyle = autoStyles.getStyle(testStyle.getStyleParentStyleNameAttribute(), testStyle.getFamily());
      if (parentStyle == null) {
        parentStyle = ((Document) fileDom.getDocument()).getDocumentStyles().getStyle(testStyle.getStyleParentStyleNameAttribute(), testStyle.getFamily());
      }

      Assert.assertNotNull(parentStyle);
    }
    if (testStyle.hasOdfAttribute(OdfName.newName(OdfDocumentNamespace.STYLE, "list-style-name"))) {
      if (testStyle.getStyleListStyleNameAttribute() != null) {
        OdfTextListStyle listStyle = autoStyles.getListStyle(testStyle.getStyleListStyleNameAttribute());
        if (listStyle == null) {
          listStyle = ((Document) fileDom.getDocument()).getDocumentStyles().getListStyle(testStyle.getStyleListStyleNameAttribute());
        }

        Assert.assertNotNull(listStyle);
      }
    }
View Full Code Here


     * Process a formatting character.
     * @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 'a':
              NumberAmPmElement ampm = new NumberAmPmElement(ownerDoc);
                this.appendChild(ampm);
                break;
View Full Code Here

  @Test
  public void testPresentationClassAttribute() {
    try {
      GraphicsDocument doc = GraphicsDocument.newGraphicsDocument();
      OdfFileDom dom = doc.getContentDom();
      OdfDrawFrame f = new OdfDrawFrame(dom);

      f.setPresentationClassAttribute(PresentationClassAttribute.Value.GRAPHIC.toString());
      Logger.getLogger(DocumentCreationTest.class.getName()).info(f.getPresentationClassAttribute());
    } catch (Exception e) {
View Full Code Here

  private void updateTableCells(Document odfdoc, String tablename,
      double[] values, String[] labels) {
    int i = 0, j = 0;
    TableTableRowElement td;
    TableTableCellElement cell;
    OdfFileDom dom;
    NodeList tableList;
    TableTableElement myTable;
    NodeList lst;
    OdfTextParagraph p;
    OfficeSpreadsheetElement spreadsheet = null;

    try {
      dom = odfdoc.getContentDom();
      tableList = dom.getElementsByTagNameNS(
          OdfDocumentNamespace.TABLE.getUri(), "table");
      spreadsheet = (OfficeSpreadsheetElement) dom.getElementsByTagNameNS(
          OdfDocumentNamespace.OFFICE.getUri(), "spreadsheet").item(0);

      i = 0;
      if (tableList.getLength() > 0) {
        for (; i < tableList.getLength(); i++) {
          String currentname = ((TableTableElement) tableList.item(i)).getTableNameAttribute();
          if (currentname == null) {
            currentname = "";
          }
          if (currentname.equalsIgnoreCase(tablename)) {
            break;
          }
        }
      }
      if (i < tableList.getLength()) //table with the specific table name is found
      {
        myTable = (TableTableElement) tableList.item(i);
      } else { //table with the specific table name is not found. Create table
        myTable = dom.newOdfElement(TableTableElement.class);
        myTable.setTableNameAttribute(tablename);
        spreadsheet.appendChild(myTable);
      }

      lst = myTable.getElementsByTagNameNS(OdfDocumentNamespace.TABLE.getUri(), "table-row");
      if (lst.getLength() == 0) { //the first table row is not existed. Create table row
        td = dom.newOdfElement(TableTableRowElement.class);
        cell = dom.newOdfElement(TableTableCellElement.class);
        p = dom.newOdfElement(OdfTextParagraph.class);
        if (tablename.startsWith("Memory")) {
          p.setTextContent("memory(b)");
        } else {
          p.setTextContent("time(ms)");
        }
        td.appendChild(cell);
        cell.appendChild(p);
        myTable.appendChild(td);
      } else {
        td = (TableTableRowElement) lst.item(0); //the first table row is existed.
      }
      cell = dom.newOdfElement(TableTableCellElement.class);
      td.appendChild(cell);
      p = dom.newOdfElement(OdfTextParagraph.class);
      p.setTextContent(testTag);
      cell.appendChild(p);


      for (i = 1; i < values.length + 1; i++) {
        if (i < lst.getLength()) { //table row is existed
          td = (TableTableRowElement) lst.item(i);
        } else { //table row is not existed.
          td = dom.newOdfElement(TableTableRowElement.class);
          myTable.appendChild(td);
          //append first cell with labels
          cell = dom.newOdfElement(TableTableCellElement.class);
          td.appendChild(cell);
          p = dom.newOdfElement(OdfTextParagraph.class);
          p.setTextContent(labels[j]);
          cell.appendChild(p);
        }
        cell = dom.newOdfElement(TableTableCellElement.class);
        cell.setOfficeValueTypeAttribute("float");
        cell.setOfficeValueAttribute(new Double(values[j]));
        p = dom.newOdfElement(OdfTextParagraph.class);
        p.setTextContent(values[j] + "");
        cell.appendChild(p);
        td.appendChild(cell);
        j++;
      }
View Full Code Here

    }
  }

  private void firsttry() throws Exception {
    Document doc = null;
    OdfFileDom dom = null;
    String filename = null;

    for (int j = 0; j < TEST_FILE_NAME.length; j++) {
      filename = TEST_FILE_FOLDER + TEST_FILE_NAME[j];
      LOG.log(Level.INFO, "filename:{0}", filename);
View Full Code Here

  }

  private void test() throws Exception {
    long start, end;
    Document doc = null;
    OdfFileDom dom = null;
    String filename = null;

    if (TEST_FILE_NAME == null) {
      return;
    }
View Full Code Here

    try {
      int i = 0, rowindex, columnindex;
      char ch;
      TableTableRowElement td;
      TableTableCellElement cell;
      OdfFileDom sheetContent;
      NodeList tableList, rowList, cellList;
      TableTableElement table;
      Vector<Double> series;
      double value;

      // get table
      sheetContent = spreadsheet.getContentDom();
      tableList = sheetContent.getElementsByTagNameNS(OdfNamespace.newNamespace(OdfDocumentNamespace.TABLE)
          .toString(), "table");
      while (!sheettable.equals(((TableTableElement) tableList.item(i)).getTableNameAttribute()))
        i++;
      table = (TableTableElement) tableList.item(i);
      rowList = table.getElementsByTagNameNS(OdfNamespace.newNamespace(OdfDocumentNamespace.TABLE).toString(),
View Full Code Here

   * @param header
   *            the header of this list.
   */
  public List(ListContainer container, String header, ListDecorator decorator) {
    OdfElement containerElement = container.getListContainerElement();
    OdfFileDom ownerDocument = (OdfFileDom) containerElement.getOwnerDocument();
    listElement = ownerDocument.newOdfElement(TextListElement.class);
    listElement.setXmlIdAttribute(getUniqueXMLID());
    containerElement.appendChild(listElement);
    setHeader(header);
    if (decorator == null) {
      Document doc = (Document) ownerDocument.getDocument();
      decorator = new BulletDecorator(doc);
    }
    this.decorator = decorator;
    decorator.decorateList(this);
  }
View Full Code Here

   * @return the added ListItem.
   * @exception IndexOutOfBoundsException
   *                when the <code>location</code> is out of the List range.
   */
  public ListItem addItem(int location, String itemContent) {
    OdfFileDom ownerDocument = (OdfFileDom) listElement.getOwnerDocument();
    TextListItemElement listItemElement = ownerDocument.newOdfElement(TextListItemElement.class);
    Node refNode = getItemByLocation(location);
    listElement.insertBefore(listItemElement, refNode);
    ListItem item = new ListItem(listItemElement);
    item.setParagraphDecorator(decorator);
    item.setTextContent(itemContent);
View Full Code Here

   * @exception IndexOutOfBoundsException
   *                when the <code>location</code> is out of the List range.
   */
  public java.util.List<ListItem> addItems(int location, String[] items) {
    java.util.List<ListItem> listCollection = new ArrayList<ListItem>();
    OdfFileDom ownerDocument = (OdfFileDom) listElement.getOwnerDocument();
    Node refNode = getItemByLocation(location);
    for (int i = items.length - 1; i >= 0; i--) {
      TextListItemElement listItemElement = ownerDocument.newOdfElement(TextListItemElement.class);
      listElement.insertBefore(listItemElement, refNode);
      ListItem item = new ListItem(listItemElement);
      item.setParagraphDecorator(decorator);
      item.setTextContent(items[i]);
      refNode = listItemElement;
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.