/** * creates a ctype value for the given {@link Code} object and the given {@link TAG}. * * @param code the code object * @param tag the xliff TAG * @return a ctype value for the given {@link Code} object and the given {@link TAG}. */ private String createCtype(Code code, TAG tag) { String result = ""; String codeType = code.getType(); if (!isValidCtype(tag, codeType)) { result = EXTENDED_CODE_TYPE_PREFIX; } if (codeType == null || codeType.isEmpty()) { result += "empty"; } else { // escape xml result += Util.escapeToXML(codeType, 1, false, null); // replace blanks in ctype values to underscores result = result.replaceAll(" ", "_"); } return result; }
sb.append(text.substring(startPos, i)); if ( tf.getCode(text.charAt(++i)).getType().equals(Code.TYPE_LB) ) { sb.append('\n');
if (!tag.supported.isEmpty() && !code.getType().equals(Code.TYPE_NULL)) { sb.append(" ctype=\"").append(createCtype(code, tag)).append("\"");
private String makeDisplayCode (Code code) { if ( mode == 0 ) { // Generic code if ( code.getData().isEmpty() ) { if ( code.getType().equals(SEGTYPECHAR) ) { return code.getOuterData();
code = codes.get(TextFragment.toIndex(codedText.charAt(++i))); if ( code.getType().equals(SEGTYPECHAR) ) { // A segment marker if ( code.getTagType() == TagType.OPENING ) { if ( seg != null ) {
tmp.append("<hi type=\"protected\">"); } else { if (Util.isEmpty(code.getType())) { tmp.append(String.format("<bpt i=\"%d\">", code.getId())); } else { tmp.append(String.format("<bpt i=\"%d\" type=\"%s\">", code.getId(), code.getType())); if (Util.isEmpty(code.getType())) { tmp.append(String.format("<ph x=\"%d\">", id)); } else { tmp.append(String.format("<ph x=\"%d\" type=\"%s\">", code.getId(), code.getType())); if (Util.isEmpty(code.getType())) { tmp.append(String.format("<it x=\"%d\" pos=\"begin\">", code.getId())); } else { tmp.append(String.format("<it x=\"%d\" pos=\"begin\" type=\"%s\">", code.getId(), code.getType())); break; case CLOSING: if (Util.isEmpty(code.getType())) { tmp.append(String.format("<it x=\"%d\" pos=\"end\">", code.getId())); } else { tmp.append(String.format("<it x=\"%d\" pos=\"end\" type=\"%s\">", code.getId(), code.getType())); } switch ( codeMode ) { case CODEMODE_GENERIC:
private void checkInlineCodes (TextFragment tf) { if ( params.getUseCodeFinder() ) { params.getCodeFinder().process(tf); } // Escape inline code content List<Code> codes = tf.getCodes(); for ( Code code : codes ) { // Escape the data of the new inline code (and only them) if ( code.getType().equals(InlineCodeFinder.TAGTYPE) ) { code.setData(encoder.encode(code.getData(), EncoderContext.SKELETON)); } } }
case TextFragment.MARKER_OPENING: code = codes.get(TextFragment.toIndex(text.charAt(++i))); if (code.getType().equals(Code.TYPE_CDATA)) { inlineCdata = true; case TextFragment.MARKER_CLOSING: code = codes.get(TextFragment.toIndex(text.charAt(++i))); if (code.getType().equals(Code.TYPE_CDATA)) { inlineCdata = false;
private void addClosingCode(TextFragment tf, RunContainer rc, Code openCode) { Code code = new Code(TagType.CLOSING, openCode.getType()); code.setData("</" + rc.getType().getValue() + openCode.getId() + ">"); code.setId(openCode.getId()); // Clear container default properties runCodeStack.pop(); tf.append(code); } }
if ( tf.getCodes().size() == 1 ) { code = tf.getCode(0); if ( code.getType().equals("font") ) {
final public String codeString() throws ParseException { if (jj_2_13(2)) { jj_consume_token(DATA); {if ("" != null) return code.getData() == null ? "" : code.getData();} } else if (jj_2_14(2)) { jj_consume_token(OUTER_DATA); {if ("" != null) return code.getOuterData() == null ? "" : code.getOuterData();} } else if (jj_2_15(2)) { jj_consume_token(ORIGINAL_ID); {if ("" != null) return code.getOriginalId() == null ? "" : code.getOriginalId();} } else if (jj_2_16(2)) { jj_consume_token(TYPE); {if ("" != null) return code.getType() == null ? "" : code.getType();} } else { jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); }
newCode.setOuterData(oriCode.getOuterData()); newCode.setReferenceFlag(oriCode.hasReference()); newCode.setType(oriCode.getType());
private void applyCodeFinder (TextFragment tf) { // Find the inline codes params.codeFinder.process(tf); // Escape inline code content List<Code> codes = tf.getCodes(); for ( Code code : codes ) { // Escape the data of the new inline code (and only them) if ( code.getType().equals(InlineCodeFinder.TAGTYPE) ) { if ( cfEncoder == null ) { encoderManager.setDefaultOptions(getParameters(), this.encoding, this.lineBreak); encoderManager.updateEncoder(getMimeType()); cfEncoder = getEncoderManager().getEncoder(); //TODO: We should use the proper output encoding here, not force UTF-8, but we do not know it cfEncoder.setOptions(params, "utf-8", lineBreak); } code.setData(cfEncoder.encode(code.getData(), EncoderContext.TEXT)); } } }
destFrag.delete(i-1, i+1); ctag = destFrag.insert(net.sf.okapi.lib.xliff2.core.TagType.OPENING, code.getType(), id, code.getData(), i-1, false, true); ctag.setDisp(code.getDisplayText()); ctag.setCanCopy(code.isCloneable()); destFrag.delete(i-1, i+1); ctag = destFrag.insert(net.sf.okapi.lib.xliff2.core.TagType.CLOSING, code.getType(), id, code.getData(), i-1, true, true); ctag.setDisp(code.getDisplayText()); ctag.setCanCopy(code.isCloneable()); destFrag.delete(i-1, i+1); ctag = destFrag.insert(net.sf.okapi.lib.xliff2.core.TagType.STANDALONE, code.getType(), id, code.getData(), i-1, false, true); ctag.setDisp(code.getDisplayText()); ctag.setCanCopy(code.isCloneable());