|
|
@@ -211,6 +211,36 @@ public class ArticleService extends BaseTransaction {
|
|
|
private void saveArticleDesc(Article article, String htmlContent) {
|
|
|
}
|
|
|
|
|
|
+ private boolean verifyArticleImageSources(String htmlContent) throws Exception {
|
|
|
+ if (StringUtil.isNull(htmlContent)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ Document doc = Jsoup.parseBodyFragment(htmlContent);
|
|
|
+ for (Element image : doc.select("img")) {
|
|
|
+ String src = image.attr("src");
|
|
|
+ String originalSrc = image.attr("data-original");
|
|
|
+ boolean missingSource = StringUtil.isNull(src) && StringUtil.isNull(originalSrc);
|
|
|
+ boolean temporarySource = (StringUtil.notNull(src) && src.startsWith("blob:"))
|
|
|
+ || (StringUtil.notNull(originalSrc) && originalSrc.startsWith("blob:"));
|
|
|
+ if (missingSource || temporarySource) {
|
|
|
+ setResponsePackage(getResponseWarningMsgPackage("正文中存在未上传完成或失效的图片,请重新上传"));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveArticleContentFiles(Article article, String content) throws Exception {
|
|
|
+ String editPath = WebEditorUtil.createHtmlFile(content);
|
|
|
+ String runContent = converArticleContentHtmlLink(getWebRootPath() + editPath,
|
|
|
+ space.apps.moudules.website.common.ConstVars.domain);
|
|
|
+ String runPath = WebEditorUtil.createHtmlFile(runContent);
|
|
|
+
|
|
|
+ article.setEditContent(editPath);
|
|
|
+ article.setContent(runPath);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 文章录入
|
|
|
*
|
|
|
@@ -242,15 +272,11 @@ public class ArticleService extends BaseTransaction {
|
|
|
if (!verifyArticleCopyNavigationList(gdba, navIdList, article)) {
|
|
|
return DEFAULT_FORWARD;
|
|
|
}
|
|
|
+ if (!verifyArticleImageSources(content)) {
|
|
|
+ return DEFAULT_FORWARD;
|
|
|
+ }
|
|
|
|
|
|
- String editPath = WebEditorUtil.createHtmlFile(content);
|
|
|
-
|
|
|
- String runContent = converArticleContentHtmlLink(getWebRootPath() + editPath,
|
|
|
- space.apps.moudules.website.common.ConstVars.domain);
|
|
|
- String runPath = WebEditorUtil.createHtmlFile(runContent);
|
|
|
-
|
|
|
- article.setContent(runPath);// 运行文件
|
|
|
- article.setEditContent(editPath);// 编辑文件
|
|
|
+ saveArticleContentFiles(article, content);
|
|
|
|
|
|
article.setUnitid(appUser.getUnitId());
|
|
|
article.setDcode(dataStatusCode.INSERT.getCode());
|
|
|
@@ -316,17 +342,13 @@ public class ArticleService extends BaseTransaction {
|
|
|
}
|
|
|
|
|
|
private Article getArticleById(GeneralDBAccess gdba, Long articleid) throws Exception {
|
|
|
- String sql = " select articleid, dcode, websiteid, unitid, ascode, navigationid, title, ajtcode, `desc`,"
|
|
|
- + " source, thumbnail, sticktop, sticktop_end_time, sticktop_schedulesid, `release`, release_time,"
|
|
|
- + " release_task_schedulesid, content, edit_content, url, read_count, create_time, last_change_time,"
|
|
|
- + " create_pid, last_change_pid from article where articleid = :articleid ";
|
|
|
- SqlCommandImpl sqlCmd = new SqlCommandImpl(sql);
|
|
|
- sqlCmd.setString("articleid", articleid);
|
|
|
- List<Article> list = gdba.selectAsList(sqlCmd, Article.class);
|
|
|
- if (list == null || list.isEmpty()) {
|
|
|
+ Article article = new Article();
|
|
|
+ article.setArticleid(articleid);
|
|
|
+ gdba.selectById(article);
|
|
|
+ if (article.getDcode() == null) {
|
|
|
throw new Exception("文章不存在");
|
|
|
}
|
|
|
- return list.get(0);
|
|
|
+ return article;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -396,15 +418,15 @@ public class ArticleService extends BaseTransaction {
|
|
|
if (!verifyArticleCopyNavigationList(gdba, navIdList, article)) {
|
|
|
return DEFAULT_FORWARD;
|
|
|
}
|
|
|
+ if (!verifyArticleImageSources(content)) {
|
|
|
+ return DEFAULT_FORWARD;
|
|
|
+ }
|
|
|
|
|
|
article.setSticktop("yes".equals(top) ? 1L : 0L);
|
|
|
|
|
|
ChangeLogUtil.addChangeLog(gdba, appUser, "Article", a2.getArticleid(), GsonUtil.toJson(a2));
|
|
|
|
|
|
- FileUtil.writeFile(content, getWebRootPath() + a2.getEditContent());// 编辑文件,获取页面上的正文内容
|
|
|
- String runContent = converArticleContentHtmlLink(getWebRootPath() + a2.getEditContent(),
|
|
|
- space.apps.moudules.website.common.ConstVars.domain);
|
|
|
- FileUtil.writeFile(runContent, getWebRootPath() + a2.getContent());// 运行文件,从编辑文件里转换为运行文件
|
|
|
+ saveArticleContentFiles(article, content);
|
|
|
|
|
|
article.setLastChangePid(appUser.getUserId());
|
|
|
article.setLastChangeTime(nowTimestamp);
|
|
|
@@ -648,6 +670,9 @@ public class ArticleService extends BaseTransaction {
|
|
|
if (!verifyArticleCopyNavigationList(gdba, navIdList, article)) {
|
|
|
return TIPS_FORWARD;
|
|
|
}
|
|
|
+ if (!verifyArticleImageSources(content)) {
|
|
|
+ return TIPS_FORWARD;
|
|
|
+ }
|
|
|
|
|
|
article.setSticktop("yes".equals(top) ? 1L : 0L);
|
|
|
|
|
|
@@ -657,10 +682,7 @@ public class ArticleService extends BaseTransaction {
|
|
|
|
|
|
verifyArticleUrl(article, a2, wn);
|
|
|
|
|
|
- FileUtil.writeFile(content, getWebRootPath() + a2.getEditContent());// 编辑文件,获取页面上的正文内容
|
|
|
- String runContent = converArticleContentHtmlLink(getWebRootPath() + a2.getEditContent(),
|
|
|
- space.apps.moudules.website.common.ConstVars.domain);
|
|
|
- FileUtil.writeFile(runContent, getWebRootPath() + a2.getContent());// 运行文件,从编辑文件里转换为运行文件
|
|
|
+ saveArticleContentFiles(article, content);
|
|
|
|
|
|
article.setDcode(dataStatusCode.STAY_SUBMIT.getCode());
|
|
|
article.setLastChangePid(appUser.getUserId());
|