xlawrence 2005/06/15 14:27:50 CEST
Modified files:
core/src/java/org/jahia/data/fields JahiaBigTextField.java
Log:
Improved and optimized method for cleaning the Internal links before storing
them
Revision Changes Path
1.9 +45 -31
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.8&r2=1.9&f=h
Index: JahiaBigTextField.java
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/java/org/jahia/data/fields/JahiaBigTextField.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JahiaBigTextField.java 14 Jun 2005 16:33:53 -0000 1.8
+++ JahiaBigTextField.java 15 Jun 2005 12:27:50 -0000 1.9
@@ -63,7 +63,7 @@
String servletName = (String)mappings.get(urlPattern);
if (servletName.equals("Jahia") && urlPattern.indexOf("do")
< 0) {
- SERVLET_PATH = urlPattern.substring(0,
+ SERVLET_PATH = urlPattern.substring(0,
urlPattern.lastIndexOf('/'));
return;
}
@@ -109,7 +109,7 @@
logger.debug("Loading big text field...");
setServletPath(jParams);
ContentBigTextField contentBigTextField = (ContentBigTextField)
- ContentBigTextField.getField(getID());
+ ContentBigTextField.getField(getID());
String val = null;
@@ -206,7 +206,7 @@
public boolean save(ParamBean jParams) throws JahiaException {
logger.debug("Save Big Text..."+ getValue());
ContentBigTextField contentBigTextField = (ContentBigTextField)
- ContentBigTextField.getField(getID());
+ ContentBigTextField.getField(getID());
EntrySaveRequest saveRequest = new
EntrySaveRequest(jParams.getUser(),
this.getLanguageCode());
if (contentBigTextField.hasActiveEntries() && getValue() != null &&
@@ -214,7 +214,7 @@
return true;
}
- String[] values = cleanUpHardCodedLinks(getValue(),
jParams.getRequest());
+ String[] values = cleanUpHardCodedLinks(getValue(),
jParams.getRequest());
setRawValue(values[0]);
setValue(values[1]);
@@ -354,7 +354,7 @@
}
/**
- * Is this kind of field shared (i.e. not one version for each language,
+ * Is this kind of field shared (i.e. not one version for each language,
* but one version for every language)
*/
public boolean isShared() {
@@ -375,7 +375,7 @@
aField.setValue(this.getValue());
aField.setRawValue(this.getRawValue());
aField.setObject(this.getObject());
- }
+ }
/**
* Replaces the URL marker in all the internal Jahia links and generates
@@ -405,7 +405,7 @@
return result;
}
- /**
+ /**
* @return an Array of String. Position[0] contains the RawValue and
position[1] the
* value that should be used when displaying the data
*/
@@ -423,7 +423,6 @@
StringBuffer displayResult = new StringBuffer();
final String delimiter = " ";
- content = StringUtils.replace(content, ">", "> ");
StringTokenizer tokenizer = new StringTokenizer(content, delimiter);
while (tokenizer.hasMoreTokens()) { // go through each token
@@ -434,17 +433,23 @@
// To know if we have to close the '<a' tag...
final boolean close = (token.indexOf('>') > -1) ? true :
false;
- String link;
+
+ String link, rest = null;
if (close) { // get rid of the href=" sequence (first 6
chars)
- link = token.substring(6, token.indexOf('>')-1);
+ link = token.substring(6, token.indexOf('>') - 1);
+ if ( (token.indexOf('>') + 1) < token.length()) {
+ rest = token.substring(token.indexOf('>') + 1);
+ }
} else {
- link = token.substring(6, token.length()-1);
+ link = token.substring(6, token.length() - 1);
}
// Check if the URL is a Jahia URL
if ( !(link.indexOf("pid") > -1 || hasOnlyDigits(link)) ) {
rawResult.append(token);
displayResult.append(token);
+ rawResult.append(delimiter);
+ displayResult.append(delimiter);
continue;
}
@@ -460,6 +465,12 @@
logger.debug("Link is (no host): "+link);
}
+ // All Jahia links are this stage are treated as relative
URLs
+ if (! link.startsWith("/") && ! link.startsWith("http") ) {
+ link = buff.append("/").append(link).toString();
+ buff.delete(0, buff.length());
+ }
+
// Get rid of the context and servlet path (i.e.
/jahia/Jahia)
final String contextAndServletPath =
buff.append(req.getContextPath())
.append(req.getServletPath()).toString();
@@ -494,41 +505,44 @@
link = link.substring(0, link.indexOf(";jsessionid"));
}
- if (link.startsWith("/site/")) { // get rid of the site
+ // Get rid of the site
+ if (link.indexOf("site/") > -1) {
link = link.substring(6);
link = link.substring(link.indexOf('/'));
}
- // Build RawResult
+ /** Build the 2 results **/
rawResult.append("href=\"");
- if (link.toLowerCase().indexOf("http") < 0 &&
- link.indexOf(URL_MARKER) < 0) {
- rawResult.append(URL_MARKER);
- }
-
- if (link.indexOf("/pid/") < 0 ) {
- rawResult.append("/pid/");
- }
-
- rawResult.append(link);
- rawResult.append("\"");
- if (close) rawResult.append(">");
-
- // Build Display Result
displayResult.append("href=\"");
+
if (link.toLowerCase().indexOf("http") < 0) {
displayResult.append(contextAndServletPath);
+ if (link.indexOf(URL_MARKER) < 0) {
+ rawResult.append(URL_MARKER);
+ }
}
- if (link.indexOf("/pid/") < 0 ) {
- displayResult.append("/pid/");
+ // All links should have a pid
+ if (link.indexOf("pid/") < 0) {
+ rawResult.append("/pid");
+ displayResult.append("/pid");
}
displayResult.append(link);
displayResult.append("\"");
- if (close) displayResult.append(">");
+ rawResult.append(link);
+ rawResult.append("\"");
+
+ if (close) {
+ rawResult.append(">");
+ displayResult.append(">");
+ if (rest != null && rest.length() > 0) {
+ rawResult.append(rest);
+ displayResult.append(rest);
+ }
+ }
- } else {
+ } else { // This token does not start with "href", simply append
it
rawResult.append(token);
displayResult.append(token);
}