<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Doomy</id>
	<title>Apache OpenOffice Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Doomy"/>
	<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/wiki/Special:Contributions/Doomy"/>
	<updated>2026-11-28T07:52:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Documentation/DevGuide/Text/Iterating_over_Text&amp;diff=216980</id>
		<title>Documentation/DevGuide/Text/Iterating over Text</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Documentation/DevGuide/Text/Iterating_over_Text&amp;diff=216980"/>
		<updated>2013-03-12T09:50:47Z</updated>

		<summary type="html">&lt;p&gt;Doomy: Made comment in code block easier to read&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Documentation/DevGuide/TextTOC&lt;br /&gt;
|Text2b=block&lt;br /&gt;
|TextWordProc=block&lt;br /&gt;
|ShowPrevNext=block&lt;br /&gt;
|PrevPage=Documentation/DevGuide/Text/Editing Text&lt;br /&gt;
|NextPage=Documentation/DevGuide/Text/Inserting a Paragraph where no Cursor can go&lt;br /&gt;
}}&lt;br /&gt;
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Text/{{SUBPAGENAME}}}} &lt;br /&gt;
 {{DISPLAYTITLE:Iterating over Text}}&lt;br /&gt;
&amp;lt;!--&amp;lt;idltopic&amp;gt;com.sun.star.text.Paragraph;com.sun.star.text.TextPortion;com.sun.star.container.XEnumerationAccess;com.sun.star.container.XContentEnumerationAccess&amp;lt;/idltopic&amp;gt;--&amp;gt;&lt;br /&gt;
The second interface of &amp;lt;idl&amp;gt;com.sun.star.text.Text&amp;lt;/idl&amp;gt; is &amp;lt;code&amp;gt;XEnumerationAccess&amp;lt;/code&amp;gt;. A Text service enumerates all paragraphs in a text and returns objects which support &amp;lt;idl&amp;gt;com.sun.star.text.Paragraph&amp;lt;/idl&amp;gt;. This includes tables, because writer sees tables as specialized paragraphs that support the &amp;lt;idl&amp;gt;com.sun.star.text.TextTable&amp;lt;/idl&amp;gt; service. &lt;br /&gt;
&lt;br /&gt;
Paragraphs also have an &amp;lt;idl&amp;gt;com.sun.star.container.XEnumerationAccess&amp;lt;/idl&amp;gt; of their own. They can enumerate every single text portion that they contain. A text portion is a text range containing a uniform piece of information that appears within the text flow. An ordinary paragraph, formatted in a uniform manner and containing nothing but a string, enumerates just a single text portion. In a paragraph that has specially formatted words or other contents, the text portion enumeration returns one &amp;lt;idl&amp;gt;com.sun.star.text.TextPortion&amp;lt;/idl&amp;gt; service for each differently formatted string, and for every other text content. Text portions include the service &amp;lt;idl&amp;gt;com.sun.star.text.TextRange&amp;lt;/idl&amp;gt; and have the properties listed below:&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=4 style=&amp;quot;border-collapse:collapse;&amp;quot;&lt;br /&gt;
|-bgcolor=#EDEDED&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Properties of &amp;lt;idl&amp;gt;com.sun.star.text.TextPortion&amp;lt;/idl&amp;gt;  &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.text.TextPortion:TextPortionType&amp;lt;/idlm&amp;gt; &lt;br /&gt;
|&amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt; - Contains the type of the text portion (see below). &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.text.TextPortion:ControlCharacter&amp;lt;/idlm&amp;gt; &lt;br /&gt;
|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt; - Returns the control character if the text portion contains a control character as defined in &amp;lt;idl&amp;gt;com.sun.star.text.ControlCharacter&amp;lt;/idl&amp;gt;. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.text.TextPortion:Bookmark&amp;lt;/idlm&amp;gt; &lt;br /&gt;
|&amp;lt;idl&amp;gt;com.sun.star.text.XTextContent&amp;lt;/idl&amp;gt;. Contains the bookmark if the portion has TextPortionType=&amp;quot;Bookmark&amp;quot;. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.text.TextPortion:DocumentIndexMark&amp;lt;/idlm&amp;gt;&lt;br /&gt;
|&amp;lt;idl&amp;gt;com.sun.star.text.XTextContent&amp;lt;/idl&amp;gt;. Contains the document index mark if the portion has TextPortionType=&amp;quot;DocumentIndexMark&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.text.TextPortion:ReferenceMark&amp;lt;/idlm&amp;gt;&lt;br /&gt;
|&amp;lt;idl&amp;gt;com.sun.star.text.XTextContent&amp;lt;/idl&amp;gt;. Contains the reference mark if the portion has TextPortionType=&amp;quot;ReferenceMark&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.text.TextPortion:Footnote&amp;lt;/idlm&amp;gt;&lt;br /&gt;
|&amp;lt;idl&amp;gt;com.sun.star.text.XFootnote&amp;lt;/idl&amp;gt;. Contains the footnote if the portion has TextPortionType=&amp;quot;Footnote&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.text.TextPortion:TextField&amp;lt;/idlm&amp;gt;&lt;br /&gt;
|&amp;lt;idl&amp;gt;com.sun.star.text.XTextContent&amp;lt;/idl&amp;gt;. Contains the text field if the portion has TextPortionType=&amp;quot;TextField&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.text.TextPortion:InContentMetadata&amp;lt;/idlm&amp;gt;&lt;br /&gt;
|&amp;lt;idl&amp;gt;com.sun.star.text.XTextContent&amp;lt;/idl&amp;gt;. Contains the text range if the portion has TextPortionType=&amp;quot;InContentMetadata&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.text.TextPortion:IsCollapsed&amp;lt;/idlm&amp;gt; &lt;br /&gt;
|&amp;lt;code&amp;gt;boolean&amp;lt;/code&amp;gt; - Contains whether the portion is a point only. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;idlm&amp;gt;com.sun.star.text.TextPortion:IsStart&amp;lt;/idlm&amp;gt; &lt;br /&gt;
|&amp;lt;code&amp;gt;boolean&amp;lt;/code&amp;gt; - Contains whether the portion is a start portion if two portions are needed to include an object, for example, &amp;lt;code&amp;gt;DocumentIndexMark&amp;lt;/code&amp;gt;. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Possible Values for &amp;lt;code&amp;gt;TextPortionType&amp;lt;/code&amp;gt; are:&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=4 style=&amp;quot;border-collapse:collapse;&amp;quot;&lt;br /&gt;
|-bgcolor=#EDEDED&lt;br /&gt;
!TextPortionType (String) &lt;br /&gt;
!Description &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;Text&amp;quot; &lt;br /&gt;
|a portion with mere string content &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;TextField&amp;quot; &lt;br /&gt;
|A &amp;lt;idl&amp;gt;com.sun.star.text.TextField&amp;lt;/idl&amp;gt; content. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;TextContent&amp;quot; &lt;br /&gt;
|A text content supplied through the interface &amp;lt;code&amp;gt;XContentEnumerationAccess&amp;lt;/code&amp;gt;. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;Footnote&amp;quot; &lt;br /&gt;
|A footnote or an endnote. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;ControlCharacter&amp;quot; &lt;br /&gt;
|A control character. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;ReferenceMark&amp;quot; &lt;br /&gt;
|A reference mark. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;DocumentIndexMark&amp;quot; &lt;br /&gt;
|A document index mark. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;Bookmark&amp;quot; &lt;br /&gt;
|A bookmark. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;Redline&amp;quot; &lt;br /&gt;
|A redline portion which is a result of the change tracking feature. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;Ruby&amp;quot; &lt;br /&gt;
|A ruby attribute which is used in Asian text. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;Frame&amp;quot;&lt;br /&gt;
|A frame supplied through the interface &amp;lt;code&amp;gt;XContentEnumerationAccess&amp;lt;/code&amp;gt;. &lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;SoftPageBreak&amp;quot;&lt;br /&gt;
|A soft page break.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;quot;InContentMetadata&amp;quot;&lt;br /&gt;
|A text range with attached metadata.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The text portion enumeration of a paragraph does not supply contents which do belong to the paragraph, but do not fuse together with the text flow. These could be text frames, graphic objects, embedded objects or drawing shapes anchored at the paragraph, characters or as character. The &amp;lt;code&amp;gt;TextPortionType&amp;lt;/code&amp;gt; &amp;quot;&amp;lt;code&amp;gt;TextContent&amp;lt;/code&amp;gt;&amp;quot; indicate if there is a content anchored at a character or as a character. If you have a &amp;lt;code&amp;gt;TextContent&amp;lt;/code&amp;gt; portion type, you know that there are shape objects anchored at a character or as a character.&lt;br /&gt;
&lt;br /&gt;
This last group of data contained in a text, &amp;lt;code&amp;gt;Paragraphs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;TextPortions&amp;lt;/code&amp;gt; in writer support the interface &amp;lt;idl&amp;gt;com.sun.star.container.XContentEnumerationAccess&amp;lt;/idl&amp;gt;. This interface tells which text contents other than the text flow contents exist, and supplies them as an &amp;lt;idl&amp;gt;com.sun.star.container.XEnumeration&amp;lt;/idl&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
  sequence&amp;lt; string &amp;gt; getAvailableServiceNames()&lt;br /&gt;
  com::sun::star::container::XEnumeration createContentEnumeration( [in] string aServiceName)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;XContentEnumerationAccess&amp;lt;/code&amp;gt; of the paragraph lists the shape objects anchored at the paragraph while the &amp;lt;code&amp;gt;XContentEnumerationAccess&amp;lt;/code&amp;gt; of a text portion lists the shape objects anchored at a character or as a character.&lt;br /&gt;
&lt;br /&gt;
{{Documentation/Note|Precisely the same enumerations are available for the current text cursor selection. The text cursor enumerates paragraphs, text portions and text contents just like the service &amp;lt;idl&amp;gt;com.sun.star.text.Text&amp;lt;/idl&amp;gt; itself.}}&lt;br /&gt;
&lt;br /&gt;
The enumeration access to text through paragraphs and text portions is used if every single paragraph in a text needs to be touched. The application area for this enumeration are export filters, that uses this enumeration to go over the whole document, writing out the paragraphs to the target file. The following code snippet centers all paragraphs in a text. &lt;br /&gt;
&amp;lt;!--[SOURCE:Text/TextDocuments.java]--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  /** This method demonstrates how to iterate over paragraphs */&lt;br /&gt;
  protected void ParagraphExample () {&lt;br /&gt;
      try {&lt;br /&gt;
          // The service &amp;#039;com.sun.star.text.Text&amp;#039; supports the XEnumerationAccess interface to&lt;br /&gt;
          // provide an enumeration&lt;br /&gt;
          // of the paragraphs contained by the text the service refers to. &lt;br /&gt;
          &lt;br /&gt;
          // Here, we access this interface&lt;br /&gt;
          XEnumerationAccess xParaAccess = (XEnumerationAccess) UnoRuntime.queryInterface(&lt;br /&gt;
              XEnumerationAccess.class, mxDocText);&lt;br /&gt;
          // Call the XEnumerationAccess&amp;#039;s only method to access the actual Enumeration&lt;br /&gt;
          XEnumeration xParaEnum = xParaAccess.createEnumeration();&lt;br /&gt;
          &lt;br /&gt;
          // While there are paragraphs, do things to them&lt;br /&gt;
          while (xParaEnum.hasMoreElements()) {&lt;br /&gt;
              // Get a reference to the next paragraphs XServiceInfo interface. TextTables&lt;br /&gt;
              // are also part of this enumeration access, so we ask the element if it is&lt;br /&gt;
              // a TextTable, if it doesn&amp;#039;t support the com.sun.star.text.TextTable&lt;br /&gt;
              // service, then it is safe to assume that it really is a paragraph&lt;br /&gt;
              XServiceInfo xInfo = (XServiceInfo) UnoRuntime.queryInterface(&lt;br /&gt;
                  XServiceInfo.class, xParaEnum.nextElement());&lt;br /&gt;
              if (!xInfo.supportsService(&amp;quot;com.sun.star.text.TextTable&amp;quot;)) {&lt;br /&gt;
                  // Access the paragraph&amp;#039;s property set...the properties in this&lt;br /&gt;
                  // property set are listed&lt;br /&gt;
                  // in: com.sun.star.style.ParagraphProperties&lt;br /&gt;
                  XPropertySet xSet = (XPropertySet) UnoRuntime.queryInterface(&lt;br /&gt;
                      XPropertySet.class, xInfo);&lt;br /&gt;
                  // Set the justification to be center justified&lt;br /&gt;
                  xSet.setPropertyValue(&amp;quot;ParaAdjust&amp;quot;, com.sun.star.style.ParagraphAdjust.CENTER);&lt;br /&gt;
              }&lt;br /&gt;
          }&lt;br /&gt;
      } catch (Exception e) {&lt;br /&gt;
          e.printStackTrace (System.out);&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
{{PDL1}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation/Developer&amp;#039;s Guide/Text Documents]]&lt;/div&gt;</summary>
		<author><name>Doomy</name></author>
	</entry>
</feed>