Search in sources :

Example 1 with Alias

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

the class SdtFinder method printSdtPrContent.

// 没有解析样式
public void printSdtPrContent(SdtPr sdtPr) {
    StringBuffer sb = new StringBuffer();
    List<Object> rprList = sdtPr.getRPrOrAliasOrLock();
    for (Object obj : rprList) {
        if (obj instanceof JAXBElement) {
            String eName = ((JAXBElement) obj).getName().getLocalPart();
            // 布尔类型特殊处理
            if ("temporary".equals(eName)) {
                sb.append(" 替换后是否删除内容控件:").append("是");
            }
            obj = XmlUtils.unwrap(obj);
            // System.out.println("------after="+ obj.getClass().getName());
            if (obj instanceof CTLock) {
                CTLock lock = (CTLock) obj;
                if (lock != null) {
                    sb.append(" 锁定方式:").append(lock.getVal());
                }
            } else if (obj instanceof Alias) {
                Alias alias = (Alias) obj;
                if (alias != null) {
                    sb.append(" 标题:").append(alias.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());
            }
        }
    }
    System.out.println(sb.toString());
}
Also used : CTLock(org.docx4j.wml.CTLock) Alias(org.docx4j.wml.SdtPr.Alias) JAXBElement(javax.xml.bind.JAXBElement) Tag(org.docx4j.wml.Tag) Id(org.docx4j.wml.Id)

Example 2 with Alias

use of org.docx4j.wml.SdtPr.Alias 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

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