Search in sources :

Example 1 with SearchEntry

use of net.heartsome.cat.ts.websearch.bean.SearchEntry in project translationstudio8 by heartsome.

the class WebSearchPreferencePage method downSelectItem.

public void downSelectItem() {
    int selectIndex = getSelectIndex();
    if (-1 == selectIndex || cache.size() - 1 == selectIndex) {
        return;
    }
    SearchEntry currentSelect = cache.get(selectIndex);
    SearchEntry lastData = cache.get(selectIndex + 1);
    cache.set(selectIndex + 1, currentSelect);
    cache.set(selectIndex, lastData);
    checkboxTableViewer.refresh();
    setDirty(true);
    updateState();
}
Also used : SearchEntry(net.heartsome.cat.ts.websearch.bean.SearchEntry)

Example 2 with SearchEntry

use of net.heartsome.cat.ts.websearch.bean.SearchEntry in project translationstudio8 by heartsome.

the class WebSearchPreferencePage method deleteSelectItem.

public void deleteSelectItem() {
    int selectIndex = getSelectIndex();
    if (-1 == selectIndex) {
        return;
    }
    SearchEntry searchEntry = cache.get(selectIndex);
    boolean config = MessageDialog.openConfirm(getShell(), Messages.getString("Websearch.WebSearcPreferencePage.tipTitle"), MessageFormat.format(Messages.getString("Websearch.WebSearcPreferencePage.deleteConfig"), searchEntry.getSearchName()));
    if (config) {
        cache.remove(selectIndex);
        checkboxTableViewer.refresh();
        setDirty(true);
        updateState();
    }
}
Also used : SearchEntry(net.heartsome.cat.ts.websearch.bean.SearchEntry)

Example 3 with SearchEntry

use of net.heartsome.cat.ts.websearch.bean.SearchEntry in project translationstudio8 by heartsome.

the class WebSearchPreferencStore method storeConfig.

/**
	 * 保存设置值
	 * @param searchEntry
	 *            ;
	 */
public void storeConfig(List<SearchEntry> searchEntry) {
    FileOutputStream out = null;
    boolean hasError = false;
    try {
        out = new FileOutputStream(customConfigPath);
        writeContent(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
        writeContent(out, "<WebSearchInfo xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instancexmlns:xsd=http://www.w3.org/2001/XMLSchema\">\r\n");
        writeContent(out, "	<Providers>\r\n");
        if (null != searchEntry) {
            for (SearchEntry s : searchEntry) {
                writeContent(out, convert2Xml(s));
            }
        }
        writeContent(out, "	</Providers>\r\n </WebSearchInfo>");
        out.flush();
        support.firePropertyChange("URL", null, getUseredConfig(searchEntry));
    } catch (FileNotFoundException e) {
        hasError = true;
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        hasError = true;
        e.printStackTrace();
    } catch (IOException e) {
        hasError = true;
        e.printStackTrace();
    } finally {
        try {
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (hasError) {
            XMLModifier modifier;
            try {
                modifier = new XMLModifier(customVu.getVTDNav());
                modifier.output(customConfigPath);
            } catch (ModifyException e) {
                e.printStackTrace();
                logger.error("", e);
            } catch (TranscodeException e) {
                e.printStackTrace();
                logger.error("", e);
            } catch (IOException e) {
                e.printStackTrace();
                logger.error("", e);
            }
        } else {
            try {
                customVu.parseFile(customConfigPath, false);
            } catch (ParseException e) {
                e.printStackTrace();
                logger.error("", e);
            } catch (IOException e) {
                e.printStackTrace();
                logger.error("", e);
            }
        }
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ModifyException(com.ximpleware.ModifyException) IOException(java.io.IOException) XPathParseException(com.ximpleware.XPathParseException) ParseException(com.ximpleware.ParseException) SearchEntry(net.heartsome.cat.ts.websearch.bean.SearchEntry) TranscodeException(com.ximpleware.TranscodeException)

Example 4 with SearchEntry

use of net.heartsome.cat.ts.websearch.bean.SearchEntry in project translationstudio8 by heartsome.

the class WebSearchPreferencStore method getConfig.

/**
	 * @param vu
	 * @param isDefault
	 *            getCustomContent===false:返回所有内容 getCustomContent===true :返回非默认的内容
	 * @return ;
	 */
private List<SearchEntry> getConfig(VTDUtils vu, boolean getCustomContent) {
    VTDNav vn = vu.getVTDNav();
    AutoPilot mainAp = new AutoPilot(vn);
    AutoPilot uesedAp = new AutoPilot(vn);
    AutoPilot nameAp = new AutoPilot(vn);
    AutoPilot urlAp = new AutoPilot(vn);
    List<SearchEntry> cache = new ArrayList<SearchEntry>();
    try {
        mainAp.selectXPath("/WebSearchInfo/Providers/ProviderInfo");
        uesedAp.selectXPath("./Used");
        nameAp.selectXPath("./Name");
        urlAp.selectXPath("./Url");
        SearchEntry temp = null;
        while (mainAp.evalXPath() != -1) {
            int attrVal = vn.getAttrVal("isDefault");
            if (getCustomContent) {
                if (-1 != attrVal) {
                    continue;
                }
            }
            temp = new SearchEntry();
            if (-1 != attrVal) {
                temp.setDefault(true);
            }
            int idIndex = vn.getAttrVal("id");
            if (-1 != idIndex) {
                temp.setId(vn.toString(idIndex));
            }
            vn.push();
            uesedAp.resetXPath();
            if (uesedAp.evalXPath() != -1) {
                int textIndex = vn.getText();
                if (-1 != textIndex && null != temp) {
                    temp.setChecked("true".equalsIgnoreCase(vn.toString(textIndex)) ? true : false);
                }
            } else {
                temp = null;
            }
            vn.pop();
            vn.push();
            nameAp.resetXPath();
            if (nameAp.evalXPath() != -1) {
                int textIndex = vn.getText();
                if (-1 != textIndex && null != temp) {
                    temp.setSearchName(TextUtil.resetSpecialString(vn.toString(textIndex)));
                }
            } else {
                temp = null;
            }
            vn.pop();
            vn.push();
            urlAp.resetXPath();
            if (urlAp.evalXPath() != -1) {
                int textIndex = vn.getText();
                if (-1 != textIndex && null != temp) {
                    temp.setSearchUrl((TextUtil.resetSpecialString(vn.toString(textIndex))));
                }
            } else {
                temp = null;
            }
            vn.pop();
            if (null != temp) {
                cache.add(temp);
            }
        }
    } catch (XPathEvalException e) {
        e.printStackTrace();
        logger.error("", e);
    } catch (NavException e) {
        e.printStackTrace();
        logger.error("", e);
    } catch (XPathParseException e) {
        e.printStackTrace();
        logger.error("", e);
    }
    return cache;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) ArrayList(java.util.ArrayList) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException) VTDNav(com.ximpleware.VTDNav) SearchEntry(net.heartsome.cat.ts.websearch.bean.SearchEntry)

Example 5 with SearchEntry

use of net.heartsome.cat.ts.websearch.bean.SearchEntry in project translationstudio8 by heartsome.

the class WebSearchPreferencStore method getDefaluSearchConfig.

/**
	 * 获取默认的配置信息,包括自定义配置文件和默认配置文件两个文件中的信息
	 * @return ;
	 */
public List<SearchEntry> getDefaluSearchConfig() {
    List<SearchEntry> config = getConfig(customVu, true);
    for (SearchEntry temp : config) {
        temp.setChecked(false);
    }
    List<SearchEntry> defaultconfig = getConfig(defaultVu, false);
    defaultconfig.addAll(config);
    return defaultconfig;
}
Also used : SearchEntry(net.heartsome.cat.ts.websearch.bean.SearchEntry)

Aggregations

SearchEntry (net.heartsome.cat.ts.websearch.bean.SearchEntry)10 XPathParseException (com.ximpleware.XPathParseException)2 AddSearchEntryDialog (net.heartsome.cat.ts.websearch.ui.dialog.AddSearchEntryDialog)2 OKHandler (net.heartsome.cat.ts.websearch.ui.dialog.AddSearchEntryDialog.OKHandler)2 AutoPilot (com.ximpleware.AutoPilot)1 ModifyException (com.ximpleware.ModifyException)1 NavException (com.ximpleware.NavException)1 ParseException (com.ximpleware.ParseException)1 TranscodeException (com.ximpleware.TranscodeException)1 VTDNav (com.ximpleware.VTDNav)1 XMLModifier (com.ximpleware.XMLModifier)1 XPathEvalException (com.ximpleware.XPathEvalException)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 BrowserTab (net.heartsome.cat.ts.websearch.ui.browser.BrowserTab)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 Image (org.eclipse.swt.graphics.Image)1