[ 
https://issues.apache.org/jira/browse/ODFTOOLKIT-330?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

DaLi Liu updated ODFTOOLKIT-330:
--------------------------------

    Attachment: 330_TextDocumentSelection.patch

The implement of replacewith TextDocument, similar with FieldSelection.java
Javadoc and testcase included.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       /**
         * Replace the Searched Content with a TextDocument with Styles.
         * <p>
         * Note: You need cache the TextNavigation.nextSelection item because 
after
         * you replace currtenTextSelection with TextDocument,
         * TextNavigation.nextSelection will search from the inserted Content, 
it
         * will make you into a loop if the Search keyword also can be found in 
the
         * new inserted Content.
         * </p>
         * The right way to use this replaceWithTextDocument(TextDocument
         * textDocument) method should like this: <Code>
         * <p>  search = new TextNavigation("SIMPLE", doc);    </p>
         * <p>  TextSelection currtenTextSelection,nextTextSelection=null;</p>
         * <p>          while (search.hasNext()) {</p>
         * <p>                  if(nextTextSelection!=null){</p>
         * <p>                          
currtenTextSelection=nextTextSelection;</p>
         * <p>                  }else {</p>
         * <p>                          currtenTextSelection = (TextSelection) 
search.nextSelection();</p>
         * <p>                  }</p>
         * <p>                  nextTextSelection = (TextSelection) 
search.nextSelection();</p>
         * <p>                  if(currtenTextSelection!=null){</p>
         * <p>                          TextDocumentSelection 
nextParagraphSelection = new TextDocumentSelection(currtenTextSelection);</p>
         * <p>                          try {</p>
         * <p>                                  
nextParagraphSelection.replaceWithTextDocument(sourcedoc);</p>
         * <p>                          } catch (Exception e) {</p>
         * <p>                                  e.printStackTrace();</p>
         * <p>                          }</p>
         * <p>                  }</p>
         * <p>          }</p>
         * <p>          if(nextTextSelection!=null){</p>
         * <p>                  TextDocumentSelection nextParagraphSelection = 
new TextDocumentSelection(nextTextSelection);</p>
         * <p>                  try {</p>
         * <p>                          
nextParagraphSelection.replaceWithTextDocument(sourcedoc);</p>
         * <p>                  } catch (Exception e) {</p>
         * <p>                          e.printStackTrace();</p>
         * <p>                  }</p>
         * <p>          }</p>
         * </Code>
         * 
         * @param textDocument
         *            the reference TextDocument to replace.
         * @throws Exception
         */
        public void replaceWithTextDocument(TextDocument textDocument) throws 
Exception 
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Using: To use it please refer to TextDocumentSelectionTest.java
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                search = new TextNavigation("SIMPLE", doc);
                TextSelection currtenTextSelection, nextTextSelection = null;
                while (search.hasNext()) {
                        if (nextTextSelection != null) {
                                currtenTextSelection = nextTextSelection;
                        } else {
                                currtenTextSelection = (TextSelection) 
search.nextSelection();
                        }
                        nextTextSelection = (TextSelection) 
search.nextSelection();
                        if (currtenTextSelection != null) {
                                TextDocumentSelection nextParagraphSelection = 
new TextDocumentSelection(currtenTextSelection);
                                try {
                                        
nextParagraphSelection.replaceWithTextDocument(sourcedoc);
                                } catch (Exception e) {
                                        e.printStackTrace();
                                }
                        }
                }
                if (nextTextSelection != null) {
                        TextDocumentSelection nextParagraphSelection = new 
TextDocumentSelection(nextTextSelection);
                        try {
                                
nextParagraphSelection.replaceWithTextDocument(sourcedoc);
                        } catch (Exception e) {
                                e.printStackTrace();
                        }
                }
                
                
> Improve the method TextSelection.replaceWith(String). new param types support
> -----------------------------------------------------------------------------
>
>                 Key: ODFTOOLKIT-330
>                 URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-330
>             Project: ODF Toolkit
>          Issue Type: Improvement
>          Components: simple api
>    Affects Versions: 0.8.6
>            Reporter: DaLi Liu
>             Fix For: 0.8.6, 0.8.7
>
>         Attachments: 330_ImageSelection.patch, 330_ParagraphSelection.patch, 
> 330_TableSelection.patch, 330_TextDocumentSelection.patch
>
>   Original Estimate: 672h
>  Remaining Estimate: 672h
>
> With the clasees TextNavigation and TextSelection, user can generation a 
> report base on some templates very easily. The method 
> TextSelection.replaceWith(String) provides an easy way to replace
> locate and replace placeholders in a document by a concrete text. However 
> that replacement should not only be limited to simple text strings but also 
> for more complex pieces of content.
> So proposal to add new replaceWith method in TextSelection.java
> 1. public void replaceWith(Table table)
> The text represented by the TextSelection object should be replaced by the 
> table
> provided. If the TextSelection object does not contain a paragraph of its 
> own, but rather is part of a paragraph, then this paragraph should be split. 
> that mean the exist paragraph split to two new paragraphs,the table be insert 
> between these two new paragraphs.
> 2.public void replaceWith(Image image)
> The text represented by the TextSelection object should be replaced by an 
> image. The image needs to replace the TextSelection exactly in-place, that 
> means: if positioned within the flow of a text paragraph, the replacement 
> should be in that very position and not at the beginning, or end of the 
> enclosing paragraph.
> 3.public void replaceWith(Paragraph p)
> The text represented by the TextSelection object should be replaced by a 
> paragraph. If the replacement is within a paragraph, it may be required to 
> split that paragraph.  that mean the exist paragraph split to two new 
> paragraphs,the Paragraph be insert between these two new paragraphs.
> 4.public void replaceWith(TextDocument document)
> Alike the replacement of a table, it should be possible to replace the 
> TextSelection with the content of a complete documents. This may require that 
> the paragraph where the replacement takes place needs to be split into two 
> paragraphs first.
> 5.public void replaceWith(Field field)
> The text represented by the TextSelection object should be replaced by the 
> field provided. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to