Package org.zanata.model

Examples of org.zanata.model.HSimpleComment


            }
        }
        if (enabledExtensions.contains(SimpleComment.ID)) {
            SimpleComment comment = extensions.findByType(SimpleComment.class);
            if (comment != null) {
                HSimpleComment hComment = to.getComment();

                if (hComment == null) {
                    hComment = new HSimpleComment();
                }
                if (!equals(comment.getValue(), hComment.getComment())) {
                    changed = true;
                    hComment.setComment(comment.getValue());
                    to.setComment(hComment);
                    log.debug("set comment:{}", comment.getValue());
                }
            }
        }
View Full Code Here


     * @see #pullPoTargetComment
     */
    protected boolean pushPoTargetComment(PoTargetHeader fromHeader,
            HPoTargetHeader toHeader, MergeType mergeType) {
        boolean changed = false;
        HSimpleComment hComment = toHeader.getComment();
        if (hComment == null) {
            hComment = new HSimpleComment();
        }
        String fromComment = fromHeader.getComment();
        String toComment = hComment.getComment();
        if (!equals(fromComment, toComment)) {
            // skip #zanata lines
            List<String> fromLines = splitLines(fromComment, ZANATA_TAG);
            StringBuilder sb = new StringBuilder(fromComment.length());
            switch (mergeType) {
            case IMPORT:
                for (String line : fromLines) {
                    if (sb.length() != 0)
                        sb.append(NEWLINE);
                    sb.append(line);
                    changed = true;
                }
                break;

            default: // AUTO or anything else will merge comments
                // to merge, we just append new lines, skip old lines
                List<String> toLines = Collections.emptyList();
                if (toComment != null) {
                    sb.append(toComment);
                    toLines = splitLines(toComment, null);
                }

                for (String line : fromLines) {
                    if (!toLines.contains(line)) {
                        if (sb.length() != 0)
                            sb.append(NEWLINE);
                        sb.append(line);
                        changed = true;
                    }
                }
                break;
            }
            if (changed) {
                hComment.setComment(sb.toString());
                toHeader.setComment(hComment);
            }
        }
        return changed;
    }
View Full Code Here

    }

    private boolean transferFromPoHeader(PoHeader from, HPoHeader to) {
        boolean changed = false;

        HSimpleComment comment = to.getComment();
        if (comment == null) {
            comment = new HSimpleComment();
        }
        if (!equals(from.getComment(), comment.getComment())) {
            changed = true;
            comment.setComment(from.getComment());
            to.setComment(comment);
        }

        String entries = PoUtility.listToHeader(from.getEntries());
        if (!equals(entries, to.getEntries())) {
View Full Code Here

     * @see #pushPoTargetComment
     */
    protected void pullPoTargetComment(HPoTargetHeader fromHeader,
            PoTargetHeader toHeader, List<HTextFlowTarget> hTargets) {
        StringBuilder sb = new StringBuilder();
        HSimpleComment comment = fromHeader.getComment();
        if (comment != null) {
            sb.append(comment.getComment());
        }
        // generate #zanata credit comments
        // order by year, then alphabetically
        Set<TranslatorCredit> zanataCredits = new TreeSet<TranslatorCredit>();
        for (HTextFlowTarget tft : hTargets) {
View Full Code Here

public class TargetCommentTransformer implements
        Transformer<SimpleComment, HasSimpleComment> {

    @Override
    public boolean transform(SimpleComment from, HasSimpleComment to) {
        HSimpleComment hComment = to.getComment();

        if (hComment == null) {
            hComment = new HSimpleComment();
        }
        if (!Objects.equal(from.getValue(), hComment.getComment())) {
            hComment.setComment(from.getValue());
            to.setComment(hComment);
            return true;
        }
        return false;
    }
View Full Code Here

            // trigger an implicit flush
            // (which will save this target even if it's not fully ready!!!)
            if (request.hasTargetComment()) {
                // FIXME this creates orphan comments, and replaces identical
                // comments with copies
                hTextFlowTarget.setComment(new HSimpleComment(request
                        .getTargetComment()));
            }

            result.baseVersion = hTextFlowTarget.getVersionNum();
            result.baseContentState = hTextFlowTarget.getState();
View Full Code Here

            @Override
            @Nullable
            public Void apply(@Nullable HDocument doc) {
                HTextFlow tf = doc.getTextFlows().get(0);
                HTextFlowTarget tft = tf.getTargets().get(as.getId());
                tft.setComment(new HSimpleComment("This is a new comment"));
                return null;
            }
        }, true);
    }
View Full Code Here

        PoTargetHeader fromHeader = new PoTargetHeader();
        String importedComment = "initial comment\nAlice #zanata\nCharlie";
        String expectedComment = "initial comment\nBob\nCharlie";
        fromHeader.setComment(importedComment);
        HPoTargetHeader toHeader = new HPoTargetHeader();
        toHeader.setComment(new HSimpleComment("initial comment\nBob"));
        resourceUtils.pushPoTargetComment(fromHeader, toHeader, MergeType.AUTO);
        assertThat("", toHeader.getComment().getComment(), is(expectedComment));
    }
View Full Code Here

        PoTargetHeader fromHeader = new PoTargetHeader();
        String importedComment = "initial comment\nAlice #zanata\nCharlie";
        String expectedComment = "initial comment\nCharlie";
        fromHeader.setComment(importedComment);
        HPoTargetHeader toHeader = new HPoTargetHeader();
        toHeader.setComment(new HSimpleComment("initial comment\nBob"));
        resourceUtils.pushPoTargetComment(fromHeader, toHeader,
                MergeType.IMPORT);
        assertThat("", toHeader.getComment().getComment(), is(expectedComment));
    }
View Full Code Here

    @Test
    public void pullCommentInitial() {

        HPoTargetHeader fromHeader = new HPoTargetHeader();
        fromHeader.setComment(new HSimpleComment("initial comment"));
        String expectedComment = "initial comment";
        PoTargetHeader toHeader = new PoTargetHeader();

        List<HTextFlowTarget> hTargets = Collections.emptyList();
        resourceUtils.pullPoTargetComment(fromHeader, toHeader, hTargets);
View Full Code Here

TOP

Related Classes of org.zanata.model.HSimpleComment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.