Hi Ahmed,

I think I found the reason for the problem:
I see the directories of the embedded documents are within your created
document /ODF Samples/gen/fields_demo/AllOffersODFDoc.odt
It seems your problem is that you are not referencing to them from the
content.xml therefore you do not see them in Apache OpenOffice.
Take a look by trying it how the content.xml should look like to
reference and than you need to see if there is already a convenient API
or you need to modulate the content.

PS: If you need an example how to create a test, take a look at my
comment how to create a test:
https://issues.apache.org/jira/browse/ODFTOOLKIT-388?focusedCommentId=13969408&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13969408

The tests within odfdom (or simple) API are beyond
    odftoolkit20140415/simple/src/test/java/org/odftoolkit/simple

The directory structure is derived from Maven, a 5min summary is here:
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Best regards,
Svante

Am 15.04.2014 11:15, schrieb Svante Schubert:
> Hi Rob,
>
> any idea, why the demos of the simple API (e.g.
> http://incubator.apache.org/odftoolkit/simple/demo/demo7.html)
> are not part of the source code repository?
>
> Wouldn't it be nice to have them as part of the regression tests?
>
> @Ahmed: Due to obstacle mentioned above, you need to debug yourself in
> the ODFDOM class OdfPackageDocument the following function:
>
>     /**
>      * Embed an OdfPackageDocument to the current OdfPackageDocument.
>      * All the file entries of child document will be embedded as well
> to the current document package.
>      * @param newDocument the OdfPackageDocument to be embedded.
>      * @param documentPath to the directory the ODF document should be
> inserted (relative to the root of this document).     
>      */
>     public void insertDocument(OdfPackageDocument newDocument, String
> documentPath) {
>         newDocument.flushDoms();
>         mPackage.insertDocument(newDocument, mDocumentPathInPackage +
> documentPath);
>     }
>
> The function is being called from the following tests:
>
>   * DocumentCreationTest.java
>   * LoadSaveErrorTest.java
>   * LoadSaveTest.java
>
> PS: A little history, the simple API was once an IBM "branch", in
> general I focus on supporting the lower ODFDOM library.
>
> Hope this helps already,
> Svante
>
>
> Am 15.04.2014 10:49, schrieb Ahmed I Ibrahim:
>> Dear all,
>>
>> Sorry for my previous mail, it had more details but my editor just get rid 
>> of them. Any way it sent the important part which is the code.
>>
>> I still have the problem and actually the problem is simple. I need to 
>> merge a set of text documents into one text document. To regenerate my 
>> problem, I modified the demo7  available at
>> http://incubator.apache.org/odftoolkit/simple/demo/demo7.html
>>
>> This demo is generating a set of documents and I modified it to also merge 
>> these documents into one document. I used two methods to do so:
>>
>> One by using  org.odftoolkit.simple.TextDocument as following:
>>
>>         public static void generateAllOffersLetterTextDocument() throws 
>> Exception {
>>                 TextDocument templateDocument = TextDocument.loadDocument(
>> fRootDirectory + "/"+ "OfferTemplate.odt");
>>  
>>                 SpreadsheetDocument dataDocument = SpreadsheetDocument.
>> loadDocument(fRootDirectory + "/"+ "Candidates.ods");
>>                 Table table = dataDocument.getTableByName("Sheet1");
>>                 int rowCount = table.getRowCount();
>>  
>>                 TextDocument offerDoc = null;
>>                 for(int i = 1; i<rowCount; i++){
>>                         Row row = table.getRowByIndex(i);
>>                         String name = 
>> row.getCellByIndex(0).getDisplayText();
>>  
>>                         offerDoc = TextDocument.loadDocument(fOutDirectory 
>> + "/" + name+"'s offer letter.odt");
>>                         templateDocument.insertDocument(offerDoc, "/" + 
>> name);
>>                 }
>>  
>>                 templateDocument.save(fOutDirectory + 
>> "/AllOffersTextDoc.odt");
>>         }
>>
>> And the other way is by extending 
>> org.odftoolkit.odfdom.doc.OdfTextDocument by a new class MyTextDocument to 
>> do exactly the same thing as follows:
>>
>>         public static void generateAllOffersODFDocument () throws 
>> Exception {
>>                 MyTextDocument allDocTextDoc = MyTextDocument.
>> newTextWorkProduct(fRootDirectory + "/"+ "OfferTemplate.ott");
>>  
>>                 SpreadsheetDocument dataDocument = SpreadsheetDocument.
>> loadDocument(fRootDirectory + "/"+ "Candidates.ods");
>>                 Table table = dataDocument.getTableByName("Sheet1");
>>                 int rowCount = table.getRowCount();
>>  
>>                 for(int i = 1; i<rowCount; i++){
>>                         Row row = table.getRowByIndex(i);
>>                         String name = 
>> row.getCellByIndex(0).getDisplayText();
>>  
>>                         allDocTextDoc.includeFile(fOutDirectory + "/" + 
>> name+"'s offer letter.odt", "/" + name);
>>                 }
>>
>>  
>>                 allDocTextDoc.save (fOutDirectory + "/AllOffersODFDoc.odt"
>> );
>>         }
>>
>> While the includeFile is as follows:
>>
>>         public void includeFile (String filePath, String documentPath) 
>> throws Exception{
>>                 OdfPackageDocument newDocument;
>>  
>>                 try {
>>                         newDocument = OdfPackageDocument.loadDocument
>> (filePath);
>>                         insertDocument(newDocument, documentPath);
>>                 } catch (Exception exception) {
>>                         throw new Exception ("Failed to include the file: 
>> " + filePath, exception);
>>                 }
>>         }
>>
>> The results were exactly the same, the generated files didn't show the 
>> agregated documents, only the first contents of the document, however the 
>> conetns of the documents are inserted in their coresponding folders in the 
>> zip file. 
>>
>> In the attached zip file in the previous message, I included the source 
>> code (FieldsDemo.java and MyTextDocument.java) as well as the source files 
>> and the generated files. Sorry again for the previous messgae. I am 
>> stucked here and I can not move forward, and I am looking for help.
>>
>>
>> Thanks & Best Regards / السلام عليكم 
>>
>> Ahmed Ibrahim
>> MBA ,Senior IT Architect, SWG Cairo Lab Services
>> BPM Client Solution Manager, MEA 
>> IT Architect Egypt Profession Lead
>> Mobile: +20 100 1615 506
>>
>>
>>
>> From:   Ahmed I Ibrahim/Egypt/IBM@IBMEG
>> To:     [email protected], 
>> Date:   04/15/2014 10:18 AM
>> Subject:        Re: How to insert a text document into another text 
>> document?
>>
>>
>> [attachment "ODF_FileMerge.zip" deleted by Ahmed I Ibrahim/Egypt/IBM] 
>>
>

Reply via email to