incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r845662 - in /websites/staging/odftoolkit/trunk/content: ./ odftoolkit/simple/document/cookbook/Manipulate TextSearch.html
Date Wed, 09 Jan 2013 06:16:20 GMT
Author: buildbot
Date: Wed Jan  9 06:16:20 2013
New Revision: 845662

Log:
Staging update by buildbot for odftoolkit

Modified:
    websites/staging/odftoolkit/trunk/content/   (props changed)
    websites/staging/odftoolkit/trunk/content/odftoolkit/simple/document/cookbook/Manipulate
TextSearch.html

Propchange: websites/staging/odftoolkit/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Wed Jan  9 06:16:20 2013
@@ -1 +1 @@
-1430697
+1430698

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 Wed Jan  9 06:16:20 2013
@@ -120,6 +120,7 @@
         }       <br/>
 </pre>
 <br/><br/><strong><a href="#TextSelection" >TextSelection</a></strong>
+<br/><br/>
 <a href="#Get Index/Text of TextSelection" >Get Index/Text of TextSelection</a>
 <div class="bodytext">
         Run the following codes will get the text content of the searched String "good" and
the corresponding index in      the text document.
@@ -165,23 +166,95 @@
             pastesource.pasteAtEndOf(item);<br/>
         }<br/>
 </pre>
-<br/><a href="#Replace String" >Replace String</a>
+<br/><a href="#Replace String with String" >Replace String with String</a>
 <div class="bodytext">
 The following codes replace all the string "replacesource" with the string "replacedest"
in the text document.
 </div>
 <br/><pre class='code' id="code4">
         search2 = <span class='basic'>null</span>;<br/>
         search2 = <span class='modifier'>new</span> <span class='javaclass'>TextNavigation</span>("replacesource",
textdoc);<br/>
-        <span class='control'>if</span> (search3.hasNext()) {<br/>
-            <span class='javaclass'>TextSelection</span> item= (<span class='javaclass'>TextSelection</span>)
search3.nextSelection();<br/>
+        <span class='control'>while</span> (search2.hasNext()) {<br/>
+        <span class='javaclass'>TextSelection</span> item= (<span class='javaclass'>TextSelection</span>)
search2.nextSelection();<br/>
             item.replaceWith("replacedest");<br/>
         }       <br/>
 </pre>
+<br/><a href="#Replace String with Paragraph" >Replace String with Paragraph</a>
+<div class="bodytext">
+The following codes replace all the string "replacesource" with a paragraph which can be
in the same document or in a different document.
+</div>
+<br/><pre class='code' id="code5">
+        search2 = <span class='basic'>null</span>;<br/>
+        search2 = <span class='modifier'>new</span> <span class='javaclass'>TextNavigation</span>("replacesource",
textdoc);<br/>
+        <span class='control'>while</span> (search2.hasNext()) {<br/>
+            <span class='javaclass'>TextSelection</span> item= (<span class='javaclass'>TextSelection</span>)
search2.nextSelection();<br/>
+            <span class='javaclass'>Paragraph</span> paragraph = textdoc.getParagraphByIndex(0,
<span class='basic'>true</span>);<br/>
+            item.replaceWith(paragraph);<br/>
+        }       <br/>
+</pre>
+<br/><a href="#Replace String with Image" >Replace String with Image</a>
+<div class="bodytext">
+The following codes replace all the string "replacesource" with an image. There are two ways
to call the replaceWith method. You can use an image URI as parameter.
+</div>
+<br/><pre class='code' id="code6">
+        search2 = <span class='basic'>null</span>;<br/>
+        search2 = <span class='modifier'>new</span> <span class='javaclass'>TextNavigation</span>("replacesource",
textdoc);<br/>
+        <span class='control'>while</span> (search2.hasNext()) {<br/>
+            <span class='javaclass'>TextSelection</span> item= (<span class='javaclass'>TextSelection</span>)
search2.nextSelection();<br/>
+    <span class='comments'>     //Use URI as parameter.</span>
+            item.replaceWith(<span class='modifier'>new</span> <span class='javaclass'>URI</span>("image.png"));<br/>
+        }       <br/>     <br />
+</pre>
+<div class="bodytext">
+Or you can use an Image object as below:
+</div>
+<br/><pre class='code' id="code7">
+    <span class='comments'>     //Use Image as parameter.</span>
+            item.replaceWith(<span class='javaclass'>Image</span>.newImage(para,
<span class='modifier'>new</span> <span class='javaclass'>URI</span>("image.png")));<br/>
+</pre>
+<br/><a href="#Replace String with Table" >Replace String with Table</a>
+<div class="bodytext">
+The following codes replace all the string "replacesource" with a table named "myTable" in
the text document.
+</div>
+<br/><pre class='code' id="code8">
+        search2 = <span class='basic'>null</span>;<br/>
+        <span class='javaclass'>Table</span> table = textdoc.getTableByName("myTable");<br/>
+        search2 = <span class='modifier'>new</span> <span class='javaclass'>TextNavigation</span>("replacesource",
textdoc);<br/>
+        <span class='control'>while</span> (search2.hasNext()) {<br/>
+            <span class='javaclass'>TextSelection</span> item= (<span class='javaclass'>TextSelection</span>)
search2.nextSelection();<br/>
+            item.replaceWith(table);<br/>
+        }       <br/>
+</pre>
+<br/><a href="#Replace String with Field" >Replace String with Field</a>
+<div class="bodytext">
+The following codes replace all the string "replacesource" with a field named "myField" in
the text document.
+</div><br />
+<br/><pre class='code' id="code9">
+        search2 = <span class='basic'>null</span>;<br/>
+        <span class='javaclass'>Field</span> field = textdoc.getVariableFieldByName("myField");<br/>
+        search2 = <span class='modifier'>new</span> <span class='javaclass'>TextNavigation</span>("replacesource",
textdoc);<br/>
+        <span class='control'>while</span> (search2.hasNext()) {<br/>
+            <span class='javaclass'>TextSelection</span> item= (<span class='javaclass'>TextSelection</span>)
search2.nextSelection();<br/>
+            item.replaceWith(field);<br/>
+        }       <br/>
+</pre>
+<br/><a href="#Replace String with TextDocument" >Replace String with TextDocument</a>
+<div class="bodytext">
+The following codes replace all the string "replacesource" with the contents of the text
document named replacedest.odt.
+</div> 
+<br/><pre class='code' id="code10">
+        search2 = <span class='basic'>null</span>;<br/>
+        <span class='javaclass'>TextDocument</span> destDoc=<span class='javaclass'>TextDocument</span>.loadDocument("replacedest.odt");
    <br/>
+        search2 = <span class='modifier'>new</span> <span class='javaclass'>TextNavigation</span>("replacesource",
textdoc);<br/>
+        <span class='control'>while</span> (search2.hasNext()) {<br/>
+            <span class='javaclass'>TextSelection</span> item= (<span class='javaclass'>TextSelection</span>)
search2.nextSelection();<br/>
+            item.replaceWith(destDoc);<br/>
+        }       <br/>
+</pre>
 <br/><a href="#Add Reference to String" >Add Reference to String</a>
 <div class="bodytext">
         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".
 </div>
-<br/><pre class='code' id="code5">
+<br/><pre class='code' id="code11">
         search2 = <span class='basic'>null</span>;<br/>
         search2 = <span class='modifier'>new</span> <span class='javaclass'>TextNavigation</span>("network",
textdoc);<br/>
         <span class='control'>while</span> (search2.hasNext()) {<br/>
@@ -193,7 +266,7 @@ The following codes replace all the stri
 <div class="bodytext">
         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".
 </div>
-<br/><pre class='code' id="code6">
+<br/><pre class='code' id="code12">
         <span class='javaclass'>TextNavigation</span> search4 = <span class='modifier'>new</span>
<span class='javaclass'>TextNavigation</span>("natwork", textdoc);<br/>
         <span class='control'>while</span> (search4.hasNext()) {<br/>
             <span class='javaclass'>TextSelection</span> selection = (<span
class='javaclass'>TextSelection</span>) search4.nextSelection();<br/>
@@ -204,7 +277,7 @@ The following codes replace all the stri
 <div class="bodytext">
         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.
 </div>
-<br/><pre class='code' id="code7">
+<br/><pre class='code' id="code13">
         <span class='javaclass'>TextDocument</span> doc = <span class='javaclass'>TextDocument</span>.loadDocument("fieldSample.odt");<br/>
         <span class='javaclass'>TextNavigation</span> search = <span class='modifier'>new</span>
<span class='javaclass'>TextNavigation</span>("<span class='javaclass'>ReplaceDateTarget</span>",
doc);<br/>
         <span class='control'>while</span> (search.hasNext()) {<br/>
@@ -216,28 +289,28 @@ The following codes replace all the stri
 <br/><div class="bodytext">
         Following code can be used to search the document content, and replace with a condition
field.
 </div>
-<br/><pre class='code' id="code8">
+<br/><pre class='code' id="code14">
         <span class='javaclass'>TextSelection</span> item = (<span class='javaclass'>TextSelection</span>)
search.nextSelection();<br/>
         <span class='javaclass'>FieldSelection</span> fieldSelection = <span
class='modifier'>new</span> <span class='javaclass'>FieldSelection</span>(item);<br/>
-        fieldSelection.replaceWithConditionField("test_con_variable == "true"", "trueText",
"falseText");<br/>
+        fieldSelection.replaceWithConditionField("test_con_variable == \"true\"", "trueText",
"falseText");<br/>
 </pre>
 <br/><div class="bodytext">
         Following code can be used to replace with a hidden field.
 </div>
-<br/><pre class='code' id="code9">
-        fieldSelection.replaceWithHiddenTextField("test_con_variable == "true"", "hiddenText");<br/>
+<br/><pre class='code' id="code15">
+        fieldSelection.replaceWithHiddenTextField("test_con_variable == \"true\"", "hiddenText");<br/>
 </pre>
 <br/><div class="bodytext">
         Following code can be used to replace with a reference field.
 </div>
-<br/><pre class='code' id="code10">
+<br/><pre class='code' id="code16">
         <span class='javaclass'>ReferenceField</span> referenceField = <span
class='javaclass'>Fields</span>.createReferenceField(doc.addParagraph("span").getOdfElement(),
"selection-test-ref");<br/>
         fieldSelection.replaceWithReferenceField(referenceField, <span class='javaclass'>ReferenceField</span>.<span
class='javaclass'>DisplayType</span>.<span class='javaclass'>TEXT</span>);<br/>
 </pre>
 <br/><div class="bodytext">
         Following code can be used to replace with a variable field.
 </div>
-<br/><pre class='code' id="code11">
+<br/><pre class='code' id="code17">
         <span class='javaclass'>VariableField</span> userVariableField = <span
class='javaclass'>Fields</span>.createUserVariableField(doc, "selection_user_variable",
"test");<br/>
         fieldSelection.replaceWithVariableField(userVariableField);<br/>
 </pre>
@@ -245,7 +318,7 @@ The following codes replace all the stri
 <div class="bodytext">
         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.
 </div>
-<br/><pre class='code' id="code12">
+<br/><pre class='code' id="code18">
         <span class='javaclass'>TextStyleNavigation</span> searchStyle1;<br/>
         <span class='javaclass'>TreeMap</span>&lt;<span class='javaclass'>OdfStyleProperty</span>,
<span class='javaclass'>String</span>&gt; searchProps = <span class='modifier'>new</span>
<span class='javaclass'>TreeMap</span>&lt;<span class='javaclass'>OdfStyleProperty</span>,
<span class='javaclass'>String</span>&gt;();<br/>
         searchProps.put(<span class='javaclass'>StyleTextPropertiesElement</span>.<span
class='javaclass'>FontName</span>, "<span class='javaclass'>Times</span>
<span class='javaclass'>New</span> Roman1");<br/>



Mime
View raw message