You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by ch...@apache.org on 2005/10/13 21:32:02 UTC

svn commit: r320885 - in /lenya/trunk/src: java/org/apache/lenya/cms/cocoon/transformation/LinkRewritingTransformer.java webapp/lenya/pubs/default/resources/shared/css/page.css

Author: chestnut
Date: Thu Oct 13 12:31:54 2005
New Revision: 320885

URL: http://svn.apache.org/viewcvs?rev=320885&view=rev
Log:
added warning|alert for broken internal links in the authoring area so that content managers know there is something to fix

Modified:
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/LinkRewritingTransformer.java
    lenya/trunk/src/webapp/lenya/pubs/default/resources/shared/css/page.css

Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/LinkRewritingTransformer.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/LinkRewritingTransformer.java?rev=320885&r1=320884&r2=320885&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/LinkRewritingTransformer.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/transformation/LinkRewritingTransformer.java Thu Oct 13 12:31:54 2005
@@ -68,14 +68,19 @@
  * <ul>
  * <li>The area is replaced by the current area (obtained from the page envelope).</li>
  * <li>A URL prefix is added depending on the proxy configuration of the publication.</li>
- * <li>If the target document does not exist, the <code>&lt;a/&gt;</code> element is removed to
- * disable the link.</li>
+ * <li>If the target document does not exist and is in the authoring area, the href attribute is 
+ * removed and a class="brokenlink" attribute is added to the <code>&lt;a/&gt;</code> element</li>
+ * <li>If the target document does not exist and is in the live area, the <code>&lt;a/&gt;</code> 
+ * element is removed to disable the link.</li>
  * </ul>
  * 
  * $Id: LinkRewritingTransformer.java,v 1.7 2004/03/16 11:12:16 gregor
  */
 public class LinkRewritingTransformer extends AbstractSAXTransformer implements Disposable {
 
+    protected static final String BROKEN_ATTRIB = "class";
+    protected static final String BROKEN_VALUE = "brokenlink";
+    
     private boolean ignoreAElement = false;
     private ServiceSelector serviceSelector;
     private PolicyManager policyManager;
@@ -239,6 +244,8 @@
 
                             if (targetDocument.exists()) {
                                 rewriteLink(newAttrs, targetDocument, anchor, queryString);
+                            } else if (getCurrentDocument().getArea().equals(Publication.AUTHORING_AREA)) {
+                                markBrokenLink(newAttrs, href);
                             } else {
                                 this.ignoreAElement = true;
                             }
@@ -271,6 +278,25 @@
                 getLogger().debug(this.indent + "<" + qname + "> sent");
             }
         }
+    }
+    
+    /**
+     * Marks a <code>&lt;a/&gt;</code> element as broken and removes href attribute.
+     * 
+     * @param newAttrs The new attributes.
+     * @throws AccessControlException when something went wrong.
+     */
+    protected void markBrokenLink(AttributesImpl newAttrs, String brokenHref)
+            throws AccessControlException {
+        if(newAttrs.getIndex(BROKEN_ATTRIB) > -1)
+            newAttrs.removeAttribute(newAttrs.getIndex(BROKEN_ATTRIB));
+        if(newAttrs.getIndex("title") > -1)
+            newAttrs.removeAttribute(newAttrs.getIndex("title"));
+        if(newAttrs.getIndex("href") > -1)
+            newAttrs.setAttribute(newAttrs.getIndex("href"),"","href","href","CDATA","");
+        String warning = "Broken Link: " + brokenHref;
+        newAttrs.addAttribute("","title","title","CDATA",warning);
+        newAttrs.addAttribute("",BROKEN_ATTRIB,BROKEN_ATTRIB,"CDATA",BROKEN_VALUE);
     }
 
     /**

Modified: lenya/trunk/src/webapp/lenya/pubs/default/resources/shared/css/page.css
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/resources/shared/css/page.css?rev=320885&r1=320884&r2=320885&view=diff
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/resources/shared/css/page.css (original)
+++ lenya/trunk/src/webapp/lenya/pubs/default/resources/shared/css/page.css Thu Oct 13 12:31:54 2005
@@ -333,3 +333,9 @@
 	font-size: small;
 }
 
+/* Broken Internal Links in Authoring area */
+a.brokenlink {
+    background-color: yellow;
+    border: 1px dashed #000000;
+    text-decoration: none;
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org