Page 1 of 1

Paragraph properties unavailable as children of paragraph

PostPosted: Thu Sep 26, 2019 4:04 am
by JoaoPereira
Having the following XML available from a template file:

Code: Select all
<w:p w14:paraId="710890F1" w14:textId="3CDF1A39" w:rsidR="00751418" w:rsidRPr="00751418" w:rsidRDefault="00751418" w:rsidP="000F57DD">
<w:pPr>
<w:spacing w:before="40" w:after="40"/>
<w:rPr>
<w:rFonts w:eastAsia="Times New Roman" w:cs="Times New Roman"/>
<w:sz w:val="18"/>
<w:szCs w:val="18"/>
</w:rPr>
</w:pPr>
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<w:bookmarkEnd w:id="0"/>
</w:p>

I want to find the paragraph properties available inside the following paragraph. However when trying to display the paragraph children, only the bookmarkStart and bookmartEnd tags are available. The corresponding code, omitting the paragraph retrieval, is as follows:

Code: Select all
P paragraph = (P) par;
String paragraphId = paragraph.getParaId();

if (paragraphId.equalsIgnoreCase("710890F1")) {
    for(int i=0; i<paragraph.getContent().size(); i++) {
        Log.d("DOCX", "String from object: " + ((JAXBElement<?>) paragraph.getContent().get(i)).getName());
    }
}

Logs are as follows:

Code: Select all
String from object: {http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkStart
String from object: {http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkEnd

What's the reason for this? Note that I am using version 6.1.1 as this is an Android deployment.

Thank you.

Re: Paragraph properties unavailable as children of paragrap

PostPosted: Thu Sep 26, 2019 4:14 pm
by jason

Re: Paragraph properties unavailable as children of paragrap

PostPosted: Thu Sep 26, 2019 11:15 pm
by JoaoPereira
Worked fine, thank you.

Any reason not to include the paragraph properties in the content? Are there any other related cases in which children are not part of the content?

Re: Paragraph properties unavailable as children of paragrap

PostPosted: Fri Sep 27, 2019 12:43 am
by JoaoPereira
Another question, from the following XML

Code: Select all
<w:sdt>
<w:sdtPr>
<w:rPr>...</w:rPr>
<w:id w:val="1083413922"/>
<w14:checkbox>
<w14:checked w14:val="1"/>
<w14:checkedState w14:val="2612" w14:font="MS Gothic"/>
<w14:uncheckedState w14:val="2610" w14:font="MS Gothic"/>
</w14:checkbox>
</w:sdtPr>
<w:sdtEndPr/>
<w:sdtContent>...</w:sdtContent>
</w:sdt>

Having reached the point of determing the CTStdCell,

Code: Select all
if (checkboxParaIdsInputMap.containsKey(paragraphId)){
    List ctSdtcellList = getAllElementFromObject(tableRow, CTSdtCell.class);

    for(Object cell : ctSdtcellList) {
        if (cell instanceof CTSdtCell) {
            CTSdtCell sdtCell = (CTSdtCell) cell;
            SdtPr cellContent = sdtCell.getSdtPr();
            ...
        }
    }
}

The CTSdtCell is being retrieved accordingly. How do I get the CTSdtCheckbox taking into consideration that SdtPr does not have a content retrieval method?

Re: Paragraph properties unavailable as children of paragrap

PostPosted: Mon Sep 30, 2019 10:29 am
by jason
How do I get the CTSdtCheckbox taking into consideration that SdtPr does not have a content retrieval method?


Acutally it does:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
    /**
     * 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 CTPlaceholder }{@code >}
     * {@link JAXBElement }{@code <}{@link CTDataBinding }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.Alias }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtCheckbox }{@code >}
     * {@link JAXBElement }{@code <}{@link BooleanDefaultTrue }{@code >}
     * {@link JAXBElement }{@code <}{@link BooleanDefaultTrue }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtComboBox }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.Citation }{@code >}
     * {@link JAXBElement }{@code <}{@link CTDataBinding }{@code >}
     * {@link JAXBElement }{@code <}{@link BooleanDefaultTrue }{@code >}
     * {@link JAXBElement }{@code <}{@link CTEmpty }{@code >}
     * {@link Tag }
     * {@link JAXBElement }{@code <}{@link SdtPr.Bibliography }{@code >}
     * {@link JAXBElement }{@code <}{@link CTEmpty }{@code >}
     * {@link JAXBElement }{@code <}{@link CTLock }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtDocPart }{@code >}
     * {@link Id }
     * {@link JAXBElement }{@code <}{@link CTSdtText }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtDate }{@code >}
     * {@link JAXBElement }{@code <}{@link CTColor }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.Equation }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtDocPart }{@code >}
     * {@link JAXBElement }{@code <}{@link BooleanDefaultTrue }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtAppearance }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtDropDownList }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.Picture }{@code >}
     * {@link JAXBElement }{@code <}{@link CTSdtRepeatedSection }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.Group }{@code >}
     * {@link JAXBElement }{@code <}{@link RPr }{@code >}
     * {@link JAXBElement }{@code <}{@link SdtPr.RichText }{@code >}
     *
     *
     */

    public List<Object> getRPrOrAliasOrLock() {
        if (rPrOrAliasOrLock == null) {
            rPrOrAliasOrLock =  new ArrayListWml<Object>(this);
        }
        return this.rPrOrAliasOrLock;
    }
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4


There is also:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
    /**
     * return the first object
     * @param clazz
     * @return
     * @since 3.0.1
     */

    public Object getByClass(Class clazz) {
       
        for (Object o : getRPrOrAliasOrLock()) {
                Object o2 = unwrap(o);
                if ( o2.getClass().equals(clazz) ) {
                        log.debug("found " + clazz.getName());
                        return o2;
                }
        }
       
        return null;           
    }
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


I encourage you to look at the source code for answers :-)

Re: Paragraph properties unavailable as children of paragrap

PostPosted: Mon Sep 30, 2019 10:19 pm
by JoaoPereira
jason wrote:I encourage you to look at the source code for answers :-)

I actually did and fooled around with that method but ultimately was not sure and couldn't accomplish what I wanted, so I gave up on it and asked here.

What actually happened in my previous attempts was that I was able to set the checkbox but the visual part is a text representation and has to be set elsewhere. Managed to do that as well.

Thank you for your help. :D