|
|
@@ -82,6 +82,8 @@ public class TemplateParser {
|
|
|
*
|
|
|
* @param content
|
|
|
* 模版内容
|
|
|
+ * @param title
|
|
|
+ * 标题
|
|
|
* @param jdbc
|
|
|
* NewbieJdbc对象
|
|
|
* @return 解析后的 json 数据
|
|
|
@@ -89,14 +91,15 @@ public class TemplateParser {
|
|
|
* @throws IOException
|
|
|
* @throws TransformerException
|
|
|
*/
|
|
|
- public String parseXml(@NotEmpty("content") String content, @NotEmpty("jdbc") NewbieJdbc jdbc)
|
|
|
+ public String parseXml(@NotEmpty("content") String content, String title, @NotEmpty("jdbc") NewbieJdbc jdbc)
|
|
|
throws DocumentException, TransformerException, IOException {
|
|
|
content = processSql(content);
|
|
|
content = processForm(content, jdbc);
|
|
|
content = processGrid(content, jdbc);
|
|
|
content = processBarAndLine(content, jdbc);
|
|
|
content = processPie(content, jdbc);
|
|
|
- return toJson(content);
|
|
|
+ content = finalProcess(content, title);
|
|
|
+ return TranslateHelper.xmlToJson(content);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -384,18 +387,44 @@ public class TemplateParser {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 将模版内容转换为 json
|
|
|
+ * 对模版内容的最终处理,包括映射、添加title等
|
|
|
*
|
|
|
* @param content
|
|
|
* 模版内容
|
|
|
- * @return 转换后的 json
|
|
|
+ * @param title
|
|
|
+ * 标题
|
|
|
+ * @return 处理后的模版内容
|
|
|
* @throws IOException
|
|
|
* @throws TransformerException
|
|
|
+ * @throws DocumentException
|
|
|
*/
|
|
|
- private String toJson(@NotEmpty("content") String content) throws TransformerException, IOException {
|
|
|
+ private String finalProcess(@NotEmpty("content") String content, String title)
|
|
|
+ throws TransformerException, IOException, DocumentException {
|
|
|
InputStream mapRuleStream = FileHelper.readStream("map-rule.xsl");
|
|
|
content = TranslateHelper.map(content, mapRuleStream);
|
|
|
- return TranslateHelper.xmlToJson(content);
|
|
|
+ if (!StringUtils.isEmpty(title)) {
|
|
|
+ content = addTitle(content, title);
|
|
|
+ }
|
|
|
+ return content;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 为模版添加 title
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ * 模版内容
|
|
|
+ * @param title
|
|
|
+ * 标题
|
|
|
+ * @return 处理后的模版内容
|
|
|
+ * @throws DocumentException
|
|
|
+ */
|
|
|
+ private String addTitle(@NotEmpty("content") String content, @NotEmpty("title") String title)
|
|
|
+ throws DocumentException {
|
|
|
+ Document document = getDocument(content);
|
|
|
+ Element rootElement = document.getRootElement();
|
|
|
+ Element titleElement = new DefaultElement("title");
|
|
|
+ titleElement.setText(title);
|
|
|
+ rootElement.add(titleElement);
|
|
|
+ return document.asXML();
|
|
|
+ }
|
|
|
}
|