|
1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.helium.metadata.ant.types.sbs; |
|
18 |
|
19 import org.xml.sax.Attributes; |
|
20 import org.xml.sax.SAXException; |
|
21 import org.xml.sax.helpers.DefaultHandler; |
|
22 |
|
23 import com.nokia.helium.metadata.ant.types.sbs.SBSLogHandler.UncategorizedItem; |
|
24 import com.nokia.helium.metadata.ant.types.sbs.SBSLogHandler.UncategorizedItemMap; |
|
25 |
|
26 /** |
|
27 * The CategorizationHandler will try to push general |
|
28 * make errors (UncategorizedItem) to a particular component. |
|
29 * |
|
30 */ |
|
31 public class CategorizationHandler extends DefaultHandler { |
|
32 private SBSLogHandler logHandler; |
|
33 private boolean record; |
|
34 private StringBuffer text = new StringBuffer(); |
|
35 private String currentComponent; |
|
36 |
|
37 /** |
|
38 * Default constructor, it needs a SBSLogHandler. |
|
39 * @param logHandler the calling SBSLogHandler |
|
40 */ |
|
41 public CategorizationHandler(SBSLogHandler logHandler) { |
|
42 this.logHandler = logHandler; |
|
43 } |
|
44 |
|
45 /** |
|
46 * {@inheritDoc} |
|
47 */ |
|
48 @Override |
|
49 public void endElement(String uri, String localName, String qName) { |
|
50 if (qName.equalsIgnoreCase("clean") && currentComponent != null) { |
|
51 record = false; |
|
52 UncategorizedItemMap uncategorizedItemMap = this.logHandler.getUncategorizedItemMap(); |
|
53 for (String line : text.toString().split("\n")) { |
|
54 line = line.trim().replace("\"", ""); |
|
55 if (line.length() > 0) { |
|
56 if (uncategorizedItemMap.containsKey(line)) { |
|
57 for (UncategorizedItem item : uncategorizedItemMap.get(line)) { |
|
58 this.logHandler.getEventHandler().add(item.getPriotity(), currentComponent, item.getText(), item.getLineNumber()); |
|
59 } |
|
60 uncategorizedItemMap.remove(line); |
|
61 } |
|
62 } |
|
63 } |
|
64 currentComponent = null; |
|
65 text.setLength(0); |
|
66 } |
|
67 } |
|
68 |
|
69 /** |
|
70 * {@inheritDoc} |
|
71 */ |
|
72 @Override |
|
73 public void startElement(String uri, String localName, String qName, |
|
74 Attributes attributes) throws SAXException { |
|
75 if (qName.equalsIgnoreCase("clean")) { |
|
76 currentComponent = this.logHandler.getComponent(attributes); |
|
77 record = true; |
|
78 text.setLength(0); |
|
79 } |
|
80 } |
|
81 |
|
82 /** |
|
83 * {@inheritDoc} |
|
84 */ |
|
85 @Override |
|
86 public void characters(char[] ch, int start, int length) |
|
87 throws SAXException { |
|
88 if (record) { |
|
89 text.append(ch, start, length); |
|
90 } |
|
91 super.characters(ch, start, length); |
|
92 } |
|
93 |
|
94 } |