1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.style; 29 30 import com.sun.star.container.XNameContainer; 31 import com.sun.star.uno.AnyConverter; 32 import com.sun.star.uno.Type; 33 import com.sun.star.xml.AttributeData; 34 import lib.MultiPropertyTest; 35 36 /** 37 * Test page properties. 38 * Testing is done by lib.MultiPropertyTest, except for properties 39 * <ul> 40 * <li>PrinterPaperTray</li> 41 * <li>UserDefinedAttribures</li> 42 * </ul> 43 */ 44 public class _PageProperties extends MultiPropertyTest { 45 46 /** 47 * Switch on Header and Footer properties 48 * so all props can be tested. 49 */ 50 protected void before() { 51 try { 52 oObj.setPropertyValue("HeaderIsOn", Boolean.TRUE); 53 oObj.setPropertyValue("FooterIsOn", Boolean.TRUE); 54 } catch (com.sun.star.beans.UnknownPropertyException upe) { 55 log.println("Don't know the Property 'HeaderIsOn' or 'FooterIsOn'"); 56 } catch (com.sun.star.lang.WrappedTargetException wte) { 57 log.println("WrappedTargetException while setting Property 'HeaderIsOn' or 'FooterIsOn'"); 58 } catch (com.sun.star.lang.IllegalArgumentException iae) { 59 log.println("IllegalArgumentException while setting Property 'HeaderIsOn' or 'FooterIsOn'"); 60 } catch (com.sun.star.beans.PropertyVetoException pve) { 61 log.println("PropertyVetoException while setting Property 'HeaderIsOn' or 'FooterIsOn'"); 62 } 63 } 64 65 /** 66 * This property is system dependent and printer dependent. 67 * So only reading it does make sense, since it cannot be determined, if 68 * it is set to a allowed value. 69 */ 70 public void _PrinterPaperTray() { 71 boolean res = false; 72 String setting = null; 73 try { 74 setting = (String)oObj.getPropertyValue("PrinterPaperTray"); 75 log.println("Property 'PrinterPaperTray' is set to '" + setting + "'."); 76 res = setting != null; 77 } 78 catch(com.sun.star.beans.UnknownPropertyException e) { 79 log.println("Don't know the Property 'PrinterPaperTray'"); 80 } catch (com.sun.star.lang.WrappedTargetException wte) { 81 log.println("WrappedTargetException while getting Property 'PrinterPaperTray'"); 82 } 83 tRes.tested("PrinterPaperTray", res); 84 } 85 86 /** 87 * Create some valid user defined attributes 88 */ 89 public void _UserDefinedAttributes() { 90 XNameContainer uda = null; 91 boolean res = false; 92 try { 93 uda = (XNameContainer) AnyConverter.toObject( 94 new Type(XNameContainer.class), 95 oObj.getPropertyValue("UserDefinedAttributes")); 96 AttributeData attr = new AttributeData(); 97 attr.Namespace = "http://www.sun.com/staroffice/apitest/Cellprop"; 98 attr.Type="CDATA"; 99 attr.Value="true"; 100 uda.insertByName("Cellprop:has-first-alien-attribute",attr); 101 String[] els = uda.getElementNames(); 102 oObj.setPropertyValue("UserDefinedAttributes",uda); 103 uda = (XNameContainer) AnyConverter.toObject( 104 new Type(XNameContainer.class), 105 oObj.getPropertyValue("UserDefinedAttributes")); 106 els = uda.getElementNames(); 107 Object obj = uda.getByName("Cellprop:has-first-alien-attribute"); 108 res = true; 109 } catch (com.sun.star.beans.UnknownPropertyException upe) { 110 log.println("Don't know the Property 'UserDefinedAttributes'"); 111 } catch (com.sun.star.lang.WrappedTargetException wte) { 112 log.println("WrappedTargetException while getting Property 'UserDefinedAttributes'"); 113 } catch (com.sun.star.container.NoSuchElementException nee) { 114 log.println("added Element isn't part of the NameContainer"); 115 } catch (com.sun.star.lang.IllegalArgumentException iae) { 116 log.println("IllegalArgumentException while getting Property 'UserDefinedAttributes'"); 117 } catch (com.sun.star.beans.PropertyVetoException pve) { 118 log.println("PropertyVetoException while getting Property 'UserDefinedAttributes'"); 119 } catch (com.sun.star.container.ElementExistException eee) { 120 log.println("ElementExistException while getting Property 'UserDefinedAttributes'"); 121 } 122 tRes.tested("UserDefinedAttributes",res); 123 } 124 125 } 126