|
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.sysdef.ant.types; |
|
18 |
|
19 import java.io.File; |
|
20 import java.util.Hashtable; |
|
21 import java.util.Map; |
|
22 |
|
23 import org.apache.tools.ant.BuildException; |
|
24 |
|
25 import com.nokia.helium.sysdef.ant.taskdefs.AbstractSydefTask; |
|
26 import com.nokia.helium.sysdef.ant.taskdefs.FilterTask; |
|
27 import com.nokia.helium.sysdef.ant.taskdefs.SysdefUtils; |
|
28 |
|
29 /** |
|
30 * This type defines a system definition filter. |
|
31 * |
|
32 */ |
|
33 public class SysdefFilter implements Filter { |
|
34 private static final String INVALID_FILTER = "nothing"; |
|
35 private static final String XSLT = "filtering.xsl"; |
|
36 private String filter; |
|
37 private String type = "has"; |
|
38 private String verbatim; |
|
39 |
|
40 /** |
|
41 * Define the verbatim to filter in, can be used in conjunction with filter. |
|
42 * @param verbatim a string representing a comma separated list of id to |
|
43 * filter in. |
|
44 * @ant.required |
|
45 */ |
|
46 public void setVerbatim(String verbatim) { |
|
47 this.verbatim = verbatim; |
|
48 } |
|
49 |
|
50 /** |
|
51 * Define the filter, can be used in conjunction with verbatim attribute. |
|
52 * @param filter the filter string. |
|
53 * @ant.required |
|
54 */ |
|
55 public void setFilter(String filter) { |
|
56 this.filter = filter; |
|
57 } |
|
58 |
|
59 /** |
|
60 * Define the filter type |
|
61 * @param type |
|
62 * @ant.not-required Default has. |
|
63 */ |
|
64 public void setType(SydefFilterTypeEnum type) { |
|
65 this.type = type.getValue(); |
|
66 } |
|
67 |
|
68 |
|
69 |
|
70 /** |
|
71 * {@inheritDoc} |
|
72 */ |
|
73 @Override |
|
74 public void filter(FilterTask task, File src, File dest) { |
|
75 FilterImpl impl = new FilterImpl(); |
|
76 impl.bindToOwner(task); |
|
77 impl.setEpocroot(task.getEpocroot()); |
|
78 impl.setSrcFile(src); |
|
79 impl.setDestFile(dest); |
|
80 impl.filter(filter, type); |
|
81 } |
|
82 |
|
83 /** |
|
84 * {@inheritDoc} |
|
85 */ |
|
86 @Override |
|
87 public void validate() { |
|
88 if (filter == null && verbatim == null) { |
|
89 throw new BuildException("'filter' or/and 'idlist' attribute is not defined."); |
|
90 } |
|
91 } |
|
92 |
|
93 private class FilterImpl extends AbstractSydefTask { |
|
94 |
|
95 /** |
|
96 * Running the filtering operation on src file and put the result in dest file. |
|
97 * @param src the source file |
|
98 * @param dest the destination file |
|
99 * @param filter the filter to use |
|
100 * @param filterType the filter type to use (e.g has, only, with) |
|
101 */ |
|
102 protected void filter(String filter, String filterType) { |
|
103 Map<String, String> params = new Hashtable<String, String>(); |
|
104 params.put("filter-type", filterType); |
|
105 if (filter == null && verbatim != null) { |
|
106 params.put("filter", INVALID_FILTER); |
|
107 } else if (filter != null) { |
|
108 params.put("filter", filter); |
|
109 } |
|
110 if (verbatim != null) { |
|
111 params.put("verbatim", verbatim); |
|
112 } |
|
113 transform(params); |
|
114 } |
|
115 |
|
116 |
|
117 /** |
|
118 * {@inheritDoc} |
|
119 */ |
|
120 @Override |
|
121 protected File getXsl() { |
|
122 return new File(SysdefUtils.getSysdefHome(getProject(), this.getEpocroot()), XSLT); |
|
123 } |
|
124 } |
|
125 |
|
126 } |