|
| 1 | +<!-- |
| 2 | +/* |
| 3 | + * Copyright IBM Corp. 2018 |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +--> |
| 18 | +# Custom Resource Filter Example - CSV Filter |
| 19 | + |
| 20 | +[Globalization Pipeline Resource Filter](https://github.com/IBM-Cloud/gp-java-tools/tree/master/gp-res-filter) provides |
| 21 | +a mechanism to implement your own custom filter, that can be used through |
| 22 | +Globalization Pipeline Maven Plugin/Ant Task and other tools. |
| 23 | + |
| 24 | +This example filter implementation read and write resource strings in CSV (Comman Separated Version) format. |
| 25 | + |
| 26 | +There are two types of resource filters. |
| 27 | + |
| 28 | +- [ResourceFilter](https://github.com/IBM-Cloud/gp-java-tools/blob/master/gp-res-filter/src/main/java/com/ibm/g11n/pipeline/resfilter/ResourceFilter.java) : |
| 29 | +This filter type parses a single resource data and produce a single Globalization |
| 30 | +Pipeline bundle. It also writes out a single Globalization Pipeline bundle into a |
| 31 | +single resource data. |
| 32 | +- [MultiBundleResourceFilter](https://github.com/IBM-Cloud/gp-java-tools/blob/master/gp-res-filter/src/main/java/com/ibm/g11n/pipeline/resfilter/MultiBundleResourceFilter.java) : |
| 33 | +This filter type parses a single resource data and produces one ore more Globalization |
| 34 | +Pipeline bundles. It also writes out one or more Globalization Pipeline bundles |
| 35 | +into a single resource data. |
| 36 | + |
| 37 | +A custom resource filter must extends one of above abstract class. Once you have |
| 38 | +one or more filter implementations ready, you need to impelment a concrete subclass |
| 39 | +of [ResourceFilterProvider](https://github.com/IBM-Cloud/gp-java-tools/blob/master/gp-res-filter/src/main/java/com/ibm/g11n/pipeline/resfilter/ResourceFilterProvider.java). |
| 40 | + |
| 41 | +In this example, [CSVFilter](https://github.com/IBM-Cloud/gp-java-tools/blob/master/examples/custom-res-filter/csv-filter/src/main/java/com/ibm/g11n/pipeline/example/CSVFilter.java) |
| 42 | +extends `ResourceFilter` and [MultiBundleCSVFilter](https://github.com/IBM-Cloud/gp-java-tools/blob/master/examples/custom-res-filter/csv-filter/src/main/java/com/ibm/g11n/pipeline/example/MultiBundleCSVFilter.java) extends `MultiBundleResourceFilter`. |
| 43 | + |
| 44 | +To integrate your custom filter implementation, you must create a text file |
| 45 | +`com.ibm.g11n.pipeline.resfilter.ResourceFilterProvider` specifying your |
| 46 | +`ResourceFilterProvider` implementation class, then place the file under |
| 47 | +`META-INF/services` in a jar file. In this CSV filter example, the service |
| 48 | +description file is found [here](https://github.com/IBM-Cloud/gp-java-tools/blob/master/examples/custom-res-filter/csv-filter/src/main/resources/META-INF/services/com.ibm.g11n.pipeline.resfilter.ResourceFilterProvider). |
| 49 | + |
| 50 | +Once your custom filter jar file is ready, you just need to put the file in |
| 51 | +your runtime class path of Globalization Pipeline tools integrated with |
| 52 | +`gp-res-filter`. |
0 commit comments