Search in sources :

Example 6 with ElementBean

use of net.heartsome.cat.ts.ui.advanced.model.ElementBean in project translationstudio8 by heartsome.

the class ADXmlHandler method getconvertXmlElements.

/**
	 * 获取转换配置文件的所有内容
	 * @return ;
	 */
public List<ElementBean> getconvertXmlElements(String xmlLocation) {
    List<ElementBean> elementsList = new LinkedList<ElementBean>();
    VTDNav vn = super.getVTDNav(xmlLocation);
    AutoPilot ap = new AutoPilot(vn);
    ElementBean bean;
    try {
        ap.selectXPath("/ini-file/tag");
        while (ap.evalXPath() != -1) {
            // 如果元素名与元素类型为空,那么当前节点不被添加
            if (vn.getText() == -1 || vn.getAttrVal("hard-break") == -1 || "".equals(vn.toString(vn.getText())) || "".equals(vn.toString(vn.getAttrVal("hard-break")))) {
                continue;
            }
            //开始添加元素名称
            bean = new ElementBean();
            bean.setName(vn.toString(vn.getText()));
            bean.setType(vn.toString(vn.getAttrVal("hard-break")));
            bean.setInlineType(vn.getAttrVal("ctype") != -1 ? vn.toString(vn.getAttrVal("ctype")) : "");
            bean.setTransAttribute(vn.getAttrVal("attributes") != -1 ? vn.toString(vn.getAttrVal("attributes")) : "");
            bean.setRemainSpace(vn.getAttrVal("keep-format") != -1 ? vn.toString(vn.getAttrVal("keep-format")) : "");
            elementsList.add(bean);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return elementsList;
}
Also used : ElementBean(net.heartsome.cat.ts.ui.advanced.model.ElementBean) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) LinkedList(java.util.LinkedList)

Example 7 with ElementBean

use of net.heartsome.cat.ts.ui.advanced.model.ElementBean in project translationstudio8 by heartsome.

the class ADXmlHandler method getAnalysisXmlData.

/**
	 * 获取分析XML文件后的数据(针对于分析XML文件)
	 * @param xmlLocation
	 * @return ;
	 */
public List<ElementBean> getAnalysisXmlData(String xmlLocation) {
    List<ElementBean> beanList = new LinkedList<ElementBean>();
    List<String> elementNameList = new ArrayList<String>();
    VTDNav vn = getVTDNav(xmlLocation);
    AutoPilot ap = new AutoPilot(vn);
    ElementBean bean;
    try {
        ap.selectXPath("//*[text()!='' or not(./*)]");
        while (ap.evalXPath() != -1) {
            String elementName = vn.toString(vn.getCurrentIndex());
            //如果元素名不重复,那么就添加到结果集中
            if (elementNameList.indexOf(elementName) == -1) {
                bean = new ElementBean();
                bean.setName(elementName);
                bean.setType("segment");
                bean.setInlineType("");
                bean.setTransAttribute("");
                bean.setRemainSpace("");
                beanList.add(bean);
                elementNameList.add(elementName);
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return beanList;
}
Also used : ElementBean(net.heartsome.cat.ts.ui.advanced.model.ElementBean) AutoPilot(com.ximpleware.AutoPilot) ArrayList(java.util.ArrayList) VTDNav(com.ximpleware.VTDNav) LinkedList(java.util.LinkedList)

Example 8 with ElementBean

use of net.heartsome.cat.ts.ui.advanced.model.ElementBean in project translationstudio8 by heartsome.

the class AddOrEditElementOfXmlConvertDialog method getElementBean.

public ElementBean getElementBean(String elementName) {
    ElementBean bean;
    Iterator<ElementBean> iter = elementsList.iterator();
    while (iter.hasNext()) {
        bean = iter.next();
        if (elementName.equals(bean.getName())) {
            return bean;
        }
    }
    return null;
}
Also used : ElementBean(net.heartsome.cat.ts.ui.advanced.model.ElementBean)

Aggregations

ElementBean (net.heartsome.cat.ts.ui.advanced.model.ElementBean)8 AutoPilot (com.ximpleware.AutoPilot)2 VTDNav (com.ximpleware.VTDNav)2 LinkedList (java.util.LinkedList)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1