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 On Tue, Jul 28, 2015 at 11:46 AM Nate Yolles <yol...@adobe.com> wrote: > 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", ""); > > } > > } > > } >