KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > repo > CommentHistoryContentHandler


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * William Mitsuda (wmitsuda@gmail.com) - Bug 153879 [Wizards] configurable size of cvs commit comment history
11  *******************************************************************************/

12
13 package org.eclipse.team.internal.ccvs.ui.repo;
14
15 import java.util.Vector JavaDoc;
16
17 import org.xml.sax.SAXException JavaDoc;
18 import org.xml.sax.helpers.DefaultHandler JavaDoc;
19 import org.xml.sax.Attributes JavaDoc;
20
21 class CommentHistoryContentHandler extends DefaultHandler JavaDoc {
22
23     private StringBuffer JavaDoc buffer;
24     private Vector JavaDoc comments;
25     public CommentHistoryContentHandler() {
26     }
27
28     /**
29      * @see ContentHandler#characters(char[], int, int)
30      */

31     public void characters(char[] chars, int startIndex, int length) throws SAXException JavaDoc {
32         if (buffer == null) return;
33         buffer.append(chars, startIndex, length);
34     }
35
36     /**
37      * @see ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
38      */

39     public void startElement(
40             String JavaDoc namespaceURI,
41             String JavaDoc localName,
42             String JavaDoc qName,
43             Attributes JavaDoc atts)
44             throws SAXException JavaDoc {
45         
46         String JavaDoc elementName = getElementName(namespaceURI, localName, qName);
47         if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) {
48             buffer = new StringBuffer JavaDoc();
49             return;
50         }
51         if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_HISTORY)) {
52             comments = new Vector JavaDoc(RepositoryManager.DEFAULT_MAX_COMMENTS);
53             return;
54         }
55     }
56     
57     /**
58      * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
59      */

60     public void endElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName) {
61         String JavaDoc elementName = getElementName(namespaceURI, localName, qName);
62         if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) {
63             comments.add(buffer.toString());
64             buffer = null;
65             return;
66         }
67         if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_HISTORY)) {
68             RepositoryManager.previousComments = new String JavaDoc[comments.size()];
69             comments.copyInto(RepositoryManager.previousComments);
70             return;
71         }
72     }
73     
74     /*
75      * Couldn't figure out from the SAX API exactly when localName vs. qName is used.
76      * However, the XML for project sets doesn't use namespaces so either of the two names
77      * is fine. Therefore, use whichever one is provided.
78      */

79     private String JavaDoc getElementName(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName) {
80         if (localName != null && localName.length() > 0) {
81             return localName;
82         } else {
83             return qName;
84         }
85     }
86 }
87
Popular Tags