001: /*
002: * ====================================================================
003: * Copyright (c) 2004 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012:
013: package de.regnis.q.sequence.line.diff;
014:
015: import java.io.*;
016: import java.util.*;
017:
018: /**
019: * @author TMate Software Ltd.
020: */
021: public final class QDiffManager {
022:
023: // Constants ==============================================================
024:
025: public static final String DEFAULT_TYPE = QDiffNormalGenerator.TYPE;
026:
027: // Static =================================================================
028:
029: private static Map ourDiffGeneratorFactories;
030:
031: public static void setup() {
032: QDiffNormalGenerator.setup();
033: QDiffUniGenerator.setup();
034: }
035:
036: public static QDiffGenerator getDiffGenerator(String type,
037: Map properties) {
038: if (ourDiffGeneratorFactories == null
039: || !ourDiffGeneratorFactories.containsKey(type)) {
040: return null;
041: }
042: return ((QDiffGeneratorFactory) ourDiffGeneratorFactories
043: .get(type)).createGenerator(properties);
044: }
045:
046: public static void generateDiffHeader(String path, String leftInfo,
047: String rightInfo, Writer output, QDiffGenerator generator)
048: throws IOException {
049: if (generator == null || output == null) {
050: throw new NullPointerException(
051: "null argument is not accepted by SVNDiffManager.generateDiff()");
052: }
053: generator.generateDiffHeader(path, leftInfo, rightInfo, output);
054: }
055:
056: public static void generateTextDiff(InputStream left,
057: InputStream right, String encoding, Writer output,
058: QDiffGenerator generator) throws IOException {
059: if (generator == null || left == null || right == null
060: || output == null) {
061: throw new NullPointerException(
062: "null argument is not accepted by SVNDiffManager.generateDiff()");
063: }
064: if (encoding == null) {
065: encoding = System.getProperty("file.encoding", "US-ASCII");
066: }
067: generator.generateTextDiff(left, right, encoding, output);
068: }
069:
070: public static void generateBinaryDiff(InputStream left,
071: InputStream right, String encoding, Writer output,
072: QDiffGenerator generator) throws IOException {
073: if (generator == null || left == null || right == null
074: || output == null) {
075: throw new NullPointerException(
076: "null argument is not accepted by SVNDiffManager.generateDiff()");
077: }
078: if (encoding == null) {
079: encoding = System.getProperty("file.encoding", "US-ASCII");
080: }
081: generator.generateBinaryDiff(left, right, encoding, output);
082: }
083:
084: public static void registerDiffGeneratorFactory(
085: QDiffGeneratorFactory factory, String type) {
086: if (factory == null || type == null) {
087: return;
088: }
089: if (ourDiffGeneratorFactories != null
090: && ourDiffGeneratorFactories.containsKey(type)) {
091: return;
092: }
093: if (ourDiffGeneratorFactories == null) {
094: ourDiffGeneratorFactories = new HashMap();
095: }
096: ourDiffGeneratorFactories.put(type, factory);
097: }
098:
099: // Setup ==================================================================
100:
101: private QDiffManager() {
102: }
103: }
|