25 import java.io.IOException; |
25 import java.io.IOException; |
26 import java.io.UnsupportedEncodingException; |
26 import java.io.UnsupportedEncodingException; |
27 import java.util.Iterator; |
27 import java.util.Iterator; |
28 import java.util.List; |
28 import java.util.List; |
29 |
29 |
|
30 import org.apache.log4j.Logger; |
30 import org.dom4j.Document; |
31 import org.dom4j.Document; |
31 import org.dom4j.DocumentException; |
32 import org.dom4j.DocumentException; |
32 import org.dom4j.Element; |
33 import org.dom4j.Element; |
33 import org.dom4j.io.OutputFormat; |
34 import org.dom4j.io.OutputFormat; |
34 import org.dom4j.io.SAXReader; |
35 import org.dom4j.io.SAXReader; |
35 import org.dom4j.io.XMLWriter; |
36 import org.dom4j.io.XMLWriter; |
36 import org.apache.log4j.Logger; |
|
37 |
|
38 |
37 |
39 /** |
38 /** |
40 * Renders model property and group description to Wiki Model Syntax |
39 * Renders model property and group description to Wiki Model Syntax |
|
40 * |
41 * @author Helium Team |
41 * @author Helium Team |
42 */ |
42 */ |
43 public class ModelPropertiesParser |
43 public class ModelPropertiesParser { |
44 { |
|
45 private File inputPath; |
44 private File inputPath; |
46 private File outputPath; |
45 private File outputPath; |
47 private Document doc; |
46 private Document doc; |
48 private Logger log = Logger.getLogger(ModelPropertiesParser.class); |
47 private Logger log = Logger.getLogger(ModelPropertiesParser.class); |
49 |
48 |
50 public ModelPropertiesParser(File inputPath, File outputPath) |
49 public ModelPropertiesParser(File inputPath, File outputPath) { |
51 { |
|
52 this.inputPath = inputPath; |
50 this.inputPath = inputPath; |
53 this.outputPath = outputPath; |
51 this.outputPath = outputPath; |
54 } |
52 } |
55 |
53 |
56 /** |
54 /** |
57 * Reads model xml file, changes description format. |
55 * Reads model xml file, changes description format. |
|
56 * |
58 * @throws DocumentException |
57 * @throws DocumentException |
59 * @throws IOException |
58 * @throws IOException |
60 */ |
59 */ |
61 public void parsePropertiesDescription() throws IOException, DocumentException |
60 public void parsePropertiesDescription() throws IOException, DocumentException { |
62 { |
|
63 SAXReader xmlReader = new SAXReader(); |
61 SAXReader xmlReader = new SAXReader(); |
64 doc = xmlReader.read(inputPath); |
62 doc = xmlReader.read(inputPath); |
65 List importNodes = doc.selectNodes("//description"); |
63 List importNodes = doc.selectNodes("//description"); |
66 for (Iterator iterator = importNodes.iterator(); iterator.hasNext();) |
64 for (Iterator iterator = importNodes.iterator(); iterator.hasNext();) { |
67 { |
|
68 Element importCurrentNode = (Element) iterator.next(); |
65 Element importCurrentNode = (Element) iterator.next(); |
69 importCurrentNode.setText(renderWikiModel(importCurrentNode.getText())); |
66 importCurrentNode.setText(renderWikiModel(importCurrentNode.getText())); |
70 writeXMLFile(); |
67 writeXMLFile(); |
71 } |
68 } |
72 } |
69 } |
73 |
70 |
74 /** |
71 /** |
75 * Writes Document object as xml file |
72 * Writes Document object as xml file |
76 */ |
73 */ |
77 private void writeXMLFile() |
74 private void writeXMLFile() { |
78 { |
|
79 try { |
75 try { |
80 if (outputPath != null) { |
76 if (outputPath != null) { |
81 XMLWriter out = new XMLWriter(new FileOutputStream(outputPath), OutputFormat.createPrettyPrint()); |
77 XMLWriter out = new XMLWriter(new FileOutputStream(outputPath), OutputFormat.createPrettyPrint()); |
82 out.write(doc); |
78 out.write(doc); |
83 } |
79 } |
84 } catch (FileNotFoundException e) { |
80 } |
85 //We are Ignoring the errors as no need to fail the build. |
81 catch (FileNotFoundException e) { |
|
82 // We are Ignoring the errors as no need to fail the build. |
86 log.debug("Not able to write into XML Document " + e.getMessage()); |
83 log.debug("Not able to write into XML Document " + e.getMessage()); |
87 } catch (UnsupportedEncodingException e) { |
84 } |
88 //We are Ignoring the errors as no need to fail the build. |
85 catch (UnsupportedEncodingException e) { |
|
86 // We are Ignoring the errors as no need to fail the build. |
89 log.debug("Not able to write into XML Document " + e.getMessage()); |
87 log.debug("Not able to write into XML Document " + e.getMessage()); |
90 } catch (IOException e) { |
88 } |
91 //We are Ignoring the errors as no need to fail the build. |
89 catch (IOException e) { |
|
90 // We are Ignoring the errors as no need to fail the build. |
92 log.debug("Not able to write into XML Document " + e.getMessage()); |
91 log.debug("Not able to write into XML Document " + e.getMessage()); |
93 } |
92 } |
94 } |
93 } |
95 |
94 |
96 /** |
95 /** |
97 * Render the description as Wiki model |
96 * Render the description as Wiki model |
|
97 * |
98 * @param String descriptionText |
98 * @param String descriptionText |
99 * @return String |
99 * @return String |
100 */ |
100 */ |
101 private String renderWikiModel(String descriptionText) throws IOException, DocumentException |
101 private String renderWikiModel(String descriptionText) throws IOException, DocumentException { |
102 { |
102 if (descriptionText != null) { |
103 if (descriptionText != null) |
|
104 { |
|
105 WikiModel wikiModel = new WikiModel("", ""); |
103 WikiModel wikiModel = new WikiModel("", ""); |
106 //If description contains unwanted symbols like "**", "==" and "- -", remove those from description. |
104 // If description contains unwanted symbols like "**", "==" and "- -", remove those from |
107 if (descriptionText.contains("**") || descriptionText.contains("==") || descriptionText.contains("- -")) |
105 // description. |
108 { |
106 if (descriptionText.contains("**") || descriptionText.contains("==") |
|
107 || descriptionText.contains("- -")) { |
109 descriptionText = descriptionText.replace("**", "").replace("==", "").replace("- -", "").trim(); |
108 descriptionText = descriptionText.replace("**", "").replace("==", "").replace("- -", "").trim(); |
110 } |
109 } |
111 //If description starts with "-", remove it. As wiki have special meaning for this symbol |
110 // If description starts with "-", remove it. As wiki have special meaning for this |
112 if (descriptionText.startsWith("-")) |
111 // symbol |
|
112 if (descriptionText.startsWith("-")) { |
113 descriptionText = descriptionText.replace("-", ""); |
113 descriptionText = descriptionText.replace("-", ""); |
|
114 } |
114 descriptionText = descriptionText.trim(); |
115 descriptionText = descriptionText.trim(); |
115 //Render description with wiki model syntax |
116 // Render description with wiki model syntax |
116 descriptionText = wikiModel.render(descriptionText); |
117 descriptionText = wikiModel.render(descriptionText); |
117 } |
118 } |
118 else |
119 else { |
119 { |
|
120 descriptionText = ""; |
120 descriptionText = ""; |
121 } |
121 } |
122 return descriptionText; |
122 return descriptionText; |
123 } |
123 } |
124 } |
124 } |
125 |
|