587
|
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 |
|
|
18 |
|
|
19 |
package com.nokia.helium.metadata.ant.types;
|
|
20 |
|
628
|
21 |
import java.util.ArrayList;
|
|
22 |
import java.util.Collection;
|
|
23 |
import java.util.regex.Pattern;
|
|
24 |
import java.util.regex.PatternSyntaxException;
|
|
25 |
|
|
26 |
import org.apache.tools.ant.BuildException;
|
587
|
27 |
import org.apache.tools.ant.types.DataType;
|
|
28 |
|
|
29 |
|
|
30 |
/**
|
|
31 |
* This class provides filter input to the metadata task.
|
|
32 |
* <pre>
|
628
|
33 |
* <metadatafilter severity="error" regex="" description="" />
|
587
|
34 |
* </pre>
|
|
35 |
* @ant.task name="metadatafilter" category="Metadata"
|
|
36 |
*/
|
628
|
37 |
public class MetaDataFilter extends DataType implements MetaDataFilterCollection {
|
587
|
38 |
|
628
|
39 |
private SeverityEnum.Severity severity;
|
587
|
40 |
private String regex;
|
|
41 |
private String description;
|
|
42 |
private Pattern pattern;
|
|
43 |
|
|
44 |
|
|
45 |
/**
|
628
|
46 |
* Defines what is the severity level for this pattern
|
|
47 |
* @param severity type of severity for this input.
|
587
|
48 |
*/
|
628
|
49 |
@Deprecated
|
|
50 |
public void setPriority(SeverityEnum severity) {
|
|
51 |
setSeverity(severity);
|
587
|
52 |
}
|
|
53 |
|
|
54 |
/**
|
628
|
55 |
* Defines what is the severity level for this pattern
|
|
56 |
* @param severity type of severity for this input.
|
587
|
57 |
*/
|
628
|
58 |
public void setSeverity(SeverityEnum severity) {
|
|
59 |
this.severity = severity.getSeverity();
|
|
60 |
}
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Helper function to return the severity type
|
|
64 |
* @return severity type
|
|
65 |
* @ant.required
|
|
66 |
*/
|
|
67 |
public SeverityEnum.Severity getSeverity() {
|
|
68 |
return severity;
|
587
|
69 |
}
|
|
70 |
|
|
71 |
/**
|
|
72 |
* Helper function called by ant to set the regex
|
|
73 |
* @param regx regular expression of the filter
|
628
|
74 |
* @ant.required
|
587
|
75 |
*/
|
628
|
76 |
public void setRegex(String regex) {
|
|
77 |
if (regex == null || regex.trim().length() == 0) {
|
|
78 |
throw new BuildException("Invalid Regular expression: the regex attribute cannot be an empty string.");
|
587
|
79 |
}
|
628
|
80 |
this.regex = regex;
|
|
81 |
try {
|
|
82 |
pattern = Pattern.compile(this.regex);
|
|
83 |
} catch (PatternSyntaxException ex) {
|
|
84 |
throw new BuildException("Invalid regular expression: " + ex.getMessage(), ex);
|
|
85 |
}
|
587
|
86 |
}
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Helper function to return the regex type
|
|
90 |
* @return regular expression of this filter
|
|
91 |
*/
|
|
92 |
public String getRegex() {
|
|
93 |
return regex;
|
|
94 |
}
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Helper function called by ant to set the description type
|
|
98 |
* @param desc description associated with filter.
|
628
|
99 |
* @ant.required
|
587
|
100 |
*/
|
|
101 |
public void setDescription(String desc) {
|
|
102 |
description = desc;
|
|
103 |
}
|
|
104 |
|
|
105 |
/**
|
|
106 |
* Helper function to return the description associated with regular expression
|
|
107 |
* @return description associated with regex.
|
|
108 |
*/
|
|
109 |
public String getDescription() {
|
|
110 |
return description;
|
|
111 |
}
|
|
112 |
|
|
113 |
/**
|
|
114 |
* Helper function to return the pattern
|
|
115 |
* @return the pattern of this filter.
|
|
116 |
*/
|
|
117 |
public Pattern getPattern() {
|
|
118 |
return pattern;
|
|
119 |
}
|
628
|
120 |
|
|
121 |
/**
|
|
122 |
* {@inheritDoc}
|
|
123 |
*/
|
|
124 |
public Collection<MetaDataFilter> getAllFilters() {
|
|
125 |
Collection<MetaDataFilter> result = new ArrayList<MetaDataFilter>();
|
|
126 |
if (this.isReference()) {
|
|
127 |
result.add((MetaDataFilter)this.getRefid().getReferencedObject());
|
|
128 |
} else {
|
|
129 |
result.add(this);
|
|
130 |
}
|
|
131 |
return result;
|
|
132 |
}
|
587
|
133 |
}
|
|
134 |
|
|
135 |
|