Author: michiel
Date: 2009-05-28 17:18:15 +0200 (Thu, 28 May 2009)
New Revision: 35480
Modified:
speeltuin/andre/mmsite/src/org/mmbase/mmsite/SiteUrlConverter.java
Log:
alowed usage of parameters on templates
Modified: speeltuin/andre/mmsite/src/org/mmbase/mmsite/SiteUrlConverter.java
===================================================================
--- speeltuin/andre/mmsite/src/org/mmbase/mmsite/SiteUrlConverter.java
2009-05-28 14:17:35 UTC (rev 35479)
+++ speeltuin/andre/mmsite/src/org/mmbase/mmsite/SiteUrlConverter.java
2009-05-28 15:18:15 UTC (rev 35480)
@@ -29,7 +29,7 @@
* <param name="useExtension">true</param><br />
* <param name="extension">.html</param><br />
* </urlconverter>
- *
+ *
* @author André van Toly
* @version $Id: SiteUrlConverter.java,v 1.5 2009-04-23 12:12:36 andre Exp $
* @since MMBase-1.9
@@ -37,7 +37,7 @@
public class SiteUrlConverter extends DirectoryUrlConverter {
private static final Logger log =
Logging.getLoggerInstance(SiteUrlConverter.class);
- protected static ArrayList<String> excludedPaths = new ArrayList();
+ protected static ArrayList<String> excludedPaths = new ArrayList();
protected static String extension = null;
protected static boolean useExtension = false;
@@ -51,39 +51,43 @@
String[] sa = l.split(",");
excludedPaths = new ArrayList(Arrays.asList(sa));
}
-
+
public void setUseExtension(boolean t) {
useExtension = t;
}
-
+
public void setExtension(String e) {
extension = e;
}
- @Override public int getDefaultWeight() {
+ @Override
+ public int getDefaultWeight() {
int q = super.getDefaultWeight();
return Math.max(q, q + 2000);
}
/**
- * Generates a nice url linking to a template for a ('pages') node.
+ * Generates a nice url linking to a template for a ('pages') node.
*/
- @Override protected void getNiceDirectoryUrl(StringBuilder b, Block block,
Parameters parameters, Parameters frameworkParameters, boolean action) throws
FrameworkException {
+ @Override
+ protected void getNiceDirectoryUrl(StringBuilder b, Block block,
Parameters parameters, Parameters frameworkParameters, boolean action) throws
FrameworkException {
if (log.isDebugEnabled()) {
log.debug("" + parameters + frameworkParameters);
log.debug("Found 'page' block: " + block);
}
int b_len = b.length();
-
+
if (block.getName().equals("page")) {
Node n = parameters.get(Framework.N);
parameters.set(Framework.N, null);
-
- String path = n.getStringValue("path");
- if (path.startsWith("/")) path = path.substring(1,
path.length());
- if (path.endsWith("/")) path = path.substring(0,
path.length() - 1);
- b.append(path);
-
+
+ String path = n.getStringValue("path");
+ if (path.startsWith("/")) {
+ path = path.substring(1, path.length());
+ }
+ if (path.endsWith("/")) path = path.substring(0, path.length() -
1);
+ b.append(path);
+
}
if (useExtension && b.length() > b_len) b.append(extension);
@@ -94,42 +98,46 @@
/**
* Translates the result of {...@link #getNiceUrl} back to an actual JSP
which can render the block
*/
- @Override public Url getFilteredInternalDirectoryUrl(List<String> pa,
Map<String, ?> params, Parameters frameworkParameters) throws
FrameworkException {
- StringBuilder result = new StringBuilder();
- Cloud cloud =
ContextProvider.getDefaultCloudContext().getCloud("mmbase");
- if (log.isDebugEnabled()) log.debug("path pieces: " + pa + ",
path size: " + pa.size());
+ @Override
+ public Url getFilteredInternalDirectoryUrl(List<String> pa, Map<String, ?>
params, Parameters frameworkParameters) throws FrameworkException {
+ StringBuilder result = new StringBuilder();
+ Cloud cloud =
ContextProvider.getDefaultCloudContext().getCloud("mmbase");
+ if (log.isDebugEnabled()) {
+ log.debug("path pieces: " + pa + ", path size: " + pa.size());
+ }
- if (excludedPaths.contains(pa.get(0))) {
- if (log.isDebugEnabled()) log.debug("Returning null,
path in excludepaths: " + pa.get(0));
- return Url.NOT;
- }
-
- StringBuilder sb = new StringBuilder();
- for (String piece: pa) {
- sb.append("/").append(piece);
- //if (log.isDebugEnabled()) log.debug("piece: " +
piece);
- }
- String path = sb.toString();
- //if (log.isDebugEnabled()) log.debug("path: " + path);
-
+ if (excludedPaths.contains(pa.get(0))) {
+ if (log.isDebugEnabled()) log.debug("Returning null, path in
excludepaths: " + pa.get(0));
+ return Url.NOT;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ for (String piece: pa) {
+ sb.append("/").append(piece);
+ //if (log.isDebugEnabled()) log.debug("piece: " + piece);
+ }
+ String path = sb.toString();
+ //if (log.isDebugEnabled()) log.debug("path: " + path);
+
if (useExtension && path.indexOf(extension) > -1) {
path = path.substring(0, path.lastIndexOf(extension));
//pa.set(pa.size() - 1, id);
}
-
+
Node node = UrlUtils.getPagebyPath(cloud, path);
if (node != null) {
String template =
node.getNodeValue("template").getStringValue("url");
if (!template.startsWith("/")) result.append("/");
- result.append(template).append("?n=" + node.getNumber());
-
+ char connector = template.indexOf("?") == -1 ? '?' : '&';
+ result.append(template).append(connector).append("n=" +
node.getNumber());
+
} else {
return Url.NOT;
}
-
+
if (log.isDebugEnabled()) log.debug("Returning: " + result.toString());
return new BasicUrl(this, result.toString());
-
+
}
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs