You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Robert Munteanu <ro...@apache.org> on 2016/01/25 16:38:55 UTC

Utility to construct paths out of strings?

Hi,

Do we have a utility class somewhere that constructs paths out of
strings? I just rolled my own ( not yet committed ) to handle joining
path segments with various leading and trailing suffices and I was
curious whether we have one that I can reuse.

I need this for less obvious combinations such as

  "/parent/" + "/child" -> "/parent/child"
  "/parent"  + "child"  -> "/parent/child"

Thanks,

Robert


Re: Utility to construct paths out of strings?

Posted by Robert Munteanu <ro...@apache.org>.
On Wed, 2016-01-27 at 15:47 +0530, Chetan Mehrotra wrote:
> FWIW Oak has a PathUtils [1]. Looking at code it has a minor
> dependency on Guava which can be fixed. So you can inline this class
> in your bundle if required

Thanks for the info.

Right now I feel more comfortable with using a minimal PathBuilder
class, but for the future we can inline the PathUtils class in the
sling bundle if we need more complex handling.

Robert

> 
> Chetan Mehrotra
> [1] https://github.com/apache/jackrabbit-oak/blob/trunk/oak-commons/s
> rc/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java
> 
> 
> On Tue, Jan 26, 2016 at 9:36 PM, Robert Munteanu <ro...@apache.org>
> wrote:
> > On Tue, 2016-01-26 at 16:15 +0100, Bertrand Delacretaz wrote:
> > > Hi Robert,
> > > 
> > > > ...
> > > >   https://issues.apache.org/jira/browse/SLING-5455
> > > >   https://svn.apache.org/r1726814 ...
> > > 
> > > I have second thoughts about this, sorry ;-)
> > > 
> > > Touching our "sacred" API bundle just for this doesn't feel
> > > right...how about creating a new bundles/extensions/sling-commons 
> > > or
> > > sling-util bundle? It will be almost empty for now but that's a
> > > good
> > > place to add such minor utilities later, without touching
> > > "important"
> > > bundles.
> > 
> > Moving out of API is fine for me.
> > 
> > Keeping in mind that this will be used by the resourceresolver
> > bundle,
> > is bundles/extensions the right place ? ( not a rhetorical
> > question, I
> > really don't know ).
> > 
> > As for the bundle name, I'm not a very big fan of commons/util
> > since
> > they tend to become onfocused, but I don't have a better idea right
> > now.
> > 
> > I've reopened SLING-5455 to track the creation of the new bundle.
> > 
> > Robert
> > 
> > > 
> > > WDYT?
> > > 
> > > -Bertrand
> > 


Re: Utility to construct paths out of strings?

Posted by Chetan Mehrotra <ch...@gmail.com>.
FWIW Oak has a PathUtils [1]. Looking at code it has a minor
dependency on Guava which can be fixed. So you can inline this class
in your bundle if required

Chetan Mehrotra
[1] https://github.com/apache/jackrabbit-oak/blob/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java


On Tue, Jan 26, 2016 at 9:36 PM, Robert Munteanu <ro...@apache.org> wrote:
> On Tue, 2016-01-26 at 16:15 +0100, Bertrand Delacretaz wrote:
>> Hi Robert,
>>
>> > ...
>> >   https://issues.apache.org/jira/browse/SLING-5455
>> >   https://svn.apache.org/r1726814 ...
>>
>> I have second thoughts about this, sorry ;-)
>>
>> Touching our "sacred" API bundle just for this doesn't feel
>> right...how about creating a new bundles/extensions/sling-commons or
>> sling-util bundle? It will be almost empty for now but that's a good
>> place to add such minor utilities later, without touching "important"
>> bundles.
>
> Moving out of API is fine for me.
>
> Keeping in mind that this will be used by the resourceresolver bundle,
> is bundles/extensions the right place ? ( not a rhetorical question, I
> really don't know ).
>
> As for the bundle name, I'm not a very big fan of commons/util since
> they tend to become onfocused, but I don't have a better idea right
> now.
>
> I've reopened SLING-5455 to track the creation of the new bundle.
>
> Robert
>
>>
>> WDYT?
>>
>> -Bertrand
>

Re: Utility to construct paths out of strings?

Posted by Robert Munteanu <ro...@apache.org>.
On Mon, 2016-02-01 at 14:17 +0100, Bertrand Delacretaz wrote:
> Hi,
> 
> On Mon, Feb 1, 2016 at 1:56 PM, Robert Munteanu <ro...@apache.org>
> wrote:
> > ...we re-re-opened the issue :-) and are leaning towards
> > moving the class back in the api bundle, in a different package..
> 
> That works for me, if it's a different package it's fine.

Thanks for confirming, re-added to the api bundle under
org.apache.sling.resource.path .

Robert

Re: Utility to construct paths out of strings?

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Mon, Feb 1, 2016 at 1:56 PM, Robert Munteanu <ro...@apache.org> wrote:
> ...we re-re-opened the issue :-) and are leaning towards
> moving the class back in the api bundle, in a different package..

That works for me, if it's a different package it's fine.

-Bertrand

Re: Utility to construct paths out of strings?

Posted by Robert Munteanu <ro...@apache.org>.
On Wed, 2016-01-27 at 16:02 +0200, Robert Munteanu wrote:
> On Tue, 2016-01-26 at 18:06 +0200, Robert Munteanu wrote:
> > On Tue, 2016-01-26 at 16:15 +0100, Bertrand Delacretaz wrote:
> > > Hi Robert,
> > > 
> > > > ...
> > > >   https://issues.apache.org/jira/browse/SLING-5455
> > > >   https://svn.apache.org/r1726814 ...
> > > 
> > > I have second thoughts about this, sorry ;-)
> > > 
> > > Touching our "sacred" API bundle just for this doesn't feel
> > > right...how about creating a new bundles/extensions/sling-commons
> > > or
> > > sling-util bundle? It will be almost empty for now but that's a
> > > good
> > > place to add such minor utilities later, without touching
> > > "important"
> > > bundles.
> > 
> > Moving out of API is fine for me.
> > 
> > Keeping in mind that this will be used by the resourceresolver
> > bundle,
> > is bundles/extensions the right place ? ( not a rhetorical
> > question,
> > I
> > really don't know ).
> > 
> > As for the bundle name, I'm not a very big fan of commons/util
> > since
> > they tend to become onfocused, but I don't have a better idea right
> > now.
> > 
> > I've reopened SLING-5455 to track the creation of the new bundle.
> 
> I've moved the PathBuilder class to a new org.apache.sling.commons
> bundle under bundles/extensions ( maybe it should be under
> bundles/commons, since it does not depend on Sling at all? )
> 
>   https://svn.apache.org/r1727058
> 
> I'll start a release vote early on Friday since I would like to
> release
> next week the resource resolver bundle ( and other which contain the
> work for the new API ).

For the record, we re-re-opened the issue :-) and are leaning towards
moving the class back in the api bundle, in a different package ( so
it's easy to split out into a different bundle, if we decide to do so
in the future ). 

Any arguments against this would be appreciated soon :-)

Thanks,

Robert

> 
> Thanks,
> 
> Robert
> 
> 
> > 
> > Robert
> > 
> > > 
> > > WDYT?
> > > 
> > > -Bertrand
> > 
> 


Re: Utility to construct paths out of strings?

Posted by Robert Munteanu <ro...@apache.org>.
On Tue, 2016-01-26 at 18:06 +0200, Robert Munteanu wrote:
> On Tue, 2016-01-26 at 16:15 +0100, Bertrand Delacretaz wrote:
> > Hi Robert,
> > 
> > > ...
> > >   https://issues.apache.org/jira/browse/SLING-5455
> > >   https://svn.apache.org/r1726814 ...
> > 
> > I have second thoughts about this, sorry ;-)
> > 
> > Touching our "sacred" API bundle just for this doesn't feel
> > right...how about creating a new bundles/extensions/sling-commons
> > or
> > sling-util bundle? It will be almost empty for now but that's a
> > good
> > place to add such minor utilities later, without touching
> > "important"
> > bundles.
> 
> Moving out of API is fine for me.
> 
> Keeping in mind that this will be used by the resourceresolver
> bundle,
> is bundles/extensions the right place ? ( not a rhetorical question,
> I
> really don't know ).
> 
> As for the bundle name, I'm not a very big fan of commons/util since
> they tend to become onfocused, but I don't have a better idea right
> now.
> 
> I've reopened SLING-5455 to track the creation of the new bundle.

I've moved the PathBuilder class to a new org.apache.sling.commons
bundle under bundles/extensions ( maybe it should be under
bundles/commons, since it does not depend on Sling at all? )

  https://svn.apache.org/r1727058

I'll start a release vote early on Friday since I would like to release
next week the resource resolver bundle ( and other which contain the
work for the new API ).

Thanks,

Robert


> 
> Robert
> 
> > 
> > WDYT?
> > 
> > -Bertrand
> 


Re: Utility to construct paths out of strings?

Posted by Robert Munteanu <ro...@apache.org>.
On Tue, 2016-01-26 at 16:15 +0100, Bertrand Delacretaz wrote:
> Hi Robert,
> 
> > ...
> >   https://issues.apache.org/jira/browse/SLING-5455
> >   https://svn.apache.org/r1726814 ...
> 
> I have second thoughts about this, sorry ;-)
> 
> Touching our "sacred" API bundle just for this doesn't feel
> right...how about creating a new bundles/extensions/sling-commons or
> sling-util bundle? It will be almost empty for now but that's a good
> place to add such minor utilities later, without touching "important"
> bundles.

Moving out of API is fine for me.

Keeping in mind that this will be used by the resourceresolver bundle,
is bundles/extensions the right place ? ( not a rhetorical question, I
really don't know ).

As for the bundle name, I'm not a very big fan of commons/util since
they tend to become onfocused, but I don't have a better idea right
now.

I've reopened SLING-5455 to track the creation of the new bundle.

Robert

> 
> WDYT?
> 
> -Bertrand


Re: Utility to construct paths out of strings?

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Robert,

> ...
>   https://issues.apache.org/jira/browse/SLING-5455
>   https://svn.apache.org/r1726814 ...

I have second thoughts about this, sorry ;-)

Touching our "sacred" API bundle just for this doesn't feel
right...how about creating a new bundles/extensions/sling-commons or
sling-util bundle? It will be almost empty for now but that's a good
place to add such minor utilities later, without touching "important"
bundles.

WDYT?

-Bertrand

Re: Utility to construct paths out of strings?

Posted by Robert Munteanu <ro...@apache.org>.
On Tue, 2016-01-26 at 15:05 +0100, Bertrand Delacretaz wrote:
> On Tue, Jan 26, 2016 at 1:57 PM, Robert Munteanu <ro...@apache.org>
> wrote:
> > org.apache.sling.api.text ? ..
> 
> org.apache.sling.api.paths maybe if it's just about paths?

Sounds good to me.

  https://issues.apache.org/jira/browse/SLING-5455
  https://svn.apache.org/r1726814

Robert

Re: Utility to construct paths out of strings?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Tue, Jan 26, 2016 at 1:57 PM, Robert Munteanu <ro...@apache.org> wrote:
> org.apache.sling.api.text ? ..

org.apache.sling.api.paths maybe if it's just about paths?

> ...I don't see a related bundle under bundles/commons and I'm not sure
> it's worth creating a new bundle just for this utility...

Agreed.

-Bertrand

Re: Utility to construct paths out of strings?

Posted by Robert Munteanu <ro...@apache.org>.
On Tue, 2016-01-26 at 11:32 +0100, Bertrand Delacretaz wrote:
> Hi Robert,
> 
> On Tue, Jan 26, 2016 at 9:44 AM, Robert Munteanu <ro...@apache.org>
> wrote:
> > ...it's not API right now, but I'll make it for the next release,
> > probably as part of org.apache.sling.api.resource ...
> 
> IMO that utility should to into its own package(s) then, to avoid
> requiring changes to existing packages just for that.

org.apache.sling.api.text ? 

I don't see a related bundle under bundles/commons and I'm not sure
it's worth creating a new bundle just for this utility.

Thanks,

Robert

Re: Utility to construct paths out of strings?

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Robert,

On Tue, Jan 26, 2016 at 9:44 AM, Robert Munteanu <ro...@apache.org> wrote:
> ...it's not API right now, but I'll make it for the next release,
> probably as part of org.apache.sling.api.resource ...

IMO that utility should to into its own package(s) then, to avoid
requiring changes to existing packages just for that.

-Bertrand

Re: Utility to construct paths out of strings?

Posted by Robert Munteanu <ro...@apache.org>.
On Mon, 2016-01-25 at 17:56 +0100, Bertrand Delacretaz wrote:
> Hi Robert,
> 
> On Mon, Jan 25, 2016 at 4:38 PM, Robert Munteanu <ro...@apache.org>
> wrote:
> > ...Do we have a utility class somewhere that constructs paths out
> > of
> > strings?...
> 
> I don't think we have a comprehensive one, there are bits and pieces
> (jackrabbit-jcr-commons maybe?) but we can probably use a general
> path
> building / deconstruction utility. I'm hoping that your uncommitted
> stuff uses a fluent syntax ;-)

Yes, it does :-)

https://github.com/apache/sling/blob/def26ada2a6be3ac42e4f1ec19421a38d2
71f33a/bundles/resourceresolver/src/main/java/org/apache/sling/resource
resolver/impl/providers/stateful/CombinedResourceProvider.java#L657-
L683

However, it's not API right now, but I'll make it for the next release,
probably as part of org.apache.sling.api.resource .

Robert

Re: Utility to construct paths out of strings?

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Robert,

On Mon, Jan 25, 2016 at 4:38 PM, Robert Munteanu <ro...@apache.org> wrote:
> ...Do we have a utility class somewhere that constructs paths out of
> strings?...

I don't think we have a comprehensive one, there are bits and pieces
(jackrabbit-jcr-commons maybe?) but we can probably use a general path
building / deconstruction utility. I'm hoping that your uncommitted
stuff uses a fluent syntax ;-)

-Bertrand