1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package mod._sw;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.io.PrintWriter;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir import lib.TestCase;
30cdf0e10cSrcweir import lib.TestEnvironment;
31cdf0e10cSrcweir import lib.TestParameters;
32cdf0e10cSrcweir import util.SOfficeFactory;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
35cdf0e10cSrcweir import com.sun.star.container.XEnumeration;
36cdf0e10cSrcweir import com.sun.star.container.XEnumerationAccess;
37cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
38cdf0e10cSrcweir import com.sun.star.text.ControlCharacter;
39cdf0e10cSrcweir import com.sun.star.text.XText;
40cdf0e10cSrcweir import com.sun.star.text.XTextCursor;
41cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
42cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
43cdf0e10cSrcweir import com.sun.star.uno.Type;
44cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
45cdf0e10cSrcweir import com.sun.star.uno.XInterface;
46cdf0e10cSrcweir import com.sun.star.util.XCloseable;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir /**
49cdf0e10cSrcweir  * Test for object which is represented by service
50cdf0e10cSrcweir  * <code>com.sun.star.text.Paragraph</code>. <p>
51cdf0e10cSrcweir  * Object implements the following interfaces :
52cdf0e10cSrcweir  * <ul>
53cdf0e10cSrcweir  *  <li> <code>com::sun::star::text::XTextContent</code></li>
54cdf0e10cSrcweir  *  <li> <code>com::sun::star::text::TextContent</code></li>
55cdf0e10cSrcweir  *  <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
56cdf0e10cSrcweir  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
57cdf0e10cSrcweir  *  <li> <code>com::sun::star::container::XElementAccess</code></li>
58cdf0e10cSrcweir  *  <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
59cdf0e10cSrcweir  *  <li> <code>com::sun::star::beans::XPropertyState</code></li>
60cdf0e10cSrcweir  *  <li> <code>com::sun::star::style::CharacterProperties</code></li>
61cdf0e10cSrcweir  *  <li> <code>com::sun::star::style::ParagraphProperties</code></li>
62cdf0e10cSrcweir  *  <li> <code>com::sun::star::lang::XComponent</code></li>
63cdf0e10cSrcweir  *  <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
64cdf0e10cSrcweir  * </ul> <p>
65cdf0e10cSrcweir  * This object test <b> is NOT </b> designed to be run in several
66cdf0e10cSrcweir  * threads concurently.
67cdf0e10cSrcweir  * @see com.sun.star.text.XTextContent
68cdf0e10cSrcweir  * @see com.sun.star.text.TextContent
69cdf0e10cSrcweir  * @see com.sun.star.style.CharacterPropertiesComplex
70cdf0e10cSrcweir  * @see com.sun.star.beans.XPropertySet
71cdf0e10cSrcweir  * @see com.sun.star.container.XElementAccess
72cdf0e10cSrcweir  * @see com.sun.star.container.XEnumerationAccess
73cdf0e10cSrcweir  * @see com.sun.star.beans.XPropertyState
74cdf0e10cSrcweir  * @see com.sun.star.style.CharacterProperties
75cdf0e10cSrcweir  * @see com.sun.star.style.ParagraphProperties
76cdf0e10cSrcweir  * @see com.sun.star.lang.XComponent
77cdf0e10cSrcweir  * @see com.sun.star.style.CharacterPropertiesAsian
78cdf0e10cSrcweir  * @see com.sun.star.text.Paragraph
79cdf0e10cSrcweir  * @see ifc.text._XTextContent
80cdf0e10cSrcweir  * @see ifc.text._TextContent
81cdf0e10cSrcweir  * @see ifc.style._CharacterPropertiesComplex
82cdf0e10cSrcweir  * @see ifc.beans._XPropertySet
83cdf0e10cSrcweir  * @see ifc.container._XElementAccess
84cdf0e10cSrcweir  * @see ifc.container._XEnumerationAccess
85cdf0e10cSrcweir  * @see ifc.beans._XPropertyState
86cdf0e10cSrcweir  * @see ifc.style._CharacterProperties
87cdf0e10cSrcweir  * @see ifc.style._ParagraphProperties
88cdf0e10cSrcweir  * @see ifc.lang._XComponent
89cdf0e10cSrcweir  * @see ifc.style._CharacterPropertiesAsian
90cdf0e10cSrcweir  */
91cdf0e10cSrcweir public class SwXParagraph extends TestCase {
92cdf0e10cSrcweir     XTextDocument xTextDoc;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     /**
95cdf0e10cSrcweir      * Creates text document.
96cdf0e10cSrcweir      */
initialize( TestParameters tParam, PrintWriter log )97cdf0e10cSrcweir     protected void initialize( TestParameters tParam, PrintWriter log ) {
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir 
cleanup(TestParameters tParam, PrintWriter log)101cdf0e10cSrcweir     protected void cleanup(TestParameters tParam, PrintWriter log) {
102cdf0e10cSrcweir         log.println("    disposing xTextDoc ");
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         try {
105cdf0e10cSrcweir             XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
106cdf0e10cSrcweir             XCloseable.class, xTextDoc);
107cdf0e10cSrcweir             closer.close(true);
108cdf0e10cSrcweir         } catch (com.sun.star.util.CloseVetoException e) {
109cdf0e10cSrcweir             log.println("couldn't close document");
110cdf0e10cSrcweir         } catch (com.sun.star.lang.DisposedException e) {
111cdf0e10cSrcweir             log.println("couldn't close document");
112cdf0e10cSrcweir         }
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     /**
117cdf0e10cSrcweir      * Creating a Testenvironment for the interfaces to be tested. To obtain
118cdf0e10cSrcweir      * test component, at first several paragraphs are inserted to a major text
119cdf0e10cSrcweir      * of text document. Then enumeration of text paragraphs is created, and
120cdf0e10cSrcweir      * some paragraph is gotten using <code>XEnumeration</code> interface.<p>
121cdf0e10cSrcweir      *     Object relations created :
122cdf0e10cSrcweir      * <ul>
123cdf0e10cSrcweir      *  <li> <code>'PARA'</code> for
124cdf0e10cSrcweir      *      {@link ifc.style._CharacterProperties} : paragraph </li>
125cdf0e10cSrcweir      *  <li> <code>'PORTION'</code> for
126cdf0e10cSrcweir      *      {@link ifc.style._CharacterProperties} : some text portion of
127cdf0e10cSrcweir      *  paragraph. To obtain text portion, enumeration of paragraph text portions is
128cdf0e10cSrcweir      *  created, and some text portion is gotten using <code>XEnumeration</code>
129cdf0e10cSrcweir      *  interface. </li>
130cdf0e10cSrcweir      *  <li> <code>'NRULES'</code> for
131cdf0e10cSrcweir      *      {@link ifc.style._ParagraphProperties} : value of property
132cdf0e10cSrcweir      *  'NumberingRules' of paragraph. Method changes property
133cdf0e10cSrcweir      *  'NumberingStyleName' of previously obtained paragraph, and gets value of
134cdf0e10cSrcweir      *  a property 'NumberingRules'. </li>
135cdf0e10cSrcweir      * </ul>
136cdf0e10cSrcweir      */
createTestEnvironment(TestParameters tParam, PrintWriter log)137cdf0e10cSrcweir     protected synchronized TestEnvironment createTestEnvironment
138cdf0e10cSrcweir     (TestParameters tParam, PrintWriter log) {
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         if (xTextDoc != null) {
141cdf0e10cSrcweir             log.println("    disposing xTextDoc ");
142cdf0e10cSrcweir 
143cdf0e10cSrcweir             try {
144cdf0e10cSrcweir                 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
145cdf0e10cSrcweir                 XCloseable.class, xTextDoc);
146cdf0e10cSrcweir                 closer.close(true);
147cdf0e10cSrcweir             } catch (com.sun.star.util.CloseVetoException e) {
148cdf0e10cSrcweir                 log.println("couldn't close document");
149cdf0e10cSrcweir             } catch (com.sun.star.lang.DisposedException e) {
150cdf0e10cSrcweir                 log.println("couldn't close document");
151cdf0e10cSrcweir             }
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory(  (XMultiServiceFactory) tParam.getMSF() );
154cdf0e10cSrcweir         try {
155cdf0e10cSrcweir             log.println( "creating a textdocument" );
156cdf0e10cSrcweir             xTextDoc = SOF.createTextDoc( null );
157cdf0e10cSrcweir         } catch ( com.sun.star.uno.Exception e ) {
158cdf0e10cSrcweir             e.printStackTrace( log );
159cdf0e10cSrcweir             throw new StatusException( "Couldn't create document", e );
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         XInterface oObj = null;
163cdf0e10cSrcweir         XPropertySet paraP = null;
164cdf0e10cSrcweir         XPropertySet portP = null;
165cdf0e10cSrcweir         Object nRules = null;
166cdf0e10cSrcweir         XInterface port = null;
167cdf0e10cSrcweir         XInterface para = null;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         log.println( "creating a test environment" );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         XText oText = xTextDoc.getText();
173cdf0e10cSrcweir         XTextCursor oCursor = oText.createTextCursor();
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         log.println( "inserting some lines" );
176cdf0e10cSrcweir         try {
177cdf0e10cSrcweir             for (int i=0; i<5; i++){
178cdf0e10cSrcweir                 oText.insertString( oCursor,"Paragraph Number: " + i, false);
179cdf0e10cSrcweir                 oText.insertString( oCursor,
180cdf0e10cSrcweir                 " The quick brown fox jumps over the lazy Dog: SwXParagraph",
181cdf0e10cSrcweir                 false);
182cdf0e10cSrcweir                 oText.insertControlCharacter(
183cdf0e10cSrcweir                 oCursor, ControlCharacter.PARAGRAPH_BREAK, false );
184cdf0e10cSrcweir                 oText.insertString( oCursor,
185cdf0e10cSrcweir                 "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG: SwXParagraph",
186cdf0e10cSrcweir                 false);
187cdf0e10cSrcweir                 oText.insertControlCharacter(oCursor,
188cdf0e10cSrcweir                 ControlCharacter.PARAGRAPH_BREAK, false );
189cdf0e10cSrcweir                 oText.insertControlCharacter(
190cdf0e10cSrcweir                 oCursor, ControlCharacter.LINE_BREAK, false );
191cdf0e10cSrcweir             }
192cdf0e10cSrcweir         } catch ( com.sun.star.lang.IllegalArgumentException e ){
193cdf0e10cSrcweir             e.printStackTrace(log);
194cdf0e10cSrcweir             throw new StatusException( "Couldn't insert lines", e );
195cdf0e10cSrcweir         }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         // Enumeration
198cdf0e10cSrcweir         XEnumerationAccess oEnumA = (XEnumerationAccess)
199cdf0e10cSrcweir         UnoRuntime.queryInterface(XEnumerationAccess.class, oText );
200cdf0e10cSrcweir         XEnumeration oEnum = oEnumA.createEnumeration();
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         try {
203cdf0e10cSrcweir             para = (XInterface) AnyConverter.toObject(
204cdf0e10cSrcweir             new Type(XInterface.class),oEnum.nextElement());
205cdf0e10cSrcweir             XEnumerationAccess oEnumB = (XEnumerationAccess)
206cdf0e10cSrcweir             UnoRuntime.queryInterface( XEnumerationAccess.class, para );
207cdf0e10cSrcweir             XEnumeration oEnum2 = oEnumB.createEnumeration();
208cdf0e10cSrcweir             port = (XInterface) AnyConverter.toObject(
209cdf0e10cSrcweir             new Type(XInterface.class),oEnum2.nextElement());
210cdf0e10cSrcweir         } catch ( com.sun.star.lang.WrappedTargetException e ) {
211cdf0e10cSrcweir             e.printStackTrace(log);
212cdf0e10cSrcweir             log.println("Error: exception occured...");
213cdf0e10cSrcweir         } catch ( com.sun.star.container.NoSuchElementException e ) {
214cdf0e10cSrcweir             e.printStackTrace(log);
215cdf0e10cSrcweir             log.println("Error: exception occured...");
216cdf0e10cSrcweir         } catch ( com.sun.star.lang.IllegalArgumentException e ) {
217cdf0e10cSrcweir             e.printStackTrace(log);
218cdf0e10cSrcweir             log.println("Error: exception occured...");
219cdf0e10cSrcweir         }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         try {
222cdf0e10cSrcweir             portP = (XPropertySet)
223cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, port);
224cdf0e10cSrcweir             paraP = (XPropertySet)
225cdf0e10cSrcweir             UnoRuntime.queryInterface(XPropertySet.class, para);
226cdf0e10cSrcweir             paraP.setPropertyValue("NumberingStyleName","Numbering 4");
227cdf0e10cSrcweir             nRules = paraP.getPropertyValue("NumberingRules");
228cdf0e10cSrcweir         } catch ( com.sun.star.lang.WrappedTargetException e ) {
229cdf0e10cSrcweir             log.println("Error, exception occured...");
230cdf0e10cSrcweir             e.printStackTrace(log);
231cdf0e10cSrcweir             throw new StatusException( "Couldn't get Paragraph", e );
232cdf0e10cSrcweir         } catch ( com.sun.star.lang.IllegalArgumentException e ) {
233cdf0e10cSrcweir             log.println("Error, exception occured...");
234cdf0e10cSrcweir             e.printStackTrace(log);
235cdf0e10cSrcweir             throw new StatusException( "Couldn't get Paragraph", e );
236cdf0e10cSrcweir         } catch ( com.sun.star.beans.UnknownPropertyException e ) {
237cdf0e10cSrcweir             log.println("Error, exception occured...");
238cdf0e10cSrcweir             e.printStackTrace(log);
239cdf0e10cSrcweir             throw new StatusException( "Couldn't get Paragraph", e );
240cdf0e10cSrcweir         } catch ( com.sun.star.beans.PropertyVetoException e ) {
241cdf0e10cSrcweir             log.println("Error, exception occured...");
242cdf0e10cSrcweir             e.printStackTrace(log);
243cdf0e10cSrcweir             throw new StatusException( "Couldn't get Paragraph", e );
244cdf0e10cSrcweir         }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         try {
248cdf0e10cSrcweir             oObj = (XInterface) AnyConverter.toObject(
249cdf0e10cSrcweir             new Type(XInterface.class),oEnum.nextElement());
250cdf0e10cSrcweir         } catch ( Exception e) {
251cdf0e10cSrcweir             log.println("Error, exception occured...");
252cdf0e10cSrcweir             e.printStackTrace(log);
253cdf0e10cSrcweir             throw new StatusException( "Couldn't get Paragraph", e );
254cdf0e10cSrcweir         }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 
257cdf0e10cSrcweir         log.println( "creating a new environment for Paragraph object" );
258cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir         log.println("adding ObjectRelation 'PARA' for CharacterProperties");
261cdf0e10cSrcweir         tEnv.addObjRelation("PARA", paraP);
262cdf0e10cSrcweir 
263cdf0e10cSrcweir         log.println("adding ObjectRelation 'PORTION' for CharacterProperties");
264cdf0e10cSrcweir         tEnv.addObjRelation("PORTION", portP);
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         log.println("adding ObjectRelation 'NRULES' for ParagraphProperties");
267cdf0e10cSrcweir         tEnv.addObjRelation("NRULES", nRules);
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         tEnv.addObjRelation("NoAttach","SwXParagraph");
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         return tEnv;
272cdf0e10cSrcweir     } // finish method getTestEnvironment
273cdf0e10cSrcweir 
274cdf0e10cSrcweir }    // finish class SwXParagraph
275cdf0e10cSrcweir 
276