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();
}
}
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);
}
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);
}
Aggregations