Even if the rewriter and Link Checker Transformer didn't work. I used a custom LinkRewriter by using the Transformer and TransformerFactory interfaces. I based on the sample from Adobe for my code. I worked out something like this:
@Component(
metatype = true,
label = "Image Link Rewriter",
description = "Maps the <img> elements src attributes"
)
@Service(value = TransformerFactory.class)
@Property(value = "global", propertyPrivate = true)
public class ImageLinkRewriter implements Transformer, TransformerFactory {
// some variables
public CustomLinkTransformer() { }
@Override
public void init(ProcessingContext context,
ProcessingComponentConfiguration config) throws IOException {
// initializations here
}
@Override
public final Transformer createTransformer() {
return new CustomLinkTransformer();
}
@Override
public void startElement(String uri, String localName,
String qName, Attributes atts) throws SAXException {
if ("img".equalsIgnoreCase(localName)) {
contentHandler.startElement(uri, localName, qName, rewriteImageLink(atts));
}
}
private Attributes rewriteImageLink(Attributes attrs) {
String attrName = "src";
AttributesImpl result = new AttributesImpl(attrs);
String link = attrs.getValue(attrName);
String mappedLink = resource.getResourceResolver().map(request, link);
result.setValue(result.getIndex(attrName), mappedLink);
return result;
}
}
Hope this helps others. Here are a few references:
<img>elements - khakiout