Search in sources :

Example 1 with ToString

use of org.apache.commons.jrcs.util.ToString in project OpenGrok by OpenGrok.

the class Archive method toString.

/**
     * Append a text image of the archive to the given buffer using
     * the given token as line separator.
     * @param s  where to append the image.
     * @param EOL the line separator.
     */
public void toString(StringBuffer s, String EOL) {
    String EOI = ";" + EOL;
    String NLT = EOL + "\t";
    s.append("head");
    if (head != null) {
        s.append("\t");
        head.getVersion().toString(s);
    }
    s.append(EOI);
    if (branch != null) {
        s.append("branch\t");
        s.append(branch.toString());
        s.append(EOI);
    }
    s.append("access");
    for (Iterator i = users.iterator(); i.hasNext(); ) {
        s.append(EOL);
        s.append("\t");
        s.append(i.next());
    }
    s.append(EOI);
    s.append("symbols");
    for (Iterator i = symbols.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry e = (Map.Entry) i.next();
        s.append(NLT);
        s.append(e.getKey().toString());
        s.append(":");
        s.append(e.getValue().toString());
    }
    s.append(EOI);
    s.append("locks");
    for (Iterator i = locked.iterator(); i.hasNext(); ) {
        String locker = ((Node) i.next()).getLocker();
        s.append(NLT);
        s.append(locker);
    }
    if (strictLocking) {
        s.append("; strict");
    }
    s.append(EOI);
    if (comment != null) {
        s.append("comment\t");
        s.append(Archive.quoteString(comment));
        s.append(EOI);
    }
    if (expand != null) {
        s.append("expand\t");
        s.append(Archive.quoteString(expand));
        s.append(EOI);
    }
    if (phrases != null) {
        phrases.toString(s, EOL);
    }
    s.append(EOL);
    for (Iterator i = nodes.values().iterator(); i.hasNext(); ) {
        Node n = (Node) i.next();
        if (!n.getVersion().isGhost() && n.getText() != null) {
            n.toString(s, EOL);
        }
    }
    s.append(EOL + EOL);
    s.append("desc");
    s.append(EOL);
    s.append(quoteString(desc));
    s.append(EOL);
    Node n = head;
    while (n != null) {
        n.toText(s, EOL);
        n = n.getRCSNext();
    }
}
Also used : ToString(org.apache.commons.jrcs.util.ToString)

Example 2 with ToString

use of org.apache.commons.jrcs.util.ToString in project OpenGrok by OpenGrok.

the class Node method toString.

/**
     * Conver the current node and all of its branches
     * to their RCS string representation and
     * add it to the given StringBuffer using the given marker as
     * line separator.
     * @param s The string buffer to add the node's image to.
     * @param EOL The line separator to use.
     */
public void toString(StringBuffer s, String EOL) {
    String EOI = ";" + EOL;
    String NLT = EOL + "\t";
    s.append(EOL);
    s.append(version.toString() + EOL);
    s.append("date");
    if (date != null) {
        DateFormat formatter = dateFormat;
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        if (cal.get(Calendar.YEAR) > 1999) {
            formatter = dateFormat2K;
        }
        s.append("\t" + formatter.format(date));
    }
    s.append(";\tauthor");
    if (author != null) {
        s.append(" " + author);
    }
    s.append(";\tstate");
    if (state != null) {
        s.append(" ");
        s.append(state);
    }
    s.append(EOI);
    s.append("branches");
    if (branches != null) {
        for (Iterator i = branches.values().iterator(); i.hasNext(); ) {
            Node n = (Node) i.next();
            if (n != null) {
                s.append(NLT + n.version);
            }
        }
    }
    s.append(EOI);
    s.append("next\t");
    if (rcsnext != null) {
        s.append(rcsnext.version.toString());
    }
    s.append(EOI);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Iterator(java.util.Iterator) ToString(org.apache.commons.jrcs.util.ToString)

Example 3 with ToString

use of org.apache.commons.jrcs.util.ToString in project OpenGrok by OpenGrok.

the class Node method patch.

/**
     * Apply the deltas in the current node to the given text.
     * @param original the text to be patched
     * @param annotate set to true to have each text line be a
     * {@link Line Line} object that identifies the revision in which
     * the line was changed or added.
     * @throws InvalidFileFormatException if the deltas cannot be parsed.
     * @throws PatchFailedException if the diff engine determines that
     * the deltas cannot apply to the given text.
     */
public void patch(List original, boolean annotate) throws InvalidFileFormatException, org.apache.commons.jrcs.diff.PatchFailedException {
    Revision revision = new Revision();
    for (int it = 0; it < text.length; it++) {
        String cmd = text[it].toString();
        java.util.StringTokenizer t = new StringTokenizer(cmd, "ad ", true);
        char action;
        int n;
        int count;
        try {
            action = t.nextToken().charAt(0);
            n = Integer.parseInt(t.nextToken());
            // skip the space
            t.nextToken();
            count = Integer.parseInt(t.nextToken());
        } catch (Exception e) {
            throw new InvalidFileFormatException(version + ":line:" + ":" + e.getMessage());
        }
        if (action == 'd') {
            revision.addDelta(new DeleteDelta(new Chunk(n - 1, count)));
        } else if (action == 'a') {
            revision.addDelta(new AddDelta(n, new Chunk(getTextLines(it + 1, it + 1 + count), 0, count, n - 1)));
            it += count;
        } else {
            throw new InvalidFileFormatException(version.toString());
        }
    }
    revision.applyTo(original);
}
Also used : StringTokenizer(java.util.StringTokenizer) Revision(org.apache.commons.jrcs.diff.Revision) DeleteDelta(org.apache.commons.jrcs.diff.DeleteDelta) StringTokenizer(java.util.StringTokenizer) AddDelta(org.apache.commons.jrcs.diff.AddDelta) ToString(org.apache.commons.jrcs.util.ToString) Chunk(org.apache.commons.jrcs.diff.Chunk) PatchFailedException(org.apache.commons.jrcs.diff.PatchFailedException)

Aggregations

ToString (org.apache.commons.jrcs.util.ToString)3 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Iterator (java.util.Iterator)1 StringTokenizer (java.util.StringTokenizer)1 AddDelta (org.apache.commons.jrcs.diff.AddDelta)1 Chunk (org.apache.commons.jrcs.diff.Chunk)1 DeleteDelta (org.apache.commons.jrcs.diff.DeleteDelta)1 PatchFailedException (org.apache.commons.jrcs.diff.PatchFailedException)1 Revision (org.apache.commons.jrcs.diff.Revision)1