KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  *******************************************************************************/

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

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

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

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

76     private String JavaDoc getElementName(String JavaDoc localName, String JavaDoc qName) {
77         if (localName != null && localName.length() > 0) {
78             return localName;
79         }
80         return qName;
81     }
82 }
83
Popular Tags