String href = attrs.getValue(ATTRIBUTE_HREF);
if (href != null) {
Publication publication = getCurrentDocument().getPublication();
DocumentBuilder builder = publication.getDocumentBuilder();
try {
newAttrs = new AttributesImpl(attrs);
if (getLogger().isDebugEnabled()) {
getLogger().debug(this.indent + "href URL: [" + href + "]");
}
String context = this.request.getContextPath();
if (href.startsWith(context + "/" + publication.getId())) {
final String webappUrlWithQueryString = href.substring(context.length());
String webappUrlWithAnchor;
String queryString = null;
int queryStringIndex = webappUrlWithQueryString.indexOf("?");
if (queryStringIndex > -1) {
webappUrlWithAnchor = webappUrlWithQueryString.substring(0, queryStringIndex);
queryString = webappUrlWithQueryString.substring(queryStringIndex + 1);
}
else {
webappUrlWithAnchor = webappUrlWithQueryString;
}
String anchor = null;
String webappUrl = null;
int anchorIndex = webappUrlWithAnchor.indexOf("#");
if (anchorIndex > -1) {
webappUrl = webappUrlWithAnchor.substring(0, anchorIndex);
anchor = webappUrlWithAnchor.substring(anchorIndex + 1);
}
else {
webappUrl = webappUrlWithAnchor;
}
if (getLogger().isDebugEnabled()) {
getLogger().debug(this.indent + "webapp URL: [" + webappUrl + "]");
getLogger().debug(this.indent + "anchor: [" + anchor + "]");
}
if (builder.isDocument(publication, webappUrl)) {
Document targetDocument = builder.buildDocument(publication, webappUrl);
if (getLogger().isDebugEnabled()) {
getLogger().debug(this.indent + "Resolved target document: ["
+ targetDocument + "]");
}
String currentAreaUrl = builder.buildCanonicalUrl(publication,
getCurrentDocument().getArea(),
targetDocument.getId(),
targetDocument.getLanguage());
targetDocument = builder.buildDocument(publication, currentAreaUrl);
if (targetDocument.exists()) {
rewriteLink(newAttrs, targetDocument, anchor, queryString);
} else {
setIgnoreAElement(true);