Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 493B9200C7A for ; Wed, 12 Apr 2017 01:13:37 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 48145160B9E; Tue, 11 Apr 2017 23:13:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 02853160BAE for ; Wed, 12 Apr 2017 01:13:33 +0200 (CEST) Received: (qmail 66283 invoked by uid 500); 11 Apr 2017 23:13:33 -0000 Mailing-List: contact odf-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: odf-dev@incubator.apache.org Delivered-To: mailing list odf-commits@incubator.apache.org Received: (qmail 66227 invoked by uid 99); 11 Apr 2017 23:13:33 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Apr 2017 23:13:33 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id F06C83A5183 for ; Tue, 11 Apr 2017 23:13:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1010270 [6/13] - in /websites/staging/odftoolkit/trunk/content: ./ odftoolkit/ odftoolkit/GSoC/ odftoolkit/docs/ odftoolkit/docs/governance/ odftoolkit/odfdom/ odftoolkit/simple/ odftoolkit/simple/demo/ odftoolkit/simple/document/ odftoolk... Date: Tue, 11 Apr 2017 23:13:31 -0000 To: odf-commits@incubator.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170411231331.F06C83A5183@svn01-us-west.apache.org> archived-at: Tue, 11 Apr 2017 23:13:37 -0000 Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo4.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo4.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo4.html Tue Apr 11 23:13:30 2017 @@ -50,7 +50,18 @@
-

General

+ +

General

-

Components

+

Components

-

Community

+

Community

-

Development

+

Development

-

PPMC

+

PPMC

-

ASF

+

ASF

  • Apache Software Foundation
  • Thanks
  • @@ -96,82 +106,83 @@
    -

    Demos > List and Table Conversion
    -

    -

    Overview
    -

    -

    Starting in version 0.4, we have added methods to support bullet, numbered and image lists to the Simple API. This includes frequently used features for processing lists and list item. This demo is designed to show the power of List API and help you learn how to use it.
    -

    + +

    Demos > List and Table Conversion

    +

    Overview

    +

    Starting in version 0.4, we have added methods to support bullet, numbered and image lists to the Simple API. This includes frequently used features for processing lists and list item. This demo is designed to show the power of List API and help you learn how to use it.

    This demo shows how to convert between a nested List and Table. As you can see in the following two pictures, on the left we have a simple outline of a corporate hierarchy. There are four departments in this company. Each department has several managers and each manager has several reporting staff. Now we want -to change this list to a table, just like the picture on the right shows.
    -

    -

    image1
    -

    -

    However, sometimes we want to convert in the opposite direction, from a table to a list. Take the following two pictures as example. The left one is table of country calling codes, which includes the codes of countries from different continents. Suppose you want to convert this table representation into a nested list. The picture on the right shows the conversion result. The first level list show the continent names and the second level list show the countries and their calling codes.
    -

    -

    image2
    -

    +to change this list to a table, just like the picture on the right shows.

    +

    image1

    +

    However, sometimes we want to convert in the opposite direction, from a table to a list. Take the following two pictures as example. The left one is table of country calling codes, which includes the codes of countries from different continents. Suppose you want to convert this table representation into a nested list. The picture on the right shows the conversion result. The first level list show the continent names and the second level list show the countries and their calling codes.

    +

    image2

    You can see similar functionality in office software, such as selective copy and paste. In the next section, I will show how easy to do these kinds of conversions using the Simple API.

    Code Introduction

    -

    Let's have a look at the main method. It will help us get an overview of this demo. First, the list data text document, "ListTable.odt" and table data spreadsheet document "TableList.ods" are loaded. Secondly, we use the list iteration function to get all of the lists in the text document and invoke the method convertFromListToTable to convert each of them to a table. Finally, we get the data table from "TableList.ods" and invoke the method convertFromTableToList to convert this table to a list. All of the updated documents are saved as new files. You can open them and see the conversion results.
    -

    -
    public static void main(String[] args) {
    -    try {
    -        TextDocument textDoc = TextDocument.loadDocument("ListTable.odt");
    -        SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.loadDocument("TableList.ods");
    -        // covert list in text document to spreadsheet table
    -        Iterator<list> listIterator = textDoc.getListIterator();
    -        int i = 1;
    -        String[] tableLabel = { "DEPARTMENT", "MANAGER", "EMPLOYEE" };
    -        while (listIterator.hasNext()) {
    -            List list = listIterator.next();
    -            Table newTable = Table.newTable(spreadsheetDoc);
    -            for (int columnIndex = 0; columnIndex < tableLabel.length; columnIndex++) {
    -                newTable.getCellByPosition(columnIndex, 0).setStringValue(tableLabel[columnIndex]);
    +

    Let's have a look at the main method. It will help us get an overview of this demo. First, the list data text document, "ListTable.odt" and table data spreadsheet document "TableList.ods" are loaded. Secondly, we use the list iteration function to get all of the lists in the text document and invoke the method convertFromListToTable to convert each of them to a table. Finally, we get the data table from "TableList.ods" and invoke the method convertFromTableToList to convert this table to a list. All of the updated documents are saved as new files. You can open them and see the conversion results.

    +
    public static void main(String[] args) {
    +    try {
    +        TextDocument textDoc = TextDocument.loadDocument("ListTable.odt");
    +        SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.loadDocument("TableList.ods");
    +        // covert list in text document to spreadsheet table
    +        Iterator<list> listIterator = textDoc.getListIterator();
    +        int i = 1;
    +        String[] tableLabel = { "DEPARTMENT", "MANAGER", "EMPLOYEE" };
    +        while (listIterator.hasNext()) {
    +            List list = listIterator.next();
    +            Table newTable = Table.newTable(spreadsheetDoc);
    +            for (int columnIndex = 0; columnIndex < tableLabel.length; columnIndex++) {
    +                newTable.getCellByPosition(columnIndex, 0).setStringValue(tableLabel[columnIndex]);
                 }
    -            newTable.setTableName("ListTable" + (i++));
    -            convertFromListToTable(list, newTable, 0, 1);
    +            newTable.setTableName("ListTable" + (i++));
    +            convertFromListToTable(list, newTable, 0, 1);
             }
    -        spreadsheetDoc.save("TableListUpdate.ods");
    -        // covert table in spreadsheet to list in text document
    -        Table sheet1 = spreadsheetDoc.getTableByName("Sheet1");
    -        textDoc.newParagraph("ListConvertedFromTable");
    -        List newList = textDoc.addList();
    -        convertFromTableToList(sheet1, newList, 0, 0, sheet1.getColumnCount() - 1, sheet1.getRowCount() - 1);
    -        textDoc.save("ListTableUpdate.odt");
    -    } catch (Exception e) {
    -        e.printStackTrace();
    +        spreadsheetDoc.save("TableListUpdate.ods");
    +        // covert table in spreadsheet to list in text document
    +        Table sheet1 = spreadsheetDoc.getTableByName("Sheet1");
    +        textDoc.newParagraph("ListConvertedFromTable");
    +        List newList = textDoc.addList();
    +        convertFromTableToList(sheet1, newList, 0, 0, sheet1.getColumnCount() - 1, sheet1.getRowCount() - 1);
    +        textDoc.save("ListTableUpdate.odt");
    +    } catch (Exception e) {
    +        e.printStackTrace();
         }
     }
     
    -

    In the following two sections, I will review the implementation of the methods convertFromListToTable and convertFromTableToList.
    -

    +

    In the following two sections, I will review the implementation of the methods convertFromListToTable and convertFromTableToList.

    Convert from List to Table

    -

    This is a recursive method, similar to a depth-first tree traversal. You determine the paste cell address by startColumn and startRow. First, all of the items in the list are retrieved. Second, each list item is converted to table cell. Its text content is extracted and set as the cell's display text. If the item has a sub list, its sub list is also handled the same as the parent list. After all of the items are converted to cells, we invoke CellRange.merge() to merge the blank cells. The generation document appears just like the picture shown earlier.
    -

    -
    private static int convertFromListToTable(List list, Table table, int startColumn, int startRow) {
    -    java.util.List<listitem> items = list.getItems();
    -    int newItemCount = startRow;
    +

    This is a recursive method, similar to a depth-first tree traversal. You determine the paste cell address by startColumn and startRow. First, all of the items in the list are retrieved. Second, each list item is converted to table cell. Its text content is extracted and set as the cell's display text. If the item has a sub list, its sub list is also handled the same as the parent list. After all of the items are converted to cells, we invoke CellRange.merge() to merge the blank cells. The generation document appears just like the picture shown earlier.

    +
    private static int convertFromListToTable(List list, Table table, int startColumn, int startRow) {
    +    java.util.List<listitem> items = list.getItems();
    +    int newItemCount = startRow;
         for (ListItem item : items) {
    -        Cell cell = table.getCellByPosition(startColumn, newItemCount);
    -        cell.setStringValue(item.getTextContent());
    -        cell.setVerticalAlignment(VerticalAlignmentType.MIDDLE);
    -        Iterator<list> listIterator = item.listIterator();
    -        startRow = newItemCount;
    -        while (listIterator.hasNext()) {
    -            List subList = listIterator.next();
    -            newItemCount = convertFromListToTable(subList, table, startColumn + 1, newItemCount);
    +        Cell cell = table.getCellByPosition(startColumn, newItemCount);
    +        cell.setStringValue(item.getTextContent());
    +        cell.setVerticalAlignment(VerticalAlignmentType.MIDDLE);
    +        Iterator<list> listIterator = item.listIterator();
    +        startRow = newItemCount;
    +        while (listIterator.hasNext()) {
    +            List subList = listIterator.next();
    +            newItemCount = convertFromListToTable(subList, table, startColumn + 1, newItemCount);
             }
    -        // merge
    -        CellRange cellRange = table.getCellRangeByPosition(startColumn, startRow, startColumn, newItemCount);
    -        cellRange.merge();
    +        // merge
    +        CellRange cellRange = table.getCellRangeByPosition(startColumn, startRow, startColumn, newItemCount);
    +        cellRange.merge();
             newItemCount++;
         }
    -    if (list.size() > 0) {
    -        return newItemCount - 1;
    +    if (list.size() > 0) {
    +        return newItemCount - 1;
         } else {
             return startRow;
         }
    @@ -180,45 +191,42 @@ to change this list to a table, just lik
     
     
     

    Convert from Table to List

    -

    This is also a recursive method. You determine the conversion range of the table by startColumn, startRow, endColumn and endRow. First, every cell in the selected range is retrieved by Table.getCellByPosition. Next, a list item is created to store the cell display text. If the rowSpannedNumber > 1, that means this item has a sub list. Parts of the cells in the right columns of this cell become the items of the sub list. They are also determined by recursive calls to convertFromTableToList. If the rowSpannedNumber = 1, there is no need to create a sub list, all of the content in the right cells is just added to this item.
    -

    -
    private static void convertFromTableToList(Table table, List list, int startColumn, int startRow, int endColumn, int endRow) {
    -    while (startRow <= endRow) {
    -        Cell cell = table.getCellByPosition(startColumn, startRow);
    -        int rowSpannedNumber = cell.getRowSpannedNumber();
    -        String cellText = cell.getDisplayText();
    -        if (!"".equals(cellText)) {
    -            ListItem item = list.addItem(cellText);
    -            int columnSpannedNumber = cell.getColumnSpannedNumber();
    -            int newStartColumn = startColumn + columnSpannedNumber;
    -            if (newStartColumn <= endColumn) {
    -                if (rowSpannedNumber > 1) {
    -                    List subList = item.addList();
    -                    convertFromTableToList(table, subList, newStartColumn, startRow, endColumn, startRow + rowSpannedNumber - 1);
    +

    This is also a recursive method. You determine the conversion range of the table by startColumn, startRow, endColumn and endRow. First, every cell in the selected range is retrieved by Table.getCellByPosition. Next, a list item is created to store the cell display text. If the rowSpannedNumber > 1, that means this item has a sub list. Parts of the cells in the right columns of this cell become the items of the sub list. They are also determined by recursive calls to convertFromTableToList. If the rowSpannedNumber = 1, there is no need to create a sub list, all of the content in the right cells is just added to this item.

    +
    private static void convertFromTableToList(Table table, List list, int startColumn, int startRow, int endColumn, int endRow) {
    +    while (startRow <= endRow) {
    +        Cell cell = table.getCellByPosition(startColumn, startRow);
    +        int rowSpannedNumber = cell.getRowSpannedNumber();
    +        String cellText = cell.getDisplayText();
    +        if (!"".equals(cellText)) {
    +            ListItem item = list.addItem(cellText);
    +            int columnSpannedNumber = cell.getColumnSpannedNumber();
    +            int newStartColumn = startColumn + columnSpannedNumber;
    +            if (newStartColumn <= endColumn) {
    +                if (rowSpannedNumber > 1) {
    +                    List subList = item.addList();
    +                    convertFromTableToList(table, subList, newStartColumn, startRow, endColumn, startRow + rowSpannedNumber - 1);
                     } else {
    -                    int tmpStartColumn = newStartColumn;
    -                    while (tmpStartColumn <= endColumn) {
    -                        cell = table.getCellByPosition(tmpStartColumn, startRow);
    -                        cellText = cell.getDisplayText();
    -                        if (!"".equals(cellText)) {
    -                            item.setTextContent(item.getTextContent() + "|" + cellText);
    +                    int tmpStartColumn = newStartColumn;
    +                    while (tmpStartColumn <= endColumn) {
    +                        cell = table.getCellByPosition(tmpStartColumn, startRow);
    +                        cellText = cell.getDisplayText();
    +                        if (!"".equals(cellText)) {
    +                            item.setTextContent(item.getTextContent() + "|" + cellText);
                             }
    -                        tmpStartColumn += cell.getColumnSpannedNumber();
    +                        tmpStartColumn += cell.getColumnSpannedNumber();
                         }
                     }
                 }
             }
    -        startRow += rowSpannedNumber;
    +        startRow += rowSpannedNumber;
         }
     }
     
    -

    Download
    -

    +

    Download

    Powered by Simple API version 0.4.
    -You can download the code of this demo from here.
    -

    +You can download the code of this demo from here.

    Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo5.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo5.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo5.html Tue Apr 11 23:13:30 2017 @@ -50,7 +50,18 @@
    -

    General

    + +

    General

    -

    Components

    +

    Components

    -

    Community

    +

    Community

    -

    Development

    +

    Development

    -

    PPMC

    +

    PPMC

    -

    ASF

    +

    ASF

    • Apache Software Foundation
    • Thanks
    • @@ -96,82 +106,79 @@
      -

      Demos > Multiple Presentations Assembler
      -

      -

      Overview
      -

      -

      If you make a lot of presentations in your daily work, you know that you don't always create a presentation from scratch.
      -

      + +

      Demos > Multiple Presentations Assembler

      +

      Overview

      +

      If you make a lot of presentations in your daily work, you know that you don't always create a presentation from scratch.

      Assembling several different presentations together to make a new presentation, e.g. copying several pages from presentation A and copying another several pages from presentation B, is a common activity for the presentation author. -This demo provides a Java application that can assemble specific pages of presentations together and make one presentation from the command line.
      -

      -

      Here is an example. I want to make a presentation with the first page from presentation A, the first page from presentation B and the first page from presentation C. I can call the following command:
      -

      -

      java PresentationAssembler -in PresentationA.odp(1) -in PresentationB.odp(1) -in PresentationC.odp(1-2) -out newPresentation.odp
      -

      -

      A new presentation will be generated which is showed in the following picture. You can see, the pictures, the styles and master pages are copied too.
      -

      -

      alt text
      -

      -

      In the next section, I will show how easy it is to create this assembling application using the Simple API.
      -

      +This demo provides a Java application that can assemble specific pages of presentations together and make one presentation from the command line.

      +

      Here is an example. I want to make a presentation with the first page from presentation A, the first page from presentation B and the first page from presentation C. I can call the following command:

      +

      java PresentationAssembler -in PresentationA.odp(1) -in PresentationB.odp(1) -in PresentationC.odp(1-2) -out newPresentation.odp

      +

      A new presentation will be generated which is showed in the following picture. You can see, the pictures, the styles and master pages are copied too.

      +

      alt text

      +

      In the next section, I will show how easy it is to create this assembling application using the Simple API.

      Code Introduction

      assemble is the method that accepts the command line parameters, analyzes them, and assembles presentations with the Simple API. In this method, a new presentation is created, and then, pages from other presentation documents are attached while the command line is being analyzed. Simple API provides very simple methods to copy pages from other presentations: PresentationDocument.copyForeignSlide(int destIndex, PresentationDocument srcDoc, int srcIndex) and -PresentationDocument.appendPresentation(PresentationDocument srcDoc).
      -

      -

      After the slides are attached, the first slide of the new presentation is deleted by invoking method PresentationDocument.deleteSlideByIndex(int index).
      -

      -

      This is because the first slide is an empty slide which was created when the new presentation was created with method PresentationDocument.newPresentationDocument()
      -

      -

      Below is the source code of method assemble. Most of the code is used to analyze the command line parameters. Only a few statements are used to attach slides to the new presentation. So you can see how powerful functions Simple API provides.
      -

      -
      public void assemble(String[] args) throws Exception
      +PresentationDocument.appendPresentation(PresentationDocument srcDoc).    

      +

      After the slides are attached, the first slide of the new presentation is deleted by invoking method PresentationDocument.deleteSlideByIndex(int index).

      +

      This is because the first slide is an empty slide which was created when the new presentation was created with method PresentationDocument.newPresentationDocument()

      +

      Below is the source code of method assemble. Most of the code is used to analyze the command line parameters. Only a few statements are used to attach slides to the new presentation. So you can see how powerful functions Simple API provides.

      +
      public void assemble(String[] args) throws Exception
       {
      -    String outputFileName="default.odp";
      -    int pageIndex = 1;
      -    PresentationDocument doc = PresentationDocument.newPresentationDocument();
      -    int i=0;
      -    while (i < args.length)
      +    String outputFileName="default.odp";
      +    int pageIndex = 1;
      +    PresentationDocument doc = PresentationDocument.newPresentationDocument();
      +    int i=0;
      +    while (i < args.length)
           {
      -        String param = args[i];
      -        if (param.equals("-out")) //get the output file name
      -            outputFileName = args[++i];
      -        else if (param.equals("-in")) //get the input file name 
      +        String param = args[i];
      +        if (param.equals("-out")) //get the output file name
      +            outputFileName = args[++i];
      +        else if (param.equals("-in")) //get the input file name 
               {
      -            String pageDesc = args[++i];
      -            String filename = pageDesc, pagelist;
      -            int indexStart = pageDesc.indexOf('('); //get the page numbers
      -            int[] srcPages = null;
      -            if (indexStart > -1)
      +            String pageDesc = args[++i];
      +            String filename = pageDesc, pagelist;
      +            int indexStart = pageDesc.indexOf('('); //get the page numbers
      +            int[] srcPages = null;
      +            if (indexStart > -1)
                   {
      -                filename = pageDesc.substring(0, indexStart);
      -                pagelist = pageDesc.substring(indexStart+1, pageDesc.length()-1);
      -                srcPages = getPageNumbers(pagelist); //analysis the page number description 
      -                                                     //and return all page numbers that need to be copied
      +                filename = pageDesc.substring(0, indexStart);
      +                pagelist = pageDesc.substring(indexStart+1, pageDesc.length()-1);
      +                srcPages = getPageNumbers(pagelist); //analysis the page number description 
      +                                                     //and return all page numbers that need to be copied
                   }
      -            PresentationDocument sourceDoc = PresentationDocument.loadDocument(new File(filename));
      +            PresentationDocument sourceDoc = PresentationDocument.loadDocument(new File(filename));
                   if (srcPages==null)
                   {
      -                doc.appendPresentation(sourceDoc);
      -                pageIndex += sourceDoc.getSlideCount();
      -            } else for(int j=0;j < srcPages.length;j++)
      +                doc.appendPresentation(sourceDoc);
      +                pageIndex += sourceDoc.getSlideCount();
      +            } else for(int j=0;j < srcPages.length;j++)
                   {
      -                doc.copyForeignSlide(pageIndex, sourceDoc, srcPages[j]);
      +                doc.copyForeignSlide(pageIndex, sourceDoc, srcPages[j]);
                       pageIndex++;
                   }
               }
      -        i++;
      +        i++;
           }
      -    doc.deleteSlideByIndex(0);
      -    doc.save(outputFileName);
      -    doc.close();
      +    doc.deleteSlideByIndex(0);
      +    doc.save(outputFileName);
      +    doc.close();
       }
       
      -

      Download
      -

      +

      Download

      Powered by the Simple Java API for ODF version 0.4.5.
      You can download the code of this demo from here.