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 On 7/28/15, 9:11 AM, "Justin Edelson" <[email protected]> wrote: >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 <[email protected]> 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(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" >> >> ] >> >> } >> >> } >> >> } >> >> } >> >> 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", ""); >> >> } >> >> } >> >> } >>
