You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2006/03/20 16:49:23 UTC
svn commit: r387225 -
/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/LinkRewriterImpl.java
Author: andreas
Date: Mon Mar 20 07:49:22 2006
New Revision: 387225
URL: http://svn.apache.org/viewcvs?rev=387225&view=rev
Log:
Don't rewrite links if resource type doesn't provide any link rewriting XPaths. Don't swallow exceptions.
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/LinkRewriterImpl.java
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/LinkRewriterImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/LinkRewriterImpl.java?rev=387225&r1=387224&r2=387225&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/LinkRewriterImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/LinkRewriterImpl.java Mon Mar 20 07:49:22 2006
@@ -104,55 +104,56 @@
ResourceType doctype = examinedDocument.getResourceType();
String[] xPaths = doctype.getLinkAttributeXPaths();
- try {
- org.w3c.dom.Document xmlDocument = SourceUtil.readDOM(examinedDocument.getSourceURI(),
- this.manager);
-
- for (int xPathIndex = 0; xPathIndex < xPaths.length; xPathIndex++) {
- NodeList nodes = XPathAPI.selectNodeList(xmlDocument,
- xPaths[xPathIndex]);
- for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
- Node node = nodes.item(nodeIndex);
- if (node.getNodeType() != Node.ATTRIBUTE_NODE) {
- throw new RuntimeException("The XPath [" + xPaths[xPathIndex]
- + "] may only match attribute nodes!");
- }
- Attr attribute = (Attr) node;
- final String url = attribute.getValue();
+ if (xPaths.length > 0) {
+ try {
+ org.w3c.dom.Document xmlDocument = SourceUtil.readDOM(examinedDocument.getSourceURI(),
+ this.manager);
+
+ for (int xPathIndex = 0; xPathIndex < xPaths.length; xPathIndex++) {
+ NodeList nodes = XPathAPI.selectNodeList(xmlDocument,
+ xPaths[xPathIndex]);
+ for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
+ Node node = nodes.item(nodeIndex);
+ if (node.getNodeType() != Node.ATTRIBUTE_NODE) {
+ throw new RuntimeException("The XPath ["
+ + xPaths[xPathIndex]
+ + "] may only match attribute nodes!");
+ }
+ Attr attribute = (Attr) node;
+ final String url = attribute.getValue();
- if (url.startsWith(contextPath + "/" + publication.getId())) {
- final String webappUrl = url.substring(contextPath.length());
+ if (url.startsWith(contextPath + "/" + publication.getId())) {
+ final String webappUrl = url.substring(contextPath.length());
- if (identityMap.isDocument(webappUrl)) {
- Document targetDocument = identityMap.getFromURL(webappUrl);
+ if (identityMap.isDocument(webappUrl)) {
+ Document targetDocument = identityMap.getFromURL(webappUrl);
- if (matches(targetDocument, originalTargetDocument)) {
- String newTargetUrl = getNewTargetURL(targetDocument,
- originalTargetDocument,
- newTargetDocument);
- attribute.setValue(contextPath + newTargetUrl);
- linksRewritten = true;
+ if (matches(targetDocument, originalTargetDocument)) {
+ String newTargetUrl = getNewTargetURL(targetDocument,
+ originalTargetDocument,
+ newTargetDocument);
+ attribute.setValue(contextPath + newTargetUrl);
+ linksRewritten = true;
+ }
}
}
}
}
- }
- if (linksRewritten) {
- examinedDocument.getRepositoryNode().lock();
- SourceUtil.writeDOM(xmlDocument,
- examinedDocument.getSourceURI(),
- this.manager);
+ if (linksRewritten) {
+ examinedDocument.getRepositoryNode().lock();
+ SourceUtil.writeDOM(xmlDocument,
+ examinedDocument.getSourceURI(),
+ this.manager);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
- } catch (SAXParseException e) {
- getLogger().warn("Document [" + examinedDocument
- + "] is not XML and will be ignored!");
- } catch (Exception e) {
- getLogger().error(e.getMessage(), e);
- } finally {
}
+
} else {
- getLogger().warn("No such document: " + examinedDocument.getSourceURI());
+ throw new RuntimeException("No such document: [" + examinedDocument
+ + "] - source URI: [" + examinedDocument.getSourceURI() + "]");
}
}
} catch (final Exception e) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org