[Yanel-dev] back2realm, back2context
simon litwan
simon.litwan at wyona.com
Fri Feb 9 10:11:16 CET 2007
Josias Thöny schrieb:
> simon litwan wrote:
>> hi all
>>
>> at the moment every resource implements back2realm and back2context
>> for it self.
>> i think it would be cool if this would be centralized.
>>
>> couldn't we add this methodes to the PathUtil?
>
> +1
> This makes a lot of sense, thanks for bringing this up.
would this make sense?
i'm not sure about importing rhe realm and overgive a realm to the
methode backToContext.
can you give me a feedback?
package org.wyona.commons.io;
import org.apache.log4j.Category;
import org.wyona.yanel.core.map.Realm;
/**
*
*/
public class PathUtil {
private static Category log = Category.getInstance(PathUtil.class);
/**
*
*/
public static String getName(String path) {
// Quick and dirty
return new java.io.File(path).getName();
}
/**
*
*/
public static String getParent(String path) {
// Quick and dirty
String parent = new java.io.File(path).getParent();
return parent;
}
/**
* Return null if no suffix exists
*/
public static String getSuffix(String path) {
int lio = path.lastIndexOf(".");
log.debug(new Integer(lio));
if (lio < 0) return null;
return path.substring(lio + 1);
}
/**
* @return a String with as many ../ as it needs to go back to from
current realm to context
*/
public static String backToContext(Realm realm) {
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
*/
public static String backToRoot(String path) {
String backToRoot = "";
int steps;
if (path.endsWith("/") && !path.equals("/")) {
steps = path.split("/").length - 1;
} else {
steps = path.split("/").length - 2;
}
for (int i = 0; i < steps; i++) {
backToRoot = backToRoot + "../";
}
return backToRoot;
}
}
simon
>
> josias
>
>>
>> WDOT?
>>
>> simon
>>
>>
>
>
> _______________________________________________
> Yanel-development mailing list
> Yanel-development at wyona.com
> http://wyona.com/cgi-bin/mailman/listinfo/yanel-development
>
--
Simon Litwan simon.litwan at wyona.com
Wyona Inc. - Open Source Content Management - Apache Lenya
http://www.wyona.com http://lenya.apache.org
More information about the Yanel-development
mailing list