xlawrence 2005/10/31 17:44:57 CET
Modified files:
core/src/java/org/jahia/data/fields JahiaBigTextField.java
core/src/java/org/jahia/engines/shared BigText_Field.java
Log:
Avoid NPE when indexing the field
Revision Changes Path
1.26 +16 -27
jahia/core/src/java/org/jahia/data/fields/JahiaBigTextField.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/data/fields/JahiaBigTextField.java.diff?r1=1.25&r2=1.26&f=h
1.32 +35 -41
jahia/core/src/java/org/jahia/engines/shared/BigText_Field.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/engines/shared/BigText_Field.java.diff?r1=1.31&r2=1.32&f=h
Index: JahiaBigTextField.java
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/java/org/jahia/data/fields/JahiaBigTextField.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- JahiaBigTextField.java 24 Oct 2005 12:42:20 -0000 1.25
+++ JahiaBigTextField.java 31 Oct 2005 16:44:56 -0000 1.26
@@ -3,32 +3,23 @@
package org.jahia.data.fields;
-import java.util.Properties;
-
+import org.apache.commons.lang.StringUtils;
import org.apache.regexp.RE;
import org.apache.regexp.RESyntaxException;
import org.jahia.data.FormDataManager;
+import org.jahia.data.webapps.Web_App_Xml;
import org.jahia.exceptions.JahiaException;
import org.jahia.params.ProcessingContext;
import org.jahia.registries.ServicesRegistry;
import org.jahia.services.fields.ContentBigTextField;
-import org.jahia.services.files.JahiaTextFileService;
+import org.jahia.services.pages.ContentPage;
+import org.jahia.services.pages.PageProperty;
import org.jahia.services.version.ContentObjectEntryState;
import org.jahia.services.version.EntryLoadRequest;
import org.jahia.services.version.EntrySaveRequest;
-import org.jahia.services.pages.PageProperty;
-import org.jahia.data.webapps.Web_App_Xml;
import org.jahia.utils.JahiaTools;
-import org.apache.commons.lang.StringUtils;
-import java.util.List;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import org.jahia.services.pages.ContentPage;
+import java.util.*;
public class JahiaBigTextField extends JahiaField implements
JahiaAllowApplyChangeToAllLangField {
@@ -75,7 +66,7 @@
final ContentBigTextField contentBigTextField = (ContentBigTextField)
ContentBigTextField.getField(getID());
- String val = null;
+ String val;
if (this.getWorkflowState() >
ContentObjectEntryState.WORKFLOW_STATE_ACTIVE
@@ -245,20 +236,12 @@
new Integer(aclID),
new Integer(versionID),
new Integer(workflowState),
- new String(getLanguageCode()));
+ getLanguageCode());
bt.setObject(objItem);
return bt;
}
/**
- * Method getTextFileService
- * @return a JahiaTextFileService instance
- */
- private JahiaTextFileService getTextFileService() {
- return ServicesRegistry.getInstance().getJahiaTextFileService();
- }
-
- /**
* Is this kind of field shared (i.e. not one version for each language,
* but one version for every language)
*/
@@ -303,7 +286,10 @@
* @return a String with valid and usable URLs.
*/
public static String rewriteURLs(String content, final ProcessingContext
jParams) {
- logger.debug("rewriteURLs...");
+
+ if (jParams.getContextPath() == null) return content;
+
+ logger.debug("rewriteURLs... " + content);
try {
if (content == null || content.length() == 0) {
@@ -319,6 +305,8 @@
final String path = buff.append(jParams.getContextPath()).
append(SERVLET_PATH).toString();
buff.delete(0, buff.length());
+
+ logger.debug("path: " + path);
final String mode = jParams.getOperationMode();
@@ -452,7 +440,7 @@
if (token.toLowerCase().startsWith("href") ) {
// To know if we have to close the '<a' tag...
- final boolean close = (token.indexOf('>') > -1) ? true :
false;
+ final boolean close = (token.indexOf('>') > -1);
String link, rest = null;
if (close) { // get rid of the href=" sequence (first 6
chars)
@@ -600,6 +588,7 @@
result[0] = rawResult.toString();
result[1] = displayResult.toString();
+ logger.debug("rawResult: "+result[0]);
logger.debug("displayResult: "+result[1]);
return result;
}
@@ -615,7 +604,7 @@
if (link == null || link.length() == 0 ||
link.indexOf(context) < 0) { return -1; }
- final String urlKey = new
String(link.substring(link.lastIndexOf('/') + 1));
+ final String urlKey = link.substring(link.lastIndexOf('/') + 1);
logger.debug("urlKey: "+urlKey);
try {
Index: BigText_Field.java
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/java/org/jahia/engines/shared/BigText_Field.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- BigText_Field.java 17 Oct 2005 15:13:56 -0000 1.31
+++ BigText_Field.java 31 Oct 2005 16:44:56 -0000 1.32
@@ -38,18 +38,16 @@
import org.jahia.params.ProcessingContext;
import org.jahia.registries.ServicesRegistry;
import org.jahia.services.acl.JahiaBaseACL;
-import org.jahia.services.htmlparser.ExtractLinksDOMVisitor;
import org.jahia.services.htmlparser.JahiaTextContentTidy;
import org.jahia.services.htmlparser.WAIValidator;
import org.jahia.services.pages.ContentPage;
import org.jahia.services.sites.JahiaSite;
import org.jahia.services.sites.SiteLanguageSettings;
import org.jahia.services.version.EntryLoadRequest;
-import org.jahia.urls.ContentServletURL;
import org.jahia.utils.I18n;
import org.jahia.utils.JahiaTools;
+import org.apache.commons.lang.StringUtils;
-import java.net.MalformedURLException;
import java.util.*;
/**
@@ -141,18 +139,14 @@
if (theScreen.equals("cancel")) {
return true;
}
-
- if (jParams.getParameter("ignoreAllWarnings") == null) {
- ignoreAllWarnings = false;
- } else {
- ignoreAllWarnings = true;
- }
+
+ ignoreAllWarnings = jParams.getParameter("ignoreAllWarnings") !=
null;
logger.debug("ignoreAllWarnings: "+ ignoreAllWarnings);
- ((ParamBean)jParams).getRequest().setAttribute("ignoreAllWarnings",
- new Boolean(ignoreAllWarnings));
+ ((ParamBean)jParams).getRequest().setAttribute("ignoreAllWarnings",
+ Boolean.valueOf(ignoreAllWarnings));
boolean out = true;
- String fieldValue = (String)jParams.getParameter(
+ String fieldValue = jParams.getParameter(
buff.append("_").append(theField.getID()).toString());
buff.delete(0, buff.length());
@@ -209,10 +203,13 @@
fieldValue = JahiaTools.replacePatternIgnoreCase(fieldValue, "<br>",
"<br/>");
logger.debug("fieldValue: " + fieldValue);
- final String values[] = ((JahiaBigTextField)theField).
- cleanUpHardCodedLinks(fieldValue, jParams,
- jParams.getLocale().toString());
-
+ fieldValue = StringUtils.replace(fieldValue,
jParams.getContextPath(), "");
+ fieldValue = StringUtils.replace(fieldValue,
jParams.getServletPath(), "");
+
+ final String values[] = ((JahiaBigTextField) theField).
+ cleanUpHardCodedLinks(fieldValue,
+ jParams, jParams.getLocale().toString());
+
theField.setRawValue(values[0]);
theField.setValue(values[1]);
theField.setObject(null);
@@ -269,18 +266,18 @@
</HEAD>
</HTML>
*
- * We ojly want to keep: <html>...</html>
+ * We only want to keep: <html>...</html>
*/
- protected String cleanEditorShit(final String fieldValue) {
- final String upper = fieldValue.toUpperCase();
- if (upper.indexOf("<HTML>") < upper.lastIndexOf("<HTML>")) {
- // The editor did it again...
- final int start = upper.lastIndexOf("<HTML>");
- final int end = upper.indexOf("</HTML>") + 7;
- return fieldValue.substring(start, end);
- }
- return fieldValue;
- }
+// protected String cleanEditorShit(final String fieldValue) {
+// final String upper = fieldValue.toUpperCase();
+// if (upper.indexOf("<HTML>") < upper.lastIndexOf("<HTML>")) {
+// // The editor did it again...
+// final int start = upper.lastIndexOf("<HTML>");
+// final int end = upper.indexOf("</HTML>") + 7;
+// return fieldValue.substring(start, end);
+// }
+// return fieldValue;
+// }
/**
*
@@ -302,9 +299,7 @@
return result;
}
- /**
- *
- */
+ /*
private void findAndStoreCrossLinks(ExtractLinksDOMVisitor
linkExtractionVisitor, ProcessingContext processingContext, Map
engineMap) {
final Set pageXRefs = new HashSet();
@@ -400,6 +395,8 @@
}
engineMap.put("pageXRefs", pageXRefs);
}
+
+ */
/**
* saves data in datasource
@@ -434,7 +431,7 @@
while (pageXRefIter.hasNext()) {
final Integer curPageIDInt = (Integer) pageXRefIter.next();
logger.debug("Found reference to page " + curPageIDInt + "
in this bigtext");
- final ObjectLink newLink = ObjectLink.createLink(fieldKey,
+ ObjectLink.createLink(fieldKey,
new ContentPageKey(curPageIDInt.intValue()),
"hardcodedLink", 1,
new Date(),
"root:0", new Date(), "root:0", new HashMap(),
@@ -484,7 +481,7 @@
}
}
- String output = "";
+ String output;
String forward = theField.getDefinition()
.getProperty(JahiaFieldDefinitionProperties.FIELD_UPDATE_JSP_FILE_PROP);
if ( forward == null ){
@@ -497,7 +494,7 @@
initHtmlEditorsHelpers(engineMap, jParams);
((ParamBean)jParams).getRequest().setAttribute("ignoreAllWarnings",
- new Boolean(ignoreAllWarnings));
+ Boolean.valueOf(ignoreAllWarnings));
if ( editable ){
final JahiaSite site = ServicesRegistry.getInstance().
@@ -592,7 +589,7 @@
logger.debug("Comparing ACLs of field "+field.getID()+ " and page "+
pageID);
final ContentPage page = ContentPage.getPage(pageID);
- final JahiaBaseACL aclObject = getFieldACLObject(field, jParams,
engineMap);
+ final JahiaBaseACL aclObject = getFieldACLObject(field, engineMap);
// Define an ACLEntry for "Read" Rights
final JahiaAclEntry aclEntry = new JahiaAclEntry();
@@ -666,8 +663,7 @@
/**
* Returns the ContentObject of the given field or its closest parent.
*/
- private JahiaBaseACL getFieldACLObject(JahiaField field,
ProcessingContext jParams,
- Map engineMap) throws JahiaException {
+ private JahiaBaseACL getFieldACLObject(JahiaField field, Map engineMap)
throws JahiaException {
if (field.getID() <= 0) { // this means the field has not yet been
saved
// fetch the parent container ACL entry instead...
final JahiaContainer container =
(JahiaContainer)engineMap.get("theContainer");
@@ -735,6 +731,8 @@
if (state == null) { return "staging"; }
if (page.isMarkedForDelete()) { return "markForDeleted"; }
+
+ if (page.getActiveVersionID() > 0) { return "staging_OK"; }
switch (state.intValue()) {
case EntryLoadRequest.ACTIVE_WORKFLOW_STATE:
@@ -840,7 +838,7 @@
state = getPageState(pid, lang);
- if ("active".equals(state)) { continue; }
+ if ("active".equals(state) ||
"staging_OK".equals(state)) { continue; }
if ("staging".equals(state)) {
if (page.getActiveVersionID() <= 0) {
final EngineMessage msg = new EngineMessage(
@@ -848,8 +846,6 @@
Integer.toString(pid));
result.add("BigText.staging", msg);
- } else {
- continue;
}
} else if ("markForDeleted".equals(state)) {
@@ -866,8 +862,6 @@
values);
result.add("BigText.waiting", msg);
- } else {
- continue;
}
} else {