From odf-commits-return-264-apmail-incubator-odf-commits-archive=incubator.apache.org@incubator.apache.org Tue Sep 6 10:21:19 2011 Return-Path: X-Original-To: apmail-incubator-odf-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-odf-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 01D577365 for ; Tue, 6 Sep 2011 10:21:19 +0000 (UTC) Received: (qmail 72367 invoked by uid 500); 6 Sep 2011 10:21:17 -0000 Delivered-To: apmail-incubator-odf-commits-archive@incubator.apache.org Received: (qmail 72312 invoked by uid 500); 6 Sep 2011 10:21:14 -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 72304 invoked by uid 99); 6 Sep 2011 10:21:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Sep 2011 10:21:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Sep 2011 10:21:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2D5182388900 for ; Tue, 6 Sep 2011 10:20:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r795380 [1/2] - /websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/ Date: Tue, 06 Sep 2011 10:20:37 -0000 To: odf-commits@incubator.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110906102038.2D5182388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: buildbot Date: Tue Sep 6 10:20:36 2011 New Revision: 795380 Log: Staging update by buildbot Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Cell Range.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Cell.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Charts.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Column and Row.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Fields.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Metadata.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Manipulate TextSearch.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Presentation Document.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Slide.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Style Handling.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Table.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Text Document.html websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/TextExtractor.html Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Cell Range.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Cell Range.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Cell Range.html Tue Sep 6 10:20:36 2011 @@ -36,10 +36,115 @@
-
+ +
- +

Documents > Cookbook >Cell Range +

+
+Get CellRange +
+
+You can get cell range by providing start and end index of the column and row,or just provide start and end address of the cell(if you are using the spreadsheet.) +
+
+        CellRange cellRange = table.getCellRangeByPosition(1, 0, 2, 0);
+ CellRange cellRangeAdd = table.getCellRangeByPosition("$E1","$E6");
+
+
Merge Text Table +
+
+The code below merges all of the selected cells into one: +
+
+        Table table1 = document.getTableByName("Table1");
+ CellRange cellrange = table1.getCellRangeByPosition(0, 0, table1.getColumnCount()-1, table1.getRowCount()-1);
+ cellRange.merge();
+
+
Merge Text Column +
+
+The code below shows how to merge the cells of the first column into one : +
+
+            table1 = document.getTableByName("Table1");
+ CellRange firstColumn = table1.getCellRangeByPosition(0, 0, 0, table1.getRowCount()-1);
+ firstColumn.merge();
+
+
Merge Text Row +
+
+The code below shows how to merge the cells of the first 2 rows into one : +
+
+        table1 = document.getTableByName("Table1");
+ int rowCount = table1.getRowCount();
+ CellRange firstTwoRow = table1.getCellRangeByPosition(0, 0, table1.getColumnCount()-1, 1);
+ firstTwoRow.merge();
+
+
Merge SpreadSheet +
+
+Merge a spreadsheet's cell is the same as text document.Especially,when getting the cell range of spreadsheet,you can use special address instead of index. +
+
+        Table sheet1 = document.getTableByName("Sheet1");
+ CellRange cellRange2 = sheet1.getCellRangeByPosition("$E1","$E6");
+ cellRange2.setCellRangeName("TimeCellRange");
+ cellRange2.merge();
+
+

+

Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Cell.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Cell.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Cell.html Tue Sep 6 10:20:36 2011 @@ -36,10 +36,303 @@
-
+ +
- +

Documents > Cookbook >Cell +

+
+Get Cell +
+
+If you want to get the specified cell in a table,you can use the getCellByPosition method of Table. +
+
+The first parameter is the column index,the second parameter is the row index. +
+
+         TextDocument document = (TextDocument) TextDocument.loadDocument(filePath);
+ Table table=document.getTableByName("stringTable");
+ Cell cell=table.getCellByPosition(1, 1);
+
+
+If you are manipulating a spreadsheet,you can get the cell by its address: +
+
+     Table sheet1 = document.getTableByName("Sheet1");
+ Cell odsCell=sheet1.getCellByPosition("A1");
+
+
+If you want to get a cell from a row,you can specify the index of the cell in the row. +
+
+     Row row=table.getRowByIndex(1);
+ Cell cell2=row.getCellByIndex(1);
+ System.out.println(cell2.getStringValue());
+
+
+What can I do if I have a Cell instance and want to know which column and row it belongs to ? +
+
+The code below shows how you can do that: +
+
+     Row row1=cell.getTableRow();
+ Column column1=cell.getTableColumn();
+
+
Control Cell Attributes +
+
+Use the getStyleName() method you can get the style name of the cell. +
+
+If you want to change the style,it must be set when you set the display text. +
+
+     String cellSytle=cell.getStyleName();
+ cell.setDisplayText("content", cellSytle);
+
+
+What can I do if I want to control the display alignment of the cell? +
+
+You can set the horizontal and vertical alignment to do so. +
+
+The code below shows how to get and set the alignment.You can refer to the javadoc about the alignment type. +
+
+      StyleTypeDefinitions.HorizontalAlignmentType horizontalAlign=cell.getHorizontalAlignmentType();
+ StyleTypeDefinitions.VerticalAlignmentType verticalAlign=cell.getVerticalAlignmentType();
+ cell.setHorizontalAlignment(StyleTypeDefinitions.HorizontalAlignmentType.CENTER);
+ cell.setVerticalAlignment(StyleTypeDefinitions.VerticalAlignmentType.BOTTOM);
+
+
+If the content of the cell is too long,you can set the wrap option of the cell. +
+
+       cell.setTextWrapped(true);
+
+
+If don't know the cell is wrapped or not,you can use the method: +
+
+       boolean isTextWrapped=cell.isTextWrapped();
+
+
+If you want to set the background color of the cell,be care that the color type is org.odftoolkit.odfdom.type.Color. +
+
+        Color cellBackgroundColor=cell.getCellBackgroundColor();
+ cell.setCellBackgroundColor(Color.valueOf("#000000"));
+
+
+How can I control the spanned number of the column/row: +
+
+        int spannedNum=cell.getcgetColumnSpannedNumber();
+ cell.setColumnSpannedNumber(spannedNum);
+ int rowSpannedNum=cell.getRowSpannedNumber();
+ cell.setRowSpannedNumber(rowSpannedNum);
+
+
+For column,maybe you want to know the column repeated number: +
+
+        int repeatedNum=cell.getColumnsRepeatedNumber();
+ cell.setColumnsRepeatedNumber(repeatedNum);
+
+
+How about formatting a cell's content? You can set the format string of the cell to do so. +
+
+For example you want to format the date to yyyy-MM-dd ,you can: +
+
+          String cellFormatStr=cell.getFormatString();
+ cell.setDateValue(new GregorianCalendar(2010,5,1));
+ cell.setFormatString("yyyy-MM-dd");
+
+
+Be care that the setFormatString only works for float, date and percentage. +
+
+You may be confused by the difference between getFormatString and getFormula,the difference is that: +
+
+For the setFormula method,it just sets as a formula attribute,the cell value will not be calculated. +
+
+          String formula=cell.getFormula();
+ cell.setFormula(formula);
+
+
+How can I clear the content of the cell? +
+
+RemoveContent remove all of the cell while the removeTextContent only remove the text content of the cell. +
+
+       cell.removeContent();
+ cell.removeTextContent();
+
+
Get&Set Cell Value Type +
+
+ The cell value can have different types,for the setValueType method: the parameter can be
  • "boolean"
  • "currency"
  • "date"
  • "float"
  • "percentage"
  • "string"
  • "time"
  • "void"
If the parameter type is not a valid cell type, an IllegalArgumentException will be thrown. +
+
+       String valueType=cell.getValueType();
+ cell.setValueType(valueType);
+
+
+For the following getXXXValue() method:it gets the cell value as xxx type.An IllegalArgumentException will be thrown if the cell type is not xxx. +
+Get&Set boolean type Cell +
+
+ For setBooleanValue method:it sets the cell value as a boolean and sets the value type to be boolean. +
+
+       boolean booleanValue=cell.getBooleanValue();
+ cell.setBooleanValue(booleanValue);
+
+
Get&Set currency type Cell +
+
+For the following getting methods,if the value type is not "currency", an IllegalArgumentException will be thrown. +
+
+The currency code of the cell is like "USD", "EUR", "CNY", and the currency symbol is like "$" +
+
+       String currencyCode=cell.getCurrencyCode();  
+ cell.setCurrencyCode("USD");
+
+
+You can also set currency value and currency format.Please note the overall format includes the symbol character, for example: $#,##0.00. +
+
+       cell.setCurrencyValue(100.00, "USD");
+ cell.setCurrencyFormat("$", "$#,##0.00");
+
+
Get&Set date type Cell +
+
+       Calendar dateValue=cell.getDateValue(); 
+ cell.setDateValue(new GregorianCalendar(2010,5,1));
+
+
Get&Set float type Cell +
+
+      double floatValue=cell.getDoubleValue();  
+ cell.setDoubleValue(new Double(22.99f));
+
+
Get&Set percentage type Cell +
+
+      double percentageValue=cell.getPercentageValue();
+ cell.setPercentageValue(0.89);
+
+
Get&Set string type Cell +
+
+If the cell type is not string, the display text will be returned. +
+
+      String stringValue=cell.getStringValue();   
+ cell.setStringValue("simple");
+
+
Deal with the Time Value +
+
+If you want to get the string type of time value,you can format it: +
+
+      cell.setTimeValue(Calendar.getInstance());
+ SimpleDateFormat simpleFormat = new SimpleDateFormat("'PT'HH'H'mm'M'ss'S'");
+ String timeString= simpleFormat.format(cell.getTimeValue().getTime());
+
+
Something about Display Text +
+
+ Please note the display text in ODF viewer might be different from the value set by this method, because the displayed text in ODF viewer is calculated and set by editor. +
+
+      String displayText=cell.getDisplayText();
+ cell.setDisplayText(displayText);
+
+
Set image +
+
+ From version 0.5.5, we support high level APIs for images. You can use following codes to set an image to a cell. +
+
+        Image myImage = cell.setImage(new URI("http://www.xxx.com/a.jpg"));
+
+
+ You can use following codes to access an image in a cell. +
+
+        Image image = cell.getImage();
+ String imagename = image.getName();
+ FrameRectangle rect = image.getRectangle();
+ rect.setX(1);
+ rect.setY(1);
+ image.setRectangle(rect);
+
+

+

Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Charts.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Charts.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Charts.html Tue Sep 6 10:20:36 2011 @@ -36,10 +36,176 @@
-
+ +
- +

Documents > Cookbook >Charts +

+
+Overview +
+
+ Since 0.6, Simple ODF provides methods to manipulate charts in text document, spreadsheet document and presentation document. You can create, update and delete charts with these methods. +
+Create charts +
+
+ We all know, a chart is associated with a table. In order to create a chart, you must determine the data set of this chart. The data set can be a cell range of a table, for example: +
+
+        CellRangeAddressList cellRange = CellRangeAddressList.valueOf("A.A1:A.B3");
+ DataSet dataSet = new DataSet(cellRange, spreadsheetDoc, true, true, false);
+
+
+ Or a two dimensional array, for example: +
+
+        int row = 2, column = 3;
+ double[][] data = new double[column][row];
+ String[] labels = new String[row];
+ String[] legends = new String[column];
+ DataSet dataset = new DataSet(labels, legends, data);
+
+
+ You should also use rectangle to define the position and the size of this chart. For example: +
+
+        Rectangle rect = new Rectangle();
+ rect.x = 2000;
+ rect.y = 2700;
+ rect.width = 15000;
+ rect.height = 8000;
+ rect.y = 110000;
+
+
+ Then you can create a chart: +
+
+        spreadsheetDoc.createChart("Page Visit", dataSet,rect);
+
+
+ There are some shortcut methods to create charts, for example, below codes show how to create a chart in a text document: +
+
+        Chart chart = textDoc.createChart(
+ "Page Visit", spreadsheetDoc,
+ cellRange, true, true, false, rect);
+
+
+ If you want to create a chart in a spreadsheet document, you need to specify a cell to be the anchor of this chart, for example: +
+
+        spreadsheetDoc.createChart("Page Visit", spreadsheetDoc, cellRange,
+ true, true, false, rect, spreadsheetDoc.getTableByName("C")
+ .getCellByPosition("D10"));
+
+
+ If you want to create a chart in a presentation document, you can use the existing layout of a slide, which means, you don't need to specify a rectangle. The layouts that could contain a chart include: TITLE_PLUS_CHART, TITLE_PLUS_2_CHART, TITLE_LEFT_CHART_RIGHT_OUTLINE, TITLE_PLUS_3_OBJECT, and TITLE_PLUS_4_OBJECT. For example: +
+
+        Slide slide = presentationDoc.newSlide(2, "Slide3",
+ SlideLayout.TITLE_PLUS_2_CHART);
+ chart = slide.createChart("Count of Visits", spreadsheetDoc,
+ cellRange, true, true, false, null);
+
+
Update charts +
+
+ You can update charts properties, for example, the title, axis title, chart type, whether to apply 3D effect, whether to use legend with API. For example: +
+
+        chart.setChartTitle("New title");
+ chart.setAxisTitle("Hour", "Number");
+ chart.setChartType(ChartType.AREA);
+ chart.setApply3DEffect(true);
+ chart.setUseLegend(true);
+
+
+ You can update the data set too. For example: +
+
+        chart.setChartData(new DataSet(CellRangeAddressList.valueOf("A.A1:A.C4"), spreadsheetDoc, true, true, true));
+
+
Get and delete charts +
+
+ You can get charts by title e.g. +
+
+        chart = textDoc.getChartByTitle("New title").get(0);
+
+
+ You can also get a chart by its unique ID. The unique ID of a chart in Simple ODF API is the path of the chart document (relative to the ODF document package). The unique ID can be gotten with method: +
+
+        String chartid = chart.getChartID();
+ chart = textDoc.getChartById(chartid);
+
+
+ You can also get the count of charts in this document. +
+
+        int count = textDoc.getChartCount();
+
+
+ You can delete a chart by ID or by title, e.g. +
+
+        textDoc.deleteChartById(chartid);
+ textDoc.deleteChartByTitle("New title");
+
+

+

Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Column and Row.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Column and Row.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Column and Row.html Tue Sep 6 10:20:36 2011 @@ -36,10 +36,159 @@
-
+ +
- +

Documents > Cookbook >Column and Row +

+
+Get Column/Row +
+
+The class Column/Row represents the column/row of table.To get all the columns or rows you can use the getColumnList or getRowList of the table instance. +
+
+    List<Column> columns = table.getColumnList();
+ List<Row> rows = table.getRowList();
+
+
+You can also get single column/row by specifying the index of the column/row. +
+
+The column/row index start from 0.If not found, null will be returned. +
+
+    
+ Column column = table.getColumnByIndex(2);
+ Row row = table.getRowByIndex(0);
+
+
+If you want to know the count of header column/row in the table,you can do like this: +
+
+    int headerColumnCount = table.getHeaderColumnCount();
+ int headerRowCount = table.getHeaderRowCount();
+
+
+If you want to know the index of the column/row,you can use the method below: +
+
+    int columnIndex=column.getColumnIndex();
+ int rowIndex=row.getRowIndex();
+
+
+Can I get the previous or next Column/Row by the current column/row instance? +
+
+Yes,you can ask the column/row instance itself,if it doesn't exist,null will be returned. +
+
+    Column previousCol=column.getPreviousColumn();
+ Column nextCol=column.getNextColumn();
+ Row previousRow=row.getPreviousRow();
+ Row nextRow=row.getNextRow();
+
+
Append or Insert Column/Row +
+
+You can add a column to the end or insert many columns before the specified index +
+
+The appendColumn/Row method add an empty column/row at the end and return the new appended column/row +
+
+    Column newColumn=table.appendColumn();
+ Row newRow=table.appendRow();
+
+
+What can I do if I want to insert a column/row into the specified position? +
+
+ You can use the insertColumn/RowBefore method,whose first parameter is the index of the column/row to be inserted before; The second parameter is the number of columns/rows to be inserted. +
+
+    List<Column> cols = table.insertColumnsBefore(1, 2);
+ List<Row> newRows = table.insertRowsBefore(0, 2);
+
+
Remove Columns/Rows +
+
+You can delete a number of columns/rows by index +
+
+The first parameter is the index of the first column/row to delete; The second parameter is the number of columns/rows to delete. +
+
+The code below remove 1 column whose index is 2;remove 2 rows whose index is 1,2. +
+
+    table.removeColumnsByIndex(2, 1);
+ table.removeRowsByIndex(1, 2);
+
+
Set Column/Row +
+
+If you want to change the width of the column or the height of the row,you can use it like this: +
+
+If the second parameter of row's setHeight is true, the row can fit the height to the text, vice versa. +
+
+    column.setWidth(column.getWidth()/2);
+ row.setHeight(row.getHeight()/2, true);
+
+

+

Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Fields.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Fields.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Fields.html Tue Sep 6 10:20:36 2011 @@ -36,10 +36,192 @@
-
+ +
- +

Documents > Cookbook >Fields +

+
+Variable Field +
+
+ You can use the following code to create a variable field, and set the value. +
+
+            TextDocument doc = TextDocument.newTextDocument();
+ Paragraph paragraph = doc.addParagraph("test_con_variable:");
+ VariableField simpleVariableField = Fields.createSimpleVariableField(doc, "test_con_variable");
+ simpleVariableField.updateField("true", paragraph.getOdfElement());
+
+
+ Following code can be used to set value to variable field, and append it to an ODF element. +
+
+            simpleVariableField.updateField("user variable content", null);
+ simpleVariableField.displayField(paragraph.getOdfElement());
+
+
Condition Field +
+
+ Following code can be used to create a condition field. +
+
+            Paragraph newParagraph = doc.addParagraph("Condition Field Test:");
+ ConditionField conditionField = Fields.createConditionField(newParagraph.getOdfElement(), "test_con_variable == "true"",
+ "trueText", "falseText");
+
+
Hidden Field +
+
+ Following code can be used to create a hidden field. +
+
+            newParagraph = doc.addParagraph("Hide Text Field Test:");
+ conditionField = Fields.createHiddenTextField(newParagraph.getOdfElement(), "test_con_variable == "true"", "hiddenText");
+
+
Cross Reference Field +
+
+ Following code can be used to create a reference field. +
+
+            OdfElement newTextSpanElement = ((TextPElement)doc.addParagraph("Reference Content:").getOdfElement()).newTextSpanElement();
+ newTextSpanElement.setTextContent("This is a test reference content.");
+ ReferenceField referenceField = Fields.createReferenceField(newTextSpanElement, "test-ref");
+
+
+ Following code can be used to append a reference field. +
+
+            referenceField.appendReferenceTo(doc.addParagraph("User Reference Field:").getOdfElement(), ReferenceField.DisplayType.TEXT);
+
+
Chapter Field +
+
+ Following code can be used to create a chapter field. +
+
+            ChapterField chapterField = Fields.createChapterField(doc.addParagraph("Chapter:").getOdfElement());
+
+
Title and Subject Field +
+
+ Following code can be used to create a title field. +
+
+            TitleField titleField = Fields.createTitleField(doc.addParagraph("The Title:").getOdfElement());
+
+
+ Following code can be used to create a subject field. +
+
+            SubjectField subjectField = Fields.createSubjectField(doc.addParagraph("The Subject:").getOdfElement());
+
+
Author Field +
+
+ Following code can be used to create a author initial field and a author name field. +
+
+            AuthorField authorField = Fields.createAuthorInitialsField(doc.addParagraph("The initials of the author :").getOdfElement());
+ authorField = Fields.createAuthorNameField(doc.addParagraph("Author:").getOdfElement());
+
+
Page Number Field +
+
+ Following code can be used to create a current page number field. +
+
+            PageNumberField numberField = Fields.createCurrentPageNumberField(doc.addParagraph("Current Page Number:").getOdfElement());
+ numberField.setNumberFormat(NumberFormat.UPPERCASE_LATIN_ALPHABET);
+ numberField.setDisplayPage(DisplayType.NEXT_PAGE);
+
+
+ Following code can be used to create a previous page number and a next page number field. +
+
+            numberField = Fields.createPreviousPageNumberField(doc.addParagraph("Previous Page Number:").getOdfElement());
+ numberField = Fields.createNextPageNumberField(doc.addParagraph("Next Page Number:").getOdfElement());
+
+
Page Number Field +
+
+ Following code can be used to create a page count field, and set the number format. +
+
+            PageCountField countField = Fields.createPageCountField(doc.addParagraph("Page Count:").getOdfElement());
+ countField.setNumberFormat(NumberFormat.UPPERCASE_LATIN_ALPHABET);
+
+
Date Field +
+
+ Following code can be used to create a date field, and set the format. +
+
+            DateField dateField = Fields.createDateField(doc.addParagraph("Date:").getOdfElement());
+ dateField.formatDate("yy-MM-dd");
+
+
Time Field +
+
+ Following code can be used to create a time field, and set the format. +
+
+            TimeField timeField = Fields.createTimeField(doc.addParagraph("Time:").getOdfElement());
+ timeField.formatTime("HH:mm:ss a");
+
+

+

Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Metadata.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Metadata.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Metadata.html Tue Sep 6 10:20:36 2011 @@ -36,10 +36,133 @@
-
+ +
- +

Documents > Cookbook >Manipulate Metadata +

+
+Overview +
+
+ This Meta API supports to access and set document metadata. It covers the metadata definitions in ODF Specification 1.2 Committee Draft05 +
+Get Meta object +
+
+ First you load an ODF text document(for example),then get the meta file DOM and then use the meta DOM to create an instance of the Meta. Use Meta you can access all the supported elements. +
+
+    TextDocument doc = (TextDocument) TextDocument.loadDocument("testtable.odt");
+ OdfFileDom metadom = doc.getMetaDom();
+ Meta metadata = new Meta(metadom);
+
+
Access metadata +
+
+ After creating the Meta instance,you can use it to manipulate the metadata: for example, you can set a value for the <meta:generator> like this: +
+
+    metadata.setGenerator("OpenOffice.org/3.0$Win32 OpenOffice.org_project/300m15$Build-9379");
+
+
+ The <meta:keyword> may contain many keywords, you can set the whole list of keywords and add one keyword as you want. the api currently do not provide the direct method for deleting one keyword ,you can get the keyword list first,and then delete the keyword,finally set the list to the element. +
+
+       metadata.addKeyword("java");
+ List<String> keywords=metadata.getKeywords();
+ keywords.remove("java");
+ metadata.setKeywords(keywords);
+
+
Access the user defined element +
+
+ To manipulate the user defined data,you should get the list of their names,and then use the names to update the data or its datatype or delete the whole user defined data. you can use the setUserDefinedData(String name, String type, String value) method to update data,if the name not exists in the document,the method will add the new user defined data. +
+
+      List<String> names=metadata.getUserDefinedDataNames();
+ for (String name : names) {
+ metadata.removeUserDefinedDataByName(name);
+ }
+ String key="newId";
+ //org.odftoolkit.odfdom.dom.attribute.meta.MetaValueTypeAttribute.Value + metadata.setUserDefinedData(key, Value.STRING.toString(), "new001");
+ //update the datatype + metadata.setUserDefinedDataType(key, Value.BOOLEAN.toString());
+ //update the data value + metadata.setUserDefinedDataValue(key, "false");
+
+ //get the datatype + String dataType=metadata.getUserDefinedDataType(key);
+ //get the data value + String dataValue=metadata.getUserDefinedDataValue(key);
+
+
Access the document statistics +
+
+ if you want to access the document statistics,you should get a DocumentStatistic instance, if the return is null,it means that this ODF document doesn't have any document statistic information,you should create a document statistics object. +
+
+    DocumentStatistic stat = metadata.getDocumentStatistic();
+ if(stat==null) {
+ stat=new DocumentStatistic(metadata.getOfficeMetaElement().newMetaDocumentStatisticElement());
+ }
+
+ stat.setCellCount(3);
+ Integer cellCount=stat.getCellCount();
+
+

+

Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Manipulate TextSearch.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Manipulate TextSearch.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Manipulate TextSearch.html Tue Sep 6 10:20:36 2011 @@ -36,10 +36,227 @@
-
+ +
- +

Documents > Cookbook >Manipulate TextSearch +

+
+TextNavigation +
+
+ First an ODF text document is needed to test the navigation operation. The following codes shows two main functions of TextNavigation :hasNext() and getCurrentItem(). The first parameter of the TextNavigation constructor is the matched pattern String, and the second is the navigation scope. +
+
+ The result of function getCurrentItem is a Selection object, so a TextSelection object is used here to check out the result.Finally the informations of all the String "What" in the text document will be printed out. +
+
+        TextDocument textdoc=(TextDocument)TextDocument.loadDocument("textsearch.odt");
+ TextNavigation search1;
+ search1=new TextNavigation("What",textdoc);
+ while (search1.hasNext()) {
+ TextSelection item1 = (TextSelection) search1.nextSelection();
+ System.out.println(item1);
+ }
+
+
TextSelection +
+Get Index/Text of TextSelection +
+
+ Run the following codes will get the text content of the searched String "good" and the corresponding index in the text document. +
+
+        TextNavigation search2=new TextNavigation("good",textdoc);
+ while(search2.hasNext()){
+ TextSelection item2=(TextSelection) search2.nextSelection();
+ String searchedText=item2.getText();
+ int searchedIndex=item2.getIndex();
+ System.out.println(searchedText);
+ System.out.println(searchedIndex);
+ }
+
+
Cut String +
+
+ To cut some specified string in a text document, you can do like the following codes which cut off all the String "day" in the document. +
+
+            search2=new TextNavigation("day",textdoc);
+ while(search2.hasNext()){
+ TextSelection item=(TextSelection) search2.nextSelection();
+ item.cut();
+ }
+
+
Paste String +
+
+ The following codes paste the string "change" both at the front and at the end of the string "good", by using the function pasteAtFrontOf() and pasteAtEndOf(). +
+
+        search2 = null;
+ search2 = new TextNavigation("good", textdoc);
+ TextSelection pastesource = null;
+ TextNavigation search3 = new TextNavigation("change", textdoc);
+ if (search3.hasNext()) {
+ pastesource = (TextSelection) search3.nextSelection();
+ }
+ while (search2.hasNext()) {
+ TextSelection item = (TextSelection) search2.nextSelection();
+ //paste "change" at the front of "good" + pastesource.pasteAtFrontOf(item);
+ //paste "change" at the end of "good" + pastesource.pasteAtEndOf(item);
+ }
+
+
Replace String +
+
+The following codes replace all the string "replacesource" with the string "replacedest" in the text document. +
+
+        search2 = null;
+ search2 = new TextNavigation("replacesource", textdoc);
+ if (search3.hasNext()) {
+ TextSelection item= (TextSelection) search3.nextSelection();
+ item.replaceWith("replacedest");
+ }
+
+
Add Reference to String +
+
+ To add reference for a string, you can do like the following codes. Here function addHref is used, the parameter of it is an URL object. The codes add network address "http:www.ibm.com" to the string "network". +
+
+        search2 = null;
+ search2 = new TextNavigation("network", textdoc);
+ while (search2.hasNext()) {
+ TextSelection item = (TextSelection) search2.nextSelection();
+ item.addHref(new URL("http://www.ibm.com"));
+ }
+
+
Add Comment +
+
+ Adding comment is a useful function when review document, such as spell check and security check. You can do it like the following codes. Here, function addComment is used, the first parameter is the comment content, the second parameter is the comment author. The codes add a spell suggestion before the string "natwork". +
+
+        TextNavigation search4 = new TextNavigation("natwork", textdoc);
+ while (search4.hasNext()) {
+ TextSelection selection = (TextSelection) search4.nextSelection();
+ selection.addComment("Please change 'natwork' with 'network'.", "SpellChecker");
+ }
+
+
FieldSelection +
+
+ Field Selection is a decorator class of TextSelection, which help user replace a text content with field. Following code can be used to search the document content, and replace with a simple field. +
+
+        TextDocument doc = TextDocument.loadDocument("fieldSample.odt");
+ TextNavigation search = new TextNavigation("ReplaceDateTarget", doc);
+ while (search.hasNext()) {
+ TextSelection item = (TextSelection) search.nextSelection();
+ FieldSelection fieldSelection = new FieldSelection(item);
+ fieldSelection.replaceWithSimpleField(Field.FieldType.FIXED_DATE_FIELD);
+ }
+
+
+ Following code can be used to search the document content, and replace with a condition field. +
+
+        TextSelection item = (TextSelection) search.nextSelection();
+ FieldSelection fieldSelection = new FieldSelection(item);
+ fieldSelection.replaceWithConditionField("test_con_variable == "true"", "trueText", "falseText");
+
+
+ Following code can be used to replace with a hidden field. +
+
+        fieldSelection.replaceWithHiddenTextField("test_con_variable == "true"", "hiddenText");
+
+
+ Following code can be used to replace with a reference field. +
+
+        ReferenceField referenceField = Fields.createReferenceField(doc.addParagraph("span").getOdfElement(), "selection-test-ref");
+ fieldSelection.replaceWithReferenceField(referenceField, ReferenceField.DisplayType.TEXT);
+
+
+ Following code can be used to replace with a variable field. +
+
+        VariableField userVariableField = Fields.createUserVariableField(doc, "selection_user_variable", "test");
+ fieldSelection.replaceWithVariableField(userVariableField);
+
+
TextStyleNavigation +
+
+ Similar with TextNavigation, TextStyleNavigation has two main functions: getCurrentItem() and hasNext() which is shown in the following codes. The input parameter of TextStyleNavigation constructor is a map of OdfStyleProperty, so here a TreeMap "searchProps" which contains the Style properties is used to construct the TextStyleNavigation object. +
+
+        TextStyleNavigation searchStyle1;
+ TreeMap<OdfStyleProperty, String> searchProps = new TreeMap<OdfStyleProperty, String>();
+ searchProps.put(StyleTextPropertiesElement.FontName, "Times New Roman1");
+ searchProps.put(StyleTextPropertiesElement.FontSize, "16pt");
+ searchStyle1 = new TextStyleNavigation(searchProps, textdoc);
+ if (searchStyle1.hasNext()) {
+ TextSelection itemstyle = (TextSelection) searchStyle1.nextSelection();
+ System.out.print((itemstyle.toString()));
+ }
+
+

+

Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Presentation Document.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Presentation Document.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Presentation Document.html Tue Sep 6 10:20:36 2011 @@ -36,10 +36,107 @@
-
+ +
- +

Documents > Cookbook >Presentation Document +

+
+Create Presentation Document +
+
+Let's create an empty presentation document first. The following codes generates an empty presentation document with one slide: +
+
+            PresentationDocument document=PresentationDocument.newPresentationDocument();  
+ document.save(filePath);
+
+
+We can also create a presentation template document by using the following codes. The operation of the template document is the same with the normal presentation document. +
+
+                    PresentationDocument documentTmp=PresentationDocument.newPresentationTemplateDocument();              
+
+
Get Presentation Document +
+
+We can get the existing presentation Document by using the loadDocument function like follows: +
+
+Here presentation.odp is the name of the existing presentation document. +
+
+Also we can append all the slides of the specified presentation document to the current document by using the following codes: +
+
+Here the slides of the documents "presentation.odp" will be appended to "document". +
+
+            PresentationDocument presentationmodel;
+ presentationmodel=(PresentationDocument)PresentationDocument.loadDocument("presentation.odp");
+ document.appendPresentation(presentationmodel);
+
+
Change Presentation Mode +
+
+We can switch the mode presentation documents by using the following codes. Here the first one convert the presentation document to a template, and the second one convert the template to a normal presentation document. +
+
+            document.changeMode(OdfMediaType.PRESENTATION_TEMPLATE); 
+ documentTmp.changeMode(OdfMediaType.PRESENTATION);
+
+

+

Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Slide.html ============================================================================== --- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Slide.html (original) +++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Slide.html Tue Sep 6 10:20:36 2011 @@ -36,10 +36,199 @@
-
+ +
- +

Documents > Cookbook >Slide +

+
+Add Slide +
+
+If you want to add new slide to the presentation document, you can use the following codes: +
+
+Here the SlideLayout is the layout model of the added slide, the first parameter is the index of the added slide and the second parameter is the name of this slide. +
+
+                PresentationDocument document=PresentationDocument.newPresentationDocument();                     
+ document.newSlide(1, "new slide", SlideLayout.TITLE_ONLY);
+
+
Get Slide +
+
+You can get the slide through the index in the presentation document, like follows: +
+
+        Slide slide;
+ slide=document.getSlideByIndex(0);
+
+
+Or you can get the slide through the name of it by using the following code: +
+
+        slide=document.getSlideByName("new slide");
+
+
+To get all the slides in the document,you can do like this: +
+
+        Iterator<Slide> slideList=document.getSlides();
+
+
+Also you can get the number of the slides in the document by the following code: +
+
+        int numSlide=document.getSlideCount();
+
+
Set/Get Slide Name/Index +
+
+If you want to set a new name for a slide, you can use the following two methods: +
+
+        slide.setSlideName("second slide"); 
+ document.getSlideByIndex(2).setSlideName("third slide");
+
+
+If you want to know the index and the name of one slide which is being operated, you can use the following codes: +
+
+        int slideIndex=slide.getSlideIndex();
+ String slideName=slide.getSlideName();
+
+
Copy Slide +
+
+You can copy a slide in the presentation document from one position to another by using the following codes: +
+
+Here the first parameter is the source position of the slide need to be copied, the second parameter is the destination position of the slide need to be copied, and the last parameter is the new name of the copied slide. +
+
+        document.copySlide(1, 2, "copied slide");
+
+
+And also you can copy a slide from another document by using the following codes: +
+
+Here the first parameter of copyForeignSlide is the new position of the copied slide in the current document, the second parameter is the source document of the copied slide, and the last one is the slide index of the source document that need to be copied. +
+
+         PresentationDocument documentmodel;
+ documentmodel=(PresentationDocument)PresentationDocument.loadDocument("presentation.odp");
+ document.copyForeignSlide(1, documentmodel, 2);
+
+
Move/Delete Slide +
+
+To move one slide to another position of this presentation position, you can use the following codes: +
+
+Here the first parameter is the current index of the slide that need to be moved, and the second parameter is the index of the destination position before the move action. +
+
+        document.moveSlide(2, 1);       
+
+
+You can delete the slide either by through the index or through the name of the specified slide, like follows: +
+
+        document.deleteSlideByIndex(1);
+ document.deleteSlideByName("third slide");
+
+
Add Text to Slide +
+
+ You can set the text content of a slide with text box API since version 0.5. Below codes will get the title text box of a slide, set the text content, and then get the outline text box, set the list content. +
+
+        Textbox titleBox = slide.getTextboxByUsage(PresentationClass.TITLE).get(0);
+ titleBox.setTextContent("This is the title");
+ Textbox outline = slide.getTextboxByUsage(PresentationClass.OUTLINE).get(0);
+ List txtList = outline.addList();
+ txtList.addItem("List Item1");
+ txtList.addItem("List Item2");
+
+
+To add some text, you can first get the notes of one slide and then add text to this corresponding notes. The following codes shows this process: +
+
+        Notes note=slide.getNotesPage();
+ note.addText("text notes");
+
+
Add Image to Slide +
+
+To add an image to slide, you can use below codes to simply add the image to the last slide of the presentation document. +
+
+        URI imageuri=new URI("namdaemun.jpg");
+ document.newImage(imageuri);
+
+
+Or you can use following code to add an image to a specific position you want +
+
+        Slide slide1 = document.getSlideByIndex(1);
+ Image image = Image.newImage(slide1, new URI("http://www.xxx.com/a.jpg"));
+ FrameRectangle rect = image.getRectangle();
+ rect.setX(4);
+ rect.setY(5.7);
+ image.setRectangle(rect);
+
+

+