Search in sources :

Example 21 with VTDException

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

the class AbstractPart method loadFile.

protected void loadFile() throws InternalFileException {
    File f = new File(this.partXmlPath);
    VTDGen vg = new VTDGen();
    FileInputStream fis = null;
    byte[] b = new byte[(int) f.length()];
    try {
        fis = new FileInputStream(f);
        fis.read(b);
    } catch (IOException e) {
        throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
                logger.error("", e);
            }
        }
    }
    vg.setDoc(b);
    try {
        vg.parse(true);
        vu = new VTDUtils(vg.getNav());
        xm = new XMLModifier(vu.getVTDNav());
    } catch (VTDException e) {
        String message = Messages.getString("msexcel.converter.exception.msg1");
        message += "\nFile:" + f.getName() + "\n" + e.getMessage();
        throw new InternalFileException(message);
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDException(com.ximpleware.VTDException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException) IOException(java.io.IOException) VTDException(com.ximpleware.VTDException)

Example 22 with VTDException

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

the class RelsPart method loadRealtionship.

public void loadRealtionship() {
    relationships = new ArrayList<Relationship>();
    String xpath = "/Relationships/Relationship";
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    try {
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            Hashtable<String, String> attrs = vu.getCurrentElementAttributs();
            if (attrs == null) {
            // TODO Error
            }
            String id = attrs.get("Id");
            String type = attrs.get("Type");
            String target = attrs.get("Target");
            Relationship rsp = new Relationship(id, type, target);
            relationships.add(rsp);
        }
    } catch (VTDException e) {
        logger.error("", e);
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) Relationship(net.heartsome.cat.converter.msexcel2007.document.rels.Relationship)

Example 23 with VTDException

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

the class SheetPart method fillShareStringTable.

/***
	 * 将Share String Tbale中的数据填充满,即每一个引用都对应独立的String item
	 * @param sst
	 *            ;
	 * @throws InternalFileException
	 */
public int fillShareStringTable(ShareStringTablePart sst, int index, StringBuffer siBf) throws InternalFileException {
    String xpath = "/worksheet/sheetData/row/c[@t='s']/v";
    try {
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            String c = vu.getElementContent();
            int cInt = 0;
            try {
                cInt = Integer.parseInt(c);
            } catch (NumberFormatException e) {
                throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
            }
            siBf.append(sst.getStringItemFragment(cInt));
            xm.updateToken(vu.getVTDNav().getCurrentIndex() + 1, index + "");
            index++;
        }
        saveAndReload();
    } catch (VTDException e) {
        logger.error("", e);
    } catch (UnsupportedEncodingException e) {
        logger.error("", e);
    }
    return index;
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException)

Example 24 with VTDException

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

the class SheetPart method loadHeaderFooter.

private void loadHeaderFooter() {
    this.headers = new ArrayList<HeaderFooter>();
    this.footers = new ArrayList<HeaderFooter>();
    String xpath = "/worksheet/headerFooter/*";
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    try {
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            String type = vu.getCurrentElementName();
            String c = vu.getElementContent();
            HeaderFooter e = new HeaderFooter(type, c);
            if (type.equals("oddHeader") || type.equals("evenHeader") || type.equals("firstHeader")) {
                headers.add(e);
            } else if (type.equals("oddFooter") || type.equals("evenFooter") || type.equals("firstFooter")) {
                footers.add(e);
            }
        }
    } catch (VTDException e) {
        logger.error("", e);
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot)

Example 25 with VTDException

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

the class StylesPart method loadRedFgStyle.

private void loadRedFgStyle() {
    redStyleIndexs = new ArrayList<Integer>();
    String xpath = "/styleSheet/cellXfs/xf";
    try {
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            String fIdx = vu.getCurrentElementAttribut("fontId", "");
            if (!fIdx.equals("") && isRedColor(Integer.parseInt(fIdx))) {
                redStyleIndexs.add(vu.getVTDNav().getCurrentDepth() - 1);
            }
        }
    } catch (VTDException e) {
        e.printStackTrace();
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot)

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