We've implemented a TransformerFactory in our project to help re-write some links from "/content/project_name" to just "/project_name".
The only downfall is that this Factory IGNORES any comments. For a number of reasons, we need to have the COMMENTS updated as well.
Is anyone aware of a way to update those comments as well?
Thank you in advance.
-Dean
Solved! Go to Solution.
Views
Replies
Total Likes
Here's a trivial example of a Transfomer which adds "HELLO" inside comments: https://gist.github.com/justinedelson/cdcf502413740bef9539faf74385a599
Views
Replies
Total Likes
Most of the use cases I have seen with this class is modifying links:
What comments are you referring to?
Views
Replies
Total Likes
We have something like this:
...
<!-- add="ASSOCIATE_1"
<div class="image parbase section">
<img src="/content/business/test-pages/components/abc/image.img.png" alt="image" class="img-responsive"/>
</div>
-->
...
So we comment out the html for certain associates. They can then uncomment and use accordingly ....
I want to use the Transformer Factory to change the following
original : <img src="/content/business/test-pages/components/abc/image.img.png" alt="image" class="img-responsive"/>
desired output : <img src="/business/test-pages/components/abc/image.img.png" alt="image" class="img-responsive"/>
However, since it's part of a comment it does not get picked up for processing.
Any thoughts?
-Dean
Views
Replies
Total Likes
HI Dean - i have not personally heard about using the Transformer to modify comments in code like this., I will check within Adobe.
Views
Replies
Total Likes
Hi,
This would theoretically be possible but it requires your Transformer implement the characters() method and parse the contents of that text yourself. If the contents of these comments are regular, you might be able to handle this with regex, but if the HTML is "normal" HTML, it is far from regular enough to be handled in this way.
If you are going to go down this path, I'd highly recommend paying attention to slides 19 through 22 of http://www.slideshare.net/justinedelson/mastering-the-sling-rewriter (blatant self-promotion)
Regards,
Justin
Views
Replies
Total Likes
Justin,
I'm open to trying anything ...
When I print out the attributes in the startElement method, I never see the comments.
Is it just ignoring them?
The contents of the comments are extremely regular ... I'd like to be able to use regex.
I've reviewed the slides but I'm still not sure how I can change these things without the comments coming into the transformer.
Thanks,
-Dean
Views
Replies
Total Likes
Justin,
I've added code to the Transformer, but I'm still not able to see the comments in the transformer.
<!-- add="ASSOCIATE_1"
<div class="image parbase section">
<img src="/content/business/test-pages/components/abc/image.img.png" alt="image" class="img-responsive"/>
</div>
-->
Any suggestions on how to implement the characters() method to obtain the comments is GREATLY appreciated?
Thank you for all your help.
-Dean
Views
Replies
Total Likes
Right, like I said, you wouldn't see the commented elements in the startElement(). You will see them (as text) in the characters() method. startElement() is useless for this use case as those aren't actually elements. They are text (character data in XML parlance).
Views
Replies
Total Likes
Here's a trivial example of a Transfomer which adds "HELLO" inside comments: https://gist.github.com/justinedelson/cdcf502413740bef9539faf74385a599
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies