You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2014/04/20 15:39:01 UTC
svn commit: r1588757 [14/25] - in /roller/branches/rome2/app/src:
main/java/org/apache/roller/ main/java/org/apache/roller/planet/business/
main/java/org/apache/roller/planet/business/fetcher/
main/java/org/apache/roller/planet/business/jpa/ main/java/...
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java Sun Apr 20 13:38:51 2014
@@ -44,166 +44,169 @@ import org.apache.roller.weblogger.util.
*/
public class StylesheetEdit extends UIAction {
- private static final long serialVersionUID = 4657591015852311907L;
+ private static final long serialVersionUID = 4657591015852311907L;
- private static Log log = LogFactory.getLog(StylesheetEdit.class);
+ private static Log log = LogFactory.getLog(StylesheetEdit.class);
private static final String MOBILE_THEME_TYPE = "mobile";
private static final String STANDARD_THEME_TYPE = "standard";
- // the template we are working on
- private WeblogTemplate template = null;
+ // the template we are working on
+ private WeblogTemplate template = null;
- // the contents of the stylesheet override
- private String contentsStandard = null;
- private String contentsMobile = null;
-
- // Do we have a custom stylesheet already for a custom theme
- private boolean customStylesheet = false;
-
- public StylesheetEdit() {
- this.actionName = "stylesheetEdit";
- this.desiredMenu = "editor";
- this.pageTitle = "stylesheetEdit.title";
- }
-
- @Override
- public List<String> requiredWeblogPermissionActions() {
- return Collections.singletonList(WeblogPermission.ADMIN);
- }
-
- @Override
- public void myPrepare() {
-
- ThemeTemplate stylesheet = null;
- try {
- stylesheet = getActionWeblog().getTheme().getStylesheet();
- } catch (WebloggerException ex) {
- log.error("Error looking up stylesheet on weblog - "
- + getActionWeblog().getHandle(), ex);
- }
-
- if (stylesheet != null) {
- log.debug("custom stylesheet path is - " + stylesheet.getLink());
- try {
- setTemplate(WebloggerFactory.getWeblogger().getWeblogManager()
- .getPageByLink(getActionWeblog(), stylesheet.getLink()));
-
- if (getTemplate() == null) {
- log.debug("custom stylesheet not found, creating it");
-
- // template doesn't exist yet, so create it
- WeblogTemplate stylesheetTmpl = new WeblogTemplate();
- stylesheetTmpl.setWebsite(getActionWeblog());
- stylesheetTmpl.setAction(ThemeTemplate.ACTION_CUSTOM);
- stylesheetTmpl.setName(stylesheet.getName());
- stylesheetTmpl.setDescription(stylesheet.getDescription());
- stylesheetTmpl.setLink(stylesheet.getLink());
- stylesheetTmpl.setContents(stylesheet.getContents());
- stylesheetTmpl.setHidden(false);
- stylesheetTmpl.setNavbar(false);
- stylesheetTmpl.setLastModified(new Date());
- stylesheetTmpl.setTemplateLanguage(stylesheet
- .getTemplateLanguage());
-
- // create template codes for available template code Types
- WeblogThemeTemplateCode standardTemplateCode = new WeblogThemeTemplateCode(
- stylesheetTmpl.getId(), STANDARD_THEME_TYPE);
- standardTemplateCode.setTemplate(stylesheetTmpl
- .getContents());
- standardTemplateCode.setTemplateLanguage(stylesheetTmpl
- .getTemplateLanguage());
-
- WeblogThemeTemplateCode mobileTemplateCode = new WeblogThemeTemplateCode(
- stylesheetTmpl.getId(), MOBILE_THEME_TYPE);
- mobileTemplateCode
- .setTemplate(stylesheetTmpl.getContents());
- mobileTemplateCode.setTemplateLanguage(stylesheetTmpl
- .getTemplateLanguage());
-
- WebloggerFactory.getWeblogger().getWeblogManager()
- .saveTemplateCode(standardTemplateCode);
- WebloggerFactory.getWeblogger().getWeblogManager()
- .saveTemplateCode(mobileTemplateCode);
-
- WebloggerFactory.getWeblogger().getWeblogManager()
- .savePage(stylesheetTmpl);
- WebloggerFactory.getWeblogger().flush();
-
- setTemplate(stylesheetTmpl);
- }
-
- // See if we have a custom style sheet from a custom theme.
- if (!WeblogTheme.CUSTOM.equals(getActionWeblog()
- .getEditorTheme())
- && getActionWeblog().getTheme().getStylesheet() != null) {
-
- ThemeTemplate override = WebloggerFactory
- .getWeblogger()
- .getWeblogManager()
- .getPageByLink(
- getActionWeblog(),
- getActionWeblog().getTheme()
- .getStylesheet().getLink());
-
- if (override != null) {
- customStylesheet = true;
- }
- }
-
- } catch (WebloggerException ex) {
- log.error(
- "Error finding/adding stylesheet tempalate from weblog - "
- + getActionWeblog().getHandle(), ex);
- }
- }
- }
-
- /**
- * Show stylesheet edit page.
- */
- public String execute() {
-
- if (getTemplate() == null) {
- return ERROR;
- }
-
- try {
-
- if (getTemplate().getTemplateCode(STANDARD_THEME_TYPE) != null) {
- setContentsStandard(getTemplate().getTemplateCode(STANDARD_THEME_TYPE)
- .getTemplate());
- } else {
- setContentsStandard(getTemplate().getContents());
- }
- if (getTemplate().getTemplateCode(MOBILE_THEME_TYPE) != null) {
- setContentsMobile(getTemplate().getTemplateCode(MOBILE_THEME_TYPE)
- .getTemplate());
- }
+ // the contents of the stylesheet override
+ private String contentsStandard = null;
+ private String contentsMobile = null;
+
+ // Do we have a custom stylesheet already for a custom theme
+ private boolean customStylesheet = false;
+
+ public StylesheetEdit() {
+ this.actionName = "stylesheetEdit";
+ this.desiredMenu = "editor";
+ this.pageTitle = "stylesheetEdit.title";
+ }
+
+ @Override
+ public List<String> requiredWeblogPermissionActions() {
+ return Collections.singletonList(WeblogPermission.ADMIN);
+ }
+
+ @Override
+ public void myPrepare() {
+
+ ThemeTemplate stylesheet = null;
+ try {
+ stylesheet = getActionWeblog().getTheme().getStylesheet();
+ } catch (WebloggerException ex) {
+ log.error("Error looking up stylesheet on weblog - "
+ + getActionWeblog().getHandle(), ex);
+ }
+
+ if (stylesheet != null) {
+ log.debug("custom stylesheet path is - " + stylesheet.getLink());
+ try {
+ setTemplate(WebloggerFactory.getWeblogger().getWeblogManager()
+ .getPageByLink(getActionWeblog(), stylesheet.getLink()));
+
+ if (getTemplate() == null) {
+ log.debug("custom stylesheet not found, creating it");
+
+ // template doesn't exist yet, so create it
+ WeblogTemplate stylesheetTmpl = new WeblogTemplate();
+ stylesheetTmpl.setWebsite(getActionWeblog());
+ stylesheetTmpl.setAction(ThemeTemplate.ACTION_CUSTOM);
+ stylesheetTmpl.setName(stylesheet.getName());
+ stylesheetTmpl.setDescription(stylesheet.getDescription());
+ stylesheetTmpl.setLink(stylesheet.getLink());
+ stylesheetTmpl.setContents(stylesheet.getContents());
+ stylesheetTmpl.setHidden(false);
+ stylesheetTmpl.setNavbar(false);
+ stylesheetTmpl.setLastModified(new Date());
+ stylesheetTmpl.setTemplateLanguage(stylesheet
+ .getTemplateLanguage());
+
+ // create template codes for available template code Types
+ WeblogThemeTemplateCode standardTemplateCode = new WeblogThemeTemplateCode(
+ stylesheetTmpl.getId(), STANDARD_THEME_TYPE);
+ standardTemplateCode.setTemplate(stylesheetTmpl
+ .getContents());
+ standardTemplateCode.setTemplateLanguage(stylesheetTmpl
+ .getTemplateLanguage());
+
+ WeblogThemeTemplateCode mobileTemplateCode = new WeblogThemeTemplateCode(
+ stylesheetTmpl.getId(), MOBILE_THEME_TYPE);
+ mobileTemplateCode
+ .setTemplate(stylesheetTmpl.getContents());
+ mobileTemplateCode.setTemplateLanguage(stylesheetTmpl
+ .getTemplateLanguage());
+
+ WebloggerFactory.getWeblogger().getWeblogManager()
+ .saveTemplateCode(standardTemplateCode);
+ WebloggerFactory.getWeblogger().getWeblogManager()
+ .saveTemplateCode(mobileTemplateCode);
+
+ WebloggerFactory.getWeblogger().getWeblogManager()
+ .savePage(stylesheetTmpl);
+ WebloggerFactory.getWeblogger().flush();
+
+ setTemplate(stylesheetTmpl);
+
+ // success message
+ addMessage("stylesheetEdit.create.success");
+ }
+
+ // See if we have a custom style sheet from a custom theme.
+ if (!WeblogTheme.CUSTOM.equals(getActionWeblog()
+ .getEditorTheme())
+ && getActionWeblog().getTheme().getStylesheet() != null) {
+
+ ThemeTemplate override = WebloggerFactory
+ .getWeblogger()
+ .getWeblogManager()
+ .getPageByLink(
+ getActionWeblog(),
+ getActionWeblog().getTheme()
+ .getStylesheet().getLink());
+
+ if (override != null) {
+ customStylesheet = true;
+ }
+ }
+
+ } catch (WebloggerException ex) {
+ log.error(
+ "Error finding/adding stylesheet tempalate from weblog - "
+ + getActionWeblog().getHandle(), ex);
+ }
+ }
+ }
+
+ /**
+ * Show stylesheet edit page.
+ */
+ public String execute() {
+
+ if (getTemplate() == null) {
+ return ERROR;
+ }
+
+ try {
- if (log.isDebugEnabled()) {
+ if (getTemplate().getTemplateCode(STANDARD_THEME_TYPE) != null) {
+ setContentsStandard(getTemplate().getTemplateCode(
+ STANDARD_THEME_TYPE).getTemplate());
+ } else {
+ setContentsStandard(getTemplate().getContents());
+ }
+ if (getTemplate().getTemplateCode(MOBILE_THEME_TYPE) != null) {
+ setContentsMobile(getTemplate().getTemplateCode(
+ MOBILE_THEME_TYPE).getTemplate());
+ }
+
+ if (log.isDebugEnabled()) {
log.debug("Standard: " + getContentsStandard() + " Mobile: "
+ getContentsMobile());
}
- } catch (WebloggerException e) {
- log.error("Error loading Weblog template codes for stylesheet", e);
- }
-
- return INPUT;
- }
-
- /**
- * Save an existing stylesheet.
- */
- public String save() {
-
- if (getTemplate() == null) {
- // TODO: i18n
- addError("Unable to locate stylesheet template");
- return ERROR;
- }
+ } catch (WebloggerException e) {
+ log.error("Error loading Weblog template codes for stylesheet", e);
+ }
+
+ return INPUT;
+ }
+
+ /**
+ * Save an existing stylesheet.
+ */
+ public String save() {
+
+ if (getTemplate() == null) {
+ // TODO: i18n
+ addError("Unable to locate stylesheet template");
+ return ERROR;
+ }
- if (!hasActionErrors()) {
+ if (!hasActionErrors()) {
try {
WeblogTemplate stylesheet = getTemplate();
@@ -262,28 +265,28 @@ public class StylesheetEdit extends UIAc
}
}
- return INPUT;
- }
+ return INPUT;
+ }
- /**
- * Revert the stylesheet to its original state.
- */
- public String revert() {
-
- if (getTemplate() == null) {
- // TODO: i18n
- addError("Unable to locate stylesheet template");
- return ERROR;
- }
-
- // make sure we are still using a shared theme so that reverting is
- // possible
- if (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
- // TODO: i18n
- addError("stylesheetEdit.error.customTheme");
- }
+ /**
+ * Revert the stylesheet to its original state.
+ */
+ public String revert() {
+
+ if (getTemplate() == null) {
+ // TODO: i18n
+ addError("Unable to locate stylesheet template");
+ return ERROR;
+ }
- if (!hasActionErrors()) {
+ // make sure we are still using a shared theme so that reverting is
+ // possible
+ if (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
+ // TODO: i18n
+ addError("stylesheetEdit.error.customTheme");
+ }
+
+ if (!hasActionErrors()) {
try {
WeblogTemplate stylesheet = getTemplate();
@@ -338,28 +341,28 @@ public class StylesheetEdit extends UIAc
}
}
- return execute();
- }
+ return execute();
+ }
+
+ /**
+ * set theme to default stylesheet, ie delete it.
+ */
+ public String delete() {
+
+ if (getTemplate() == null) {
+ log.error("Unable to locate stylesheet template");
+ addError("error.recordnotfound");
+ return ERROR;
+ }
- /**
- * set theme to default stylesheet, ie delete it.
- */
- public String delete() {
-
- if (getTemplate() == null) {
- log.error("Unable to locate stylesheet template");
- addError("error.recordnotfound");
- return ERROR;
- }
-
- // make sure we are still using a shared theme so that deleting is
- // possible
- if (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
- log.error("Unable to delete stylesheet");
- addError("stylesheetEdit.error.customTheme");
- }
+ // make sure we are still using a shared theme so that deleting is
+ // possible
+ if (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
+ log.error("Unable to delete stylesheet");
+ addError("stylesheetEdit.error.customTheme");
+ }
- if (!hasActionErrors()) {
+ if (!hasActionErrors()) {
try {
WeblogTemplate stylesheet = getTemplate();
@@ -397,92 +400,92 @@ public class StylesheetEdit extends UIAc
}
}
- return "delete";
+ return "delete";
- }
+ }
- /**
- * Checks if is custom theme.
- *
- * @return true, if is custom theme
- */
- public boolean isCustomTheme() {
- return (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme()));
- }
-
- /**
- * Gets the template.
- *
- * @return the template
- */
- public WeblogTemplate getTemplate() {
- return template;
- }
-
- /**
- * Sets the template.
- *
- * @param template
- * the new template
- */
- public void setTemplate(WeblogTemplate template) {
- this.template = template;
- }
-
- /**
- * Gets the contents standard.
- *
- * @return the contents standard
- */
- public String getContentsStandard() {
- return this.contentsStandard;
- }
-
- /**
- * Sets the contents standard.
- *
- * @param contents
- * the new contents standard
- */
- public void setContentsStandard(String contents) {
- this.contentsStandard = contents;
- }
-
- /**
- * Gets the contents mobile.
- *
- * @return the contents mobile
- */
- public String getContentsMobile() {
- return this.contentsMobile;
- }
-
- /**
- * Sets the contents mobile.
- *
- * @param contents
- * the new contents mobile
- */
- public void setContentsMobile(String contents) {
- this.contentsMobile = contents;
- }
-
- /**
- * Checks if is custom stylesheet.
- *
- * @return true, if checks if is custom stylesheet
- */
- public boolean isCustomStylesheet() {
- return customStylesheet;
- }
-
- /**
- * Sets the custom stylesheet.
- *
- * @param customStylesheet
- * the custom stylesheet
- */
- public void setCustomStylesheet(boolean customStylesheet) {
- this.customStylesheet = customStylesheet;
- }
+ /**
+ * Checks if is custom theme.
+ *
+ * @return true, if is custom theme
+ */
+ public boolean isCustomTheme() {
+ return (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme()));
+ }
+
+ /**
+ * Gets the template.
+ *
+ * @return the template
+ */
+ public WeblogTemplate getTemplate() {
+ return template;
+ }
+
+ /**
+ * Sets the template.
+ *
+ * @param template
+ * the new template
+ */
+ public void setTemplate(WeblogTemplate template) {
+ this.template = template;
+ }
+
+ /**
+ * Gets the contents standard.
+ *
+ * @return the contents standard
+ */
+ public String getContentsStandard() {
+ return this.contentsStandard;
+ }
+
+ /**
+ * Sets the contents standard.
+ *
+ * @param contents
+ * the new contents standard
+ */
+ public void setContentsStandard(String contents) {
+ this.contentsStandard = contents;
+ }
+
+ /**
+ * Gets the contents mobile.
+ *
+ * @return the contents mobile
+ */
+ public String getContentsMobile() {
+ return this.contentsMobile;
+ }
+
+ /**
+ * Sets the contents mobile.
+ *
+ * @param contents
+ * the new contents mobile
+ */
+ public void setContentsMobile(String contents) {
+ this.contentsMobile = contents;
+ }
+
+ /**
+ * Checks if is custom stylesheet.
+ *
+ * @return true, if checks if is custom stylesheet
+ */
+ public boolean isCustomStylesheet() {
+ return customStylesheet;
+ }
+
+ /**
+ * Sets the custom stylesheet.
+ *
+ * @param customStylesheet
+ * the custom stylesheet
+ */
+ public void setCustomStylesheet(boolean customStylesheet) {
+ this.customStylesheet = customStylesheet;
+ }
}
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java Sun Apr 20 13:38:51 2014
@@ -18,7 +18,7 @@
package org.apache.roller.weblogger.ui.struts2.editor;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.WebloggerException;
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEditBean.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEditBean.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEditBean.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEditBean.java Sun Apr 20 13:38:51 2014
@@ -169,7 +169,8 @@ public class TemplateEditBean {
tc.setTemplate(contentsMobile);
} else {
WeblogThemeTemplateCode tc = new WeblogThemeTemplateCode(dataHolder.getId(), "mobile");
- tc.setTemplate(""); // empty, we've got no default mobile template
+ // empty, we've got no default mobile template
+ tc.setTemplate("");
WebloggerFactory.getWeblogger().getWeblogManager().saveTemplateCode(tc);
}
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateRemove.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateRemove.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateRemove.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateRemove.java Sun Apr 20 13:38:51 2014
@@ -140,6 +140,15 @@ public class TemplateRemove extends UIAc
return "confirm";
}
+
+ /**
+ * Cancel.
+ *
+ * @return the string
+ */
+ public String cancel() {
+ return CANCEL;
+ }
public String getRemoveId() {
return removeId;
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Templates.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Templates.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Templates.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Templates.java Sun Apr 20 13:38:51 2014
@@ -18,9 +18,10 @@
package org.apache.roller.weblogger.ui.struts2.editor;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.roller.util.RollerConstants;
import org.apache.roller.weblogger.WebloggerException;
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.pojos.WeblogPermission;
@@ -42,15 +43,14 @@ public class Templates extends UIAction
private static Log log = LogFactory.getLog(Templates.class);
// list of templates to display
- private List<WeblogTemplate> templates = Collections.EMPTY_LIST;
+ private List<WeblogTemplate> templates = Collections.emptyList();
// list of template action types user is allowed to create
- private List availableActions = Collections.EMPTY_LIST;
+ private List availableActions = Collections.emptyList();
// name and action of new template if we are adding a template
private String newTmplName = null;
private String newTmplAction = null;
- private String type = null;
public Templates() {
this.actionName = "templates";
@@ -86,39 +86,39 @@ public class Templates extends UIAction
setTemplates(pages);
// build list of action types that may be added
- List availableActions = new ArrayList();
- availableActions.add(WeblogTemplate.ACTION_CUSTOM);
+ List<String> actionsList = new ArrayList<String>();
+ actionsList.add(WeblogTemplate.ACTION_CUSTOM);
if (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
// if the weblog is using a custom theme then determine which
// action templates are still available to be created
- availableActions.add(WeblogTemplate.ACTION_PERMALINK);
- availableActions.add(WeblogTemplate.ACTION_SEARCH);
- availableActions.add(WeblogTemplate.ACTION_WEBLOG);
- availableActions.add(WeblogTemplate.ACTION_TAGSINDEX);
+ actionsList.add(WeblogTemplate.ACTION_PERMALINK);
+ actionsList.add(WeblogTemplate.ACTION_SEARCH);
+ actionsList.add(WeblogTemplate.ACTION_WEBLOG);
+ actionsList.add(WeblogTemplate.ACTION_TAGSINDEX);
for (WeblogTemplate tmpPage : getTemplates()) {
if (!WeblogTemplate.ACTION_CUSTOM.equals(tmpPage
.getAction())) {
- availableActions.remove(tmpPage.getAction());
+ actionsList.remove(tmpPage.getAction());
}
}
} else {
// Make sure we have an option for the default web page
- availableActions.add(WeblogTemplate.ACTION_WEBLOG);
+ actionsList.add(WeblogTemplate.ACTION_WEBLOG);
if (StringUtils.isEmpty(getNewTmplAction())) {
setNewTmplAction(WeblogTemplate.ACTION_WEBLOG);
}
for (WeblogTemplate tmpPage : getTemplates()) {
if (WeblogTemplate.ACTION_WEBLOG
.equals(tmpPage.getAction())) {
- availableActions.remove(WeblogTemplate.ACTION_WEBLOG);
+ actionsList.remove(WeblogTemplate.ACTION_WEBLOG);
setNewTmplAction(null);
break;
}
}
}
- setAvailableActions(availableActions);
+ setAvailableActions(actionsList);
} catch (WebloggerException ex) {
log.error("Error getting templates for weblog - "
@@ -223,7 +223,7 @@ public class Templates extends UIAction
// make sure name is non-null and within proper size
if (StringUtils.isEmpty(getNewTmplName())) {
addError("Template.error.nameNull");
- } else if (getNewTmplName().length() > 255) {
+ } else if (getNewTmplName().length() > RollerConstants.TEXTWIDTH_255) {
addError("Template.error.nameSize");
}
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplatesRemove.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplatesRemove.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplatesRemove.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplatesRemove.java Sun Apr 20 13:38:51 2014
@@ -39,92 +39,92 @@ import org.apache.roller.weblogger.util.
*/
public class TemplatesRemove extends UIAction {
- private static final long serialVersionUID = 895186156151331087L;
- private static Log log = LogFactory.getLog(TemplatesRemove.class);
+ private static final long serialVersionUID = 895186156151331087L;
+ private static Log log = LogFactory.getLog(TemplatesRemove.class);
- // Templates to remove
- private String[] idSelections = null;
+ // Templates to remove
+ private String[] idSelections = null;
- // Limit updates to just this set of comma-separated IDs
- private String ids = null;
+ // Limit updates to just this set of comma-separated IDs
+ private String ids = null;
- // list of templates to display
- private List<WeblogTemplate> templates = Collections.emptyList();;
-
- public TemplatesRemove() {
- this.actionName = "templatesRemove";
- this.desiredMenu = "editor";
- this.pageTitle = "editPages.title.removeOK";
- }
-
- @Override
- public List<String> requiredWeblogPermissionActions() {
- return Collections.singletonList(WeblogPermission.ADMIN);
- }
+ // list of templates to display
+ private List<WeblogTemplate> templates = Collections.emptyList();
+
+ public TemplatesRemove() {
+ this.actionName = "templatesRemove";
+ this.desiredMenu = "editor";
+ this.pageTitle = "editPages.title.removeOK";
+ }
+
+ @Override
+ public List<String> requiredWeblogPermissionActions() {
+ return Collections.singletonList(WeblogPermission.ADMIN);
+ }
- public void myPrepare() {
+ public void myPrepare() {
if (getIdSelections() != null) {
- // query for templates list
- try {
+ // query for templates list
+ try {
+
+ WeblogManager mgr = WebloggerFactory.getWeblogger()
+ .getWeblogManager();
+
+ List<WeblogTemplate> pages = new ArrayList<WeblogTemplate>();
+ WeblogTemplate template = null;
+
+ String[] idsToDelete = getIdSelections();
+ if (idsToDelete != null && idsToDelete.length > 0) {
+
+ for (int i = 0; i < idsToDelete.length; i++) {
+ if (!idsToDelete[i].equals("")) {
+ template = mgr.getPage(idsToDelete[i]);
+ if (template != null) {
+ pages.add(template);
+ }
+ }
+ }
+
+ }
+
+ // Set page data
+ setTemplates(pages);
+ setIds(Utilities.stringArrayToString(idsToDelete, ","));
+
+ // Flush for operation
+ WebloggerFactory.getWeblogger().flush();
+
+ } catch (Exception ex) {
+ log.error("Error getting templates for weblog - "
+ + getActionWeblog().getHandle(), ex);
+ addError("error.unexpected");
+ }
- WeblogManager mgr = WebloggerFactory.getWeblogger()
- .getWeblogManager();
+ }
+ }
+
+ /**
+ * Display the remove template confirmation.
+ */
+ public String execute() {
+
+ if (getIds() != null && getTemplates() != null
+ && getTemplates().size() > 0) {
+ return "confirm";
+ } else {
+ return SUCCESS;
+ }
- List<WeblogTemplate> pages = new ArrayList<WeblogTemplate>();
- WeblogTemplate template = null;
+ }
- String[] idsToDelete = getIdSelections();
- if (idsToDelete != null && idsToDelete.length > 0) {
-
- for (int i = 0; i < idsToDelete.length; i++) {
- if (!idsToDelete[i].equals("")) {
- template = mgr.getPage(idsToDelete[i]);
- if (template != null) {
- pages.add(template);
- }
- }
- }
-
- }
-
- // Set page data
- setTemplates(pages);
- setIds(Utilities.stringArrayToString(idsToDelete, ","));
-
- // Flush for operation
- WebloggerFactory.getWeblogger().flush();
-
- } catch (Exception ex) {
- log.error("Error getting templates for weblog - "
- + getActionWeblog().getHandle(), ex);
- addError("error.unexpected");
- }
-
- }
- }
-
- /**
- * Display the remove template confirmation.
- */
- public String execute() {
-
- if (getIds() != null && getTemplates() != null
- && getTemplates().size() > 0) {
- return "confirm";
- } else {
- return SUCCESS;
- }
-
- }
-
- /**
- * Remove Selected templates
- */
- public String remove() {
+ /**
+ * Remove Selected templates
+ */
+ public String remove() {
- if (getIds() != null) {
+ if (getIds() != null) {
try {
String[] idsToDelete = Utilities.stringToStringArray(getIds(),
@@ -143,8 +143,8 @@ public class TemplatesRemove extends UIA
template = mgr.getPage(idsToDelete[i]);
if (!template.isRequired()
|| !WeblogTemplate.ACTION_CUSTOM
- .equals(getActionWeblog()
- .getEditorTheme())) {
+ .equals(getActionWeblog()
+ .getEditorTheme())) {
// if weblog template remove custom style sheet
// also
@@ -157,12 +157,12 @@ public class TemplatesRemove extends UIA
// Delete style sheet if the same name
if (stylesheet != null
&& getActionWeblog().getTheme()
- .getStylesheet() != null
+ .getStylesheet() != null
&& stylesheet.getLink().equals(
- getActionWeblog()
- .getTheme()
- .getStylesheet()
- .getLink())) {
+ getActionWeblog()
+ .getTheme()
+ .getStylesheet()
+ .getLink())) {
// Same so OK to delete
WeblogTemplate css = mgr.getPageByLink(
getActionWeblog(),
@@ -206,63 +206,63 @@ public class TemplatesRemove extends UIA
}
}
- return "confirm";
- }
+ return "confirm";
+ }
- /**
- * Cancel.
- *
- * @return the string
- */
- public String cancel() {
- return "cancel";
- }
-
- /**
- * Gets the templates.
- *
- * @return the templates
- */
- public List<WeblogTemplate> getTemplates() {
- return templates;
- }
-
- /**
- * Sets the templates.
- *
- * @param templates
- * the new templates
- */
- public void setTemplates(List<WeblogTemplate> templates) {
- this.templates = templates;
- }
-
- /**
- * Select check boxes for deleting records
- */
- public String[] getIdSelections() {
- return idSelections.clone();
- }
-
- /**
- * Select check boxes for deleting records
- */
- public void setIdSelections(String[] idSelections) {
- this.idSelections = idSelections.clone();
- }
-
- /**
- * Comma separated list if ids to remove
- */
- public String getIds() {
- return ids;
- }
-
- /**
- * Comma separated list if ids to remove
- */
- public void setIds(String ids) {
- this.ids = ids;
- }
+ /**
+ * Cancel.
+ *
+ * @return the string
+ */
+ public String cancel() {
+ return CANCEL;
+ }
+
+ /**
+ * Gets the templates.
+ *
+ * @return the templates
+ */
+ public List<WeblogTemplate> getTemplates() {
+ return templates;
+ }
+
+ /**
+ * Sets the templates.
+ *
+ * @param templates
+ * the new templates
+ */
+ public void setTemplates(List<WeblogTemplate> templates) {
+ this.templates = templates;
+ }
+
+ /**
+ * Select check boxes for deleting records
+ */
+ public String[] getIdSelections() {
+ return idSelections;
+ }
+
+ /**
+ * Select check boxes for deleting records
+ */
+ public void setIdSelections(String[] idSelections) {
+ this.idSelections = idSelections;
+ }
+
+ /**
+ * Comma separated list if ids to remove
+ */
+ public String getIds() {
+ return ids;
+ }
+
+ /**
+ * Comma separated list if ids to remove
+ */
+ public void setIds(String ids) {
+ this.ids = ids;
+ }
}
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java Sun Apr 20 13:38:51 2014
@@ -20,10 +20,12 @@ package org.apache.roller.weblogger.ui.s
import java.util.Collections;
import java.util.List;
-import org.apache.commons.lang.StringUtils;
+
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.WebloggerException;
+import org.apache.roller.weblogger.business.WeblogManager;
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.business.themes.SharedTheme;
import org.apache.roller.weblogger.business.themes.ThemeManager;
@@ -42,113 +44,123 @@ import org.apache.roller.weblogger.util.
*/
public class ThemeEdit extends UIAction {
- private static Log log = LogFactory.getLog(Templates.class);
+ private static final long serialVersionUID = 4644653507344432426L;
- // list of available themes
- private List themes = Collections.EMPTY_LIST;
+ private static Log log = LogFactory.getLog(Templates.class);
- // type of theme desired, either 'shared' or 'custom'
- private String themeType = null;
+ // list of available themes
+ private List<Theme> themes = Collections.emptyList();
- // the chosen shared theme id
- private String themeId = null;
-
- // import the selected theme to the action weblog
- private boolean importTheme = false;
-
- // the chosen import theme id
- private String importThemeId = null;
-
- // Do we have a custom stylesheet already
- private boolean customStylesheet = false;
-
- public ThemeEdit() {
- this.actionName = "themeEdit";
- this.desiredMenu = "editor";
- this.pageTitle = "themeEditor.title";
- }
-
- public List<String> requiredWeblogPermissionActions() {
- return Collections.singletonList(WeblogPermission.ADMIN);
- }
-
- public void myPrepare() {
-
- ThemeManager themeMgr = WebloggerFactory.getWeblogger()
- .getThemeManager();
- setThemes(themeMgr.getEnabledThemesList());
- }
-
- public String execute() {
-
- // set theme to current value
- if (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
- setThemeId(null);
- } else {
- setThemeId(getActionWeblog().getTheme().getId());
- setImportThemeId(getActionWeblog().getTheme().getId());
- }
-
- // See if we have a custom style sheet from a custom theme.
- try {
- if (!WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())
- && getActionWeblog().getTheme().getStylesheet() != null) {
-
- ThemeTemplate override = WebloggerFactory
- .getWeblogger()
- .getWeblogManager()
- .getPageByLink(
- getActionWeblog(),
- getActionWeblog().getTheme().getStylesheet()
- .getLink());
- if (override != null) {
- customStylesheet = true;
- }
- }
- } catch (WebloggerException ex) {
- log.error("Error looking up stylesheet on weblog - "
- + getActionWeblog().getHandle(), ex);
- }
-
- if (!WebloggerRuntimeConfig
- .getBooleanProperty("themes.customtheme.allowed")) {
- return "input-sharedonly";
- } else {
- return INPUT;
- }
- }
-
- /**
- * Save new theme configuration.
- */
- public String save() {
-
- Weblog weblog = getActionWeblog();
-
- // we are dealing with a custom theme scenario
- if (WeblogTheme.CUSTOM.equals(getThemeType())) {
-
- // only continue if custom themes are allowed
- if (WebloggerRuntimeConfig
- .getBooleanProperty("themes.customtheme.allowed")) {
-
- // do theme import if necessary
- SharedTheme t = null;
- if (isImportTheme() && !StringUtils.isEmpty(getImportThemeId())) {
- try {
- ThemeManager themeMgr = WebloggerFactory.getWeblogger()
- .getThemeManager();
- t = themeMgr.getTheme(getImportThemeId());
+ // type of theme desired, either 'shared' or 'custom'
+ private String themeType = null;
+
+ // the chosen shared theme id
+ private String themeId = null;
+
+ // import the selected theme to the action weblog
+ private boolean importTheme = false;
+
+ // the chosen import theme id
+ private String importThemeId = null;
+
+ // Do we have a custom stylesheet already
+ private boolean customStylesheet = false;
+
+ public ThemeEdit() {
+ this.actionName = "themeEdit";
+ this.desiredMenu = "editor";
+ this.pageTitle = "themeEditor.title";
+ }
+
+ public List<String> requiredWeblogPermissionActions() {
+ return Collections.singletonList(WeblogPermission.ADMIN);
+ }
+
+ public void myPrepare() {
+
+ ThemeManager themeMgr = WebloggerFactory.getWeblogger()
+ .getThemeManager();
+ setThemes(themeMgr.getEnabledThemesList());
+ }
+
+ public String execute() {
+
+ // set theme to current value
+ if (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())) {
+ setThemeId(null);
+ } else {
+ setThemeId(getActionWeblog().getTheme().getId());
+ setImportThemeId(getActionWeblog().getTheme().getId());
+ }
+
+ // See if we have a custom style sheet from a custom theme.
+ try {
+ if (!WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme())
+ && getActionWeblog().getTheme().getStylesheet() != null) {
+
+ ThemeTemplate override = WebloggerFactory
+ .getWeblogger()
+ .getWeblogManager()
+ .getPageByLink(
+ getActionWeblog(),
+ getActionWeblog().getTheme().getStylesheet()
+ .getLink());
+ if (override != null) {
+ customStylesheet = true;
+ }
+ }
+ } catch (WebloggerException ex) {
+ log.error("Error looking up stylesheet on weblog - "
+ + getActionWeblog().getHandle(), ex);
+ }
+
+ if (!WebloggerRuntimeConfig
+ .getBooleanProperty("themes.customtheme.allowed")) {
+ return "input-sharedonly";
+ } else {
+ return INPUT;
+ }
+ }
+
+ /**
+ * Save new theme configuration.
+ */
+ public String save() {
+
+ Weblog weblog = getActionWeblog();
+
+ // we are dealing with a custom theme scenario
+ if (WeblogTheme.CUSTOM.equals(getThemeType())) {
+
+ // only continue if custom themes are allowed
+ if (WebloggerRuntimeConfig
+ .getBooleanProperty("themes.customtheme.allowed")) {
+
+ // do theme import if necessary
+ SharedTheme t = null;
+
+ try {
+ ThemeManager themeMgr = WebloggerFactory.getWeblogger()
+ .getThemeManager();
+ t = themeMgr.getTheme(getImportThemeId());
+ if (isImportTheme()
+ && !StringUtils.isEmpty(getImportThemeId())) {
themeMgr.importTheme(getActionWeblog(), t);
- } catch (Exception re) {
- log.error("Error customizing theme for weblog - "
- + getActionWeblog().getHandle(), re);
- // TODO: i18n
- addError("Error importing theme");
+ } else {
+ // Reset our custom from base
+ if (t.getStylesheet() != null) {
+ weblog.setCustomStylesheetPath(t.getStylesheet()
+ .getLink());
+ }
}
+ } catch (Exception re) {
+ log.error("Error customizing theme for weblog - "
+ + getActionWeblog().getHandle(), re);
+ // TODO: i18n
+ addError("Error importing theme");
}
- if (!hasActionErrors()) {
+ if (!hasActionErrors()) {
try {
weblog.setEditorTheme(WeblogTheme.CUSTOM);
log.debug("Saving custom theme for weblog "
@@ -181,41 +193,65 @@ public class ThemeEdit extends UIAction
addError("Error setting theme");
}
}
- } else {
- // TODO: i18n
- addError("Sorry, custom themes are not allowed");
- }
-
- // we are dealing with a shared theme scenario
- } else if ("shared".equals(getThemeType())) {
-
- // make sure theme is valid and enabled
- Theme newTheme = null;
- if (getThemeId() == null) {
- // TODO: i18n
- addError("No theme specified");
-
- } else {
- try {
- ThemeManager themeMgr = WebloggerFactory.getWeblogger()
- .getThemeManager();
- newTheme = themeMgr.getTheme(getThemeId());
-
- if (!newTheme.isEnabled()) {
- // TODO: i18n
- addError("Theme not enabled");
- }
-
- } catch (Exception ex) {
- log.warn(ex);
- // TODO: i18n
- addError("Theme not found");
- }
- }
+ } else {
+ // TODO: i18n
+ addError("Sorry, custom themes are not allowed");
+ }
- if (!hasActionErrors()) {
+ // we are dealing with a shared theme scenario
+ } else if ("shared".equals(getThemeType())) {
+
+ // make sure theme is valid and enabled
+ Theme newTheme = null;
+ if (getThemeId() == null) {
+ // TODO: i18n
+ addError("No theme specified");
+
+ } else {
try {
+ ThemeManager themeMgr = WebloggerFactory.getWeblogger()
+ .getThemeManager();
+ newTheme = themeMgr.getTheme(getThemeId());
+
+ if (!newTheme.isEnabled()) {
+ // TODO: i18n
+ addError("Theme not enabled");
+ }
+
+ } catch (Exception ex) {
+ log.warn(ex);
+ // TODO: i18n
+ addError("Theme not found");
+ }
+ }
+
+ if (!hasActionErrors()) {
+ try {
+
+ String originalTheme = weblog.getEditorTheme();
+
+ WeblogManager mgr = WebloggerFactory.getWeblogger()
+ .getWeblogManager();
+
+ // Remove old style sheet
+ if (!WeblogTheme.CUSTOM.equals(originalTheme)
+ && !originalTheme.equals(getThemeId())
+ && getActionWeblog().getTheme().getStylesheet() != null) {
+
+ WeblogTemplate stylesheet = mgr.getPageByLink(
+ getActionWeblog(), getActionWeblog().getTheme()
+ .getStylesheet().getLink());
+
+ if (stylesheet != null) {
+ // Remove template and page codes
+ mgr.removePage(stylesheet);
+ // Reset
+ weblog.setCustomStylesheetPath(null);
+ }
+ }
+
weblog.setEditorTheme(getThemeId());
+
log.debug("Saving theme " + getThemeId() + " for weblog "
+ weblog.getHandle());
@@ -228,9 +264,10 @@ public class ThemeEdit extends UIAction
// change
CacheManager.invalidate(weblog);
- // TODO: i18n
- addMessage("Successfully set theme to - "
- + newTheme.getName());
+ // Theme set to..
+ if (!originalTheme.equals(getThemeId())) {
+ addMessage("themeEditor.settheme", newTheme.getName());
+ }
} catch (WebloggerException re) {
log.error("Error saving weblog - "
@@ -239,91 +276,91 @@ public class ThemeEdit extends UIAction
}
}
- // unknown theme scenario, error
- } else {
- // invalid theme type
- // TODO: i18n
- addError("no valid theme type submitted");
- }
-
- return execute();
- }
-
- public boolean isCustomTheme() {
- return (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme()));
- }
-
- // has this weblog had a custom theme before?
- public boolean isFirstCustomization() {
- try {
- return (WebloggerFactory
- .getWeblogger()
- .getWeblogManager()
- .getPageByAction(getActionWeblog(),
- WeblogTemplate.ACTION_WEBLOG) == null);
- } catch (WebloggerException ex) {
- log.error("Error looking up weblog template", ex);
- }
- return false;
- }
-
- public List getThemes() {
- return themes;
- }
-
- public void setThemes(List themes) {
- this.themes = themes;
- }
-
- public String getThemeType() {
- return themeType;
- }
-
- public void setThemeType(String themeType) {
- this.themeType = themeType;
- }
-
- public String getThemeId() {
- return themeId;
- }
-
- public void setThemeId(String theme) {
- this.themeId = theme;
- }
-
- public boolean isImportTheme() {
- return importTheme;
- }
-
- public void setImportTheme(boolean importTheme) {
- this.importTheme = importTheme;
- }
-
- public String getImportThemeId() {
- return importThemeId;
- }
-
- public void setImportThemeId(String importThemeId) {
- this.importThemeId = importThemeId;
- }
-
- /**
- * Checks if we have a custom stylesheet.
- *
- * @return true, if checks if is custom stylesheet
- */
- public boolean isCustomStylesheet() {
- return customStylesheet;
- }
-
- /**
- * Sets the custom stylesheet.
- *
- * @param customStylesheet
- * the custom stylesheet
- */
- public void setCustomStylesheet(boolean customStylesheet) {
- this.customStylesheet = customStylesheet;
- }
+ // unknown theme scenario, error
+ } else {
+ // invalid theme type
+ // TODO: i18n
+ addError("no valid theme type submitted");
+ }
+
+ return execute();
+ }
+
+ public boolean isCustomTheme() {
+ return (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme()));
+ }
+
+ // has this weblog had a custom theme before?
+ public boolean isFirstCustomization() {
+ try {
+ return (WebloggerFactory
+ .getWeblogger()
+ .getWeblogManager()
+ .getPageByAction(getActionWeblog(),
+ WeblogTemplate.ACTION_WEBLOG) == null);
+ } catch (WebloggerException ex) {
+ log.error("Error looking up weblog template", ex);
+ }
+ return false;
+ }
+
+ public List<Theme> getThemes() {
+ return themes;
+ }
+
+ public void setThemes(List<Theme> themes) {
+ this.themes = themes;
+ }
+
+ public String getThemeType() {
+ return themeType;
+ }
+
+ public void setThemeType(String themeType) {
+ this.themeType = themeType;
+ }
+
+ public String getThemeId() {
+ return themeId;
+ }
+
+ public void setThemeId(String theme) {
+ this.themeId = theme;
+ }
+
+ public boolean isImportTheme() {
+ return importTheme;
+ }
+
+ public void setImportTheme(boolean importTheme) {
+ this.importTheme = importTheme;
+ }
+
+ public String getImportThemeId() {
+ return importThemeId;
+ }
+
+ public void setImportThemeId(String importThemeId) {
+ this.importThemeId = importThemeId;
+ }
+
+ /**
+ * Checks if we have a custom stylesheet.
+ *
+ * @return true, if checks if is custom stylesheet
+ */
+ public boolean isCustomStylesheet() {
+ return customStylesheet;
+ }
+
+ /**
+ * Sets the custom stylesheet.
+ *
+ * @param customStylesheet
+ * the custom stylesheet
+ */
+ public void setCustomStylesheet(boolean customStylesheet) {
+ this.customStylesheet = customStylesheet;
+ }
}
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogConfig.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogConfig.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogConfig.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogConfig.java Sun Apr 20 13:38:51 2014
@@ -21,7 +21,6 @@ package org.apache.roller.weblogger.ui.s
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -29,6 +28,7 @@ import org.apache.commons.logging.LogFac
import org.apache.roller.weblogger.business.plugins.PluginManager;
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.business.WeblogEntryManager;
+import org.apache.roller.weblogger.business.plugins.entry.WeblogEntryPlugin;
import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
import org.apache.roller.weblogger.pojos.Weblog;
import org.apache.roller.weblogger.pojos.WeblogPermission;
@@ -51,13 +51,13 @@ public class WeblogConfig extends UIActi
private WeblogConfigBean bean = new WeblogConfigBean();
// categories list
- private List weblogCategories = Collections.EMPTY_LIST;
+ private List weblogCategories = Collections.emptyList();
// list of available editors
- private List editorsList = Collections.EMPTY_LIST;
+ private List editorsList = Collections.emptyList();
// list of available plugins
- private List pluginsList = Collections.EMPTY_LIST;
+ private List pluginsList = Collections.emptyList();
public WeblogConfig() {
@@ -79,23 +79,23 @@ public class WeblogConfig extends UIActi
WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
// set categories list
- setWeblogCategories(wmgr.getWeblogCategories(getActionWeblog(), false));
+ setWeblogCategories(wmgr.getWeblogCategories(getActionWeblog()));
// set the Editor Page list
UIPluginManager pmgr = RollerContext.getUIPluginManager();
- List editorsList = pmgr.getWeblogEntryEditors();
- if(editorsList != null) {
- setEditorsList(editorsList);
+ List editorList = pmgr.getWeblogEntryEditors();
+ if(editorList != null) {
+ setEditorsList(editorList);
}
// set plugins list
PluginManager ppmgr = WebloggerFactory.getWeblogger().getPluginManager();
- Map pluginsMap = ppmgr.getWeblogEntryPlugins(getActionWeblog());
- List plugins = new ArrayList();
- Iterator iter = pluginsMap.values().iterator();
- while(iter.hasNext()) {
- plugins.add(iter.next());
+ Map<String, WeblogEntryPlugin> pluginsMap = ppmgr.getWeblogEntryPlugins(getActionWeblog());
+ List<WeblogEntryPlugin> plugins = new ArrayList<WeblogEntryPlugin>();
+ for (WeblogEntryPlugin entryPlugin : pluginsMap.values()) {
+ plugins.add(entryPlugin);
}
+
// sort
setPluginsList(plugins);
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogConfigBean.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogConfigBean.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogConfigBean.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogConfigBean.java Sun Apr 20 13:38:51 2014
@@ -18,7 +18,7 @@
package org.apache.roller.weblogger.ui.struts2.editor;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.roller.weblogger.pojos.Weblog;
@@ -27,7 +27,6 @@ import org.apache.roller.weblogger.pojos
*/
public class WeblogConfigBean {
- private String id = null;
private String handle = null;
private String name = null;
private String description = null;
@@ -54,15 +53,10 @@ public class WeblogConfigBean {
private String about = null;
private String bloggerCategoryId = null;
- private String defaultCategoryId = null;
private String[] defaultPluginsArray = null;
private boolean applyCommentDefaults = false;
- public void setId( String id ) {
- this.id = id;
- }
-
public String getHandle() {
return this.handle;
}
@@ -246,15 +240,7 @@ public class WeblogConfigBean {
public void setBloggerCategoryId(String bloggerCategoryId) {
this.bloggerCategoryId = bloggerCategoryId;
}
-
- public String getDefaultCategoryId() {
- return defaultCategoryId;
- }
-
- public void setDefaultCategoryId(String defeaultCategoryId) {
- this.defaultCategoryId = defeaultCategoryId;
- }
-
+
public String[] getDefaultPluginsArray() {
return defaultPluginsArray;
}
@@ -282,7 +268,6 @@ public class WeblogConfigBean {
public void copyFrom(Weblog dataHolder) {
- this.id = dataHolder.getId();
this.handle = dataHolder.getHandle();
this.name = dataHolder.getName();
this.description = dataHolder.getDescription();
@@ -307,10 +292,6 @@ public class WeblogConfigBean {
this.pageModels = dataHolder.getPageModels();
setIcon(dataHolder.getIconPath());
setAbout(dataHolder.getAbout());
-
- if (dataHolder.getDefaultCategory() != null) {
- defaultCategoryId = dataHolder.getDefaultCategory().getId();
- }
if (dataHolder.getBloggerCategory() != null) {
bloggerCategoryId = dataHolder.getBloggerCategory().getId();
}
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogExport.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogExport.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogExport.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/WeblogExport.java Sun Apr 20 13:38:51 2014
@@ -41,6 +41,7 @@ import javax.servlet.http.HttpServletRes
// import org.apache.abdera.model.Feed;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.roller.util.RollerConstants;
import org.apache.roller.weblogger.WebloggerException;
import org.apache.roller.weblogger.business.MediaFileManager;
import org.apache.roller.weblogger.business.URLStrategy;
@@ -50,6 +51,7 @@ import org.apache.roller.weblogger.confi
import org.apache.roller.weblogger.pojos.MediaFile;
import org.apache.roller.weblogger.pojos.MediaFileDirectory;
import org.apache.roller.weblogger.pojos.WeblogEntry;
+import org.apache.roller.weblogger.pojos.WeblogEntrySearchCriteria;
import org.apache.roller.weblogger.pojos.WeblogPermission;
import org.apache.roller.weblogger.pojos.wrapper.WeblogEntryCommentWrapper;
import org.apache.roller.weblogger.pojos.wrapper.WeblogEntryWrapper;
@@ -80,8 +82,6 @@ public final class WeblogExport extends
private static final SimpleDateFormat MT_DATE_FORMAT =
new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
- private static final SimpleDateFormat ATOM_ID_DATE_FORMAT =
- new SimpleDateFormat("yyyy-MM-dd");
private static final String MT_FORMAT = "mtimport";
private static final String MT_PLUS_FORMAT = "mtimportplus";
@@ -154,7 +154,6 @@ public final class WeblogExport extends
options.put(MT_FORMAT, getText("weblogExport.format.mtimport"));
options.put(MT_PLUS_FORMAT, getText("weblogExport.format.mtimportplus"));
- // options.put(ATOM_FORMAT, getText("weblogExport.format.atom"));
return options;
}
@@ -200,9 +199,10 @@ public final class WeblogExport extends
URLStrategy urlStrategy;
urlStrategy = WebloggerFactory.getWeblogger().getUrlStrategy();
- List rawEntries;
- rawEntries = wmgr.getWeblogEntries(getActionWeblog(), null, null,
- null, null, null, null, null, null, null, null, 0, -1);
+ List<WeblogEntry> rawEntries;
+ WeblogEntrySearchCriteria wesc = new WeblogEntrySearchCriteria();
+ wesc.setWeblog(getActionWeblog());
+ rawEntries = wmgr.getWeblogEntries(wesc);
List<WeblogEntryWrapper> entries;
entries = new ArrayList<WeblogEntryWrapper>();
@@ -309,7 +309,7 @@ public final class WeblogExport extends
// Create a buffer for reading the files
byte[] buffer;
- buffer = new byte[1024];
+ buffer = new byte[RollerConstants.ONE_KB_IN_BYTES];
ServletOutputStream servletOutput;
servletOutput = response.getOutputStream();
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIAction.java Sun Apr 20 13:38:51 2014
@@ -19,7 +19,7 @@
package org.apache.roller.weblogger.ui.struts2.util;
import com.opensymphony.xwork2.ActionSupport;
-import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.roller.weblogger.business.UserManager;
import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.config.WebloggerConfig;
@@ -35,12 +35,9 @@ import org.apache.struts2.interceptor.Re
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.HashSet;
/**
* Extends the Struts2 ActionSupport class to add in support for handling an
@@ -59,7 +56,10 @@ public abstract class UIAction extends A
// a common result name used to indicate the result should list some data
public static final String LIST = "list";
-
+
+ // a result for a cancel.
+ public static final String CANCEL = "cancel";
+
// the authenticated user accessing this action, or null if client is not logged in
private User authenticatedUser = null;
@@ -390,8 +390,6 @@ public abstract class UIAction extends A
return opts;
}
- private static Set OPEN_CHARS = new HashSet(Arrays.asList('$', '%'));
-
private static String cleanExpressions(String s) {
return (s == null || s.contains("${") || s.contains("%{")) ? "" : s;
}
@@ -401,13 +399,13 @@ public abstract class UIAction extends A
return s;
}
// escape HTML
- return StringEscapeUtils.escapeHtml(cleanExpressions(s));
+ return StringEscapeUtils.escapeHtml4(cleanExpressions(s));
}
public static String cleanTextArg(String s) {
if (s == null || s.isEmpty()) {
return s;
}
- return StringEscapeUtils.escapeHtml(s);
+ return StringEscapeUtils.escapeHtml4(s);
}
}
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java Sun Apr 20 13:38:51 2014
@@ -22,7 +22,7 @@ import com.opensymphony.xwork2.ActionCon
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import javax.servlet.http.HttpServletRequest;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.business.WebloggerFactory;
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIUtils.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIUtils.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIUtils.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIUtils.java Sun Apr 20 13:38:51 2014
@@ -31,19 +31,19 @@ import java.util.TimeZone;
*/
public final class UIUtils {
- private static final List locales;
- private static final List timeZones;
+ private static final List LOCALES;
+ private static final List TIME_ZONES;
// load up the locales and time zones lists
static {
// build locales list
- locales = Arrays.asList(Locale.getAvailableLocales());
- Collections.sort(locales, new LocaleComparator());
+ LOCALES = Arrays.asList(Locale.getAvailableLocales());
+ Collections.sort(LOCALES, new LocaleComparator());
// build time zones list
- timeZones = Arrays.asList(TimeZone.getAvailableIDs());
- Collections.sort(timeZones);
+ TIME_ZONES = Arrays.asList(TimeZone.getAvailableIDs());
+ Collections.sort(TIME_ZONES);
}
@@ -53,7 +53,7 @@ public final class UIUtils {
}
public static List getLocales() {
- return locales;
+ return LOCALES;
}
public static String getTimeZone(String timeZoneName) {
@@ -61,11 +61,11 @@ public final class UIUtils {
}
public static List getTimeZones() {
- return timeZones;
+ return TIME_ZONES;
}
- // special comparator for sorting locales
+ // special comparator for sorting LOCALES
private static final class LocaleComparator implements Comparator {
public int compare(Object obj1, Object obj2) {
if (obj1 instanceof Locale && obj2 instanceof Locale) {
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/StringTagSupport.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/StringTagSupport.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/StringTagSupport.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/StringTagSupport.java Sun Apr 20 13:38:51 2014
@@ -33,13 +33,9 @@ import javax.servlet.jsp.tagext.BodyTagS
* out to the html page.
* </dd>
* </dl>
- *
- * @author bayard@generationjava.com
*/
public abstract class StringTagSupport extends BodyTagSupport {
-
-
/**
* PageContext attribute to store the result in.
*/
@@ -73,15 +69,6 @@ public abstract class StringTagSupport e
*/
public int doEndTag() throws JspException {
- /*
- * Although most of the tags that extends must have a body, some don't, like RandomStringTag
- * So I'm removing the code below...
- */
-
-// if( (bodyContent == null) && (!canBeEmpty()) ) {
- // return EVAL_PAGE;
- // }
-
String text = "";
if(bodyContent != null) {
StringWriter body = new StringWriter();
@@ -101,15 +88,7 @@ public abstract class StringTagSupport e
// then, try to transform it
text = changeString(text);
- // TODO: RandomString is not working if body is set...
- /*
- System.err.println("...."+text+"....");
- if ( text != null ) {
- System.out.println( "length = " + text.length());
- }
- */
-
- if(this.var == null) {
+ if (this.var == null) {
JspWriter writer = pageContext.getOut();
try {
writer.print(text);
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/TruncateNicelyTag.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/TruncateNicelyTag.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/TruncateNicelyTag.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/TruncateNicelyTag.java Sun Apr 20 13:38:51 2014
@@ -16,9 +16,11 @@
package org.apache.roller.weblogger.ui.tags;
import javax.servlet.jsp.JspException;
-import org.apache.commons.lang.math.NumberUtils;
+import org.apache.commons.lang3.math.NumberUtils;
/**
+ * Code grabbed from retired Jakarta Tablibs project: http://jakarta.apache.org/taglibs/string/
+ *
* A more intelligent substring. It attempts to cut off a string after
* a space, following predefined or user-supplied lower and upper limits,
* useful for making short descriptions from long text. Can also strip
@@ -38,15 +40,14 @@ import org.apache.commons.lang.math.Numb
* String to append to end of truncated string.
* </dd>
* </dl>
- *
+ *
* @author timster@mac.com
*/
public class TruncateNicelyTag extends StringTagSupport {
- private String stripMarkup;
private String lower;
private String upper;
- private String appendToEnd;
+ private String appendToEnd;
public TruncateNicelyTag() {
super();
@@ -54,7 +55,8 @@ public class TruncateNicelyTag extends S
/**
* Get the lower property
- * @return String lower property
+ *
+ * @return String lower property
*/
public String getLower() {
return this.lower;
@@ -62,15 +64,17 @@ public class TruncateNicelyTag extends S
/**
* Set the upper property
+ *
* @param lower String property
*/
- public void setLower(String l) {
- this.lower = l;
+ public void setLower(String lower) {
+ this.lower = lower;
}
/**
* Get the upper property
- * @return String upper property
+ *
+ * @return String upper property
*/
public String getUpper() {
return this.upper;
@@ -78,34 +82,114 @@ public class TruncateNicelyTag extends S
/**
* Set the upper property
+ *
* @param upper String property
*/
- public void setUpper(String u) {
- this.upper = u;
+ public void setUpper(String upper) {
+ this.upper = upper;
}
- public String getAppendToEnd() {
- return this.appendToEnd;
- }
+ public String getAppendToEnd() {
+ return this.appendToEnd;
+ }
- public void setAppendToEnd(String s) {
- this.appendToEnd = s;
- }
+ public void setAppendToEnd(String s) {
+ this.appendToEnd = s;
+ }
public String changeString(String text) throws JspException {
-
- int l = NumberUtils.stringToInt(lower);
- int u = NumberUtils.stringToInt(upper);
-
- return StringW.truncateNicely(text, l, u, this.appendToEnd);
+
+ int l = NumberUtils.toInt(lower);
+ int u = NumberUtils.toInt(upper);
+
+ return truncateNicely(text, l, u, this.appendToEnd);
}
public void initAttributes() {
- this.lower = "10";
- this.upper = "-1";
- this.appendToEnd = "...";
+ this.lower = "10";
+ this.upper = "-1";
+ this.appendToEnd = "...";
+
+ }
+ /**
+ * Truncates a string nicely. It will search for the first space
+ * after the lower limit and truncate the string there. It will
+ * also append any string passed as a parameter to the end of the
+ * string. The hard limit can be specified to forcibily truncate a
+ * string (in the case of an extremely long word or such). All
+ * HTML/XML markup will be stripped from the string prior to
+ * processing for truncation.
+ *
+ * @param str String the string to be truncated.
+ * @param lower int value of the lower limit.
+ * @param upper int value of the upper limit, -1 if no limit is
+ * desired. If the uppper limit is lower than the
+ * lower limit, it will be adjusted to be same as
+ * the lower limit.
+ * @param appendToEnd String to be appended to the end of the
+ * truncated string.
+ * This is appended ONLY if the string was indeed
+ * truncated. The append is does not count towards
+ * any lower/upper limits.
+ */
+ private static String truncateNicely(String str, int lower, int upper, String appendToEnd)
+ {
+ // strip markup from the string
+ str = removeXml(str);
+
+ // quickly adjust the upper if it is set lower than 'lower'
+ if(upper < lower) {
+ upper = lower;
+ }
+
+ // now determine if the string fits within the upper limit
+ // if it does, go straight to return, do not pass 'go' and collect $200
+ if(str.length() > upper) {
+ // the magic location int
+ int loc;
+
+ // first we determine where the next space appears after lower
+ loc = str.lastIndexOf(' ', upper);
+
+ // now we'll see if the location is greater than the lower limit
+ if(loc >= lower) {
+ // yes it was, so we'll cut it off here
+ str = str.substring(0, loc);
+ } else {
+ // no it wasn't, so we'll cut it off at the upper limit
+ str = str.substring(0, upper);
+ }
+
+ // the string was truncated, so we append the appendToEnd String
+ str = str + appendToEnd;
+ }
+
+ return str;
+ }
+
+ /**
+ * Remove any xml tags from a String.
+ */
+ private static String removeXml(String str) {
+ int sz = str.length();
+ StringBuilder buffer = new StringBuilder(sz);
+ boolean inTag = false;
+ for (int i=0; i<sz; i++) {
+ char ch = str.charAt(i);
+ if (ch == '<') {
+ inTag = true;
+ } else
+ if (ch == '>') {
+ inTag = false;
+ continue;
+ }
+ if (!inTag) {
+ buffer.append(ch);
+ }
+ }
+ return buffer.toString();
}
}
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/WordWrapTag.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/WordWrapTag.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/WordWrapTag.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/ui/tags/WordWrapTag.java Sun Apr 20 13:38:51 2014
@@ -16,13 +16,17 @@
package org.apache.roller.weblogger.ui.tags;
import javax.servlet.jsp.JspException;
-import org.apache.commons.lang.math.NumberUtils;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.math.NumberUtils;
/**
- * Word-wrap a String. This involves formatting a long
+ * Code grabbed from retired Jakarta Tablibs project: http://jakarta.apache.org/taglibs/string/
+ *
+ * Word-wrap a String. This involves formatting a long
* String to fit within a certain character width of page.
- * A delimiter may be passed in to put at the end of each
- * line and a splitting character can be specified for when
+ * A delimiter may be passed in to put at the end of each
+ * line and a splitting character can be specified for when
* a word has to be cut in half.
*
* <dl>
@@ -43,8 +47,7 @@ import org.apache.commons.lang.math.Numb
* Default is true.
* </dd>
* </dl>
- *
- * @author bayard@generationjava.com
+ *
*/
public class WordWrapTag extends StringTagSupport {
@@ -132,18 +135,111 @@ public class WordWrapTag extends StringT
}
public String changeString(String text) throws JspException {
- return StringW.wordWrap(text, NumberUtils.stringToInt(width), delimiter, split, delimiterInside );
+ return wordWrap(text, NumberUtils.toInt(width), delimiter, split, delimiterInside);
}
public void initAttributes() {
-
this.width = "80";
-
this.delimiter = "\n";
-
this.split = "-";
-
this.delimiterInside = true;
}
+ /**
+ * Word-wrap a string.
+ *
+ * @param str String to word-wrap
+ * @param width int to wrap at
+ * @param delim String to use to separate lines
+ * @param split String to use to split a word greater than width long
+ * @param delimInside wheter or not delim should be included in chunk before length reaches width.
+ * @return String that has been word wrapped
+ */
+ public static String wordWrap(String str, int width, String delim,
+ String split, boolean delimInside) {
+ int sz = str.length();
+
+ /// shift width up one. mainly as it makes the logic easier
+ width++;
+
+ // our best guess as to an initial size
+ StringBuilder buffer = new StringBuilder(sz / width * delim.length() + sz);
+
+ // every line might include a delim on the end
+ if (delimInside) {
+ width = width - delim.length();
+ } else {
+ width--;
+ }
+
+ int idx;
+ String substr;
+
+ // beware: i is rolled-back inside the loop
+ for (int i = 0; i < sz; i += width) {
+
+ // on the last line
+ if (i > sz - width) {
+ buffer.append(str.substring(i));
+ break;
+ }
+
+ // the current line
+ substr = str.substring(i, i + width);
+
+ // is the delim already on the line
+ idx = substr.indexOf(delim);
+ if (idx != -1) {
+ buffer.append(substr.substring(0, idx));
+ buffer.append(delim);
+ i -= width - idx - delim.length();
+
+ // Erase a space after a delim. Is this too obscure?
+ if (substr.length() > idx + 1 && (substr.charAt(idx + 1) != '\n') && Character.isWhitespace(substr.charAt(idx + 1))) {
+ i++;
+ }
+ continue;
+ }
+
+ idx = -1;
+
+ // figure out where the last space is
+ char[] chrs = substr.toCharArray();
+ for (int j = width; j > 0; j--) {
+ if (Character.isWhitespace(chrs[j - 1])) {
+ idx = j;
+ break;
+ }
+ }
+
+ // idx is the last whitespace on the line.
+ if (idx == -1) {
+ for (int j = width; j > 0; j--) {
+ if (chrs[j - 1] == '-') {
+ idx = j;
+ break;
+ }
+ }
+ if (idx == -1) {
+ buffer.append(substr);
+ buffer.append(delim);
+ } else {
+ if (idx != width) {
+ idx++;
+ }
+ buffer.append(substr.substring(0, idx));
+ buffer.append(delim);
+ i -= width - idx;
+ }
+ } else {
+ // insert spaces
+ buffer.append(substr.substring(0, idx));
+ buffer.append(StringUtils.repeat(" ", width - idx));
+ buffer.append(delim);
+ i -= width - idx;
+ }
+ }
+
+ return buffer.toString();
+ }
}
Modified: roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/Blacklist.java
URL: http://svn.apache.org/viewvc/roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/Blacklist.java?rev=1588757&r1=1588756&r2=1588757&view=diff
==============================================================================
--- roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/Blacklist.java (original)
+++ roller/branches/rome2/app/src/main/java/org/apache/roller/weblogger/util/Blacklist.java Sun Apr 20 13:38:51 2014
@@ -33,15 +33,16 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+
+import org.apache.roller.util.RollerConstants;
import org.apache.roller.weblogger.config.WebloggerConfig;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.roller.util.DateUtil;
/**
@@ -61,7 +62,7 @@ import org.apache.roller.util.DateUtil;
* @author Lance Lavandowska
* @author Allen Gilliland
*/
-public class Blacklist {
+public final class Blacklist {
private static Log mLogger = LogFactory.getLog(Blacklist.class);
@@ -73,8 +74,8 @@ public class Blacklist {
private static final String BLACKLIST_URL = null;
private Date lastModified = null;
- private List blacklistStr = new LinkedList();
- private List blacklistRegex = new LinkedList();
+ private List<String> blacklistStr = new LinkedList<String>();
+ private List<Pattern> blacklistRegex = new LinkedList<Pattern>();
// setup our singleton at class loading time
static {
@@ -92,11 +93,6 @@ public class Blacklist {
return blacklist;
}
- /** Updated MT blacklist if necessary. */
- public static void checkForUpdate() {
- getBlacklist().update();
- }
-
/** Non-Static update method. */
public void update() {
if (BLACKLIST_URL != null) {
@@ -161,8 +157,8 @@ public class Blacklist {
mLogger.debug("writing updated MT blacklist to "+path);
// read from url and write to file
- byte[] buf = new byte[4096];
- int length = 0;
+ byte[] buf = new byte[RollerConstants.FOUR_KB_IN_BYTES];
+ int length;
while((length = instream.read(buf)) > 0) {
outstream.write(buf, 0, length);
}
@@ -193,7 +189,7 @@ public class Blacklist {
*/
public void loadBlacklistFromFile(String blacklistFilePath) {
- InputStream txtStream = null;
+ InputStream txtStream;
try {
String path = blacklistFilePath;
if (path == null) {
@@ -232,7 +228,7 @@ public class Blacklist {
/**
* Read in the InputStream for rules.
- * @param txtStream
+ * @param txtStream stream to read from
*/
private String readFromStream(InputStream txtStream, boolean saveStream) {
String line;
@@ -277,7 +273,8 @@ public class Blacklist {
// line has a comment?
if (str.indexOf('#') > 0) {
int commentLoc = str.indexOf('#');
- rule = str.substring(0, commentLoc-1).trim(); // strip comment
+ // strip comment
+ rule = str.substring(0, commentLoc-1).trim();
}
// regex rule?
@@ -319,7 +316,7 @@ public class Blacklist {
* @param moreRegexRules Additional regex rules to consider
*/
public boolean isBlacklisted(
- String str, List moreStringRules, List moreRegexRules) {
+ String str, List<String> moreStringRules, List<Pattern> moreRegexRules) {
if (str == null || StringUtils.isEmpty(str)) {
return false;
}
@@ -329,9 +326,9 @@ public class Blacklist {
// As soon as there is a hit in either case return true
// test plain String.indexOf
- List stringRules = blacklistStr;
+ List<String> stringRules = blacklistStr;
if (moreStringRules != null && moreStringRules.size() > 0) {
- stringRules = new ArrayList();
+ stringRules = new ArrayList<String>();
stringRules.addAll(moreStringRules);
stringRules.addAll(blacklistStr);
}
@@ -340,9 +337,9 @@ public class Blacklist {
}
// test regex blacklisted
- List regexRules = blacklistRegex;
+ List<Pattern> regexRules = blacklistRegex;
if (moreRegexRules != null && moreRegexRules.size() > 0) {
- regexRules = new ArrayList();
+ regexRules = new ArrayList<Pattern>();
regexRules.addAll(moreRegexRules);
regexRules.addAll(blacklistRegex);
}
@@ -356,27 +353,19 @@ public class Blacklist {
* @param regexRules Regex rules to consider
*/
public static boolean matchesRulesOnly(
- String str, List stringRules, List regexRules) {
- if (testStringRules(str, stringRules)) {
- return true;
- }
- return testRegExRules(str, regexRules);
+ String str, List<String> stringRules, List<Pattern> regexRules) {
+ return testStringRules(str, stringRules) || testRegExRules(str, regexRules);
}
/** Test String against the RegularExpression rules. */
- private static boolean testRegExRules(String str, List regexRules) {
- boolean hit = false;
- Pattern testPattern = null;
- Iterator iter = regexRules.iterator();
- while (iter.hasNext()) {
- testPattern = (Pattern)iter.next();
-
+ private static boolean testRegExRules(String str, List<Pattern> regexRules) {
+ for (Pattern testPattern : regexRules) {
// want to see what it is matching on, but only in debug mode
if (mLogger.isDebugEnabled()) {
Matcher matcher = testPattern.matcher(str);
if (matcher.find()) {
- mLogger.debug(matcher.group()
- + " matched by " + testPattern.pattern());
+ mLogger.debug(matcher.group()
+ + " matched by " + testPattern.pattern());
return true;
}
} else {
@@ -385,7 +374,7 @@ public class Blacklist {
}
}
}
- return hit;
+ return false;
}
/**
@@ -444,7 +433,7 @@ public class Blacklist {
/** Utility method to populate lists based a blacklist in string form */
public static void populateSpamRules(
- String blacklist, List stringRules, List regexRules, String addendum) {
+ String blacklist, List<String> stringRules, List<Pattern> regexRules, String addendum) {
String weblogWords = blacklist;
weblogWords = (weblogWords == null) ? "" : weblogWords;
String siteWords = (addendum != null) ? addendum : "";
@@ -464,9 +453,8 @@ public class Blacklist {
/** Return pretty list of String and RegEx rules. */
public String toString() {
- StringBuilder buf = new StringBuilder("blacklist ");
- buf.append(blacklistStr).append("\n");
- buf.append("Regex blacklist ").append(blacklistRegex);
- return buf.toString();
+ String val = "blacklist " + blacklistStr;
+ val += "\nRegex blacklist " + blacklistRegex;
+ return val;
}
}