Discussion:
Adding link rewrite to the pipeline throws exception
Nate Yolles
2015-07-28 15:46:19 UTC
Permalink
Hello,

I’m trying to add a link rewriter into the pipeline but I’m running into some trouble. I’ve done this in AEM/CQ a few times but this is the first time I’m attempting it in a pure Sling application. I’m using
“org.apache.sling.launchpad-7-standalone.jar” with Sightly. When I try to load a page I get the error “Unable to get component of class ‘interface org.apache.sling.rewriter.Generator’ with type ‘htmlparser’.”

Any guidance would be appreciated.

Thank you!


28.07.2015 08:07:26.341 *ERROR* [0:0:0:0:0:0:0:1 [1438096046286] GET /content/blog/index.html HTTP/1.1] org.apache.sling.servlets.resolver.internal.SlingServletResolver Original error class java.io.IOException

java.io.IOException: Unable to get component of class 'interface org.apache.sling.rewriter.Generator' with type 'htmlparser'.

at org.apache.sling.rewriter.impl.PipelineImpl.getPipelineComponent(PipelineImpl.java:160)

at org.apache.sling.rewriter.impl.PipelineImpl.init(PipelineImpl.java:85)

at org.apache.sling.rewriter.impl.ProcessorManagerImpl.getProcessor(ProcessorManagerImpl.java:445)

at org.apache.sling.rewriter.impl.RewriterResponse.getProcessor(RewriterResponse.java:172)

at org.apache.sling.rewriter.impl.RewriterResponse.getWriter(RewriterResponse.java:110)

at org.apache.sling.scripting.core.impl.helper.OnDemandWriter.getWriter(OnDemandWriter.java:38)

at org.apache.sling.scripting.core.impl.helper.OnDemandWriter.write(OnDemandWriter.java:75)

at java.io.PrintWriter.write(PrintWriter.java:456)

at java.io.PrintWriter.write(PrintWriter.java:473)

at libs.publick.pages.page.SightlyJava_html.render(SightlyJava_html.java:37)

I have a configuration node under /apps/mysite/config/rewriter/linkrewriter along with /apps/mysite/config/rewriter/linkrewriter/generator-htmlparser


{

"jcr:primaryType": "sling:Folder",

"rewriter" : {

"jcr:primaryType": "sling:Folder",

"linkrewriter" : {

"jcr:primaryType" : "nt:unstructured",

"contentTypes" : [

"text/html"

],

"enabled" : true,

"generatorType" : "htmlparser",

"order" : 1,

"paths" : [

"/content"

],

"serializerType" : "htmlwriter",

"transformerTypes" : [

"linkrewriter"

],

"generator-htmlparser" : {

"jcr:primaryType" : "nt:unstructured",

"includeTags" : [

"A",

"/A"

]

}

}

}

}

Then I have the Transformer and TransformerFactory implementations:


import java.io.IOException;

import java.util.Map;


import org.apache.felix.scr.annotations.Activate;

import org.apache.felix.scr.annotations.Component;

import org.apache.felix.scr.annotations.Deactivate;

import org.apache.felix.scr.annotations.Properties;

import org.apache.felix.scr.annotations.Property;

import org.apache.felix.scr.annotations.Reference;

import org.apache.felix.scr.annotations.Service;

import org.apache.sling.api.SlingHttpServletRequest;

import org.apache.sling.commons.osgi.PropertiesUtil;

import org.apache.sling.rewriter.ProcessingComponentConfiguration;

import org.apache.sling.rewriter.ProcessingContext;

import org.apache.sling.rewriter.Transformer;

import org.apache.sling.rewriter.TransformerFactory;

import org.osgi.service.component.ComponentContext;

import org.xml.sax.Attributes;

import org.xml.sax.ContentHandler;

import org.xml.sax.Locator;

import org.xml.sax.SAXException;

import org.xml.sax.helpers.AttributesImpl;


@Component

@Service

@Property(name="pipeline.type", value="linkrewriter", propertyPrivate=true)

public class LinkRewriterTransformerFactory implements TransformerFactory {


public Transformer createTransformer() {

return new LinkRewriterTransformer();

}


@Activate

protected void activate(Map<String, Object> properties) {

}


@Deactivate

protected void deactivate(ComponentContext ctx) {

}


private class LinkRewriterTransformer implements Transformer {

private ContentHandler contentHandler;


public void characters(char[] ch, int start, int length) throws SAXException {

contentHandler.characters(ch, start, length);

}


public void dispose() {

}


public void endDocument() throws SAXException {

contentHandler.endDocument();

}


public void endElement(String uri, String localName, String qName) throws SAXException {

contentHandler.endElement(uri, localName, qName);

}


public void endPrefixMapping(String prefix) throws SAXException {

contentHandler.endPrefixMapping(prefix);

}


public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {

contentHandler.ignorableWhitespace(ch, start, length);

}


public void init(ProcessingContext context, ProcessingComponentConfiguration config) throws IOException {

}


public void processingInstruction(String target, String data) throws SAXException {

contentHandler.processingInstruction(target, data);

}


public void setContentHandler(ContentHandler handler) {

this.contentHandler = handler;

}


public void setDocumentLocator(Locator locator) {

contentHandler.setDocumentLocator(locator);

}


public void skippedEntity(String name) throws SAXException {

contentHandler.skippedEntity(name);

}


public void startDocument() throws SAXException {

contentHandler.startDocument();

}


public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {

contentHandler.startElement(uri, localName, qName, atts);



// final AttributesImpl attributes = new AttributesImpl(atts);

// final String href = attributes.getValue("href");

// final boolean enableRewritePath = true;

//

// if (href != null && href.startsWith("/")) {

//

// for (int i = 0; i < attributes.getLength(); i++) {

// if ("href".equalsIgnoreCase(attributes.getQName(i))) {

// attributes.setValue(i, enableRewritePath ? rewritePath(href) : href);

// }

// }

// }

//

// contentHandler.startElement(uri, localName, qName, attributes);

}


public void startPrefixMapping(String prefix, String uri) throws SAXException {

contentHandler.startPrefixMapping(prefix, uri);

}


private String rewritePath(final String href) {

return href.replace("/content", "");

}

}

}
Justin Edelson
2015-07-28 16:11:17 UTC
Permalink
Hi Nate,
IIUC, in Sling, you need to use "html-generator". "htmlparser" refers to an
AEM component.

See
https://github.com/apache/sling/blob/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/components/HtmlGeneratorFactory.java

Regards,
Justin
Post by Nate Yolles
Hello,
I’m trying to add a link rewriter into the pipeline but I’m running into
some trouble. I’ve done this in AEM/CQ a few times but this is the first
time I’m attempting it in a pure Sling application. I’m using
“org.apache.sling.launchpad-7-standalone.jar” with Sightly. When I try to
load a page I get the error “Unable to get component of class ‘interface
org.apache.sling.rewriter.Generator’ with type ‘htmlparser’.”
Any guidance would be appreciated.
Thank you!
28.07.2015 08:07:26.341 *ERROR* [0:0:0:0:0:0:0:1 [1438096046286] GET
/content/blog/index.html HTTP/1.1]
org.apache.sling.servlets.resolver.internal.SlingServletResolver Original
error class java.io.IOException
java.io.IOException: Unable to get component of class 'interface
org.apache.sling.rewriter.Generator' with type 'htmlparser'.
at
org.apache.sling.rewriter.impl.PipelineImpl.getPipelineComponent(PipelineImpl.java:160)
at org.apache.sling.rewriter.impl.PipelineImpl.init(PipelineImpl.java:85)
at
org.apache.sling.rewriter.impl.ProcessorManagerImpl.getProcessor(ProcessorManagerImpl.java:445)
at
org.apache.sling.rewriter.impl.RewriterResponse.getProcessor(RewriterResponse.java:172)
at
org.apache.sling.rewriter.impl.RewriterResponse.getWriter(RewriterResponse.java:110)
at
org.apache.sling.scripting.core.impl.helper.OnDemandWriter.getWriter(OnDemandWriter.java:38)
at
org.apache.sling.scripting.core.impl.helper.OnDemandWriter.write(OnDemandWriter.java:75)
at java.io.PrintWriter.write(PrintWriter.java:456)
at java.io.PrintWriter.write(PrintWriter.java:473)
at
libs.publick.pages.page.SightlyJava_html.render(SightlyJava_html.java:37)
I have a configuration node under
/apps/mysite/config/rewriter/linkrewriter along with
/apps/mysite/config/rewriter/linkrewriter/generator-htmlparser
{
"jcr:primaryType": "sling:Folder",
"rewriter" : {
"jcr:primaryType": "sling:Folder",
"linkrewriter" : {
"jcr:primaryType" : "nt:unstructured",
"contentTypes" : [
"text/html"
],
"enabled" : true,
"generatorType" : "htmlparser",
"order" : 1,
"paths" : [
"/content"
],
"serializerType" : "htmlwriter",
"transformerTypes" : [
"linkrewriter"
],
"generator-htmlparser" : {
"jcr:primaryType" : "nt:unstructured",
"includeTags" : [
"A",
"/A"
]
}
}
}
}
import java.io.IOException;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.rewriter.ProcessingComponentConfiguration;
import org.apache.sling.rewriter.ProcessingContext;
import org.apache.sling.rewriter.Transformer;
import org.apache.sling.rewriter.TransformerFactory;
import org.osgi.service.component.ComponentContext;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@Component
@Service
@Property(name="pipeline.type", value="linkrewriter", propertyPrivate=true)
public class LinkRewriterTransformerFactory implements TransformerFactory {
public Transformer createTransformer() {
return new LinkRewriterTransformer();
}
@Activate
protected void activate(Map<String, Object> properties) {
}
@Deactivate
protected void deactivate(ComponentContext ctx) {
}
private class LinkRewriterTransformer implements Transformer {
private ContentHandler contentHandler;
public void characters(char[] ch, int start, int length) throws SAXException {
contentHandler.characters(ch, start, length);
}
public void dispose() {
}
public void endDocument() throws SAXException {
contentHandler.endDocument();
}
public void endElement(String uri, String localName, String qName)
throws SAXException {
contentHandler.endElement(uri, localName, qName);
}
public void endPrefixMapping(String prefix) throws SAXException {
contentHandler.endPrefixMapping(prefix);
}
public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException {
contentHandler.ignorableWhitespace(ch, start, length);
}
public void init(ProcessingContext context,
ProcessingComponentConfiguration config) throws IOException {
}
public void processingInstruction(String target, String data) throws SAXException {
contentHandler.processingInstruction(target, data);
}
public void setContentHandler(ContentHandler handler) {
this.contentHandler = handler;
}
public void setDocumentLocator(Locator locator) {
contentHandler.setDocumentLocator(locator);
}
public void skippedEntity(String name) throws SAXException {
contentHandler.skippedEntity(name);
}
public void startDocument() throws SAXException {
contentHandler.startDocument();
}
public void startElement(String uri, String localName, String
qName, Attributes atts) throws SAXException {
contentHandler.startElement(uri, localName, qName, atts);
// final AttributesImpl attributes = new AttributesImpl(atts);
// final String href = attributes.getValue("href");
// final boolean enableRewritePath = true;
//
// if (href != null && href.startsWith("/")) {
//
// for (int i = 0; i < attributes.getLength(); i++) {
// if ("href".equalsIgnoreCase(attributes.getQName(i))) {
// attributes.setValue(i, enableRewritePath ?
rewritePath(href) : href);
// }
// }
// }
//
// contentHandler.startElement(uri, localName, qName, attributes);
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
contentHandler.startPrefixMapping(prefix, uri);
}
private String rewritePath(final String href) {
return href.replace("/content", "");
}
}
}
Nate Yolles
2015-07-28 16:59:00 UTC
Permalink
Thank you Justin!

After changing the generatorType to ³html-generator² and the
SerializerType to ³html-serializer² everything worked great.

Are there other options for generator, serializer and transformer types?
If so, are there any docs that list all of the options?

Thanks again,

Nate
Post by Justin Edelson
Hi Nate,
IIUC, in Sling, you need to use "html-generator". "htmlparser" refers to an
AEM component.
See
https://github.com/apache/sling/blob/trunk/contrib/extensions/rewriter/src
/main/java/org/apache/sling/rewriter/impl/components/HtmlGeneratorFactory.
java
Regards,
Justin
Post by Nate Yolles
Hello,
I¹m trying to add a link rewriter into the pipeline but I¹m running into
some trouble. I¹ve done this in AEM/CQ a few times but this is the first
time I¹m attempting it in a pure Sling application. I¹m using
³org.apache.sling.launchpad-7-standalone.jar² with Sightly. When I try
to
load a page I get the error ³Unable to get component of class Œinterface
org.apache.sling.rewriter.Generator¹ with type Œhtmlparser¹.²
Any guidance would be appreciated.
Thank you!
28.07.2015 08:07:26.341 *ERROR* [0:0:0:0:0:0:0:1 [1438096046286] GET
/content/blog/index.html HTTP/1.1]
org.apache.sling.servlets.resolver.internal.SlingServletResolver Original
error class java.io.IOException
java.io.IOException: Unable to get component of class 'interface
org.apache.sling.rewriter.Generator' with type 'htmlparser'.
at
org.apache.sling.rewriter.impl.PipelineImpl.getPipelineComponent(Pipeline
Impl.java:160)
at
org.apache.sling.rewriter.impl.PipelineImpl.init(PipelineImpl.java:85)
at
org.apache.sling.rewriter.impl.ProcessorManagerImpl.getProcessor(Processo
rManagerImpl.java:445)
at
org.apache.sling.rewriter.impl.RewriterResponse.getProcessor(RewriterResp
onse.java:172)
at
org.apache.sling.rewriter.impl.RewriterResponse.getWriter(RewriterRespons
e.java:110)
at
org.apache.sling.scripting.core.impl.helper.OnDemandWriter.getWriter(OnDe
mandWriter.java:38)
at
org.apache.sling.scripting.core.impl.helper.OnDemandWriter.write(OnDemand
Writer.java:75)
at java.io.PrintWriter.write(PrintWriter.java:456)
at java.io.PrintWriter.write(PrintWriter.java:473)
at
libs.publick.pages.page.SightlyJava_html.render(SightlyJava_html.java:37)
I have a configuration node under
/apps/mysite/config/rewriter/linkrewriter along with
/apps/mysite/config/rewriter/linkrewriter/generator-htmlparser
{
"jcr:primaryType": "sling:Folder",
"rewriter" : {
"jcr:primaryType": "sling:Folder",
"linkrewriter" : {
"jcr:primaryType" : "nt:unstructured",
"contentTypes" : [
"text/html"
],
"enabled" : true,
"generatorType" : "htmlparser",
"order" : 1,
"paths" : [
"/content"
],
"serializerType" : "htmlwriter",
"transformerTypes" : [
"linkrewriter"
],
"generator-htmlparser" : {
"jcr:primaryType" : "nt:unstructured",
"includeTags" : [
"A",
"/A"
]
}
}
}
}
import java.io.IOException;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.rewriter.ProcessingComponentConfiguration;
import org.apache.sling.rewriter.ProcessingContext;
import org.apache.sling.rewriter.Transformer;
import org.apache.sling.rewriter.TransformerFactory;
import org.osgi.service.component.ComponentContext;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@Component
@Service
@Property(name="pipeline.type", value="linkrewriter",
propertyPrivate=true)
public class LinkRewriterTransformerFactory implements
TransformerFactory {
public Transformer createTransformer() {
return new LinkRewriterTransformer();
}
@Activate
protected void activate(Map<String, Object> properties) {
}
@Deactivate
protected void deactivate(ComponentContext ctx) {
}
private class LinkRewriterTransformer implements Transformer {
private ContentHandler contentHandler;
public void characters(char[] ch, int start, int length) throws SAXException {
contentHandler.characters(ch, start, length);
}
public void dispose() {
}
public void endDocument() throws SAXException {
contentHandler.endDocument();
}
public void endElement(String uri, String localName, String qName)
throws SAXException {
contentHandler.endElement(uri, localName, qName);
}
public void endPrefixMapping(String prefix) throws SAXException {
contentHandler.endPrefixMapping(prefix);
}
public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException {
contentHandler.ignorableWhitespace(ch, start, length);
}
public void init(ProcessingContext context,
ProcessingComponentConfiguration config) throws IOException {
}
public void processingInstruction(String target, String data)
throws SAXException {
contentHandler.processingInstruction(target, data);
}
public void setContentHandler(ContentHandler handler) {
this.contentHandler = handler;
}
public void setDocumentLocator(Locator locator) {
contentHandler.setDocumentLocator(locator);
}
public void skippedEntity(String name) throws SAXException {
contentHandler.skippedEntity(name);
}
public void startDocument() throws SAXException {
contentHandler.startDocument();
}
public void startElement(String uri, String localName, String
qName, Attributes atts) throws SAXException {
contentHandler.startElement(uri, localName, qName, atts);
// final AttributesImpl attributes = new
AttributesImpl(atts);
// final String href = attributes.getValue("href");
// final boolean enableRewritePath = true;
//
// if (href != null && href.startsWith("/")) {
//
// for (int i = 0; i < attributes.getLength(); i++) {
// if
("href".equalsIgnoreCase(attributes.getQName(i)))
{
// attributes.setValue(i, enableRewritePath ?
rewritePath(href) : href);
// }
// }
// }
//
// contentHandler.startElement(uri, localName, qName, attributes);
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
contentHandler.startPrefixMapping(prefix, uri);
}
private String rewritePath(final String href) {
return href.replace("/content", "");
}
}
}
Julian Sedding
2015-07-28 17:59:16 UTC
Permalink
Hi Nate

You can look in the webconsole at /system/console/status-Services and
use your browser search to find the string "pipeline.type". That will
point you to all kind of implementations. To fully understand what
each does, you may need to dive into the source.

Regards
Julian
Post by Nate Yolles
Thank you Justin!
After changing the generatorType to ³html-generator² and the
SerializerType to ³html-serializer² everything worked great.
Are there other options for generator, serializer and transformer types?
If so, are there any docs that list all of the options?
Thanks again,
Nate
Post by Justin Edelson
Hi Nate,
IIUC, in Sling, you need to use "html-generator". "htmlparser" refers to an
AEM component.
See
https://github.com/apache/sling/blob/trunk/contrib/extensions/rewriter/src
/main/java/org/apache/sling/rewriter/impl/components/HtmlGeneratorFactory.
java
Regards,
Justin
Post by Nate Yolles
Hello,
I¹m trying to add a link rewriter into the pipeline but I¹m running into
some trouble. I¹ve done this in AEM/CQ a few times but this is the first
time I¹m attempting it in a pure Sling application. I¹m using
³org.apache.sling.launchpad-7-standalone.jar² with Sightly. When I try
to
load a page I get the error ³Unable to get component of class Œinterface
org.apache.sling.rewriter.Generator¹ with type Œhtmlparser¹.²
Any guidance would be appreciated.
Thank you!
28.07.2015 08:07:26.341 *ERROR* [0:0:0:0:0:0:0:1 [1438096046286] GET
/content/blog/index.html HTTP/1.1]
org.apache.sling.servlets.resolver.internal.SlingServletResolver Original
error class java.io.IOException
java.io.IOException: Unable to get component of class 'interface
org.apache.sling.rewriter.Generator' with type 'htmlparser'.
at
org.apache.sling.rewriter.impl.PipelineImpl.getPipelineComponent(Pipeline
Impl.java:160)
at
org.apache.sling.rewriter.impl.PipelineImpl.init(PipelineImpl.java:85)
at
org.apache.sling.rewriter.impl.ProcessorManagerImpl.getProcessor(Processo
rManagerImpl.java:445)
at
org.apache.sling.rewriter.impl.RewriterResponse.getProcessor(RewriterResp
onse.java:172)
at
org.apache.sling.rewriter.impl.RewriterResponse.getWriter(RewriterRespons
e.java:110)
at
org.apache.sling.scripting.core.impl.helper.OnDemandWriter.getWriter(OnDe
mandWriter.java:38)
at
org.apache.sling.scripting.core.impl.helper.OnDemandWriter.write(OnDemand
Writer.java:75)
at java.io.PrintWriter.write(PrintWriter.java:456)
at java.io.PrintWriter.write(PrintWriter.java:473)
at
libs.publick.pages.page.SightlyJava_html.render(SightlyJava_html.java:37)
I have a configuration node under
/apps/mysite/config/rewriter/linkrewriter along with
/apps/mysite/config/rewriter/linkrewriter/generator-htmlparser
{
"jcr:primaryType": "sling:Folder",
"rewriter" : {
"jcr:primaryType": "sling:Folder",
"linkrewriter" : {
"jcr:primaryType" : "nt:unstructured",
"contentTypes" : [
"text/html"
],
"enabled" : true,
"generatorType" : "htmlparser",
"order" : 1,
"paths" : [
"/content"
],
"serializerType" : "htmlwriter",
"transformerTypes" : [
"linkrewriter"
],
"generator-htmlparser" : {
"jcr:primaryType" : "nt:unstructured",
"includeTags" : [
"A",
"/A"
]
}
}
}
}
import java.io.IOException;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.rewriter.ProcessingComponentConfiguration;
import org.apache.sling.rewriter.ProcessingContext;
import org.apache.sling.rewriter.Transformer;
import org.apache.sling.rewriter.TransformerFactory;
import org.osgi.service.component.ComponentContext;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@Component
@Service
@Property(name="pipeline.type", value="linkrewriter",
propertyPrivate=true)
public class LinkRewriterTransformerFactory implements
TransformerFactory {
public Transformer createTransformer() {
return new LinkRewriterTransformer();
}
@Activate
protected void activate(Map<String, Object> properties) {
}
@Deactivate
protected void deactivate(ComponentContext ctx) {
}
private class LinkRewriterTransformer implements Transformer {
private ContentHandler contentHandler;
public void characters(char[] ch, int start, int length) throws SAXException {
contentHandler.characters(ch, start, length);
}
public void dispose() {
}
public void endDocument() throws SAXException {
contentHandler.endDocument();
}
public void endElement(String uri, String localName, String qName)
throws SAXException {
contentHandler.endElement(uri, localName, qName);
}
public void endPrefixMapping(String prefix) throws SAXException {
contentHandler.endPrefixMapping(prefix);
}
public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException {
contentHandler.ignorableWhitespace(ch, start, length);
}
public void init(ProcessingContext context,
ProcessingComponentConfiguration config) throws IOException {
}
public void processingInstruction(String target, String data)
throws SAXException {
contentHandler.processingInstruction(target, data);
}
public void setContentHandler(ContentHandler handler) {
this.contentHandler = handler;
}
public void setDocumentLocator(Locator locator) {
contentHandler.setDocumentLocator(locator);
}
public void skippedEntity(String name) throws SAXException {
contentHandler.skippedEntity(name);
}
public void startDocument() throws SAXException {
contentHandler.startDocument();
}
public void startElement(String uri, String localName, String
qName, Attributes atts) throws SAXException {
contentHandler.startElement(uri, localName, qName, atts);
// final AttributesImpl attributes = new
AttributesImpl(atts);
// final String href = attributes.getValue("href");
// final boolean enableRewritePath = true;
//
// if (href != null && href.startsWith("/")) {
//
// for (int i = 0; i < attributes.getLength(); i++) {
// if
("href".equalsIgnoreCase(attributes.getQName(i)))
{
// attributes.setValue(i, enableRewritePath ?
rewritePath(href) : href);
// }
// }
// }
//
// contentHandler.startElement(uri, localName, qName, attributes);
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
contentHandler.startPrefixMapping(prefix, uri);
}
private String rewritePath(final String href) {
return href.replace("/content", "");
}
}
}
Nate Yolles
2015-08-12 01:50:45 UTC
Permalink
My Sling rewriter changes all HTML elements to full uppercase.

Before: <div><h1 class="page-header">Welcome</h1></div>

After: <DIV><H1 class="page-header">Welcome</H1></DIV>

Is there a way to prevent this?

Thank you,

Nate
Post by Justin Edelson
Hi Nate
You can look in the webconsole at /system/console/status-Services and
use your browser search to find the string "pipeline.type". That will
point you to all kind of implementations. To fully understand what
each does, you may need to dive into the source.
Regards
Julian
Post by Nate Yolles
Thank you Justin!
After changing the generatorType to ³html-generator² and the
SerializerType to ³html-serializer² everything worked great.
Are there other options for generator, serializer and transformer types?
If so, are there any docs that list all of the options?
Thanks again,
Nate
Post by Justin Edelson
Hi Nate,
IIUC, in Sling, you need to use "html-generator". "htmlparser" refers to an
AEM component.
See
https://github.com/apache/sling/blob/trunk/contrib/extensions/rewriter/s
rc
/main/java/org/apache/sling/rewriter/impl/components/HtmlGeneratorFactor
y.
java
Regards,
Justin
Post by Nate Yolles
Hello,
I¹m trying to add a link rewriter into the pipeline but I¹m running into
some trouble. I¹ve done this in AEM/CQ a few times but this is the first
time I¹m attempting it in a pure Sling application. I¹m using
³org.apache.sling.launchpad-7-standalone.jar² with Sightly. When I try
to
load a page I get the error ³Unable to get component of class Œinterface
org.apache.sling.rewriter.Generator¹ with type Œhtmlparser¹.²
Any guidance would be appreciated.
Thank you!
28.07.2015 08:07:26.341 *ERROR* [0:0:0:0:0:0:0:1 [1438096046286] GET
/content/blog/index.html HTTP/1.1]
org.apache.sling.servlets.resolver.internal.SlingServletResolver Original
error class java.io.IOException
java.io.IOException: Unable to get component of class 'interface
org.apache.sling.rewriter.Generator' with type 'htmlparser'.
at
org.apache.sling.rewriter.impl.PipelineImpl.getPipelineComponent(Pipeli
ne
Impl.java:160)
at
org.apache.sling.rewriter.impl.PipelineImpl.init(PipelineImpl.java:85)
at
org.apache.sling.rewriter.impl.ProcessorManagerImpl.getProcessor(Proces
so
rManagerImpl.java:445)
at
org.apache.sling.rewriter.impl.RewriterResponse.getProcessor(RewriterRe
sp
onse.java:172)
at
org.apache.sling.rewriter.impl.RewriterResponse.getWriter(RewriterRespo
ns
e.java:110)
at
org.apache.sling.scripting.core.impl.helper.OnDemandWriter.getWriter(On
De
mandWriter.java:38)
at
org.apache.sling.scripting.core.impl.helper.OnDemandWriter.write(OnDema
nd
Writer.java:75)
at java.io.PrintWriter.write(PrintWriter.java:456)
at java.io.PrintWriter.write(PrintWriter.java:473)
at
libs.publick.pages.page.SightlyJava_html.render(SightlyJava_html.java:3
7)
I have a configuration node under
/apps/mysite/config/rewriter/linkrewriter along with
/apps/mysite/config/rewriter/linkrewriter/generator-htmlparser
{
"jcr:primaryType": "sling:Folder",
"rewriter" : {
"jcr:primaryType": "sling:Folder",
"linkrewriter" : {
"jcr:primaryType" : "nt:unstructured",
"contentTypes" : [
"text/html"
],
"enabled" : true,
"generatorType" : "htmlparser",
"order" : 1,
"paths" : [
"/content"
],
"serializerType" : "htmlwriter",
"transformerTypes" : [
"linkrewriter"
],
"generator-htmlparser" : {
"jcr:primaryType" : "nt:unstructured",
"includeTags" : [
"A",
"/A"
]
}
}
}
}
import java.io.IOException;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.rewriter.ProcessingComponentConfiguration;
import org.apache.sling.rewriter.ProcessingContext;
import org.apache.sling.rewriter.Transformer;
import org.apache.sling.rewriter.TransformerFactory;
import org.osgi.service.component.ComponentContext;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@Component
@Service
@Property(name="pipeline.type", value="linkrewriter",
propertyPrivate=true)
public class LinkRewriterTransformerFactory implements
TransformerFactory {
public Transformer createTransformer() {
return new LinkRewriterTransformer();
}
@Activate
protected void activate(Map<String, Object> properties) {
}
@Deactivate
protected void deactivate(ComponentContext ctx) {
}
private class LinkRewriterTransformer implements Transformer {
private ContentHandler contentHandler;
public void characters(char[] ch, int start, int length)
throws
SAXException {
contentHandler.characters(ch, start, length);
}
public void dispose() {
}
public void endDocument() throws SAXException {
contentHandler.endDocument();
}
public void endElement(String uri, String localName, String qName)
throws SAXException {
contentHandler.endElement(uri, localName, qName);
}
public void endPrefixMapping(String prefix) throws
SAXException
{
contentHandler.endPrefixMapping(prefix);
}
public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException {
contentHandler.ignorableWhitespace(ch, start, length);
}
public void init(ProcessingContext context,
ProcessingComponentConfiguration config) throws IOException {
}
public void processingInstruction(String target, String data)
throws SAXException {
contentHandler.processingInstruction(target, data);
}
public void setContentHandler(ContentHandler handler) {
this.contentHandler = handler;
}
public void setDocumentLocator(Locator locator) {
contentHandler.setDocumentLocator(locator);
}
public void skippedEntity(String name) throws SAXException {
contentHandler.skippedEntity(name);
}
public void startDocument() throws SAXException {
contentHandler.startDocument();
}
public void startElement(String uri, String localName, String
qName, Attributes atts) throws SAXException {
contentHandler.startElement(uri, localName, qName, atts);
// final AttributesImpl attributes = new
AttributesImpl(atts);
// final String href = attributes.getValue("href");
// final boolean enableRewritePath = true;
//
// if (href != null && href.startsWith("/")) {
//
// for (int i = 0; i < attributes.getLength(); i++) {
// if
("href".equalsIgnoreCase(attributes.getQName(i)))
{
// attributes.setValue(i, enableRewritePath ?
rewritePath(href) : href);
// }
// }
// }
//
// contentHandler.startElement(uri, localName, qName, attributes);
}
public void startPrefixMapping(String prefix, String uri)
throws
SAXException {
contentHandler.startPrefixMapping(prefix, uri);
}
private String rewritePath(final String href) {
return href.replace("/content", "");
}
}
}
Loading...