On Apr 17, 2009, at 9:18 AM, Vincent Massol wrote:
>
> On Apr 16, 2009, at 11:42 PM, Vincent Massol wrote:
>
>>
>> On Apr 16, 2009, at 11:38 PM, Sergiu Dumitriu wrote:
>>
>>> Vincent Massol wrote:
>>>> Hi,
>>>>
>>>> In the rendering code we have several places where we've had to
>>>> create
>>>> generic string manipulation classes/methods (for example a method
>>>> to
>>>> remove a single NL at start and end of string).
>>>> I think it would be better to create one or several components for
>>>> these string manipulation methods (same as we have xwiki-xml for
>>>> xml
>>>> manipulation).
>>>>
>>>> The idea is that we should use existing framework as much as
>>>> possible
>>>> (StringUtils from commons lang for ex) but when we cannot find an
>>>> existing framework to manipulate text then we would put it in
>>>> xwiki-
>>>> text.
>>>>
>>>> WDYT?
>>>>
>>>
>>> I don't know if this is really needed. StringUtils is supposed to
>>> be the
>>> library for string manipulation.
>
> I'd love that too and I'd be much happier without any extra module.
> Check CleanUtil.java in the converter module; you'll see it contains
> lots of utility methods.
>
>>> Isn't StringUtils.removeStart(content,
>>> "\n") + StringUtils.chomp(content) enough?
>>
>> removeStart removes all NL not only the first one. BTW it's not
>> only "\n" but "\n", "\r" or "\r\n".
Just to be clear this is the code I have right now in
MacroTransformation and I don't feel it's the right place for it:
private String normalizeContent(MacroHolder macroHolder)
{
String normalizedContent = macroHolder.macroBlock.getContent();
if (normalizedContent != null && normalizedContent.length() >
0) {
// Remove leading New Line
if (normalizedContent.charAt(0) == '\n') {
normalizedContent = normalizedContent.substring(1);
} else if (normalizedContent.length() > 1 &&
normalizedContent.charAt(0) == '\r'
&& normalizedContent.charAt(1) == '\n')
{
normalizedContent = normalizedContent.substring(2);
} else if (normalizedContent.charAt(0) == '\r') {
normalizedContent = normalizedContent.substring(1);
}
// Remove trailing New Line
normalizedContent = StringUtils.chomp(normalizedContent);
}
return normalizedContent;
}
Thanks
-Vincent
>>
>>
>>> If we just need a couple of methods on top of StringUtils, then I'd
>>> rather not introduce a new component. Especially one that's as
>>> simple as
>>> this one.
>
> I think I prefer to have components rather than statics (same for
> XMLUtils btw which I started I know... :)) but that's a detail
> compared to the larger question of whether we want a xwiki-text
> module for containing all our generic text manipulation code. BTW it
> wouldn't be a single class. For example I envision one called
> WhitespaceUtil for all NL/WS manipulations.
>
> I have thought about merging xwiki-xml and xwiki-text into something
> like xwiki-utils but I don't think it flies (especially since we
> have the HTML cleaner in xwiki-xml). Of course we could have xwiki-
> utils and another xwiki-html or xwiki-htmlcleaner module.
>
> -Vincent
>
>> Where would you put them then? Copy paste them?
>>
>> Right now for ex we have duplication in the 1.0 converter and in
>> the MacroTransformation.
>>
>> -Vincent
>
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs