Re: something similar with setOutputMarkupContainerClassName

2012-10-23 Thread Decebal Suiu
public class DesignModeListener implements IComponentInstantiationListener {

private boolean designMode = true;

@Override
public void onInstantiation(Component component) {
if (component instanceof WebMarkupContainer) {
Class? klass = component.getClass();
while (klass.isAnonymousClass()) {
klass = klass.getSuperclass();
}

if (klass.getName().startsWith(com.acme)) {
component.add(new DesignModeBehavior());
}
}
}

private class DesignModeBehavior extends Behavior {

private static final long serialVersionUID = 1L;

@Override
public void beforeRender(Component component) {
super.beforeRender(component);

if (designMode) {
// TODO
Class? klass = component.getClass();
while (klass.isAnonymousClass()) {
klass = klass.getSuperclass();
}

Response response = component.getResponse();
response.write(\n);
}
}

@Override
public void afterRender(Component component) {
super.afterRender(component);

if (designMode) {
// TODO
Class? klass = component.getClass();
while (klass.isAnonymousClass()) {
klass = klass.getSuperclass();
}

Response response = component.getResponse();
response.write(\n);
}   
}

}

}

In WicketApplication.init(): getComponentInstantiationListeners().add(new
DesignModeListener());

In WebPage.java: add(new HeaderPanel(header));

In WebPage.html:   div wicket:id=header id=header/div

My problem is that DesignModeBehavior decorates HeaderPanel with two
comments (before and after component tag) but the behavior what I want to
achieve is the same with setOutputMarkupContainerClassName on DebugSettings
(see MarkupContainer.renderAssociatedMarkup) - the comments are placed
before and after component tag body.

Is it more clear now?

Best regards,
Decebal



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202p4653243.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: something similar with setOutputMarkupContainerClassName

2012-10-23 Thread Martin Grigorov
Hi,

On Tue, Oct 23, 2012 at 10:49 AM, Decebal Suiu decebal.s...@asf.ro wrote:
 public class DesignModeListener implements IComponentInstantiationListener {

 private boolean designMode = true;

 @Override
 public void onInstantiation(Component component) {
 if (component instanceof WebMarkupContainer) {
 Class? klass = component.getClass();
 while (klass.isAnonymousClass()) {
 klass = klass.getSuperclass();
 }

 if (klass.getName().startsWith(com.acme)) {
 component.add(new DesignModeBehavior());
 }
 }
 }

 private class DesignModeBehavior extends Behavior {

 private static final long serialVersionUID = 1L;

 @Override
 public void beforeRender(Component component) {
 super.beforeRender(component);

 if (designMode) {
 // TODO
 Class? klass = component.getClass();
 while (klass.isAnonymousClass()) {
 klass = klass.getSuperclass();
 }

 Response response = component.getResponse();
 response.write(\n);
 }
 }

 @Override
 public void afterRender(Component component) {
 super.afterRender(component);

 if (designMode) {
 // TODO
 Class? klass = component.getClass();
 while (klass.isAnonymousClass()) {
 klass = klass.getSuperclass();
 }

 Response response = component.getResponse();
 response.write(\n);
 }
 }

 }

 }

 In WicketApplication.init(): getComponentInstantiationListeners().add(new
 DesignModeListener());

 In WebPage.java: add(new HeaderPanel(header));

 In WebPage.html:   div wicket:id=header id=header/div

 My problem is that DesignModeBehavior decorates HeaderPanel with two
 comments (before and after component tag) but the behavior what I want to
 achieve is the same with setOutputMarkupContainerClassName on DebugSettings
 (see MarkupContainer.renderAssociatedMarkup) - the comments are placed
 before and after component tag body.

 Is it more clear now?

Yes, it is more clear.
There was a similar question few days ago by Jesse Long in users@ -
subject Behavior modifying component body.
 Currently Behavior.java doesn't provide methods to write in the
component tag body.
You can use AbstractTransformBehavior as a workaround.


 Best regards,
 Decebal



 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202p4653243.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: something similar with setOutputMarkupContainerClassName

2012-10-23 Thread Decebal Suiu
AbstractTransformerBehavior can be a solution but I must parse the output to
retrieve the component tag body. For a particular situation (Jesse Long
situation) to parse the output it's not a big deal but in my situation
(something general for all my markup containers) I don't see a solution.
Maybe I suppose that all my container markups are divs (div .../div). Is
it an util class in wicket that can help me with the parsing operation? I
want to retrieve the component tag body only.

Best regards,
Decebal



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202p4653252.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: something similar with setOutputMarkupContainerClassName

2012-10-23 Thread Martin Grigorov
You just need to put something after the first closing tag and before
the last opening one.

For the first case it is something like (not tested, and better use
compiled Pattern):

String replaced = original.replaceAll(^(.*?])(.*), $1+theComment + $2);

Once again I agree that having the two additional methods in
Behavior.java will simplify these use cases.

On Tue, Oct 23, 2012 at 11:55 AM, Decebal Suiu decebal.s...@asf.ro wrote:
 AbstractTransformerBehavior can be a solution but I must parse the output to
 retrieve the component tag body. For a particular situation (Jesse Long
 situation) to parse the output it's not a big deal but in my situation
 (something general for all my markup containers) I don't see a solution.
 Maybe I suppose that all my container markups are divs (div .../div). Is
 it an util class in wicket that can help me with the parsing operation? I
 want to retrieve the component tag body only.

 Best regards,
 Decebal



 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202p4653252.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: something similar with setOutputMarkupContainerClassName

2012-10-23 Thread Jesse Long

This was my solution, works for me:

public abstract class AbstractBodyTransformerBehavior
extends AbstractTransformerBehavior
{
protected abstract CharSequence transformBody(Component component, 
CharSequence body) throws Exception;


private static int indexOfCharacterInSequence(CharSequence 
haystack, char needle)

{
int max = haystack.length();

for (int i = 0; i  max; i++){
if (haystack.charAt(i) == needle){
return i;
}
}

return -1;
}

private static int lastIndexOfCharacterInSequence(CharSequence 
haystack, char needle)

{
int max = haystack.length();

for (int i = (max - 1); i = 0; i--){
if (haystack.charAt(i) == needle){
return i;
}
}

return -1;
}

@Override
public CharSequence transform(Component component, CharSequence 
output) throws Exception

{
int bodyStart = indexOfCharacterInSequence(output, '') + 1;

int bodyEnd = lastIndexOfCharacterInSequence(output, '');

if (bodyStart  1 || bodyEnd  0){
throw new WicketRuntimeException(Unable to find body for 
component:  + output);

}

StringBuilder sb = new StringBuilder(output.length());

sb.append(output.subSequence(0, bodyStart));

sb.append(transformBody(component, 
output.subSequence(bodyStart, bodyEnd)));


sb.append(output.subSequence(bodyEnd, output.length()));

return sb;
}
}


On 23/10/2012 11:04, Martin Grigorov wrote:

You just need to put something after the first closing tag and before
the last opening one.

For the first case it is something like (not tested, and better use
compiled Pattern):

String replaced = original.replaceAll(^(.*?])(.*), $1+theComment + $2);

Once again I agree that having the two additional methods in
Behavior.java will simplify these use cases.

On Tue, Oct 23, 2012 at 11:55 AM, Decebal Suiu decebal.s...@asf.ro wrote:

AbstractTransformerBehavior can be a solution but I must parse the output to
retrieve the component tag body. For a particular situation (Jesse Long
situation) to parse the output it's not a big deal but in my situation
(something general for all my markup containers) I don't see a solution.
Maybe I suppose that all my container markups are divs (div .../div). Is
it an util class in wicket that can help me with the parsing operation? I
want to retrieve the component tag body only.

Best regards,
Decebal



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202p4653252.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org







-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: something similar with setOutputMarkupContainerClassName

2012-10-23 Thread Decebal Suiu
And this is my implementation:

private class DesignModeBehavior extends AbstractTransformerBehavior {

private static final long serialVersionUID = 1L;

@Override
public CharSequence transform(Component component, CharSequence 
output)
throws Exception {  
String className = 
component.getMetaData(CLASS_NAME_KEY);

StringBuilder pre = new StringBuilder();
pre.append(!- quot;);
pre.append(className);
pre.append(quot; BEGINquot;);
pre.append(quot; -\n);

StringBuilder post = new StringBuilder();
post.append(!- quot;);
post.append(className);
post.append(quot; ENDquot;);
post.append(quot; -\n);

StringBuilder tmp = new StringBuilder(output);
int i1 = tmp.indexOf();
int i2 = tmp.lastIndexOf();
tmp.insert(i2, post.toString());
tmp.insert(i1 + 1, pre.toString());

return tmp;
}

}



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202p4653263.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



something similar with setOutputMarkupContainerClassName

2012-10-22 Thread Decebal Suiu
Hi

I want to implement something like setOutputMarkupContainerClassName but
more dynamic (not a simple flag in IDebugSettings and not a hard-coded html
comment).

My situation is that I want to offer an application as a service. In my
application, in design mode (an url parameter in request), I want to display
the information about the markup container that rendered that html fragment
as a comment (for example if com.acme.web.BasePage rendered that html
fragment I want something like !-- BasePage Begin).


Is it possible?

Best regards,
Decebal





--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: something similar with setOutputMarkupContainerClassName

2012-10-22 Thread Martin Grigorov
Hi,

You can use a Behavior#beforeRender() for that.

See how org.apache.wicket.devutils.inspector.RenderPerformanceListener works.

On Mon, Oct 22, 2012 at 4:04 PM, Decebal Suiu decebal.s...@asf.ro wrote:
 Hi

 I want to implement something like setOutputMarkupContainerClassName but
 more dynamic (not a simple flag in IDebugSettings and not a hard-coded html
 comment).

 My situation is that I want to offer an application as a service. In my
 application, in design mode (an url parameter in request), I want to display
 the information about the markup container that rendered that html fragment
 as a comment (for example if com.acme.web.BasePage rendered that html
 fragment I want something like !-- BasePage Begin).


 Is it possible?

 Best regards,
 Decebal





 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: something similar with setOutputMarkupContainerClassName

2012-10-22 Thread Decebal Suiu
Thanks Martin for response.

I implemented an DesignModeListener that implements
IComponentInstantiationListener. The main problem is that my comment is
placed before the container markup tag.

Example:
div id=container
  
  div id=header
   
   ...
   
  /div
  

  ...
/div

Above you can see the difference between DesignModeListener and
IDebugSettings.setOutputMarkupContainerClassName. The div with id=header
is not generated by HeaderPanel.
 
Best regards,
Decebal



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202p4653205.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: something similar with setOutputMarkupContainerClassName

2012-10-22 Thread Martin Grigorov
Show us your code please.
How do you use it ?

On Mon, Oct 22, 2012 at 5:17 PM, Decebal Suiu decebal.s...@asf.ro wrote:
 Thanks Martin for response.

 I implemented an DesignModeListener that implements
 IComponentInstantiationListener. The main problem is that my comment is
 placed before the container markup tag.

 Example:
 div id=container

   div id=header

...

   /div


   ...
 /div

 Above you can see the difference between DesignModeListener and
 IDebugSettings.setOutputMarkupContainerClassName. The div with id=header
 is not generated by HeaderPanel.

 Best regards,
 Decebal



 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/something-similar-with-setOutputMarkupContainerClassName-tp4653202p4653205.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org