KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > diff > builtin > provider > BuiltInDiffProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.diff.builtin.provider;
21
22 import java.io.BufferedReader JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.Reader JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.openide.util.NbBundle;
29
30 import org.netbeans.api.diff.Difference;
31 import org.netbeans.spi.diff.DiffProvider;
32
33 /**
34  *
35  * @author Martin Entlicher
36  */

37 public class BuiltInDiffProvider extends DiffProvider implements java.io.Serializable JavaDoc {
38
39     /**
40      * Holds value of property trimLines.
41      */

42     private boolean trimLines = true;
43
44     static final long serialVersionUID = 1L;
45     
46     /** Creates a new instance of BuiltInDiffProvider */
47     public BuiltInDiffProvider() {
48     }
49     
50     /**
51      * Get the display name of this diff provider.
52      */

53     public String JavaDoc getDisplayName() {
54         return NbBundle.getMessage(BuiltInDiffProvider.class, "BuiltInDiffProvider.displayName");
55     }
56     
57     /**
58      * Get a short description of this diff provider.
59      */

60     public String JavaDoc getShortDescription() {
61         return NbBundle.getMessage(BuiltInDiffProvider.class, "BuiltInDiffProvider.shortDescription");
62     }
63     
64     /**
65      * Create the differences of the content two streams.
66      * @param r1 the first source
67      * @param r2 the second source to be compared with the first one.
68      * @return the list of differences found, instances of {@link Difference};
69      * or <code>null</code> when some error occured.
70      */

71     public Difference[] computeDiff(Reader JavaDoc r1, Reader JavaDoc r2) throws IOException JavaDoc {
72         return HuntDiff.diff(getLines(r1), getLines(r2), trimLines);
73     }
74     
75     private String JavaDoc[] getLines(Reader JavaDoc r) throws IOException JavaDoc {
76         BufferedReader JavaDoc br = new BufferedReader JavaDoc(r);
77         String JavaDoc line;
78         List JavaDoc<String JavaDoc> lines = new ArrayList JavaDoc<String JavaDoc>();
79         while ((line = br.readLine()) != null) {
80             lines.add(line);
81         }
82         return lines.toArray(new String JavaDoc[0]);
83     }
84
85
86     /** On true all lines are trimmed before passing to diff engine. */
87     public boolean isTrimLines() {
88         return this.trimLines;
89     }
90
91     /**
92      * Setter for property trimLines.
93      * @param trimLines New value of property trimLines.
94      */

95     public void setTrimLines(boolean trimLines) {
96         this.trimLines = trimLines;
97     }
98
99
100     
101 }
102
Popular Tags