xlawrence 2005/06/27 17:55:30 CEST
Modified files:
core/src/java/org/jahia/data/fields JahiaBigTextField.java
core/src/java/org/jahia/engines/shared BigText_Field.java
Log:
Added management and rewriting of hardcoded link containing URLKeys
Revision Changes Path
1.14 +21 -9
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.13&r2=1.14&f=h
1.14 +3 -2
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.13&r2=1.14&f=h
Index: JahiaBigTextField.java
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/java/org/jahia/data/fields/JahiaBigTextField.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- JahiaBigTextField.java 25 Jun 2005 08:51:26 -0000 1.13
+++ JahiaBigTextField.java 27 Jun 2005 15:55:29 -0000 1.14
@@ -377,7 +377,12 @@
return "";
}
+ if (content.indexOf(URL_MARKER) < 0) { // nothing to rewrite...
+ return content;
+ }
+
final StringBuffer buff = new StringBuffer();
+
buff.append(jParams.getRequest().getContextPath()).
append(SERVLET_PATH);
@@ -399,6 +404,7 @@
result = StringUtils.replace(result, buff.toString(), "");
buff.delete(0, buff.length());
}
+ logger.debug("rewritten: "+result);
return result;
}
@@ -478,8 +484,9 @@
}
// Check if the URL is a Jahia URL...
+ int pid = -1;
if ( !(link.indexOf("pid") > -1 || hasOnlyDigits(link) ||
- getPidFromUrlKey(link, contextAndServletPath) > 0) )
{
+ (pid = getPidFromUrlKey(link,
contextAndServletPath)) > 0) ) {
logger.debug("Not a Jahia Link: "+ link);
rawResult.append(token);
displayResult.append(token);
@@ -488,6 +495,11 @@
continue;
}
+ if (pid > 0) {
+ link = buff.append("/pid/").append(pid).toString();
+ buff.delete(0, buff.length());
+ }
+
logger.debug("\n\nFound a Jahia HardCoded link: " + token);
if (link.indexOf(req.getServerName()) > -1) {
@@ -507,7 +519,7 @@
}
// Get rid of the context and servlet path
- if (link.startsWith(contextAndServletPath)) {
+ if (link.indexOf(contextAndServletPath) > -1) {
link = StringUtils.replaceOnce(link,
contextAndServletPath, "");
}
@@ -583,6 +595,7 @@
result[0] = rawResult.toString();
result[1] = displayResult.toString();
+ logger.debug("displayResult: "+result[1]);
return result;
}
@@ -592,24 +605,20 @@
*
* @return The pid value or -1 if not found or something went wrong
*/
- protected int getPidFromUrlKey(final String link, final String context)
{
+ protected int getPidFromUrlKey(String link, final String context) {
+ logger.debug("getPidFromUrlKey: " + link);
if (link == null || link.length() == 0 ||
link.indexOf(context) < 0) { return -1; }
- String urlKey = link;
-
- urlKey = urlKey.substring(urlKey.lastIndexOf('/') + 1);
- logger.debug("getPidFromUrlKey: " + urlKey);
+ final String urlKey = link.substring(link.lastIndexOf('/') + 1);
try {
final List pageProperties = ServicesRegistry.getInstance().
getJahiaPageService().getPagePropertiesByValue(urlKey);
logger.debug("pageProperties.size(): "+pageProperties.size());
if (pageProperties.size() == 1) {
- logger.debug("1");
final PageProperty pageProperty = (PageProperty)
pageProperties.get(0);
if
(pageProperty.getName().equals(PageProperty.PAGE_URL_KEY_PROPNAME)) {
- logger.debug("2");
return pageProperty.getPageID();
}
}
@@ -633,6 +642,9 @@
return true;
}
+ /**
+ *
+ */
protected String getPID(final String s) {
final String value = s.substring(s.lastIndexOf('/') + 1);
Index: BigText_Field.java
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/java/org/jahia/engines/shared/BigText_Field.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- BigText_Field.java 25 Jun 2005 08:51:27 -0000 1.13
+++ BigText_Field.java 27 Jun 2005 15:55:30 -0000 1.14
@@ -48,7 +48,6 @@
import org.jahia.utils.JahiaTools;
import org.jahia.services.htmlparser.ExtractLinksDOMVisitor;
import org.jahia.urls.ContentServletURL;
-import java.net.MalformedURLException;
import org.jahia.services.pages.ContentPage;
import org.jahia.content.ContentFieldKey;
import org.jahia.content.ObjectLink;
@@ -63,6 +62,8 @@
import org.jahia.services.workflow.WorkflowService;
+import java.net.MalformedURLException;
+
/**
* Sub-Engine for managing BigText Fields
*
@@ -545,7 +546,7 @@
groupID = groupID.split(":")[0];
// only add the group name once
- if (!result.contains(groupID)) {
+ if (! result.contains(groupID)) {
result.addElement(groupID);
logger.debug("Adding group "+groupID+ " to result");
}