1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.style;
25 
26 import com.sun.star.container.XNameContainer;
27 import com.sun.star.uno.AnyConverter;
28 import com.sun.star.uno.Type;
29 import com.sun.star.xml.AttributeData;
30 import lib.MultiPropertyTest;
31 
32 /**
33  * Test page properties.
34  * Testing is done by lib.MultiPropertyTest, except for properties
35  * <ul>
36  *  <li>PrinterPaperTray</li>
37  *  <li>UserDefinedAttribures</li>
38  * </ul>
39  */
40 public class _PageProperties  extends MultiPropertyTest {
41 
42     /**
43      * Switch on Header and Footer properties
44      * so all props can be tested.
45      */
before()46     protected void before() {
47         try {
48             oObj.setPropertyValue("HeaderIsOn", Boolean.TRUE);
49             oObj.setPropertyValue("FooterIsOn", Boolean.TRUE);
50         } catch (com.sun.star.beans.UnknownPropertyException upe) {
51             log.println("Don't know the Property 'HeaderIsOn' or 'FooterIsOn'");
52         } catch (com.sun.star.lang.WrappedTargetException wte) {
53             log.println("WrappedTargetException while setting Property 'HeaderIsOn' or 'FooterIsOn'");
54         } catch (com.sun.star.lang.IllegalArgumentException iae) {
55             log.println("IllegalArgumentException while setting Property 'HeaderIsOn' or 'FooterIsOn'");
56         } catch (com.sun.star.beans.PropertyVetoException pve) {
57             log.println("PropertyVetoException while setting Property 'HeaderIsOn' or 'FooterIsOn'");
58         }
59     }
60 
61     /**
62      * This property is system dependent and printer dependent.
63      * So only reading it does make sense, since it cannot be determined, if
64      * it is set to a allowed value.
65      */
_PrinterPaperTray()66     public void _PrinterPaperTray() {
67         boolean res = false;
68         String setting = null;
69         try {
70             setting = (String)oObj.getPropertyValue("PrinterPaperTray");
71             log.println("Property 'PrinterPaperTray' is set to '" + setting + "'.");
72             res = setting != null;
73         }
74         catch(com.sun.star.beans.UnknownPropertyException e) {
75             log.println("Don't know the Property 'PrinterPaperTray'");
76         } catch (com.sun.star.lang.WrappedTargetException wte) {
77             log.println("WrappedTargetException while getting Property 'PrinterPaperTray'");
78         }
79         tRes.tested("PrinterPaperTray", res);
80     }
81 
82     /**
83      * Create some valid user defined attributes
84      */
_UserDefinedAttributes()85     public void _UserDefinedAttributes() {
86         XNameContainer uda = null;
87         boolean res = false;
88         try {
89             uda = (XNameContainer) AnyConverter.toObject(
90                 new Type(XNameContainer.class),
91                     oObj.getPropertyValue("UserDefinedAttributes"));
92             AttributeData attr = new AttributeData();
93             attr.Namespace = "http://www.sun.com/staroffice/apitest/Cellprop";
94             attr.Type="CDATA";
95             attr.Value="true";
96             uda.insertByName("Cellprop:has-first-alien-attribute",attr);
97             String[] els = uda.getElementNames();
98             oObj.setPropertyValue("UserDefinedAttributes",uda);
99             uda = (XNameContainer) AnyConverter.toObject(
100                 new Type(XNameContainer.class),
101                     oObj.getPropertyValue("UserDefinedAttributes"));
102             els = uda.getElementNames();
103             Object obj = uda.getByName("Cellprop:has-first-alien-attribute");
104             res = true;
105         } catch (com.sun.star.beans.UnknownPropertyException upe) {
106             log.println("Don't know the Property 'UserDefinedAttributes'");
107         } catch (com.sun.star.lang.WrappedTargetException wte) {
108             log.println("WrappedTargetException while getting Property 'UserDefinedAttributes'");
109         } catch (com.sun.star.container.NoSuchElementException nee) {
110             log.println("added Element isn't part of the NameContainer");
111         } catch (com.sun.star.lang.IllegalArgumentException iae) {
112             log.println("IllegalArgumentException while getting Property 'UserDefinedAttributes'");
113         } catch (com.sun.star.beans.PropertyVetoException pve) {
114             log.println("PropertyVetoException while getting Property 'UserDefinedAttributes'");
115         } catch (com.sun.star.container.ElementExistException eee) {
116             log.println("ElementExistException while getting Property 'UserDefinedAttributes'");
117         }
118         tRes.tested("UserDefinedAttributes",res);
119     }
120 
121 }
122