1 package net.sf.jpkgmk;
2
3 import net.sf.jpkgmk.util.StringUtil;
4 import net.sf.jpkgmk.util.StringUtil.KeyValuePair;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8
9
10
11
12
13
14
15
16 public class PkgInfoParser extends AbstractParser<PkgInfo>
17 {
18 private Log log = LogFactory.getLog(PkgInfoParser.class);
19
20 public PkgInfoParser()
21 {
22 }
23
24
25 @Override
26 protected PkgInfo createResult() {
27 return new PkgInfo();
28 }
29
30 @Override
31 protected void parseAndAddLine(String line, PkgInfo resultObject) {
32 KeyValuePair keyValuePair = StringUtil.resolveKeyValue(line);
33
34 String key = keyValuePair.getKey();
35 if(key.equals(PkgInfo.VAR_ARCH)) {
36 resultObject.setArch(keyValuePair.getValue());
37 } else if(key.equals(PkgInfo.VAR_BASEDIR)) {
38 resultObject.setPkgInfoBasedir(keyValuePair.getValue());
39 } else if(key.equals(PkgInfo.VAR_CATEGORY)) {
40 resultObject.setCategory(keyValuePair.getValue());
41 } else if(key.equals(PkgInfo.VAR_DESC)) {
42 resultObject.setDesc(keyValuePair.getValue());
43 } else if(key.equals(PkgInfo.VAR_NAME)) {
44 resultObject.setName(keyValuePair.getValue());
45 } else if(key.equals(PkgInfo.VAR_PKG)) {
46 resultObject.setPkg(keyValuePair.getValue());
47 } else if(key.equals(PkgInfo.VAR_VENDOR)) {
48 resultObject.setVendor(keyValuePair.getValue());
49 } else if(key.equals(PkgInfo.VAR_VERSION)) {
50 resultObject.setVersion(keyValuePair.getValue());
51 } else {
52 log.info("The key '" + key + "' is unknown and parsed as an additional 'option'.");
53 String option = key + "=" + keyValuePair.getValue();
54 resultObject.addOption(option);
55 }
56
57 }
58
59 }