incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r795160 - /websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo7.html
Date Fri, 02 Sep 2011 09:30:59 GMT
Author: buildbot
Date: Fri Sep  2 09:30:58 2011
New Revision: 795160

Log:
Staging update by buildbot

Modified:
    websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo7.html

Modified: websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo7.html
==============================================================================
--- websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo7.html (original)
+++ websites/staging/odftoolkit/trunk/content/odftoolkit/simple/demo/demo7.html Fri Sep  2 09:30:58 2011
@@ -78,224 +78,156 @@
   <div id="contenta">
   
     
-    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<link rel="stylesheet" href="../images/style.css" type="text/css" />
-<link type="text/css" rel="stylesheet" href="styles/shCoreEclipse.css"/>
-<title>Demos - SimpleODF</title>
-<style type="text/css">
-<!--
-.STYLE1 {
-    color: #FFFFFF;
-    font-size: 24px;
-}
-.STYLE2 {font-size: 32px}
-.STYLE3 {font-size: 16px}
-.STYLE4 {font-size: 36px}
--->
-</style>
-<script type="text/javascript" src="scripts/shCore.js"></script>  
-<script type="text/javascript" src="scripts/shBrushJava.js"></script>  
-<script type="text/javascript"> SyntaxHighlighter.all();</script>
-<script type="text/javascript">
-
-<p>var _gaq = _gaq || [];
-  _gaq.push(['_setAccount', 'UA-22366020-1']);
-  _gaq.push(['_trackPageview']);</p>
-<p>(function() {
-    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
-    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
-    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
-  })();</p>
-<p></script>
-</head>
-<body>
-<div id="page" align="center">
-  <div id="content" style="width:920px" class="contentpanel">
-    <div id="topheader">
-      <div class="topright"> </div>
-    </div>
-    <div id="menu">
-      <div align="left" class="smallwhitetext"> <a href="../index.html" class="home"> </a> <a href="../downloads.html" class="download"></a> <a href="../documents.html" class="document"></a> <a href="../demo/index.html" class="sample"> </a> </div>
-    </div>
-    <div id="subcontent" align ="left">
-        <div align="left" class="titletext"> <span >
-        <a href="index.html">Simple Demos<a> &gt; 
-        <a href="demo7.html">Demo 6: Offer Letter with Text Fields<a>
-        </span> 
-        </div></p>
-<div class="codehilite"><pre>    <span class="sr">&lt;!----------------------------------------------------------------------------------------------------&gt;</span>
+    <p><a href="index.html">Simple Demos<a> &gt; <b> Offer Letter with Text Fields</b> <br />
+</p>
+<p><strong>Overview</strong>  <br />
+</p>
+<p>We have introduced several samples about how to use Simple ODF API to generate document from the predefined templete, for example, Demo: <a href="demo3.html">Navigation API in Hotel Receipt</a>. I believe you have known how easy it is. But sounds like, we never talk about how to create a template document using  Simple ODF API. <br />
+</p>
+<p>Today, let's do it. <br />
+</p>
+<p>Simple API provides Fields API since version 0.5. OpenDocument text documents or OpenDocument text content embedded in other types of documents may contain variable text elements called fields. Fields are commonly used for, a page number field displays the number of the page on which it appears or a creation date field displays the date on which a document was created. Besides, there are several advance field, such as, variable field and condition field.    <br />
+</p>
+<p>This demo provides a Java application which can create the offer letter template document from a sample and use it to generate new offer letters with the information from a spreadsheet. The template document contains some fields whose content is decided by the information from data file.   <br />
+</p>
+<p>The following picture show a sample offer letter. I have labeled the variable content with blod and color style.  <br />
+</p>
+<p><img alt="image1" src="image/offer-letter-sample.png" />  <br />
+</p>
+<p>This offer was generated on "2011-01-20". It also can be in any other date, so this text content should be replaced by a date field. "Tom King" is the receiver, this name can be replaced with a variable field, then we can send it to any other perpson. Similarly, "software engineer" is the job title of "Tom King", "R&amp;D" is the branch which he belongs to, and "2011-03-12" is his onboard date, all of them should be replaced by variable field in a template document.<br/><br/> 
+Salary and allowance are more complex. Different job titles and branches have different rules. Simplicity, we assume that except "Secretary" is 5,500,00, all of the other job titles are 6,000.00. We also assume that employees from "Sales" don't have allowance. Condition field or Hidden Text field is needed to realize these rules. The same as certificates/testimonials, for campus hires, they need supply "Educational certificates", while for professinal hires, they need supply "Experience certificates from previous employers" and "Copy of resignation/acceptation letter and relieving letter". This is another use case of condition field.<br/><br/>
+After replaced all of these variable content with fields, the template document is ready. The process of generate new offer letter is very simple. Only need to load the following data, update the variable values with the data and save as a new document.  <br />
+</p>
+<p><img alt="image2" src="image/candidate-data.png" />  <br />
+</p>
+<p>No need text content search, no need target replace. It's faster than the content replace way. Beside, the variable content is highlighted automatically by Symphony or Open Office when the document is opend. The following is a generated letter sample.  <br />
+</p>
+<p><img alt="image3" src="image/generated-offer-letter.png" /></p>
+<p>As using fields, the new offer letter is easily updated without inconsistent, even though after generated. You can do it in Symphony or Open Office.
+Code Introduction
+There are two methods in the class, <code>createFieldTemplate()</code> is used to create template document from sample, and <code>generateOfferLetterDocument()</code> is used to generated new document using template and data file.  <br />
+</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">static</span> <span class="n">void</span> <span class="n">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
+    <span class="n">try</span> <span class="p">{</span>
+        <span class="sr">//</span> <span class="n">create</span> <span class="n">offer</span> <span class="n">letter</span> <span class="n">template</span> <span class="n">with</span> <span class="n">sample</span> <span class="n">offer</span> <span class="n">letter</span><span class="o">.</span>
+        <span class="n">createFieldTemplate</span><span class="p">();</span>
+        <span class="sr">//</span> <span class="n">generate</span> <span class="n">offer</span> <span class="n">letters</span> <span class="k">for</span> <span class="n">the</span> <span class="n">candidates</span> <span class="n">from</span> <span class="n">spreadsheet</span> <span class="n">document</span><span class="o">.</span>
+        <span class="n">generateOfferLetterDocument</span><span class="p">();</span>
+    <span class="p">}</span> <span class="n">catch</span> <span class="p">(</span><span class="n">Exception</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
+        <span class="n">e</span><span class="o">.</span><span class="n">printStackTrace</span><span class="p">();</span>
+    <span class="p">}</span>
+<span class="p">}</span>
 </pre></div>
 
 
-<p><div class="contenttitle">
-    <a name="overview">Overview</a>
-</div>
-<div class="bodytext">
-    <p> We have introduced several samples about how to use Simple ODF API to generate document from the predefined templete, for example, <a href="demo3.html"><img src="../images/link.png">Demo 3: Navigation API in Hotel Receipt</a>. I believe you have known how easy it is. But sounds like, we never talk about how to create a template document using  Simple ODF API. <br/><br/>
-Today, let's do it.<br/><br/>
-Simple ODF API provides Fields API since version 0.5. OpenDocument text documents or OpenDocument text content embedded in other types of documents may contain variable text elements called fields. Fields are commonly used for, a page number field displays the number of the page on which it appears or a creation date field displays the date on which a document was created. Besides, there are several advance field, such as, variable field and condition field.<br/><br/>
-This demo provides a Java application which can create the offer letter template document from a sample and use it to generate new offer letters with the information from a spreadsheet. The template document contains some fields whose content is decided by the information from data file.<br/><br/>
-The following picture show a sample offer letter. I have labeled the variable content with blod and color style.<br/><br/>
-<img src="image/offer-letter-sample.png" ><br/><br/> 
-This offer was generated on "2011-01-20". It also can be in any other date, so this text content should be replaced by a date field. "Tom King" is the receiver, this name can be replaced with a variable field, then we can send it to any other perpson. Similarly, "software engineer" is the job title of "Tom King", "R&amp;D" is the branch which he belongs to, and "2011-03-12" is his onboard date, all of them should be replaced by variable field in a template document.<br/><br/> 
-Salary and allowance are more complex. Different job titles and branches have different rules. Simplicity, we assume that except "Secretary" is 5,500,00, all of the other job titles are 6,000.00. We also assume that employees from "Sales" don't have allowance. Condition field or Hidden Text field is needed to realize these rules. The same as certificates/testimonials, for campus hires, they need supply "Educational certificates", while for professinal hires, they need supply "Experience certificates from previous employers" and "Copy of resignation/acceptation letter and relieving letter". This is another use case of condition field.<br/><br/>
-After replaced all of these variable content with fields, the template document is ready. The process of generate new offer letter is very simple. Only need to load the following data, update the variable values with the data and save as a new document. <br/><br/>
-<img src="image/candidate-data.png" ><br/><br/>
-No need text content search, no need target replace. It's faster than the content replace way. Beside, the variable content is highlighted automatically by Symphony or Open Office when the document is opend. The following is a generated letter sample.<br/><br/>
-<img src="image/generated-offer-letter.png" ><br/><br/>
-As using fields, the new offer letter is easily updated without inconsistent, even though after generated. You can do it in Symphony or Open Office.
-</p>
-</div>
-<hr/>
-<div class="contenttitle">
-    <a name="codeintroduction">Code Introduction</a>
-</div>
-<div class="bodytext">
-    <p>
-    There are two methods in the class, <code>createFieldTemplate()</code> is used to create template document from sample, and <code>generateOfferLetterDocument()</code> is used to generated new document using template and data file.<br/>
-    <!--java code-->
-    <pre class="brush:java;">
-    public static void main(String[] args) {
-        try {
-            // create offer letter template with sample offer letter.
-            createFieldTemplate();
-            // generate offer letters for the candidates from spreadsheet document.
-            generateOfferLetterDocument();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-    </pre>
-    </p>
-    <p>Below is the source code of method <code>createFieldTemplate()</code>. The basic process is find the variable content and replace it with a field. We use <code>FixedDateField</code>, <code>UserVariableField</code>, <code>ConditionField</code> and <code>HiddenTextField</code> in this method. Simple ODF API provides more types of fields. For more information, please reference the <a href="../javadoc/index.html"><img src="../images/link.png"></img>Javadoc</a> or <a href="../cookbook/index.html"><img src="../images/link.png"></img>CookBook</a>.<br/>
-    <!--java code-->
-    <pre class="brush:java;">
-    public static void createFieldTemplate() throws Exception {
-        TextDocument sampleDocument = TextDocument.loadDocument("Tom's Offer.odt");
-        // replace offer date with FixedDateField
-        TextNavigation search = new TextNavigation("2011-01-20", sampleDocument);
-        while (search.hasNext()) {
-            TextSelection item = (TextSelection) search.nextSelection();
-            FieldSelection fieldSelection = new FieldSelection(item);
-            fieldSelection.replaceWithSimpleField(Field.FieldType.FIXED_DATE_FIELD);
-        }
-        // replace candidate name with UserVariableField
-        VariableField candidateVar = Fields.createUserVariableField(sampleDocument, "candidateVar", "Tom King");
-        search = new TextNavigation("Tom King", sampleDocument);
-        while (search.hasNext()) {
-            TextSelection item = (TextSelection) search.nextSelection();
-            FieldSelection fieldSelection = new FieldSelection(item);
-            fieldSelection.replaceWithVariableField(candidateVar);
-        }
-        // replace job title with UserVariableField
-        VariableField jobTitleVar = Fields.createUserVariableField(sampleDocument, "jobTitleVar", "software engineer");
-        search = new TextNavigation("software engineer", sampleDocument);
-        while (search.hasNext()) {
-            TextSelection item = (TextSelection) search.nextSelection();
-            FieldSelection fieldSelection = new FieldSelection(item);
-            fieldSelection.replaceWithVariableField(jobTitleVar);
-        }
-        // replace branch with UserVariableField
-        VariableField branchVar = Fields.createUserVariableField(sampleDocument, "branchVar", "R&amp;D");
-        search = new TextNavigation("R&amp;D", sampleDocument);
-        while (search.hasNext()) {
-            TextSelection item = (TextSelection) search.nextSelection();
-            FieldSelection fieldSelection = new FieldSelection(item);
-            fieldSelection.replaceWithVariableField(branchVar);
-        }
-        // replace onboard date with UserVariableField
-        VariableField onBoardDateVar = Fields.createUserVariableField(sampleDocument, "onBoardDateVar", "2011-03-12");
-        search = new TextNavigation("2011-03-12", sampleDocument);
-        while (search.hasNext()) {
-            TextSelection item = (TextSelection) search.nextSelection();
-            FieldSelection fieldSelection = new FieldSelection(item);
-            fieldSelection.replaceWithVariableField(onBoardDateVar);
-        }
-        // replace salary with ConditionField
-        search = new TextNavigation("6,000.00", sampleDocument);
-        while (search.hasNext()) {
-            TextSelection item = (TextSelection) search.nextSelection();
-            FieldSelection fieldSelection = new FieldSelection(item);
-            fieldSelection.replaceWithConditionField("jobTitleVar != "Secretary"", "6,000.00", "5,500.00");
-        }
-        // replace consolidated allowance with HiddenTextField
-        search = new TextNavigation(" and a Consolidated Allowance of 400\$ per month", sampleDocument);
-        while (search.hasNext()) {
-            TextSelection item = (TextSelection) search.nextSelection();
-            FieldSelection fieldSelection = new FieldSelection(item);
-            fieldSelection.replaceWithHiddenTextField("branchVar == "Sales"", " and a Consolidated Allowance of 400$ per month");
-        }
-        // replace certificates/testimonials with ConditionField
-        Fields.createUserVariableField(sampleDocument, "campusHireVar", "N");
-        search = new TextNavigation("\<em> Educational certificates", sampleDocument);
-        while (search.hasNext()) {
-            TextSelection item = (TextSelection) search.nextSelection();
-            FieldSelection fieldSelection = new FieldSelection(item);
-            fieldSelection
-                    .replaceWithConditionField(
-                            "campusHireVar == "Y"",
-                            "</em> Educational certificates",
-                            "<em> Experience certificates from previous employersn</em> Copy of resignation/acceptation letter and relieving letter");
-        }
-        sampleDocument.save("OfferTemplate.odt");
-    }
-    </pre>
-</p>
-<p>Method <code>generateOfferLetterDocument()</code> is easier. Just load the template document and data docuemnt and fill new value to all of the variables. <code>getVariableFieldByName()</code> is a method of <code>VariableContainer</code> used to iterate variable field by name.
-<br/>
-    <!--java code-->
-    <pre class="brush:java;">
-    public static void generateOfferLetterDocument() throws Exception {
-        TextDocument templateDocument = TextDocument.loadDocument("OfferTemplate.odt");
-        SpreadsheetDocument dataDocument = SpreadsheetDocument.loadDocument("Candidates.ods");
-        Table table = dataDocument.getTableByName("Sheet1");
-        int rowCount = table.getRowCount();
-        for(int i = 1; i &amp;lt rowCount; i++)
-        {
-            Row row = table.getRowByIndex(i);
-            String name = row.getCellByIndex(0).getDisplayText();
-            VariableField candidateVar = templateDocument.getVariableFieldByName("candidateVar");
-            candidateVar.updateField(name, null);
-            String jobTitle = row.getCellByIndex(1).getDisplayText();
-            VariableField jobTitleVar = templateDocument.getVariableFieldByName("jobTitleVar");
-            jobTitleVar.updateField(jobTitle, null);
-            String branch = row.getCellByIndex(2).getDisplayText();
-            VariableField branchVar = templateDocument.getVariableFieldByName("branchVar");
-            branchVar.updateField(branch, null);
-            String isCampusHire = row.getCellByIndex(3).getDisplayText();
-            VariableField campusHireVar = templateDocument.getVariableFieldByName("campusHireVar");
-            campusHireVar.updateField(isCampusHire, null);
-            String onBoradDate = row.getCellByIndex(4).getDisplayText();
-            VariableField onBoardDateVar = templateDocument.getVariableFieldByName("onBoardDateVar");
-            onBoardDateVar.updateField(onBoradDate, null);
-            templateDocument.save(name+"'s offer letter.odt");
-        }
-    }
-    </pre>
-</p>
-</div>
-<hr/>
-<div class="contenttitle">
-    <a name="download">Download</a>
-</div>
-<div class="bodytext">
-  <p>
-    Powered by the Simple Java API for ODF version  <a target="_new" href="../downloads.html"><img src="../images/link.png"></img>0.5</a>.
-  </p>
-  <p>
-    You can download the code of this demo from <a href="demo7.zip"><img src="../images/link.png"></img>here</a>.
-  </p>
-</div>
-<!---------------------------------------------------------------------------------------------------->   <br />
-</div>
-<div id="footer" class="smallgraytext"> <a href="#">Home</a> | <a href="#">About Us</a> | <a href="#">Contact Us</a> </div>
-</div>
-</div>
-</body>
-</html> </p>
+<p>Below is the source code of method <code>createFieldTemplate()</code>. The basic process is find the variable content and replace it with a field. We use <code>FixedDateField</code>, <code>UserVariableField</code>, <code>ConditionField</code> and <code>HiddenTextField</code> in this method. Simple ODF API provides more types of fields. For more information, please reference the <a href="../javadoc/index.html">Javadoc</a> or <a href="../cookbook/index.html">CookBook</a>.<br />
+</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">static</span> <span class="n">void</span> <span class="n">createFieldTemplate</span><span class="p">()</span> <span class="n">throws</span> <span class="n">Exception</span> <span class="p">{</span>
+    <span class="n">TextDocument</span> <span class="n">sampleDocument</span> <span class="o">=</span> <span class="n">TextDocument</span><span class="o">.</span><span class="n">loadDocument</span><span class="p">(</span><span class="s">&quot;Tom&#39;s Offer.odt&quot;</span><span class="p">);</span>
+    <span class="sr">//</span> <span class="n">replace</span> <span class="n">offer</span> <span class="n">date</span> <span class="n">with</span> <span class="n">FixedDateField</span>
+    <span class="n">TextNavigation</span> <span class="n">search</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TextNavigation</span><span class="p">(</span><span class="s">&quot;2011-01-20&quot;</span><span class="p">,</span> <span class="n">sampleDocument</span><span class="p">);</span>
+    <span class="k">while</span> <span class="p">(</span><span class="n">search</span><span class="o">.</span><span class="n">hasNext</span><span class="p">())</span> <span class="p">{</span>
+        <span class="n">TextSelection</span> <span class="n">item</span> <span class="o">=</span> <span class="p">(</span><span class="n">TextSelection</span><span class="p">)</span> <span class="n">search</span><span class="o">.</span><span class="n">nextSelection</span><span class="p">();</span>
+        <span class="n">FieldSelection</span> <span class="n">fieldSelection</span> <span class="o">=</span> <span class="k">new</span> <span class="n">FieldSelection</span><span class="p">(</span><span class="n">item</span><span class="p">);</span>
+        <span class="n">fieldSelection</span><span class="o">.</span><span class="n">replaceWithSimpleField</span><span class="p">(</span><span class="n">Field</span><span class="o">.</span><span class="n">FieldType</span><span class="o">.</span><span class="n">FIXED_DATE_FIELD</span><span class="p">);</span>
+    <span class="p">}</span>
+    <span class="sr">//</span> <span class="n">replace</span> <span class="n">candidate</span> <span class="n">name</span> <span class="n">with</span> <span class="n">UserVariableField</span>
+    <span class="n">VariableField</span> <span class="n">candidateVar</span> <span class="o">=</span> <span class="n">Fields</span><span class="o">.</span><span class="n">createUserVariableField</span><span class="p">(</span><span class="n">sampleDocument</span><span class="p">,</span> <span class="s">&quot;candidateVar&quot;</span><span class="p">,</span> <span class="s">&quot;Tom King&quot;</span><span class="p">);</span>
+    <span class="n">search</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TextNavigation</span><span class="p">(</span><span class="s">&quot;Tom King&quot;</span><span class="p">,</span> <span class="n">sampleDocument</span><span class="p">);</span>
+    <span class="k">while</span> <span class="p">(</span><span class="n">search</span><span class="o">.</span><span class="n">hasNext</span><span class="p">())</span> <span class="p">{</span>
+        <span class="n">TextSelection</span> <span class="n">item</span> <span class="o">=</span> <span class="p">(</span><span class="n">TextSelection</span><span class="p">)</span> <span class="n">search</span><span class="o">.</span><span class="n">nextSelection</span><span class="p">();</span>
+        <span class="n">FieldSelection</span> <span class="n">fieldSelection</span> <span class="o">=</span> <span class="k">new</span> <span class="n">FieldSelection</span><span class="p">(</span><span class="n">item</span><span class="p">);</span>
+        <span class="n">fieldSelection</span><span class="o">.</span><span class="n">replaceWithVariableField</span><span class="p">(</span><span class="n">candidateVar</span><span class="p">);</span>
+    <span class="p">}</span>
+    <span class="sr">//</span> <span class="n">replace</span> <span class="n">job</span> <span class="n">title</span> <span class="n">with</span> <span class="n">UserVariableField</span>
+    <span class="n">VariableField</span> <span class="n">jobTitleVar</span> <span class="o">=</span> <span class="n">Fields</span><span class="o">.</span><span class="n">createUserVariableField</span><span class="p">(</span><span class="n">sampleDocument</span><span class="p">,</span> <span class="s">&quot;jobTitleVar&quot;</span><span class="p">,</span> <span class="s">&quot;software engineer&quot;</span><span class="p">);</span>
+    <span class="n">search</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TextNavigation</span><span class="p">(</span><span class="s">&quot;software engineer&quot;</span><span class="p">,</span> <span class="n">sampleDocument</span><span class="p">);</span>
+    <span class="k">while</span> <span class="p">(</span><span class="n">search</span><span class="o">.</span><span class="n">hasNext</span><span class="p">())</span> <span class="p">{</span>
+        <span class="n">TextSelection</span> <span class="n">item</span> <span class="o">=</span> <span class="p">(</span><span class="n">TextSelection</span><span class="p">)</span> <span class="n">search</span><span class="o">.</span><span class="n">nextSelection</span><span class="p">();</span>
+        <span class="n">FieldSelection</span> <span class="n">fieldSelection</span> <span class="o">=</span> <span class="k">new</span> <span class="n">FieldSelection</span><span class="p">(</span><span class="n">item</span><span class="p">);</span>
+        <span class="n">fieldSelection</span><span class="o">.</span><span class="n">replaceWithVariableField</span><span class="p">(</span><span class="n">jobTitleVar</span><span class="p">);</span>
+    <span class="p">}</span>
+    <span class="sr">//</span> <span class="n">replace</span> <span class="n">branch</span> <span class="n">with</span> <span class="n">UserVariableField</span>
+    <span class="n">VariableField</span> <span class="n">branchVar</span> <span class="o">=</span> <span class="n">Fields</span><span class="o">.</span><span class="n">createUserVariableField</span><span class="p">(</span><span class="n">sampleDocument</span><span class="p">,</span> <span class="s">&quot;branchVar&quot;</span><span class="p">,</span> <span class="s">&quot;R&amp;D&quot;</span><span class="p">);</span>
+    <span class="n">search</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TextNavigation</span><span class="p">(</span><span class="s">&quot;R&amp;D&quot;</span><span class="p">,</span> <span class="n">sampleDocument</span><span class="p">);</span>
+    <span class="k">while</span> <span class="p">(</span><span class="n">search</span><span class="o">.</span><span class="n">hasNext</span><span class="p">())</span> <span class="p">{</span>
+        <span class="n">TextSelection</span> <span class="n">item</span> <span class="o">=</span> <span class="p">(</span><span class="n">TextSelection</span><span class="p">)</span> <span class="n">search</span><span class="o">.</span><span class="n">nextSelection</span><span class="p">();</span>
+        <span class="n">FieldSelection</span> <span class="n">fieldSelection</span> <span class="o">=</span> <span class="k">new</span> <span class="n">FieldSelection</span><span class="p">(</span><span class="n">item</span><span class="p">);</span>
+        <span class="n">fieldSelection</span><span class="o">.</span><span class="n">replaceWithVariableField</span><span class="p">(</span><span class="n">branchVar</span><span class="p">);</span>
+    <span class="p">}</span>
+    <span class="sr">//</span> <span class="n">replace</span> <span class="n">onboard</span> <span class="n">date</span> <span class="n">with</span> <span class="n">UserVariableField</span>
+    <span class="n">VariableField</span> <span class="n">onBoardDateVar</span> <span class="o">=</span> <span class="n">Fields</span><span class="o">.</span><span class="n">createUserVariableField</span><span class="p">(</span><span class="n">sampleDocument</span><span class="p">,</span> <span class="s">&quot;onBoardDateVar&quot;</span><span class="p">,</span> <span class="s">&quot;2011-03-12&quot;</span><span class="p">);</span>
+    <span class="n">search</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TextNavigation</span><span class="p">(</span><span class="s">&quot;2011-03-12&quot;</span><span class="p">,</span> <span class="n">sampleDocument</span><span class="p">);</span>
+    <span class="k">while</span> <span class="p">(</span><span class="n">search</span><span class="o">.</span><span class="n">hasNext</span><span class="p">())</span> <span class="p">{</span>
+        <span class="n">TextSelection</span> <span class="n">item</span> <span class="o">=</span> <span class="p">(</span><span class="n">TextSelection</span><span class="p">)</span> <span class="n">search</span><span class="o">.</span><span class="n">nextSelection</span><span class="p">();</span>
+        <span class="n">FieldSelection</span> <span class="n">fieldSelection</span> <span class="o">=</span> <span class="k">new</span> <span class="n">FieldSelection</span><span class="p">(</span><span class="n">item</span><span class="p">);</span>
+        <span class="n">fieldSelection</span><span class="o">.</span><span class="n">replaceWithVariableField</span><span class="p">(</span><span class="n">onBoardDateVar</span><span class="p">);</span>
+    <span class="p">}</span>
+    <span class="sr">//</span> <span class="n">replace</span> <span class="n">salary</span> <span class="n">with</span> <span class="n">ConditionField</span>
+    <span class="n">search</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TextNavigation</span><span class="p">(</span><span class="s">&quot;6,000.00&quot;</span><span class="p">,</span> <span class="n">sampleDocument</span><span class="p">);</span>
+    <span class="k">while</span> <span class="p">(</span><span class="n">search</span><span class="o">.</span><span class="n">hasNext</span><span class="p">())</span> <span class="p">{</span>
+        <span class="n">TextSelection</span> <span class="n">item</span> <span class="o">=</span> <span class="p">(</span><span class="n">TextSelection</span><span class="p">)</span> <span class="n">search</span><span class="o">.</span><span class="n">nextSelection</span><span class="p">();</span>
+        <span class="n">FieldSelection</span> <span class="n">fieldSelection</span> <span class="o">=</span> <span class="k">new</span> <span class="n">FieldSelection</span><span class="p">(</span><span class="n">item</span><span class="p">);</span>
+        <span class="n">fieldSelection</span><span class="o">.</span><span class="n">replaceWithConditionField</span><span class="p">(</span><span class="s">&quot;jobTitleVar != \&quot;Secretary\&quot;&quot;</span><span class="p">,</span> <span class="s">&quot;6,000.00&quot;</span><span class="p">,</span> <span class="s">&quot;5,500.00&quot;</span><span class="p">);</span>
+    <span class="p">}</span>
+    <span class="sr">//</span> <span class="n">replace</span> <span class="n">consolidated</span> <span class="n">allowance</span> <span class="n">with</span> <span class="n">HiddenTextField</span>
+    <span class="n">search</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TextNavigation</span><span class="p">(</span><span class="s">&quot; and a Consolidated Allowance of 400\\$ per month&quot;</span><span class="p">,</span> <span class="n">sampleDocument</span><span class="p">);</span>
+    <span class="k">while</span> <span class="p">(</span><span class="n">search</span><span class="o">.</span><span class="n">hasNext</span><span class="p">())</span> <span class="p">{</span>
+        <span class="n">TextSelection</span> <span class="n">item</span> <span class="o">=</span> <span class="p">(</span><span class="n">TextSelection</span><span class="p">)</span> <span class="n">search</span><span class="o">.</span><span class="n">nextSelection</span><span class="p">();</span>
+        <span class="n">FieldSelection</span> <span class="n">fieldSelection</span> <span class="o">=</span> <span class="k">new</span> <span class="n">FieldSelection</span><span class="p">(</span><span class="n">item</span><span class="p">);</span>
+        <span class="n">fieldSelection</span><span class="o">.</span><span class="n">replaceWithHiddenTextField</span><span class="p">(</span><span class="s">&quot;branchVar == \&quot;Sales\&quot;&quot;</span><span class="p">,</span> <span class="s">&quot; and a Consolidated Allowance of 400$ per month&quot;</span><span class="p">);</span>
+    <span class="p">}</span>
+    <span class="sr">//</span> <span class="n">replace</span> <span class="n">certificates</span><span class="o">/</span><span class="n">testimonials</span> <span class="n">with</span> <span class="n">ConditionField</span>
+    <span class="n">Fields</span><span class="o">.</span><span class="n">createUserVariableField</span><span class="p">(</span><span class="n">sampleDocument</span><span class="p">,</span> <span class="s">&quot;campusHireVar&quot;</span><span class="p">,</span> <span class="s">&quot;N&quot;</span><span class="p">);</span>
+    <span class="n">search</span> <span class="o">=</span> <span class="k">new</span> <span class="n">TextNavigation</span><span class="p">(</span><span class="s">&quot;\\* Educational certificates&quot;</span><span class="p">,</span> <span class="n">sampleDocument</span><span class="p">);</span>
+    <span class="k">while</span> <span class="p">(</span><span class="n">search</span><span class="o">.</span><span class="n">hasNext</span><span class="p">())</span> <span class="p">{</span>
+        <span class="n">TextSelection</span> <span class="n">item</span> <span class="o">=</span> <span class="p">(</span><span class="n">TextSelection</span><span class="p">)</span> <span class="n">search</span><span class="o">.</span><span class="n">nextSelection</span><span class="p">();</span>
+        <span class="n">FieldSelection</span> <span class="n">fieldSelection</span> <span class="o">=</span> <span class="k">new</span> <span class="n">FieldSelection</span><span class="p">(</span><span class="n">item</span><span class="p">);</span>
+        <span class="n">fieldSelection</span>
+                <span class="o">.</span><span class="n">replaceWithConditionField</span><span class="p">(</span>
+                        <span class="s">&quot;campusHireVar == \&quot;Y\&quot;&quot;</span><span class="p">,</span>
+                        <span class="s">&quot;* Educational certificates&quot;</span><span class="p">,</span>
+                        <span class="s">&quot;* Experience certificates from previous employers\n* Copy of resignation/acceptation letter and relieving letter&quot;</span><span class="p">);</span>
+    <span class="p">}</span>
+    <span class="n">sampleDocument</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="s">&quot;OfferTemplate.odt&quot;</span><span class="p">);</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p>Method <code>generateOfferLetterDocument()</code> is easier. Just load the template document and data docuemnt and fill new value to all of the variables. <code>getVariableFieldByName()</code> is a method of <code>VariableContainer</code> used to iterate variable field by name.</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">static</span> <span class="n">void</span> <span class="n">generateOfferLetterDocument</span><span class="p">()</span> <span class="n">throws</span> <span class="n">Exception</span> <span class="p">{</span>
+    <span class="n">TextDocument</span> <span class="n">templateDocument</span> <span class="o">=</span> <span class="n">TextDocument</span><span class="o">.</span><span class="n">loadDocument</span><span class="p">(</span><span class="s">&quot;OfferTemplate.odt&quot;</span><span class="p">);</span>
+    <span class="n">SpreadsheetDocument</span> <span class="n">dataDocument</span> <span class="o">=</span> <span class="n">SpreadsheetDocument</span><span class="o">.</span><span class="n">loadDocument</span><span class="p">(</span><span class="s">&quot;Candidates.ods&quot;</span><span class="p">);</span>
+    <span class="n">Table</span> <span class="n">table</span> <span class="o">=</span> <span class="n">dataDocument</span><span class="o">.</span><span class="n">getTableByName</span><span class="p">(</span><span class="s">&quot;Sheet1&quot;</span><span class="p">);</span>
+    <span class="nb">int</span> <span class="n">rowCount</span> <span class="o">=</span> <span class="n">table</span><span class="o">.</span><span class="n">getRowCount</span><span class="p">();</span>
+    <span class="k">for</span><span class="p">(</span><span class="nb">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o">&amp;</span><span class="ow">lt</span> <span class="n">rowCount</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
+    <span class="p">{</span>
+        <span class="n">Row</span> <span class="n">row</span> <span class="o">=</span> <span class="n">table</span><span class="o">.</span><span class="n">getRowByIndex</span><span class="p">(</span><span class="n">i</span><span class="p">);</span>
+        <span class="n">String</span> <span class="n">name</span> <span class="o">=</span> <span class="n">row</span><span class="o">.</span><span class="n">getCellByIndex</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">getDisplayText</span><span class="p">();</span>
+        <span class="n">VariableField</span> <span class="n">candidateVar</span> <span class="o">=</span> <span class="n">templateDocument</span><span class="o">.</span><span class="n">getVariableFieldByName</span><span class="p">(</span><span class="s">&quot;candidateVar&quot;</span><span class="p">);</span>
+        <span class="n">candidateVar</span><span class="o">.</span><span class="n">updateField</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+        <span class="n">String</span> <span class="n">jobTitle</span> <span class="o">=</span> <span class="n">row</span><span class="o">.</span><span class="n">getCellByIndex</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">getDisplayText</span><span class="p">();</span>
+        <span class="n">VariableField</span> <span class="n">jobTitleVar</span> <span class="o">=</span> <span class="n">templateDocument</span><span class="o">.</span><span class="n">getVariableFieldByName</span><span class="p">(</span><span class="s">&quot;jobTitleVar&quot;</span><span class="p">);</span>
+        <span class="n">jobTitleVar</span><span class="o">.</span><span class="n">updateField</span><span class="p">(</span><span class="n">jobTitle</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+        <span class="n">String</span> <span class="n">branch</span> <span class="o">=</span> <span class="n">row</span><span class="o">.</span><span class="n">getCellByIndex</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">getDisplayText</span><span class="p">();</span>
+        <span class="n">VariableField</span> <span class="n">branchVar</span> <span class="o">=</span> <span class="n">templateDocument</span><span class="o">.</span><span class="n">getVariableFieldByName</span><span class="p">(</span><span class="s">&quot;branchVar&quot;</span><span class="p">);</span>
+        <span class="n">branchVar</span><span class="o">.</span><span class="n">updateField</span><span class="p">(</span><span class="n">branch</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+        <span class="n">String</span> <span class="n">isCampusHire</span> <span class="o">=</span> <span class="n">row</span><span class="o">.</span><span class="n">getCellByIndex</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">getDisplayText</span><span class="p">();</span>
+        <span class="n">VariableField</span> <span class="n">campusHireVar</span> <span class="o">=</span> <span class="n">templateDocument</span><span class="o">.</span><span class="n">getVariableFieldByName</span><span class="p">(</span><span class="s">&quot;campusHireVar&quot;</span><span class="p">);</span>
+        <span class="n">campusHireVar</span><span class="o">.</span><span class="n">updateField</span><span class="p">(</span><span class="n">isCampusHire</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+        <span class="n">String</span> <span class="n">onBoradDate</span> <span class="o">=</span> <span class="n">row</span><span class="o">.</span><span class="n">getCellByIndex</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">getDisplayText</span><span class="p">();</span>
+        <span class="n">VariableField</span> <span class="n">onBoardDateVar</span> <span class="o">=</span> <span class="n">templateDocument</span><span class="o">.</span><span class="n">getVariableFieldByName</span><span class="p">(</span><span class="s">&quot;onBoardDateVar&quot;</span><span class="p">);</span>
+        <span class="n">onBoardDateVar</span><span class="o">.</span><span class="n">updateField</span><span class="p">(</span><span class="n">onBoradDate</span><span class="p">,</span> <span class="n">null</span><span class="p">);</span>
+        <span class="n">templateDocument</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">name</span><span class="o">+</span><span class="s">&quot;&#39;s offer letter.odt&quot;</span><span class="p">);</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
+<p><strong>Download</strong><br />
+</p>
+<p>Powered by the Simple Java API for ODF version <a href="../downloads.html">0.5</a>. <br />
+You can download the code of this demo from <a href="demo7.zip">here</a>.</p>
   </div>
 
   <div id="footera">



Mime
View raw message