Search in sources :

Example 1 with RStyle

use of org.docx4j.wml.RStyle in project TranskribusCore by Transkribus.

the class DocxBuilder method addFootnote.

public static void addFootnote(int i, String text, FootnotesPart footnotesPart, R r) throws JAXBException, Docx4JException {
    // Add the note number in the run
    CTFtnEdnRef ftnednref = factory.createCTFtnEdnRef();
    JAXBElement<org.docx4j.wml.CTFtnEdnRef> ftnednrefWrapped = factory.createRFootnoteReference(ftnednref);
    r.getContent().add(ftnednrefWrapped);
    ftnednref.setId(BigInteger.valueOf(i));
    // escape the special chars for XML
    String escapedText = StringEscapeUtils.escapeXml(text);
    /*
	     * Test: try to set footnote reference
	     */
    org.docx4j.wml.RPr props = factory.createRPr();
    RStyle rStyle = new RStyle();
    rStyle.setVal("FootnoteReference");
    props.setRStyle(rStyle);
    r.setRPr(props);
    // Create a footnote in the footnotesPart
    String openXML = "<w:footnote w:id=\"" + i + "\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\">" + "<w:p>" + "<w:pPr>" + "<w:pStyle w:val=\"FootnoteText\"/>" + "<w:rPr>" + "<w:lang w:val=\"en-AU\"/>" + "</w:rPr>" + "</w:pPr>" + "<w:r>" + "<w:rPr>" + "<w:rStyle w:val=\"FootnoteReference\"/>" + "<w:vertAlign w:val=\"superscript\" />" + "</w:rPr>" + "<w:footnoteRef/>" + "</w:r>" + "<w:r>" + "<w:t xml:space=\"preserve\"> </w:t>" + "</w:r>" + "<w:r>" + "<w:rPr>" + "<w:lang w:val=\"en-AU\"/>" + "</w:rPr>" + "<w:t>" + escapedText + "</w:t>" + "</w:r>" + "</w:p>" + "</w:footnote>";
    CTFtnEdn ftnedn = (CTFtnEdn) XmlUtils.unmarshalString(openXML, Context.jc, CTFtnEdn.class);
    footnotesPart.getContents().getFootnote().add(ftnedn);
}
Also used : CTFtnEdnRef(org.docx4j.wml.CTFtnEdnRef) CTFtnEdn(org.docx4j.wml.CTFtnEdn) RStyle(org.docx4j.wml.RStyle) RPr(org.docx4j.wml.RPr)

Example 2 with RStyle

use of org.docx4j.wml.RStyle in project docx4j-template by vindell.

the class SdtFinder_2 method printSdtPrContent.

// 解析样式,区分纯文本和格式文本
public void printSdtPrContent(SdtPr sdtPr) {
    StringBuffer sb = new StringBuffer();
    List<Object> rprList = sdtPr.getRPrOrAliasOrLock();
    boolean flag = false;
    for (Object obj : rprList) {
        if (obj instanceof JAXBElement) {
            String eName = ((JAXBElement) obj).getName().getLocalPart();
            // 布尔类型特殊处理
            if ("temporary".equals(eName)) {
                sb.append(" 替换后是否删除内容控件:").append("是");
            } else if ("text".equals(eName)) {
                // 纯文本是否允许回车特殊处理
                // CTSdtText判断是否回车代码不准确
                // if (this.multiLine == null) {
                // return true;
                // }
                flag = true;
                String textXml = XmlUtils.marshaltoString(obj, true, true);
                if (textXml.indexOf("w:multiLine") != -1) {
                    sb.append(" 是否允许回车:").append("是");
                }
            }
            obj = XmlUtils.unwrap(obj);
            if (obj instanceof Alias) {
                Alias alias = (Alias) obj;
                if (alias != null) {
                    sb.append(" 标题:").append(alias.getVal());
                }
            } else if (obj instanceof CTLock) {
                CTLock lock = (CTLock) obj;
                if (lock != null) {
                    if (lock.getVal().value().toUpperCase().equals("CONTENTLOCKED")) {
                        sb.append(" 锁定方式:").append("无法编辑内容");
                    } else if (lock.getVal().value().toUpperCase().equals("SDTLOCKED")) {
                        sb.append(" 锁定方式:").append("无法删除内容控件");
                    } else if (lock.getVal().value().toUpperCase().equals("SDTCONTENTLOCKED")) {
                        sb.append(" 锁定方式:").append("无法删除内容控件,无法编辑内容");
                    } else {
                        sb.append(" 锁定方式:").append(lock.getVal());
                    }
                }
            } else if (obj instanceof RPr) {
                RPr rpr = (RPr) obj;
                if (rpr != null) {
                    RStyle rprStyle = rpr.getRStyle();
                    if (rprStyle != null) {
                        sb.append(" 样式名称:").append(rprStyle.getVal());
                    }
                }
            }
        } else if (obj instanceof Tag) {
            Tag tag = (Tag) obj;
            if (tag != null) {
                sb.append(" tag标记:").append(tag.getVal());
            }
        } else if (obj instanceof Id) {
            Id id = (Id) obj;
            if (id != null) {
                sb.append(" id:").append(id.getVal());
            }
        }
    }
    if (flag) {
        sb.append(" 内容控件类型:").append("纯文本");
    } else {
        sb.append(" 内容控件类型:").append("格式文本");
    }
    System.out.println(sb.toString());
}
Also used : CTLock(org.docx4j.wml.CTLock) RPr(org.docx4j.wml.RPr) Alias(org.docx4j.wml.SdtPr.Alias) RStyle(org.docx4j.wml.RStyle) JAXBElement(javax.xml.bind.JAXBElement) Tag(org.docx4j.wml.Tag) Id(org.docx4j.wml.Id)

Aggregations

RPr (org.docx4j.wml.RPr)2 RStyle (org.docx4j.wml.RStyle)2 JAXBElement (javax.xml.bind.JAXBElement)1 CTFtnEdn (org.docx4j.wml.CTFtnEdn)1 CTFtnEdnRef (org.docx4j.wml.CTFtnEdnRef)1 CTLock (org.docx4j.wml.CTLock)1 Id (org.docx4j.wml.Id)1 Alias (org.docx4j.wml.SdtPr.Alias)1 Tag (org.docx4j.wml.Tag)1