[Yanel-dev] back2realm, back2context
Josias Thöny
josias.thoeny at wyona.com
Fri Feb 9 15:18:36 CET 2007
simon litwan wrote:
> 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?
The code looks good.
Perhaps we could add an additional method:
public static String backToContext(Realm realm, String path) {
return backToContext(realm) + backToRealm(path);
}
because in most cases we probably need to do both at the same time. WDYT?
BTW, if you have time you could write a junit test (PathUtilTest.java)
to test those methods (with tests for special cases, e.g. empty path etc).
thanks,
josias
>
> 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
>>
>
>
More information about the Yanel-development
mailing list