Page 1 of 1

how to set showingPlcHdr in SdtPr

PostPosted: Wed May 25, 2011 10:42 pm
by Richard
Hi,

I'd like to set the "showingPlcHdr" property for an SdtPr object. Unfortunatelly it is represented by a BooleanDefaultTrue object, which from my understanding also stands for the "temporary" property (s.b.). How can I ensure that the "showingPlcHdr" property is set and not the "temporary" one?

This is the corresponding part from SdtPr.java:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
/**
 * <element name="lock" type="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}CT_Lock" minOccurs="0"/>
 * <element name="placeholder" type="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}CT_Placeholder" minOccurs="0"/>
 * <element name="showingPlcHdr" type="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}BooleanDefaultTrue" minOccurs="0"/>
 * <element name="dataBinding" type="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}CT_DataBinding" minOccurs="0"/>
 * <element name="temporary" type="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}BooleanDefaultTrue" minOccurs="0"/>
 * <element ref="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}id" minOccurs="0"/>
 * <element ref="{http://schemas.openxmlformats.org/wordprocessingml/2006/main}tag" minOccurs="0"/>
**/


 /**
     * Gets the value of the rPrOrAliasOrLock property.
     *
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the rPrOrAliasOrLock property.
     *
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getRPrOrAliasOrLock().add(newItem);
     * </pre>
     *
     *
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link JAXBElement }{@code <}{@link CTSdtDate }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtComboBox }{@code >}
     * {@link JAXBElement }{@code <}{@link CTDataBinding }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtDocPart }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.RichText }{@code >}
     * {@link JAXBElement }{@code <}{@link RPr }{@code >}
     * {@link JAXBElement }{@code <}{@link BooleanDefaultTrue }{@code >}
     * {@link JAXBElement }{@code <}{@link CTLock }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.Group }{@code >}
     * {@link Id }
     * {@link JAXBElement }{@code <}{@link SdtPr.Citation }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.Picture }{@code >}
     * {@link JAXBElement }{@code <}{@link CTPlaceholder }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtText }{@code >}
     * {@link JAXBElement }{@code <}{@link BooleanDefaultTrue }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.Alias }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtDocPart }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.Equation }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtDropDownList }{@code >}
     * {@link Tag }
     * {@link JAXBElement }{@code <}{@link SdtPr.Bibliography }{@code >}
     *
     *
     */

 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4


Richard

Re: how to set showingPlcHdr in SdtPr

PostPosted: Thu May 26, 2011 1:14 am
by jason
Use the ObjectFactory method:
Code: Select all
public JAXBElement<BooleanDefaultTrue> createSdtPrShowingPlcHdr(BooleanDefaultTrue value)


The JAXBElement wrapper tells JAXB what it needs to know.

Re: how to set showingPlcHdr in SdtPr

PostPosted: Thu May 26, 2011 6:40 pm
by Richard
And if I want to test for this property? At the moment I'm using:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
List<Object> property = elem.getSdtPr().getRPrOrAliasOrLock();

for (Object o: property) {
    o = XmlUtils.unwrap(o);
       
    if (o instanceof BooleanDefaultTrue) {
        // code goes here
   }
}

 
Parsed in 0.013 seconds, using GeSHi 1.0.8.4


Is there a more typesafe way to perform the check for showingPlcHdr?

Re: how to set showingPlcHdr in SdtPr

PostPosted: Thu May 26, 2011 9:21 pm
by jason
Don't call XmlUtils.unwrap(o); instead, look at:

Code: Select all
         log.debug("Unwrapped " + ((JAXBElement)o).getDeclaredType().getName() );
         log.debug("name: " + ((JAXBElement)o).getName() );