Search in sources :

Example 1 with IInnerTagFactory

use of net.heartsome.cat.common.innertag.factory.IInnerTagFactory in project translationstudio8 by heartsome.

the class InnerTagUtil method parseXmlToDisplayValue.

/**
	 * 将带内部标记的文本由XML格式转换为显示格式的文本
	 * @param originalValue
	 *            原始的带内部标记的XML格式的文本
	 * @return ;
	 */
public static TreeMap<String, InnerTagBean> parseXmlToDisplayValue(StringBuffer originalValue, TagStyle style) {
    // 得到标签映射map(key: 内部标记;value: 内部标记实体)
    TreeMap<String, InnerTagBean> tags = new TreeMap<String, InnerTagBean>(new Comparator<String>() {

        public int compare(String str1, String str2) {
            int num1 = InnerTagUtil.getStyledTagNum(str1);
            int num2 = InnerTagUtil.getStyledTagNum(str2);
            if (num1 == num2) {
                return str1.indexOf(String.valueOf(num1)) - str2.indexOf(String.valueOf(num1));
            }
            return num1 - num2;
        }
    });
    if (originalValue == null || originalValue.length() == 0) {
        return tags;
    }
    placeHolderCreater.setStyle(style);
    IInnerTagFactory innerTagFactory = new XliffInnerTagFactory(originalValue.toString(), placeHolderCreater);
    // 提取标记之后的文本。
    originalValue.replace(0, originalValue.length(), innerTagFactory.getText());
    List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
    if (innerTagBeans != null && innerTagBeans.size() > 0) {
        for (int i = 0; i < innerTagBeans.size(); i++) {
            String placeHolder = placeHolderCreater.getPlaceHolder(innerTagBeans, i);
            tags.put(placeHolder, innerTagBeans.get(i));
        // originalValue.replace(innerTagBean.getOffset(), innerTagBean.getOffset(), innerTag.toString());
        }
    }
    return tags;
}
Also used : XliffInnerTagFactory(net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory) InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean) IInnerTagFactory(net.heartsome.cat.common.innertag.factory.IInnerTagFactory) TreeMap(java.util.TreeMap)

Example 2 with IInnerTagFactory

use of net.heartsome.cat.common.innertag.factory.IInnerTagFactory in project translationstudio8 by heartsome.

the class InnerTagUtil method parseXmlToDisplayValueFromSource.

/**
	 * 根据 source 的内容显示内部标记
	 * @param originalValue
	 *            原始值
	 * @param srcOriginalValue
	 *            Source 值
	 * @return ;
	 */
public static Map<String, InnerTagBean> parseXmlToDisplayValueFromSource(String source, StringBuffer originalValue, TagStyle style) {
    // 得到标签映射map(key: 内部标记;value: 内部标记实体)
    TreeMap<String, InnerTagBean> tags = new TreeMap<String, InnerTagBean>(new Comparator<String>() {

        public int compare(String str1, String str2) {
            int num1 = InnerTagUtil.getStyledTagNum(str1);
            int num2 = InnerTagUtil.getStyledTagNum(str2);
            if (num1 == num2) {
                return str1.indexOf(String.valueOf(num1)) - str2.indexOf(String.valueOf(num1));
            }
            return num1 - num2;
        }
    });
    if (originalValue == null || originalValue.length() == 0) {
        return tags;
    }
    placeHolderCreater.setStyle(style);
    IInnerTagFactory innerTagFactory = new XliffInnerTagFactory(source, placeHolderCreater);
    List<InnerTagBean> sourceInnerTagBeans = innerTagFactory.getInnerTagBeans();
    if (sourceInnerTagBeans != null && sourceInnerTagBeans.size() > 0) {
        int index = -1;
        for (int i = 0; i < sourceInnerTagBeans.size(); i++) {
            InnerTagBean innerTagBean = sourceInnerTagBeans.get(i);
            String placeHolder = placeHolderCreater.getPlaceHolder(sourceInnerTagBeans, i);
            tags.put(placeHolder, innerTagBean);
            // String xml1 = FindReplaceDocumentAdapter.escapeForRegExPattern(entry.getValue());
            String xml = innerTagBean.getContent();
            if ((index = originalValue.indexOf(xml, index)) != -1) {
                // 替换 Source 中存在的标记
                originalValue.replace(index, index + xml.length(), placeHolder);
                index += placeHolder.length();
            }
        }
    }
    // 替换目标文本中的错误标记
    String target = innerTagFactory.parseInnerTag(originalValue.toString());
    originalValue.replace(0, originalValue.length(), target);
    return tags;
}
Also used : XliffInnerTagFactory(net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory) InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean) IInnerTagFactory(net.heartsome.cat.common.innertag.factory.IInnerTagFactory) TreeMap(java.util.TreeMap)

Example 3 with IInnerTagFactory

use of net.heartsome.cat.common.innertag.factory.IInnerTagFactory in project translationstudio8 by heartsome.

the class SegmentViewer method setText.

/**
	 * @see net.heartsome.cat.ts.ui.innertag.ISegmentViewer#setText(java.lang.String)
	 */
public void setText(String text) {
    // 重置缓存的标记。
    reset();
    if (isSource()) {
        // 当前是源文本
        IInnerTagFactory innerTagFactory = new XliffInnerTagFactory(text, placeHolderBuilder);
        List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
        for (InnerTagBean innerTagBean : innerTagBeans) {
            InnerTag innerTag = InnerTagUtil.createInnerTagControl(getTextWidget(), innerTagBean, tagStyle);
            innerTag.setVisible(false);
            innerTagCacheList.add(innerTag);
            sourceMaxTagIndex = Math.max(sourceMaxTagIndex, innerTagBean.getIndex());
        }
        // 记录错误标记的起始,source 中所有标记都不是错误标记。
        errorTagStart = innerTagCacheList.size();
        text = innerTagFactory.getText();
    } else {
        // 当前是目标文本
        XliffInnerTagFactory innerTagFactory = new XliffInnerTagFactory(source, placeHolderBuilder);
        // source 中包含的内部标记。
        List<InnerTagBean> sourceInnerTagBeans = innerTagFactory.getInnerTagBeans();
        // 记录错误标记的起始,source 中所有标记都不是错误标记。
        errorTagStart = sourceInnerTagBeans.size();
        // 如果当前是 Target,就先记录 Source 中的最大索引。
        for (InnerTagBean innerTagBean : sourceInnerTagBeans) {
            // 记录source中内部标记的最大标记索引。
            sourceMaxTagIndex = Math.max(sourceMaxTagIndex, innerTagBean.getIndex());
        }
        text = innerTagFactory.parseInnerTag(text, true);
        List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
        for (InnerTagBean innerTagBean : innerTagBeans) {
            InnerTag innerTag = InnerTagUtil.createInnerTagControl(getTextWidget(), innerTagBean, tagStyle);
            innerTag.setVisible(false);
            innerTagCacheList.add(innerTag);
        }
    }
    getTextWidget().setText(resetRegularString(text));
}
Also used : XliffInnerTagFactory(net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory) InnerTag(net.heartsome.cat.common.ui.innertag.InnerTag) IInnerTagFactory(net.heartsome.cat.common.innertag.factory.IInnerTagFactory) InnerTagBean(net.heartsome.cat.common.innertag.InnerTagBean)

Aggregations

InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)3 IInnerTagFactory (net.heartsome.cat.common.innertag.factory.IInnerTagFactory)3 XliffInnerTagFactory (net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory)3 TreeMap (java.util.TreeMap)2 InnerTag (net.heartsome.cat.common.ui.innertag.InnerTag)1