[Yanel-commits] rev 22532 - in public/yanel/trunk/src/resources:
directory/src/java/org/wyona/yanel/impl/resources
testing-control/src/java/org/wyona/yanel/impl/resources
testing-times/src/java/org/wyona/yanel/impl/resources
xml/src/java/org/wyona/yanel/impl/resources
michi at wyona.com
michi at wyona.com
Thu Feb 8 12:36:04 CET 2007
Author: michi
Date: 2007-02-08 12:36:03 +0100 (Thu, 08 Feb 2007)
New Revision: 22532
Modified:
public/yanel/trunk/src/resources/directory/src/java/org/wyona/yanel/impl/resources/DirectoryResource.java
public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java
public/yanel/trunk/src/resources/testing-times/src/java/org/wyona/yanel/impl/resources/TestingTimes.java
public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
Log:
back to context fixed and back to realm improved
Modified: public/yanel/trunk/src/resources/directory/src/java/org/wyona/yanel/impl/resources/DirectoryResource.java
===================================================================
--- public/yanel/trunk/src/resources/directory/src/java/org/wyona/yanel/impl/resources/DirectoryResource.java 2007-02-08 11:35:25 UTC (rev 22531)
+++ public/yanel/trunk/src/resources/directory/src/java/org/wyona/yanel/impl/resources/DirectoryResource.java 2007-02-08 11:36:03 UTC (rev 22532)
@@ -128,16 +128,6 @@
}
try {
- String assetPath = "";
- if (getPath().endsWith("/") && !isRoot(getPath())) {
- assetPath = "../";
- }
-
- String parentPath = "./";
- if (p.toString().endsWith("/")) {
- parentPath = "../";
- }
-
TransformerFactory tfactory = TransformerFactory.newInstance();
String[] xsltTransformers = getXSLTprop();
@@ -148,9 +138,9 @@
transformerIntern.setParameter("yanel.path.name", PathUtil.getName(getPath()));
transformerIntern.setParameter("yanel.path", getPath().toString());
- transformerIntern.setParameter("yanel.back2context", backToRoot(getPath(), assetPath));
- transformerIntern.setParameter("yarep.back2realm", backToRoot(getPath(), assetPath));
- transformerIntern.setParameter("yarep.parent", parentPath);
+ transformerIntern.setParameter("yanel.back2context", backToContext()+backToRoot());
+ transformerIntern.setParameter("yarep.back2realm", backToRoot());
+ transformerIntern.setParameter("yarep.parent", getParent(p.toString()));
transformerIntern.transform(orig, new StreamResult(baos));
if (xsltTransformers != null) {
@@ -161,9 +151,9 @@
Transformer transformer = tfactory.newTransformer(new StreamSource(contentRepo.getInputStream(new org.wyona.yarep.core.Path(new Path(xsltTransformers[i]).toString()))));
transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
transformer.setParameter("yanel.path", getPath().toString());
- transformer.setParameter("yanel.back2context", backToRoot(getPath(), assetPath));
- transformer.setParameter("yarep.back2realm", backToRoot(getPath(), assetPath));
- transformer.setParameter("yarep.parent", parentPath);
+ transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
+ transformer.setParameter("yarep.back2realm", backToRoot());
+ transformer.setParameter("yarep.parent", getParent(p.toString()));
transformer.transform(orig, new StreamResult(baos));
}
}
@@ -226,23 +216,45 @@
return "application/xhtml+xml";
}
+ /**
+ * @return a String with as many ../ as it needs to go back to from current realm to context
+ */
+ private String backToContext() {
+ String backToContext = "";
+ int steps = realm.getMountPoint().split("/").length - 1;
+ for (int i = 0; i < steps; i++) {
+ backToContext = backToContext + "../";
+ }
+ return backToContext;
+ }
/**
- *
- */
- private String backToRoot(String path, String backToRoot) {
- String parent = PathUtil.getParent(path);
- if (parent != null && !isRoot(parent)) {
- return backToRoot(parent, backToRoot + "../");
- }
- return backToRoot;
- }
-
- /**
- *
- */
- private boolean isRoot(String path) {
- if (path.equals(File.separator)) return true;
- return false;
- }
+ * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
+ */
+ private String backToRoot() {
+ String backToRoot = "";
+ int steps;
+
+ if (getPath().endsWith("/") && !getPath().equals("/")) {
+ steps = getPath().split("/").length - 1;
+ } else {
+ steps = getPath().split("/").length - 2;
+ }
+
+ for (int i = 0; i < steps; i++) {
+ backToRoot = backToRoot + "../";
+ }
+ return backToRoot;
+ }
+
+ /**
+ * @return a String ../ if path ends with a trailing slash. Otherwise a String ./
+ */
+ private String getParent(String path) {
+ String parentPath = "./";
+ if (path.endsWith("/")) {
+ parentPath = "../";
+ }
+ return parentPath;
+ }
}
Modified: public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java
===================================================================
--- public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java 2007-02-08 11:35:25 UTC (rev 22531)
+++ public/yanel/trunk/src/resources/testing-control/src/java/org/wyona/yanel/impl/resources/TestingControlResource.java 2007-02-08 11:36:03 UTC (rev 22532)
@@ -53,6 +53,7 @@
import org.wyona.yarep.core.NoSuchNodeException;
import org.wyona.yarep.core.Repository;
import org.wyona.yarep.core.RepositoryFactory;
+import org.wyona.yanel.core.util.PathUtil;
import org.wyona.yarep.util.RepoPath;
import org.wyona.yarep.util.YarepUtil;
@@ -384,9 +385,8 @@
.newTransformer(new StreamSource(repo.getInputStream(getXSLTPath(path))));
transformer.setParameter("yanel.path.name", path.getName());
transformer.setParameter("yanel.path", path.toString());
- transformer.setParameter("yanel.back2context", backToRoot(path, ""));
- transformer.setParameter("yarep.back2realm",
- backToRoot(new org.wyona.yanel.core.Path(rp.getPath().toString()), ""));
+ transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
+ transformer.setParameter("yarep.back2realm", backToRoot());
return transformer;
} else {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
@@ -413,20 +413,37 @@
return yanel.getRepositoryFactory("RTIRepositoryFactory");
}
- private String backToRoot(Path path, String backToRoot) {
- org.wyona.commons.io.Path parent = path.getParent();
- if (parent != null && !isRoot(parent)) {
- return backToRoot(new Path(parent.toString()), backToRoot + "../");
+ /**
+ * @return a String with as many ../ as it needs to go back to from current realm to context
+ */
+ private String backToContext() {
+ String backToContext = "";
+ int steps = realm.getMountPoint().split("/").length - 1;
+
+ for (int i = 0; i < steps; i++) {
+ backToContext = backToContext + "../";
}
+ return backToContext;
+ }
+
+ /**
+ * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
+ */
+ private String backToRoot() {
+ String backToRoot = "";
+ int steps;
+
+ if (getPath().endsWith("/") && !getPath().equals("/")) {
+ steps = getPath().split("/").length - 1;
+ } else {
+ steps = getPath().split("/").length - 2;
+ }
+ for (int i = 0; i < steps; i++) {
+ backToRoot = backToRoot + "../";
+ }
return backToRoot;
}
- private boolean isRoot(org.wyona.commons.io.Path path) {
- if (path.toString().equals(File.separator))
- return true;
- return false;
- }
-
/**
* get Tests.
* @param htmlOrJunit type of tests should be selected. can be htmlunit or junit.
Modified: public/yanel/trunk/src/resources/testing-times/src/java/org/wyona/yanel/impl/resources/TestingTimes.java
===================================================================
--- public/yanel/trunk/src/resources/testing-times/src/java/org/wyona/yanel/impl/resources/TestingTimes.java 2007-02-08 11:35:25 UTC (rev 22531)
+++ public/yanel/trunk/src/resources/testing-times/src/java/org/wyona/yanel/impl/resources/TestingTimes.java 2007-02-08 11:36:03 UTC (rev 22532)
@@ -18,6 +18,8 @@
import org.wyona.yanel.core.api.attributes.ViewableV1;
import org.wyona.yanel.core.attributes.viewable.View;
import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
+import org.wyona.yanel.core.util.PathUtil;
+
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -401,9 +403,8 @@
.newTransformer(new StreamSource(repo.getInputStream(getXSLTPath())));
transformer.setParameter("yanel.path.name", path.getName());
transformer.setParameter("yanel.path", path.toString());
- transformer.setParameter("yanel.back2context", backToRoot(path, ""));
- transformer.setParameter("yarep.back2realm",
- backToRoot(new org.wyona.yanel.core.Path(rp.getPath().toString()), ""));
+ transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
+ transformer.setParameter("yarep.back2realm", backToRoot());
return transformer;
} else {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
@@ -422,18 +423,35 @@
return null;
}
- private String backToRoot(Path path, String backToRoot) {
- org.wyona.commons.io.Path parent = path.getParent();
- if (parent != null && !isRoot(parent)) {
- return backToRoot(new Path(parent.toString()), backToRoot + "../");
+ /**
+ * @return a String with as many ../ as it needs to go back to from current realm to context
+ */
+ private String backToContext() {
+ String backToContext = "";
+ int steps = realm.getMountPoint().split("/").length - 1;
+
+ for (int i = 0; i < steps; i++) {
+ backToContext = backToContext + "../";
}
+ return backToContext;
+ }
+
+ /**
+ * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
+ */
+ private String backToRoot() {
+ String backToRoot = "";
+ int steps;
+
+ if (getPath().endsWith("/") && !getPath().equals("/")) {
+ steps = getPath().split("/").length - 1;
+ } else {
+ steps = getPath().split("/").length - 2;
+ }
+ for (int i = 0; i < steps; i++) {
+ backToRoot = backToRoot + "../";
+ }
return backToRoot;
- }
-
- private boolean isRoot(org.wyona.commons.io.Path path) {
- if (path.toString().equals(File.separator))
- return true;
- return false;
}
private RepoPath contentRepo() throws Exception {
Modified: public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
===================================================================
--- public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java 2007-02-08 11:35:25 UTC (rev 22531)
+++ public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java 2007-02-08 11:36:03 UTC (rev 22532)
@@ -110,9 +110,8 @@
Transformer transformer = tf.newTransformer(new StreamSource(repo.getNode(xsltPath).getInputStream()));
transformer.setParameter("yanel.path.name", PathUtil.getName(getPath()));
transformer.setParameter("yanel.path", getPath());
- //TODO: There seems to be a bug re back2context ...
- transformer.setParameter("yanel.back2context", backToRoot(getPath(), ""));
- transformer.setParameter("yarep.back2realm", backToRoot(getPath(), ""));
+ transformer.setParameter("yanel.back2context", backToContext()+backToRoot());
+ transformer.setParameter("yarep.back2realm", backToRoot());
String userAgent = getRequest().getHeader("User-Agent");
String os = getOS(userAgent);
if (os != null) transformer.setParameter("os", os);
@@ -286,22 +285,34 @@
}
/**
- *
+ * @return a String with as many ../ as it needs to go back to from current realm to context
*/
- private String backToRoot(String path, String backToRoot) {
- String parent = PathUtil.getParent(path);
- if (parent != null && !isRoot(parent)) {
- return backToRoot(parent, backToRoot + "../");
+ private String backToContext() {
+ String backToContext = "";
+ int steps = realm.getMountPoint().split("/").length - 1;
+
+ for (int i = 0; i < steps; i++) {
+ backToContext = backToContext + "../";
}
- return backToRoot;
+ return backToContext;
}
-
+
/**
- *
+ * @return a String with as many ../ as it needs to go back to from current resource to the realm-root
*/
- private boolean isRoot(String path) {
- if (path.equals(File.separator)) return true;
- return false;
+ private String backToRoot() {
+ String backToRoot = "";
+ int steps;
+
+ if (getPath().endsWith("/") && !getPath().equals("/")) {
+ steps = getPath().split("/").length - 1;
+ } else {
+ steps = getPath().split("/").length - 2;
+ }
+ for (int i = 0; i < steps; i++) {
+ backToRoot = backToRoot + "../";
+ }
+ return backToRoot;
}
/**
More information about the Yanel-commits
mailing list