Search in sources :

Example 6 with VTDException

use of com.ximpleware.VTDException in project translationstudio8 by heartsome.

the class ShapeTxBody method loadParagraph.

private void loadParagraph() {
    pList = new ArrayList<ShapeParagraph>();
    String xpath = "/xdr:txBody/a:p";
    AutoPilot ap = getDeclareNSAutoPilot();
    try {
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            ShapeParagraph p = new ShapeParagraph(vu.getElementFragment());
            pList.add(p);
        }
    } catch (VTDException e) {
        logger.error("", e);
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot)

Example 7 with VTDException

use of com.ximpleware.VTDException in project translationstudio8 by heartsome.

the class Cell method getNonTextContent.

/**
	 * Get rPh & phoneticPr Element fragment
	 * @return ;
	 */
private String getNonTextContent() {
    StringBuffer result = new StringBuffer();
    VTDGen vg = new VTDGen();
    vg.setDoc(content.getBytes());
    VTDUtils vu = null;
    try {
        vg.parse(true);
        vu = new VTDUtils(vg.getNav());
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath("/si/rPh | phoneticPr");
        while (ap.evalXPath() != -1) {
            result.append(vu.getElementFragment());
        }
    } catch (VTDException e) {
        e.printStackTrace();
    }
    return result.toString();
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) VTDGen(com.ximpleware.VTDGen)

Example 8 with VTDException

use of com.ximpleware.VTDException in project translationstudio8 by heartsome.

the class Cell method loadCellCharacterStyle.

private List<Object[]> loadCellCharacterStyle(String content, String cellText) {
    List<Object[]> result = new ArrayList<Object[]>();
    VTDGen vg = new VTDGen();
    vg.setDoc(content.getBytes());
    VTDUtils vu = null;
    try {
        vg.parse(true);
        vu = new VTDUtils(vg.getNav());
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath("/si/r");
        if (ap.evalXPath() != -1) {
            StringBuffer bf = new StringBuffer();
            int start = 0;
            do {
                String rPrC = vu.getChildContent("rPr");
                if (rPrC != null) {
                    rPrC = "<rPr>" + rPrC + "</rPr>";
                    bf.append("rPr=\"").append(ReaderUtil.cleanAttribute(rPrC)).append("\"");
                } else {
                    bf.append(" ");
                }
                String tVal = vu.getChildContent("t");
                if (tVal == null || tVal.length() == 0) {
                    // clear
                    bf.delete(0, bf.length());
                    continue;
                }
                int sos = cellText.indexOf(tVal, start);
                int length = tVal.length();
                Object[] obj = new Object[3];
                obj[0] = sos;
                obj[1] = start = sos + length;
                obj[2] = bf.toString();
                result.add(obj);
                // clear
                bf.delete(0, bf.length());
            } while (ap.evalXPath() != -1);
        }
    } catch (VTDException e) {
        logger.error("", e);
    }
    return result;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) ArrayList(java.util.ArrayList) VTDGen(com.ximpleware.VTDGen)

Example 9 with VTDException

use of com.ximpleware.VTDException in project translationstudio8 by heartsome.

the class Cell method loadCellText.

/**
	 * 加载Cell的文本内容
	 * @param content
	 * @return ;
	 */
private String loadCellText(String content) {
    String result = "";
    VTDGen vg = new VTDGen();
    vg.setDoc(content.getBytes());
    VTDUtils vu = null;
    try {
        vg.parse(true);
        vu = new VTDUtils(vg.getNav());
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath("/si/r");
        if (ap.evalXPath() != -1) {
            StringBuffer bf = new StringBuffer();
            do {
                String tVal = vu.getChildContent("t");
                bf.append(tVal);
            } while (ap.evalXPath() != -1);
            result = bf.toString();
        } else {
            vu.pilot("/si/t");
            result = vu.getElementContent();
        }
    } catch (VTDException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) VTDGen(com.ximpleware.VTDGen)

Example 10 with VTDException

use of com.ximpleware.VTDException in project translationstudio8 by heartsome.

the class DrawingsPart method loadShapeAnchor.

private void loadShapeAnchor() {
    cellAnchorList = new ArrayList<CellAnchor>();
    AutoPilot ap = getAutoPilot();
    try {
        ap.selectXPath("/xdr:wsDr/xdr:twoCellAnchor | xdr:oneCellAnchor");
        while (ap.evalXPath() != -1) {
            String anchorXML = vu.getElementFragment();
            String fromCol = vu.getElementContent("./xdr:from/xdr:col");
            String fromRow = vu.getElementContent("./xdr:from/xdr:row");
            CellAnchor a = new CellAnchor(anchorXML, fromRow, fromCol);
            cellAnchorList.add(a);
        }
    } catch (VTDException e) {
    }
    // sort by row&col ASC
    if (cellAnchorList.size() > 0) {
        Collections.sort(cellAnchorList, new Comparator<CellAnchor>() {

            public int compare(CellAnchor o1, CellAnchor o2) {
                int o1r = Integer.parseInt(o1.getFromRow());
                int o2r = Integer.parseInt(o2.getFromRow());
                int o1c = Integer.parseInt(o1.getFromCol());
                int o2c = Integer.parseInt(o2.getFromCol());
                if (o1r != o2r) {
                    return o1r - o2r;
                } else {
                    return o1c - o2c;
                }
            }
        });
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) CellAnchor(net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor)

Aggregations

VTDException (com.ximpleware.VTDException)27 AutoPilot (com.ximpleware.AutoPilot)20 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)9 VTDGen (com.ximpleware.VTDGen)8 IOException (java.io.IOException)6 InternalFileException (net.heartsome.cat.converter.msexcel2007.common.InternalFileException)5 XMLModifier (com.ximpleware.XMLModifier)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Relationship (net.heartsome.cat.converter.msexcel2007.document.rels.Relationship)3 NavException (com.ximpleware.NavException)2 VTDNav (com.ximpleware.VTDNav)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 EOFException (com.ximpleware.EOFException)1 EncodingException (com.ximpleware.EncodingException)1 EntityException (com.ximpleware.EntityException)1 ModifyException (com.ximpleware.ModifyException)1