From odf-commits-return-206-apmail-incubator-odf-commits-archive=incubator.apache.org@incubator.apache.org Tue Sep 6 02:10:03 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 A1F3D7B9F for ; Tue, 6 Sep 2011 02:10:03 +0000 (UTC) Received: (qmail 3545 invoked by uid 500); 6 Sep 2011 02:10:03 -0000 Delivered-To: apmail-incubator-odf-commits-archive@incubator.apache.org Received: (qmail 3517 invoked by uid 500); 6 Sep 2011 02:10:03 -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 3510 invoked by uid 99); 6 Sep 2011 02:10:03 -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 02:10:03 +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 02:09:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9E6D7238897D; Tue, 6 Sep 2011 02:09:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1165478 [2/3] - in /incubator/odf/site/trunk/content/odftoolkit/simple: ./ demo/scripts/ demo/styles/ document/ document/cookbook/ document/javadoc/ javadoc/ Date: Tue, 06 Sep 2011 02:09:28 -0000 To: odf-commits@incubator.apache.org From: devinhan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110906020929.9E6D7238897D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Presentation.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate%20Presentation.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Presentation.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Presentation.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,98 @@ + + + + +Manipulate Presentation + + + + +
+
+
+
+
+ +
+ + +
+ +
+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();			    
+
+
+
+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);
+
+
+
+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);
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Slide.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate%20Slide.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Slide.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Slide.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,202 @@ + + + + +Manipulate 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();
+
+
+
+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);
+
+
+
+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");
+
+
+
+ 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");
+
+
+
+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);
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Table.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate%20Table.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Table.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Table.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,154 @@ + + + + +Manipulate Table + + + + +
+
+
+
+
+ +
+ + +
+
+
+Overview +
+
+
+ This Table API supports to manipulate tables in text and spreadsheet documents. It covers the table definition in ODF Specification 1.2 Committee Draft05 +
+
+
+Create Table +
+
+
+Let's create an empty table first.By default,the code below create a table with 5 columns and 2 rows. +
+
+            TextDocument document = TextDocument.newTextDocument();
+ Table table1 = Table.newTable(document);
+ table1.setTableName("table1");
+ document.save(filePath);
+
+
+If you want to create table with specified column and row,you can do like this: +
+
+            int row=4;
+ int column=3;
+ Table table2=Table.newTable(document, row, column);
+ table2.setTableName("table2");
+
+
+ If you want to put some numbers into a table while creating it, you can use the constructor Table.newTable(document,rowlabels,columnlabels, data) which you should specify a 2 dimension array as the data and 2 String arrays as table labels,one for row and the other for column. +
+
+        int rowcount = 10, columncount = 4;
+ double[][] data = new double[rowcount][columncount];
+ String[] rowlabels = new String[rowcount];
+ String[] columnlabels = new String[columncount];
+ Table table3=Table.newTable(document,rowlabels,columnlabels, data);
+ table3.setTableName("dataTable");
+
+
+You can also fill table with string values while creating it, to do this you should provide a 2 dimension string array instead of double array. +
+
+     	String[][] stringData = new String[rowcount][columncount];
+ Table table4 = Table.newTable(document, rowlabels, columnlabels, stringData);
+ table4.setTableName("stringTable");
+
+
+
+Find Table +
+
+
+To get all the tables in the document,you can do like this: +
+
+        List<Table> tableList=document.getTableList();
+
+
+If you want to get a single table,you can use the table name to find it.If it's not found,the method returns null. +
+
+        Table emptyTable=document.getTableByName("table1");
+
+
+
+Delete Table +
+
+
+        Table table = document.getTableByName("DeletedTable");
+ if (table != null) {
+ table.remove();
+ }
+
+
+
+Set Table +
+
+
+You can set or update table name,which can be regarded as table identifier in a document. +
+
+           table1.getTableName();
+ table1.setTableName("EnglishScore");
+
+
+If you want to change table width,you can do like this: +
+
+        Table tableWidth=document.getTableByName("table1");
+ if(tableWidth!=null) {
+ long width=500;
+ tableWidth.setWidth(width);
+ tableWidth.getWidth();
+ }
+
+
+Each table in the document has a protect attribute to show whether it is protected or not. +
+
+           boolean isProtected=table1.isProtected();
+ table1.setProtected(true);
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Text Document.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate%20Text%20Document.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Text Document.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate Text Document.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,433 @@ + + + + +Manipulate Text Document + + + + +
+
+
+
+
+ +
+ + +
+
+
+Overview +
+
+
+Till now, we support high level APIs to manipulate text document, paragraph, section and list. +
+ +
+ There are typically four kinds of Text Documents with different modes can be generated: text document, master document, template document and web document. +
+
+The following codes generates an empty text document. +
+
+            TextDocument document1=TextDocument.newTextDocument();	 
+ document1.save(filePath);
+
+
+ There are two methods to generate a new document, one with a parameter of OdfMediaType, and the other one just use the corresponding new function. +
+
+ The following two lines of codes generate the same kinds of document(Master document). The other three kinds of document are similar. +
+
+	    TextDocument documentMedia1=TextDocument.newTextDocument(OdfMediaType.TEXT_MASTER);
+ TextDocument documentMedia2=TextDocument.newTextMasterDocument();
+
+
+
+ We can get the existing Text Document by using the loadDocument function like follows. The loadDocument function has four kinds of parameters: File, InputStream, OdfPackageDocument and String. Here the one with string parameter is used as an example. +
+
+	    TextDocument document2=(TextDocument)TextDocument.loadDocument("textdocument.odt");
+
+
+Also we can change the mode of one text document by using the following codes: +
+
+	    document2.changeMode(OdfMediaType.TEXT_WEB);
+
+
+
+ To add a new paragraph to a text document, the following codes can be used, the first one add an empty paragraph to the end of the document, and the second one add a new paragraph with the corresponding texts to the document. +
+
+	    document1.addParagraph(null);
+ document1.addParagraph("test newParagraph function in textDocument");
+
+
+ The first one will get the second paragraph of this document. The second statement will get the last paragraph with text content. The paragraph without text content will be ignored if the second parameter is true. +
+
+The following codes can be used to append text to the end of a paragrah. +
+
+	    para1.appendTextContent("test addText function in textDocument");
+
+
+The following code is to set the horizontal alignment of a paragraph. +
+
+	    para1.getStyleHandler().getParagraphPropertiesForWrite().setHorizontalAlignment(HorizontalAlignmentType.CENTER);
+
+
+
+ From version 0.4, we support high level APIs for section. You can use the following code to get a section by name: +
+
+		Section aSection = document1.getSectionByName("ImageSection");
+
+
+ or use the following code to get an iterator of sections. All sections in the document would be returned, including sections in footer and header. +
+
+		Iterator<Section> sections = document1.getSectionIterator();
+ while (sections.hasNext()) {
+ Section theSection = sections.next();
+ }
+
+
+ After you get the object of section, you can use the following codes to set and get the name of the section. +
+
+		String name = aSection.getName();
+ aSection.setName("NewName");
+
+
+ You can use the following code to copy and append a section at the end of a document. Copying from a foreign document is supported. You don't need to care whether or not the document is the owner of the source section. +
+
+		document1.appendSection(aSection, true);
+
+
+ If you want to copy and append a section within a same document, you can specify with the second parameter of "copyAppendSection(Section section, boolean isResourceCopied)" whether the linked resources to this section are copied or not. The following code means to copy a section and append it at the end, but the linked resources are shared between the source section and the copied section. +
+
+		document1.appendSection(aSection, false);
+
+
+ You can remove this Section from the document content, all the resources that are only linked with this section would be removed too. +
+
+		aSection.remove();
+
+
+
+ From version 0.4, we support high level APIs for list. You can use the following code to create a list. The two methods are same. +
+
+		List newList1 = document1.addList();
+ List newList2 = new List(document1);
+
+
+ Actually, you can append list to table cell, list item, presentation slide and notes. They all have the same ability with text document for list. We call them ListContainer, which can append, remove and get the iterator of list. +
+
+		Iterator<List> lists = document1.getListIterator();
+ List list =null;
+ while (lists.hasNext()) {
+ list = lists.next();
+ }
+
+
+ After you get the object of list, you can use the following methods to set and get the header of the list. +
+
+		String header = list.getHeader();
+ list.setHeader("NewHeader");
+
+
+ You can get all of the existing items in this list. They are returned as java.util.List. +
+
+		java.util.List<ListItem> items = list.getItems();
+
+
+ If you only want to get the item at a specific location, you can use the following code: +
+
+		int location = 2;
+ ListItem item = list.getItem(location);
+
+
+ There are several ways to help you append item(s) to the list. Please reference the following code: +
+
+		// add single item
+		ListItem newItem1 = list.addItem(item);
+ ListItem newItem2 = list.addItem("itemContent");
+ // add clone items + ListItem[] newItems = new ListItem[]{newItem1, newItem2};
+ list.addItems(newItems);
+ // add string items + String[] newItemContents = new String[]{"itemContent1", "itemContent2"};
+ list.addItems(newItemContents);
+
+
+ You can specify a location to insert new item(s). +
+
+		newItem1 = list.addItem(location, item);
+ newItem2 = list.addItem(location, "itemContent");
+ list.addItems(location, newItems);
+ list.addItems(location, newItemContents);
+
+
+ If you want to replace a list item with a new one, you can use the following code. +
+
+		item = list.set(location, newItem1);
+ item = list.set(location, "itemContent");
+
+
+ You can use the following methods to remove item(s). +
+
+		list.removeItem(item);
+ //item in specific location. + list.removeItem(location);
+ //item in specific collection. + list.removeItems(items);
+
+
+ You can specify with the following methods whether the numbering of the previous list is continued by this list: +
+
+		// the numbering of the proximate list is continued
+		newList1.setContinueNumbering(true);
+ // the numbering of the specified list is continued by this list + newList2.setContinueList(list);
+
+
+ You can use the following method to know whether the list is a number list. +
+
+		ListType type = list.getType();
+
+
+ Now, List API support 3 types of lists, ListType.BULLET, ListType.NUMBER and ListType.IMAGE. The default created list is ListType.BULLET, bullet list. How to create a number list or a image list then? ListDecorator has powerful functions that can help you. ListDecorator is an interface which decides how to decorate a list and its list items. We supply 4 implementations of this interface, BulletDecorator, NumberDecorator, ImageDecorator and OutlineDecorator. +
+
+		// create a number list.
+		ListDecorator numberDecorator = new NumberDecorator(document1);
+ List numberList1 = document1.addList(numberDecorator);
+ List numberList2 = new List(document1, numberDecorator);
+
+
+ You can implement your own ListDecorator as need, or extend the default four implementations. +
+
+ You can remove a list from the document, the following two methods are same. +
+
+		list.remove();
+ document1.removeList(list);
+
+
+ We also provide funtions to manipulate list items. You can use the following methods to get and set the text content of a item. +
+
+		String itemContent = item.getTextContent();
+ item.setTextContent("new item content");
+
+
+ You can get the item index and its owner list. +
+
+		int index = item.getIndex();
+ List ownerList = item.getOwnerList();
+
+
+ When you want to remove an item, besides List.removeItem(ListItem), you can use the following method directly. +
+
+		item.remove();
+
+
+ With the help of the following code, the start number of list item can be set. +
+
+		item.setStartNumber(3);
+
+
+ Since list item is also a ListContainer, you can add sub list to an item. +
+
+		item.addList();
+
+
+
+ From version 0.4.5, we support high level APIs for footer and header. You can use the following code to get the header and footer. +
+
+		Header docHeader = doc.getHeader();
+ Footer footer = doc.getFooter();
+
+
+ In order to add contents to header and arrange these contents in a good layout, I suggest you to use table. It's easy to add a none-border table to header. Below codes show how to add a table with 2 columns and 1 row to header, and then add some text content to the left cell, and add an image to the right cell. +
+
+		Table table = docHeader.addTable(1,2);
+ table.getCellByPosition(0, 0).setStringValue("header table cell");
+ Cell cell = table.getCellByPosition(1, 0);
+ Image image1 = cell.setImage(new URI("file:/c:/image.jpg"));
+
+
+ Below codes show how to add a table with 1 column and 1 row to footer, and then add some text content to the cell. You can easily set the style of these text content. The codes describe how to put the text content in the center, set the font of the text content, and set the background of the cell. +
+
+		table = footer.addTable(1, 1);
+ Cell cellByPosition = table.getCellByPosition(0, 0);
+ cellByPosition.setStringValue("footer table cell");
+ cellByPosition.setHorizontalAlignment(HorizontalAlignmentType.CENTER);
+ Font myFont = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.BLUE);
+ cellByPosition.setFont(myFont);
+ cellByPosition.setCellBackgroundColor(Color.YELLOW);
+
+
+
+Textbox +
+
+
+ From version 0.5, we support high level APIs for text box. Below codes will create a text box and add it to the text document with a paragraph as the anchor position. The FrameRectangle specifies an area and the position of this text box. +
+
+		Paragraph paragraph = doc.getParagraphByIndex(0, false);
+ Textbox box = paragraph.addTextbox(new FrameRectangle(1,1,2,1,SupportedLinearMeasure.IN));
+
+
+ Below codes is to set the text content and name of this text box; +
+
+		box.setTextContent("this is a text box");
+ box.setName("MyTextbox");
+
+
+ Below codes is to get a text box by name or get an iterator of text box contained by a paragraph. +
+
+		Textbox myBox=paragraph.getTextboxByName("MyTextbox");
+ Iterator<Textbox> boxIter = paragraph.getTextboxIterator();
+
+
+ Below code is to set the background color of a text box. +
+
+		myBox.setBackgroundColor(Color.BLUE);
+
+
+ Below code is to remove a text box; +
+
+		paragraph.removeTextbox(myBox);
+
+
+
+Image +
+
+
+ From version 0.5.5, we support high level APIs for images. Below codes will create a image and add it to a document with a paragraph as the anchor position. +
+
+		Paragraph para = doc.getParagraphByIndex(1, false);
+ Image image = Image.newImage(para, new URI("file:/c:/image.jpg"));
+
+
+ Below codes can set the properties of image, and even the vertical (or horizontal) alignment. +
+
+		image.setTitle("Image title");
+ image.setDescription("This is a sample image");
+ image.setVerticalPosition(FrameVerticalPosition.TOP);
+ image.setHorizontalPosition(FrameHorizontalPosition.RIGHT);
+
+
+ If you want to handle more style settings of image, you can try FrameStyleHandler. +
+
+		FrameStyleHandler handler = image.getStyleHandler();
+ handler.setAchorType(AnchorType.AS_CHARACTER);
+ handler.setHorizontalRelative(HorizontalRelative.PAGE);
+ handler.setVerticalRelative(VerticalRelative.PAGE);
+
+
+
+Span +
+
+
+ From version 0.5.5, we support high level APIs for span. You can create a span based on a text selection. With span, you can set a different style to this small unit. +
+
+		TextNavigation navigation = new TextNavigation("test", doc);
+ TextSelection sel = (TextSelection) navigation.nextSelection();
+ Span span = Span.newSpan(sel);
+ DefaultStyleHandler styleHandler = span.getStyleHandler();
+ Font font1Base = new Font("Arial", FontStyle.ITALIC, 10, Color.BLACK, TextLinePosition.THROUGH);
+ styleHandler.getTextPropertiesForWrite().setFont(font1Base);
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate TextSearch.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate%20TextSearch.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate TextSearch.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Manipulate TextSearch.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,252 @@ + + + + +Manipulate TextSearch + + + + + +
+
+
+
+
+ +
+ + +
+ +
+ 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);
+ }
+
+
+ +
+ 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);
+ }
+
+
+
+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");
+ }
+
+
+
+ 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");
+ }
+
+
+
+ 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);
+
+
+
+ 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()));
+ }
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Presentation Document.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Presentation%20Document.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Presentation Document.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Presentation Document.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,111 @@ + + + + +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();			    
+
+
+
+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);
+
+
+
+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);
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Slide.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Slide.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Slide.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Slide.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,215 @@ + + + + +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();
+
+
+
+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);
+
+
+
+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");
+
+
+
+ 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");
+
+
+
+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);
+
+

+ +
+
+ +
+
+ + Added: incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Style Handling.html URL: http://svn.apache.org/viewvc/incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Style%20Handling.html?rev=1165478&view=auto ============================================================================== --- incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Style Handling.html (added) +++ incubator/odf/site/trunk/content/odftoolkit/simple/document/cookbook/Style Handling.html Tue Sep 6 02:09:27 2011 @@ -0,0 +1,150 @@ + + + + +Style Handling + + + + + +
+
+
+
+
+ +
+ + +
+
+
+Overview +
+
+
+Style handling methods provide convenient methods to set font and borders. +
+ +
+ The most simple method to define font settings is to create a font object, and set it to a cell object. The below code snippet defines a font object to describe "Arial" italic font with size "12pt" and black color, and then set it to a cell. The font will work for western characters by default. +
+
+		SpreadsheetDocument document = SpreadsheetDocument.newSpreadsheetDocument();
+ Table table = document.getTableByName("Sheet1");
+ Font font = new Font("Arial", StyleTypeDefinitions.FontStyle.ITALIC, 12, Color.BLACK);
+ Cell cell = table.getCellByPosition("A1");
+ cell.setFont(font);
+
+
+ The most simple method to get font settings of western characters is: +
+
+		Font theFont = cell.getFont();
+ double size = theFont.getSize();
+ String fontName = theFont.getFamilyName();
+ StyleTypeDefinitions.FontStyle fontStyle = theFont.getFontStyle();
+ Color fontColor = theFont.getColor();
+
+
+
+ CellStyleHandler can help you to achieve advanced functions. In Open Document Format, there can be different font settings for different script types. For example, a font setting for English characters and another font setting for Chinese characters. If you want to define the font setting for other script types, you can reference to below codes. The below code snippet defines a font for Chinese characters. +
+
+		cell.getStyleHandler().setFont(font, new Locale(Locale.CHINESE.getLanguage(), Locale.CHINA.getCountry()));
+
+
+ The below code snippet shows how to get the font setting for other kinds of scripts. +
+
+		CellStyleHandler styleHandler = cell.getStyleHandler();
+ Font westernFont = styleHandler.getFont(Document.ScriptType.WESTERN);
+ Font chineseFont = styleHandler.getFont(Document.ScriptType.CJK);
+ Font complexFont = styleHandler.getFont(Document.ScriptType.CTL);
+
+
+
+ The most simple way to set border is to create a border object and then set it to a cell object. Below code snippet illustrates how to set a cell object with four borders. +
+
+		cell = table.getCellByPosition("A1");
+ cell.setStringValue("four border");
+ Border border = new Border(Color.RED, 1, StyleTypeDefinitions.SupportedLinearMeasure.PT);
+ cell.setBorders(CellBordersType.ALL_FOUR, border);
+
+
+ Below code snippet illustrates how to set a cell object with left and right borders, top and bottom borders and diagonal lines. +
+
+		cell.setBorders(CellBordersType.LEFT_RIGHT, border);
+ cell.setBorders(CellBordersType.TOP_BOTTOM, border);
+ cell.setBorders(CellBordersType.DIAGONAL_LINES, border);
+
+
+ Below code snippet illustrates how to set a cell object with left border, top border and diagonal from bottom left to top right. +
+
+		cell.setBorders(CellBordersType.LEFT, border);
+ cell.setBorders(CellBordersType.TOP, border);
+ cell.setBorders(CellBordersType.DIAGONALBLTR, border);
+
+
+ Below code snippet illustrates how to get a border definition. +
+
+		Border thisBorder = cell.getBorder(CellBordersType.LEFT);
+ thisBorder = cell.getBorder(CellBordersType.TOP);
+ thisBorder = cell.getBorder(CellBordersType.DIAGONALBLTR);
+
+

+ +
+
+ +
+
+ +