svn commit: r575290 - in /lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms: cocoon/components/source/impl/ content/ publication/

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: solprovider
Date: Thu Sep 13 05:37:05 2007
New Revision: 575290

URL: http://svn.apache.org/viewvc?rev=575290&view=rev
Log:
Merged last year's changes.

Modified:
    lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/ContentSourceFactory.java
    lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/ModuleSourceFactory.java
    lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/StringSource.java
    lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/VirtualSourceFactory.java
    lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java
    lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
    lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DefaultDocument.java

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/ContentSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/ContentSourceFactory.java?rev=575290&r1=575289&r2=575290&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/ContentSourceFactory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/ContentSourceFactory.java Thu Sep 13 05:37:05 2007
@@ -1,6 +1,5 @@
 package org.apache.lenya.cms.cocoon.components.source.impl;
 
-import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.util.Map;
@@ -24,23 +23,24 @@
 import org.apache.lenya.cms.publication.PageEnvelope;
 import org.apache.lenya.cms.publication.PageEnvelopeFactory;
 import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationFactory;
 import org.w3c.dom.Document;
 
 /**
- * Implements content: protocol. This should call the Content API that calls a
- * Content Impl.
- *  == Content API == Source getResourceByUNID(String unid, String translation,
- * String revision) Source getResourceByID(String structure, String id, String
- * translation, String revision)
- *  == Content Impls == ContentHierarchical (Lenya 1.2) ContentFlat (Lenya 1.3)
+ * Implements content: protocol. <BR>
+ * This should call the Content API that calls a Content Impl. <BR>
+ * <BR>== Content API == <BR>
+ * Source getResourceByUNID(String unid, String translation, String revision) <BR>
+ * Source getResourceByID(String structure, String id, String translation, String revision) <BR>
+ * <BR>== Content Impls == <BR>
+ * ContentHierarchical (Lenya 1.2) <BR>
+ * ContentFlat (Lenya 1.3)
  */
 public class ContentSourceFactory implements SourceFactory, ThreadSafe, URIAbsolutizer, Contextualizable {
     private static final int REQUEST_DATA = 0;
     private static final int REQUEST_META = 1;
     private static final int REQUEST_INFO = 2;
     protected org.apache.avalon.framework.context.Context context;
-    private String servletContextPath;
+    // private String servletContextPath;
     String pubsPrefix;
     DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
     SourceResolver resolver = null;
@@ -50,53 +50,50 @@
     public Source getSource(String plocation, Map parameters) throws IOException, MalformedURLException {
         String location = plocation;
         int pos;
-        Map contextmap = ContextHelper.getObjectModel(context);
-        org.apache.cocoon.environment.http.HttpContext httpcontext = (org.apache.cocoon.environment.http.HttpContext) contextmap.get("context");
-        servletContextPath = httpcontext.getRealPath("");
-        // TODO: Move resolver, pubsPrefix and other init out of getSource(). Make
-        // static?
+        // Map contextmap = ContextHelper.getObjectModel(context);
+        // org.apache.cocoon.environment.http.HttpContext httpcontext = (org.apache.cocoon.environment.http.HttpContext) contextmap.get("context");
+        // servletContextPath = httpcontext.getRealPath("");
+        // TODO: Move resolver, pubsPrefix and other init out of getSource(). Make static?
         ComponentManager manager = CocoonComponentManager.getSitemapComponentManager();
-        try {
+        try{
             resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
-        } catch (org.apache.avalon.framework.component.ComponentException ce) {
-        }
-        if (null == resolver) {
-            throw new SourceNotFoundException("No Resolver: " + plocation);
+        }catch(org.apache.avalon.framework.component.ComponentException ce){
         }
+        if(null == resolver){ throw new SourceNotFoundException("No Resolver: " + plocation); }
         String uri = resolver.resolveURI("").getURI();
         pos = uri.indexOf("/pubs/");
-        if (pos > 0) {
+        if(pos > 0){
             pubsPrefix = uri.substring(0, pos + 6);
-        } else {
+        }else{
             pos = uri.indexOf("/modules/");
-            if (pos > 0) {
+            if(pos > 0){
                 pubsPrefix = uri.substring(0, pos) + "/pubs/";
             }
         }
-        String publication;
-        String contentpath;
+        // String publication;
+        // String contentpath;
         Publication pub;
         Content content;
-        try {
+        try{
             PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(ContextHelper.getObjectModel(context));
             pub = envelope.getPublication();
-            publication = pub.getId();
+            // publication = pub.getId();
             content = pub.getContent();
-            contentpath = pub.getContentDirectory().getAbsolutePath() + File.separator;
-        } catch (org.apache.lenya.cms.publication.PageEnvelopeException pee) {
+            // contentpath = pub.getContentDirectory().getAbsolutePath() + File.separator;
+        }catch(org.apache.lenya.cms.publication.PageEnvelopeException pee){
             throw new MalformedURLException("Could not get Publication ID.");
         }
         // Revision
         String revision = "live";
         pos = location.lastIndexOf("!");
-        if (pos != -1) {
+        if(pos != -1){
             revision = location.substring(pos + 1);
             location = location.substring(0, pos);
         }
         // Language
         String language = "";
         pos = location.lastIndexOf("_");
-        if (pos != -1) {
+        if(pos != -1){
             language = location.substring(pos + 1);
             location = location.substring(0, pos);
         }
@@ -104,38 +101,35 @@
         // System.out.println("LOC="+location);
         // Decide Usage
         StringTokenizer tokens = new StringTokenizer(location, "/:", true);
-        if (!tokens.hasMoreTokens())
-            throw new MalformedURLException("Nothing specified.");
+        if(!tokens.hasMoreTokens()) throw new MalformedURLException("Nothing specified.");
         String token = tokens.nextToken();
-        if (location.indexOf(":") > 0)
-            token = tokens.nextToken(); // Remove
-        // protocol
+        if(location.indexOf(":") > 0) token = tokens.nextToken(); // Remove protocol
         int colonCount = 0;
-        while (token.equals(":")) {
+        while(token.equals(":")){
             colonCount++;
             token = tokens.nextToken();
         }
         int slashCount = 0;
-        while (token.equals("/")) {
+        while(token.equals("/")){
             slashCount++;
             token = tokens.nextToken();
         }
         int requestType = colonCount - 1;
         boolean isFormat2 = false;
-        if (token.equals("DATA")) {
+        if(token.equals("DATA")){
             requestType = REQUEST_DATA;
             isFormat2 = true;
-        } else if (token.equals("META")) {
+        }else if(token.equals("META")){
             requestType = REQUEST_META;
             isFormat2 = true;
-        } else if (token.equals("INFO")) {
+        }else if(token.equals("INFO")){
             requestType = REQUEST_INFO;
             isFormat2 = true;
         }
-        if (isFormat2) {
+        if(isFormat2){
             token = tokens.nextToken();
             int slashCount2 = 0;
-            while (token.equals("/")) {
+            while(token.equals("/")){
                 slashCount2++;
                 token = tokens.nextToken();
             }
@@ -145,67 +139,58 @@
         String structure = "";
         String unid = "";
         String fullid = "";
-        if (slashCount == 1) {
-            if (tokens.hasMoreTokens()) {
+        if(slashCount == 1){
+            if(tokens.hasMoreTokens()){
                 slashCount = 0;
-            } else unid = token;
+            }else unid = token;
         }
-        if ((slashCount == 0) || (slashCount == 2)) {
+        if((slashCount == 0) || (slashCount == 2)){
             structure = token;
         }
-        if ((slashCount == 0) || (slashCount == 2) || (slashCount == 3)) {
+        if((slashCount == 0) || (slashCount == 2) || (slashCount == 3)){
             StringBuffer buffer = new StringBuffer();
-            while (tokens.hasMoreTokens())
+            while(tokens.hasMoreTokens())
                 buffer.append(tokens.nextToken());
             fullid = buffer.toString();
         }
         // Convert fullid to unid
-        if (unid.length() < 1) {
+        if(unid.length() < 1){
             unid = content.getUNID(structure, fullid);
         }
         // Defaults
-        if (language.length() < 1) {
+        if(language.length() < 1){
             Resource resource = content.getResource(unid);
-            if (resource != null)
-                language = resource.getDefaultLanguage();
+            if(resource != null) language = resource.getDefaultLanguage();
         }
-        if (language.length() < 1)
-            language = pub.getDefaultLanguage();
+        if(language.length() < 1) language = pub.getDefaultLanguage();
         /** ******** Get Source (uses Content) ************ */
         Source source;
-        if (REQUEST_INFO == requestType) {
+        if(REQUEST_INFO == requestType){
             // TODO: Catch errors
             Resource resource = content.getResource(unid);
-            if (resource == null)
-                System.out.println("NO RESOURCE");
+            if(resource == null) System.out.println("NO RESOURCE");
             Document doc = resource.getInfoDocument();
-            if (doc == null)
-                System.out.println("NO DOC");
+            if(doc == null) System.out.println("NO DOC");
             source = new StringSource(manager, doc);
-            if (source == null)
-                System.out.println("NO SOURCE");
+            if(source == null) System.out.println("NO SOURCE");
             return source;
         }
-        if (REQUEST_META == requestType) {
+        if(REQUEST_META == requestType){
             source = resolver.resolveURI(content.getMetaURI(unid, language, revision));
-            if (source.exists()) {
-                if (resolver != null)
-                    manager.release((Component) resolver);
+            if(source.exists()){
+                if(resolver != null) manager.release((Component) resolver);
                 return source;
             }
         }
-        // System.out.println("CSF UNID=" + unid + " LANG=" + language + " REV=" +
-        // revision);
+        // System.out.println("CSF UNID=" + unid + " LANG=" + language + " REV=" + revision);
         String curi = content.getURI(unid, language, revision);
         // System.out.println("CSF CURI=" + curi);
         source = resolver.resolveURI(curi);
-        if (source.exists()) {
-            if (resolver != null)
-                manager.release((Component) resolver);
+        if(source.exists()){
+            if(resolver != null) manager.release((Component) resolver);
             return source;
         }
-        if (resolver != null)
-            manager.release((Component) resolver);
+        if(resolver != null) manager.release((Component) resolver);
         throw new SourceNotFoundException("Not found: " + plocation + " (" + curi + ")");
     }
     public void release(Source source1) {
@@ -213,11 +198,11 @@
     public String absolutize(String baseURI, String location) {
         return SourceUtil.absolutize(baseURI, location, false, false);
     }
-    private Publication getPublication(String publication) {
-        try {
-            return PublicationFactory.getPublication(publication, servletContextPath);
-        } catch (org.apache.lenya.cms.publication.PublicationException pe) {
-            return (Publication) null;
-        }
-    }
+    // private Publication getPublication(String publication) {
+    // try{
+    // return PublicationFactory.getPublication(publication, servletContextPath);
+    // }catch(org.apache.lenya.cms.publication.PublicationException pe){
+    // return (Publication) null;
+    // }
+    // }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/ModuleSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/ModuleSourceFactory.java?rev=575290&r1=575289&r2=575290&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/ModuleSourceFactory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/ModuleSourceFactory.java Thu Sep 13 05:37:05 2007
@@ -34,9 +34,7 @@
     String pubsPrefix;
     String globalPrefix;
     private Set publications = new HashSet(); // Publications checked
-    static private Map moduleInheritance = new HashMap(); // Key={publication,
-    // module} Value =
-    // Next publication
+    static private Map moduleInheritance = new HashMap(); // Key={publication, module} Value = Next publication
     public void contextualize(org.apache.avalon.framework.context.Context context) throws ContextException {
         this.context = context;
     }
@@ -48,11 +46,11 @@
         servletContextPath = httpcontext.getRealPath("");
         SourceResolver resolver = null;
         ComponentManager manager = CocoonComponentManager.getSitemapComponentManager();
-        try {
+        try{
             resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
-        } catch (org.apache.avalon.framework.component.ComponentException ce) {
+        }catch(org.apache.avalon.framework.component.ComponentException ce){
         }
-        if (null == resolver) {
+        if(null == resolver){
             System.out.println("ModuleSourceFactory ComponentException");
             return new FileSource(location);
         }
@@ -60,11 +58,11 @@
         StringTokenizer tokens = new StringTokenizer(uri, "/\\:", true);
         StringBuffer buffer = new StringBuffer();
         boolean done = false;
-        while (tokens.hasMoreTokens() & !done) {
+        while(tokens.hasMoreTokens() & !done){
             String token = tokens.nextToken();
-            if (token.equalsIgnoreCase("pubs") | token.equalsIgnoreCase("modules")) {
+            if(token.equalsIgnoreCase("pubs") | token.equalsIgnoreCase("modules")){
                 done = true;
-            } else buffer.append(token);
+            }else buffer.append(token);
         }
         String tmpPrefix = buffer.toString();
         globalPrefix = tmpPrefix + "modules" + File.separator;
@@ -72,18 +70,17 @@
         String publication;
         Modules modules;
         publications.clear();
-        try {
+        try{
             PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(ContextHelper.getObjectModel(context));
             Publication pub = envelope.getPublication();
             publication = pub.getId();
             modules = pub.getModules();
-        } catch (org.apache.lenya.cms.publication.PageEnvelopeException pee) {
+        }catch(org.apache.lenya.cms.publication.PageEnvelopeException pee){
             throw new MalformedURLException("ModuleSourceFactory PageEnvelopeException. Could not get Publication.");
         }
         // Reset moduleInheritance
         pos = location.indexOf("::");
-        if (pos != -1)
-            moduleInheritance.clear();
+        if(pos != -1) moduleInheritance.clear();
         // Decide Usage
         pos = location.indexOf(":///");
         int endpos;
@@ -93,106 +90,96 @@
         // If filepath has a default, the second attempt will error.
         // Not having the default destroys Flow:
         // source = resolver.resolveURI("cocoon:/pipeline");
-        // var is = new
-        // Packages.org.xml.sax.InputSource(source.getInputStream());
+        // var is = new Packages.org.xml.sax.InputSource(source.getInputStream());
         // This errors.
         // Every Module must have a module.xmap (even if it is empty)!
         // String filepath = "";
         String filepath = "module.xmap";
-        if (pos != -1) {
+        if(pos != -1){
             // module:/filepath/filename.ext
             // Get current Module ID
             filepath = location.substring(pos + 4);
-        } else {
+        }else{
             pos = location.indexOf("://");
-            if (pos != -1) {
+            if(pos != -1){
                 // module://modulename/filepath/filename.ext
                 pos += 3;
                 endpos = location.indexOf("/", pos + 1);
-                if (endpos > 0) {
+                if(endpos > 0){
                     module = location.substring(pos, endpos);
                     filepath = location.substring(endpos + 1);
                     // System.out.println("MSF MOD=" + module + " FIL=" + filepath);
-                } else {
+                }else{
                     module = location.substring(pos);
                     // System.out.println("MSF MOD=" + module + " POS=" + pos);
                 }
-            } else {
+            }else{
                 pos = location.indexOf(":/");
-                if (pos != -1) {
+                if(pos != -1){
                     // module:///publication/modulename/filepath/filename.ext
                     pos += 2;
                     endpos = location.indexOf("/", pos);
-                    if (endpos > 0) {
+                    if(endpos > 0){
                         publication = location.substring(pos, endpos);
                         pos = endpos + 1;
                         endpos = location.indexOf("/", pos);
-                        if (endpos > 0) {
+                        if(endpos > 0){
                             module = location.substring(pos, endpos);
                             filepath = location.substring(endpos + 1);
-                        } else {
+                        }else{
                             module = location.substring(pos);
                         }
-                    } else {
+                    }else{
                         publication = location.substring(pos);
                     }
-                } else {
+                }else{
                     // /filepath/filename.ext (Default protocol)
                     filepath = location;
                 }
             }
         }
         // Verify
-        if (publication.length() < 1)
-            throw new MalformedURLException("No Publication ID found.");
-        if (module.length() < 1)
-            module = getModuleID(uri);
+        if(publication.length() < 1) throw new MalformedURLException("No Publication ID found.");
+        if(module.length() < 1) module = getModuleID(uri);
         // BUG ALERT: See descrption above about no default
-        if (filepath.length() < 1)
-            filepath = "module.xmap";
+        if(filepath.length() < 1) filepath = "module.xmap";
         // Check current publication
-        if (!modules.isAllowed(module))
-            throw new SourceNotFoundException("Not allowed: " + publication + "/" + module + "/" + filepath);
+        if(!modules.isAllowed(module)) throw new SourceNotFoundException("Not allowed: " + publication + "/" + module + "/" + filepath);
         /** ******** Get Source ************ */
         // String newpath;
         String newlocation = pubsPrefix + publication + File.separator + "modules" + File.separator + module + File.separator + filepath;
         // Check if exists locally. Yes = done.
-        try {
+        try{
             Source source = resolver.resolveURI(newlocation);
-            if (source.exists()) {
-                if (resolver != null)
-                    manager.release((Component) resolver);
+            if(source.exists()){
+                if(resolver != null) manager.release((Component) resolver);
                 return source;
             }
-        } catch (java.net.MalformedURLException mue2) {
-        } catch (java.io.IOException ioe1) {
+        }catch(java.net.MalformedURLException mue2){
+        }catch(java.io.IOException ioe1){
         }
         publications.add(publication);
         // Check inherited publication(s)
-        if (null != modules) {
+        if(null != modules){
             Source ret = getInheritedSource(publication, module, filepath, modules.getTemplates(module), parameters, resolver);
-            if (null != ret) {
-                if (resolver != null)
-                    manager.release((Component) resolver);
+            if(null != ret){
+                if(resolver != null) manager.release((Component) resolver);
                 return ret;
             }
         }
         // Check global
         newlocation = globalPrefix + module + File.separator + filepath;
-        try {
+        try{
             Source source = resolver.resolveURI(newlocation);
-            if (source.exists()) {
-                if (resolver != null)
-                    manager.release((Component) resolver);
+            if(source.exists()){
+                if(resolver != null) manager.release((Component) resolver);
                 return source;
             }
-        } catch (java.net.MalformedURLException mue2) {
-        } catch (java.io.IOException ioe1) {
+        }catch(java.net.MalformedURLException mue2){
+        }catch(java.io.IOException ioe1){
         }
-        if (resolver != null)
-            manager.release((Component) resolver);
-        // System.out.println("Not found: " + publication + "/" + module + "/" +
-        // filepath);
+        if(resolver != null) manager.release((Component) resolver);
+        // System.out.println("Not found: " + publication + "/" + module + "/" +filepath);
         throw new SourceNotFoundException("Not found: " + publication + "/" + module + "/" + filepath);
     }
     public void release(Source source1) {
@@ -203,12 +190,12 @@
     private String getModuleID(String uri) throws MalformedURLException {
         String module = "";
         int pos = uri.indexOf("modules/");
-        if (pos > -1) {
+        if(pos > -1){
             pos += "modules/".length();
             int endpos = uri.indexOf("/", pos);
-            if (endpos > -1) {
+            if(endpos > -1){
                 module = uri.substring(pos, endpos);
-            } else module = uri.substring(pos);
+            }else module = uri.substring(pos);
         }
         return module;
     }
@@ -219,54 +206,50 @@
         Modules modules = (Modules) null;
         String key = publication + "~" + module;
         String newpublication = "";
-        if (moduleInheritance.containsKey(key)) {
+        if(moduleInheritance.containsKey(key)){
             newpublication = (String) moduleInheritance.get(key);
             Publication pub = getPublication(newpublication);
             modules = pub.getModules();
             found = true;
             publications.add(templates[i]);
-        } else {
-            while (!found & (i < templates.length)) {
+        }else{
+            while(!found & (i < templates.length)){
                 newpublication = templates[i];
                 // Do not repeat publication
-                if (!publications.contains(newpublication)) {
+                if(!publications.contains(newpublication)){
                     modules = (Modules) null;
                     Publication pub = getPublication(newpublication);
-                    if (null != pub) {
+                    if(null != pub){
                         modules = pub.getModules();
-                        if (modules.isAllowed(module))
-                            found = true;
+                        if(modules.isAllowed(module)) found = true;
                     }
                     publications.add(newpublication);
                 }
                 i++;
             }
         }
-        if (found) {
+        if(found){
             moduleInheritance.put(key, newpublication);
             String newlocation = pubsPrefix + newpublication + File.separator + "modules" + File.separator + module + File.separator + filepath;
-            try {
+            try{
                 Source source = resolver.resolveURI(newlocation);
-                if (source.exists()) {
-                    return source;
-                }
-            } catch (java.net.MalformedURLException mue2) {
-            } catch (java.io.IOException ioe1) {
+                if(source.exists()){ return source; }
+            }catch(java.net.MalformedURLException mue2){
+            }catch(java.io.IOException ioe1){
             }
-            if (null != modules) {
+            if(null != modules){
                 // First check if module name was overridden
                 Source ret = getInheritedSource(newpublication, modules.getInheritedModule(module), filepath, modules.getTemplates(module), parameters, resolver);
-                if (null != ret)
-                    return ret;
+                if(null != ret) return ret;
                 return getInheritedSource(newpublication, module, filepath, modules.getTemplates(module), parameters, resolver);
             }
         }
         return (Source) null;
     }
     private Publication getPublication(String publication) {
-        try {
+        try{
             return PublicationFactory.getPublication(publication, servletContextPath);
-        } catch (org.apache.lenya.cms.publication.PublicationException pe) {
+        }catch(org.apache.lenya.cms.publication.PublicationException pe){
             return (Publication) null;
         }
     }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/StringSource.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/StringSource.java?rev=575290&r1=575289&r2=575290&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/StringSource.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/StringSource.java Thu Sep 13 05:37:05 2007
@@ -1,86 +1,87 @@
 package org.apache.lenya.cms.cocoon.components.source.impl;
 
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.ByteArrayInputStream;
-import java.util.Map;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.cocoon.xml.dom.DOMStreamer;
 import org.apache.excalibur.source.SourceException;
 import org.apache.excalibur.source.impl.AbstractSource;
 import org.apache.excalibur.xml.sax.XMLizable;
-import org.apache.cocoon.serialization.XMLSerializer;
-import org.apache.cocoon.xml.dom.DOMStreamer;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.ComponentSelector;
 
 /**
- * Creates a Source from a String, Document, Node, or XMLizable.
- * 
- * If a String does not start with "<", it is wrapped with <text> tags.
- * If a String does not start with "<?xml", an XML header is added.
+ * Creates a Source from a String, Document, Node, or XMLizable. If a String does not start with "<", it is wrapped with <text> tags. If a String does not start with "<?xml", an XML header is added.
  */
-
 public class StringSource extends AbstractSource {
     final static private String ENCODING = "ISO-8859-1";
     private Object inputObject;
     private boolean exists = true;
-    private ComponentManager manager;
-
-    public StringSource(ComponentManager mgr, Object object){
-       manager = mgr;
-       inputObject = object;
+    // private ComponentManager manager;
+    public StringSource(ComponentManager mgr, Object object) {
+        // manager = mgr;
+        inputObject = object;
     }
-    
     /**
      * Implement this method to obtain SAX events.
      */
     public void toSAX(ContentHandler handler) throws SAXException {
-        if (inputObject instanceof Document ) {
-            DOMStreamer domStreamer = new DOMStreamer( handler );
-            domStreamer.stream( (Document)inputObject );
-        } else if(inputObject instanceof Node ) {
-            DOMStreamer domStreamer = new DOMStreamer( handler );
+        /* 
+         * domStreamer.setNormalizeNamespaces(false) is necessary because the default true will "normalize" namespaces.
+         * The effect is to remove:
+         *    xmlns:xhtml="http://www.w3.org/1999/xhtml"
+         * It does not remove:
+         *    xhtml:dummy="FIXME:keepNamespace"
+         * causing the error:
+         *   The prefix "xhtml" for attribute "xhtml:dummy" associated with an element type "html" is not bound.
+         * which some people may find annoying.
+         */
+        if (inputObject instanceof Document) {
+            DOMStreamer domStreamer = new DOMStreamer(handler);
+            domStreamer.setNormalizeNamespaces(false);
+            domStreamer.stream((Document) inputObject);
+        } else if (inputObject instanceof Node) {
+            DOMStreamer domStreamer = new DOMStreamer(handler);
+            domStreamer.setNormalizeNamespaces(false);
             handler.startDocument();
-            domStreamer.stream( (Node)inputObject );
+            domStreamer.stream((Node) inputObject);
             handler.endDocument();
-        } else if(inputObject instanceof XMLizable ) {
-            ((XMLizable)inputObject).toSAX( handler );
+        } else if (inputObject instanceof XMLizable) {
+            ((XMLizable) inputObject).toSAX(handler);
         } else {
             exists = false;
-            throw new SAXException("The " + inputObject.getClass() +" could not be serialized to XML.");
+            throw new SAXException("The " + inputObject.getClass() + " could not be serialized to XML.");
         }
     }
-
     /**
      * Return an <code>InputStream</code> object to read from the source.
-     *
      * @throws IOException if I/O error occured.
      */
     public InputStream getInputStream() throws IOException, SourceException {
         ByteArrayInputStream inputStream = null;
-        if (inputObject instanceof String){
-           String temp = (String) inputObject;
-           if(!temp.startsWith("<")) temp="<text>" + temp + "</text>";
-           if(!temp.startsWith("<?xml")) temp = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + temp;
-           inputStream = new ByteArrayInputStream(temp.getBytes(ENCODING));
-        }else{
-           // Serialize the SAX events to the XMLSerializer:
-           ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-           try{
-org.apache.xml.serialize.OutputFormat format = new org.apache.xml.serialize.OutputFormat("xml", "UTF-8", true);
-org.apache.xml.serialize.XMLSerializer serializer = new org.apache.xml.serialize.XMLSerializer(outputStream, format);
-              toSAX( serializer );
-              inputStream = new ByteArrayInputStream(outputStream.toByteArray());
-           }catch(SAXException se){
-              exists = false;
-              throw new SourceException("Could not serialize to a ByteArray.", se );
-           }
+        if (inputObject instanceof String) {
+            String temp = (String) inputObject;
+            if (!temp.startsWith("<"))
+                temp = "<text>" + temp + "</text>";
+            if (!temp.startsWith("<?xml"))
+                temp = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + temp;
+            inputStream = new ByteArrayInputStream(temp.getBytes(ENCODING));
+        } else {
+            // Serialize the SAX events to the XMLSerializer:
+            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+            try {
+                org.apache.xml.serialize.OutputFormat format = new org.apache.xml.serialize.OutputFormat("xml", "UTF-8", true);
+                org.apache.xml.serialize.XMLSerializer serializer = new org.apache.xml.serialize.XMLSerializer(outputStream, format);
+                toSAX(serializer);
+                inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+            } catch (SAXException se) {
+                exists = false;
+                throw new SourceException("Could not serialize to a ByteArray.", se);
+            }
         }
         return inputStream;
     }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/VirtualSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/VirtualSourceFactory.java?rev=575290&r1=575289&r2=575290&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/VirtualSourceFactory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/components/source/impl/VirtualSourceFactory.java Thu Sep 13 05:37:05 2007
@@ -11,31 +11,44 @@
 public class VirtualSourceFactory implements SourceFactory, ThreadSafe {
     static private Map sources = new HashMap();
     static private Random random = new Random();
-
-    public Source getSource(String plocation, Map parameters) throws SourceNotFoundException{
-       String location = plocation;
-//System.out.println("VS LOC=" + location);
-       int pos = location.lastIndexOf("/");
-       if((pos > -1) && (pos + 1 < location.length())) location = location.substring(pos + 1);
-       pos = location.lastIndexOf(":");
-       if((pos > -1) && (pos + 1 < location.length())) location = location.substring(pos + 1);
-       if(sources.containsKey(location)) return (Source) sources.get(location);
-       throw new SourceNotFoundException("VirtualSource not found: " + location);
-    }
-    public void release(Source source1){
-    }
-//TODO: synchronize
-   static public String addSource(Source source){
-      String key = Integer.toString(random.nextInt(1000)) + getDateString();
-      while(sources.containsKey(key)) key = key + Integer.toString(random.nextInt(1000));
-      sources.put(key, source);
-      return key;
-   }
-   static public void releaseSource(String key){
-      if(sources.containsKey(key)) sources.remove(key);
-   }
-   static private String getDateString(){
-      return Long.toString(new java.util.Date().getTime());
-   }
-
+    public Source getSource(String plocation, Map parameters) throws SourceNotFoundException {
+        String location = plocation;
+        // System.out.println("VS LOC=" + location);
+        int pos = location.lastIndexOf("/");
+        if ((pos > -1) && (pos + 1 < location.length()))
+            location = location.substring(pos + 1);
+        pos = location.lastIndexOf(":");
+        if ((pos > -1) && (pos + 1 < location.length()))
+            location = location.substring(pos + 1);
+        if (sources.containsKey(location))
+            return (Source) sources.get(location);
+        throw new SourceNotFoundException("VirtualSource not found: " + location);
+    }
+    public void release(Source source1) {
+        sources = null;
+    }
+    static public String addSource(Source source) {
+        return addSource(reserve(), source);
+    }
+    static public String addSource(String key, Source source) {
+        sources.put(key, source);
+        return key;
+    }
+    static public synchronized String reserve() {
+        String key = Integer.toString(random.nextInt(1000)) + getDateString();
+        while (hasKey(key))
+            key = key + Integer.toString(random.nextInt(1000));
+        sources.put(key, null);
+        return key;
+    }
+    static public void releaseSource(String key) {
+        if (hasKey(key))
+            sources.remove(key);
+    }
+    static public boolean hasKey(String key) {
+        return sources.containsKey(key);
+    }
+    static private String getDateString() {
+        return Long.toString(new java.util.Date().getTime());
+    }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java?rev=575290&r1=575289&r2=575290&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java Thu Sep 13 05:37:05 2007
@@ -1,49 +1,29 @@
 package org.apache.lenya.cms.content;
 
-import org.apache.cocoon.transformation.AbstractDOMTransformer;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
-import org.apache.lenya.cms.content.Content;
-import org.apache.lenya.cms.content.Resource;
+import org.apache.cocoon.transformation.AbstractDOMTransformer;
 import org.apache.lenya.cms.publication.PageEnvelope;
 import org.apache.lenya.cms.publication.Publication;
-import org.w3c.dom.Document;
 
 /**
- * This transformer modifies the structural information of a Resource.
- * 
- * It accepts a UNID as the src parameter.
- * It can:
- * - change the id and defaultlanguage of the Resource,
- * - delete Translations and Revisions, 
- * - change the live and edit Revisions of Translations.
- * 
- * <resource [id="newid"] [defaultlanguage="aa"]>
- *    <translation language="xx" [action="delete"] [live="1137958604000"] [edit="1137958604000"]>
- *       <revision revision="1137958604000" [action="delete"]/>
- *    </translation>
- * </resource>
- * 
- * action="delete" has top priority.
- * Any settings not included will not be affected.
- * 
+ * This transformer modifies the structural information of a Resource. It accepts a UNID as the src parameter. It can: - change the id and defaultlanguage of the Resource, - delete Translations and Revisions, - change the live and edit Revisions of Translations. <resource [id="newid"] [defaultlanguage="aa"]> <translation language="xx" [action="delete"] [live="1137958604000"] [edit="1137958604000"]> <revision revision="1137958604000" [action="delete"]/> </translation> </resource> action="delete" has top priority. Any settings not included will not be affected.
  * @author <a href="mailto:[email protected]">Paul Ercolino</a>
  */
-public class ResourceTransformer extends AbstractDOMTransformer{
-    protected org.w3c.dom.Document transform(org.w3c.dom.Document doc){
-System.out.println("ResourceTransformer - BEGIN");
-       String unid = this.source;
-       Request request = ObjectModelHelper.getRequest(super.objectModel);
-       return transformDocument(request, unid, doc);
+public class ResourceTransformer extends AbstractDOMTransformer {
+    protected org.w3c.dom.Document transform(org.w3c.dom.Document doc) {
+        System.out.println("ResourceTransformer - BEGIN");
+        String unid = this.source;
+        Request request = ObjectModelHelper.getRequest(super.objectModel);
+        return transformDocument(request, unid, doc);
     }
-    static public org.w3c.dom.Document transformDocument(Request request, String unid, org.w3c.dom.Document doc){
-       PageEnvelope envelope = (PageEnvelope) request.getAttribute(PageEnvelope.class.getName());
-       Publication pub = envelope.getPublication();
-       Content content = pub.getContent();
-       Resource resource = content.getResource(unid);
-       resource.update(doc);
-System.out.println("ResourceTransformer - RETURN");
-       return doc;
+    static public org.w3c.dom.Document transformDocument(Request request, String unid, org.w3c.dom.Document doc) {
+        PageEnvelope envelope = (PageEnvelope) request.getAttribute(PageEnvelope.class.getName());
+        Publication pub = envelope.getPublication();
+        Content content = pub.getContent();
+        Resource resource = content.getResource(unid);
+        resource.update(doc);
+        // System.out.println("ResourceTransformer - RETURN");
+        return doc;
     }
-
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/AbstractPublication.java?rev=575290&r1=575289&r2=575290&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/AbstractPublication.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/AbstractPublication.java Thu Sep 13 05:37:05 2007
@@ -25,20 +25,19 @@
 import java.util.Map;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import org.apache.lenya.cms.publishing.PublishingEnvironment;
-import org.apache.log4j.Category;
-// Lenya1.3 - BEGIN
 import org.apache.lenya.cms.content.Content;
 import org.apache.lenya.cms.content.flat.FlatContent;
 import org.apache.lenya.cms.content.hierarchical.HierarchicalContent;
+import org.apache.lenya.cms.publishing.PublishingEnvironment;
+import org.apache.log4j.Logger;
 
 // Lenya1.3 - END
 /**
  * A publication.
  */
 public abstract class AbstractPublication implements Publication {
-    private static Category log = Category.getInstance(AbstractPublication.class);
-    private static final String[] areas = { AUTHORING_AREA, STAGING_AREA, LIVE_AREA, ADMIN_AREA, ARCHIVE_AREA, TRASH_AREA, INFO_AREA_PREFIX + AUTHORING_AREA, INFO_AREA_PREFIX + STAGING_AREA, INFO_AREA_PREFIX + LIVE_AREA, INFO_AREA_PREFIX + ARCHIVE_AREA, INFO_AREA_PREFIX + TRASH_AREA };
+    private static Logger log = Logger.getLogger(AbstractPublication.class);
+    private static final String[] areas = {AUTHORING_AREA, STAGING_AREA, LIVE_AREA, ADMIN_AREA, ARCHIVE_AREA, TRASH_AREA, INFO_AREA_PREFIX + AUTHORING_AREA, INFO_AREA_PREFIX + STAGING_AREA, INFO_AREA_PREFIX + LIVE_AREA, INFO_AREA_PREFIX + ARCHIVE_AREA, INFO_AREA_PREFIX + TRASH_AREA };
     private String id;
     private PublishingEnvironment environment;
     private File servletContext;
@@ -67,14 +66,9 @@
     // Lenya1.3 - END
     /**
      * Creates a new instance of Publication
-     * 
-     * @param id
-     *            the publication id
-     * @param servletContextPath
-     *            the servlet context of this publication
-     * 
-     * @throws PublicationException
-     *             if there was a problem reading the config file
+     * @param id the publication id
+     * @param servletContextPath the servlet context of this publication
+     * @throws PublicationException if there was a problem reading the config file
      */
     protected AbstractPublication(String id, String servletContextPath) throws PublicationException {
         // assert id != null;
@@ -90,43 +84,43 @@
         Configuration config;
         String pathMapperClassName = null;
         String documentBuilderClassName = null;
-        try {
+        try{
             config = builder.buildFromFile(configFile);
-            try {
+            try{
                 pathMapperClassName = config.getChild(ELEMENT_PATH_MAPPER).getValue();
                 Class pathMapperClass = Class.forName(pathMapperClassName);
                 this.mapper = (DocumentIdToPathMapper) pathMapperClass.newInstance();
-            } catch (ClassNotFoundException e) {
+            }catch(ClassNotFoundException e){
                 throw new PublicationException("Cannot instantiate documentToPathMapper: [" + pathMapperClassName + "]", e);
             }
-            try {
+            try{
                 Configuration documentBuilderConfiguration = config.getChild(ELEMENT_DOCUMENT_BUILDER, false);
-                if (documentBuilderConfiguration != null) {
+                if(documentBuilderConfiguration != null){
                     documentBuilderClassName = documentBuilderConfiguration.getValue();
                     Class documentBuilderClass = Class.forName(documentBuilderClassName);
                     this.documentBuilder = (DocumentBuilder) documentBuilderClass.newInstance();
                 }
-            } catch (ClassNotFoundException e) {
+            }catch(ClassNotFoundException e){
                 throw new PublicationException("Cannot instantiate document builder: [" + pathMapperClassName + "]", e);
             }
             Configuration[] languages = config.getChild(LANGUAGES).getChildren();
-            for (int i = 0; i < languages.length; i++) {
+            for(int i = 0; i < languages.length; i++){
                 Configuration languageConfig = languages[i];
                 String language = languageConfig.getValue();
                 this.languages.add(language);
-                if (languageConfig.getAttribute(DEFAULT_LANGUAGE_ATTR, null) != null) {
+                if(languageConfig.getAttribute(DEFAULT_LANGUAGE_ATTR, null) != null){
                     defaultLanguage = language;
                 }
             }
             Configuration siteStructureConfiguration = config.getChild(ELEMENT_SITE_STRUCTURE, false);
-            if (siteStructureConfiguration != null) {
+            if(siteStructureConfiguration != null){
                 String siteStructureType = siteStructureConfiguration.getAttribute(ATTRIBUTE_TYPE);
-                if (!siteStructureType.equals("sitetree")) {
+                if(!siteStructureType.equals("sitetree")){
                     hasSitetree = false;
                 }
             }
             Configuration[] proxyConfigs = config.getChildren(ELEMENT_PROXY);
-            for (int i = 0; i < proxyConfigs.length; i++) {
+            for(int i = 0; i < proxyConfigs.length; i++){
                 String url = proxyConfigs[i].getAttribute(ATTRIBUTE_URL);
                 String ssl = proxyConfigs[i].getAttribute(ATTRIBUTE_SSL);
                 String area = proxyConfigs[i].getAttribute(ATTRIBUTE_AREA);
@@ -134,19 +128,19 @@
                 proxy.setUrl(url);
                 Object key = getProxyKey(area, Boolean.valueOf(ssl).booleanValue());
                 this.areaSsl2proxy.put(key, proxy);
-                if (log.isDebugEnabled()) {
+                if(log.isDebugEnabled()){
                     log.debug("Adding proxy: [" + proxy + "] for area=[" + area + "] SSL=[" + ssl + "]");
                 }
             }
             Configuration[] rewriteAttributeConfigs = config.getChildren(ELEMENT_REWRITE_ATTRIBUTE);
             List xPaths = new ArrayList();
-            for (int i = 0; i < rewriteAttributeConfigs.length; i++) {
+            for(int i = 0; i < rewriteAttributeConfigs.length; i++){
                 String xPath = rewriteAttributeConfigs[i].getAttribute(ATTRIBUTE_XPATH);
                 xPaths.add(xPath);
             }
             this.rewriteAttributeXPaths = (String[]) xPaths.toArray(new String[xPaths.size()]);
             Configuration[] contentDirConfigs = config.getChildren(ELEMENT_CONTENT_DIR);
-            for (int i = 0; i < contentDirConfigs.length; i++) {
+            for(int i = 0; i < contentDirConfigs.length; i++){
                 String area = contentDirConfigs[i].getAttribute(ATTRIBUTE_AREA);
                 String dir = contentDirConfigs[i].getValue();
                 Object key = getContentDirKey(area);
@@ -159,17 +153,17 @@
             String contentConfigValue = contentConfig.getValue(CONTENT_PATH);
             publicationDirectory = new File(getServletContext(), PUBLICATION_PREFIX + File.separator + getId());
             contentDirectory = new File(publicationDirectory, contentConfigValue);
-            if (contentType.equalsIgnoreCase("flat")) {
+            if(contentType.equalsIgnoreCase("flat")){
                 content = (Content) new FlatContent(contentDirectory, getLanguages());
-            } else {
+            }else{
                 content = (Content) new HierarchicalContent(contentDirectory, getLanguages());
             }
             // Modules
             modules = new Modules(id, servletContextPath, config.getChild("modules"));
             // Lenya1.3 - END
-        } catch (PublicationException e) {
+        }catch(PublicationException e){
             throw e;
-        } catch (Exception e) {
+        }catch(Exception e){
             log.error(e);
             throw new PublicationException("Problem with config file: " + configFile.getAbsolutePath(), e);
         }
@@ -193,7 +187,6 @@
     // Lenya1.3 - END
     /**
      * Returns the publication ID.
-     * 
      * @return A string value.
      */
     public String getId() {
@@ -201,18 +194,14 @@
     }
     /**
      * Returns the publishing environment of this publication.
-     * 
      * @return A {@link PublishingEnvironment}object.
-     * @deprecated It is planned to decouple the environments from the
-     *             publication.
+     * @deprecated It is planned to decouple the environments from the publication.
      */
     public PublishingEnvironment getEnvironment() {
         return environment;
     }
     /**
-     * Returns the servlet context this publication belongs to (usually, the
-     * <code>webapps/lenya</code> directory).
-     * 
+     * Returns the servlet context this publication belongs to (usually, the <code>webapps/lenya</code> directory).
      * @return A <code>File</code> object.
      */
     public File getServletContext() {
@@ -221,22 +210,16 @@
     // Lenya1.3 BEGIN - changed
     /**
      * Returns the publication directory.
-     * 
      * @return A <code>File</code> object.
      */
     public File getDirectory() {
-        if (null == publicationDirectory)
-            publicationDirectory = new File(getServletContext(), PUBLICATION_PREFIX + File.separator + getId());
+        if(null == publicationDirectory) publicationDirectory = new File(getServletContext(), PUBLICATION_PREFIX + File.separator + getId());
         return publicationDirectory;
     }
     // Lenya1.3 - deprecated
     /**
      * Return the directory of a specific area.
-     * 
-     * @param area
-     *            a <code>File</code> representing the root of the area
-     *            content directory.
-     * 
+     * @param area a <code>File</code> representing the root of the area content directory.
      * @return the directory of the given content area.
      * @deprecated Areas are bad. Do not use them.
      */
@@ -244,17 +227,15 @@
     public File getContentDirectory(String area) {
         Object key = getContentDirKey(area);
         String contentDir = (String) this.areaContentDir.get(key);
-        if (contentDir != null) {
+        if(contentDir != null){
             return new File(contentDir);
-        } else {
+        }else{
             return new File(getDirectory(), CONTENT_PATH + File.separator + area);
         }
     }
     /**
      * DOCUMENT ME!
-     * 
-     * @param mapper
-     *            DOCUMENT ME!
+     * @param mapper DOCUMENT ME!
      */
     public void setPathMapper(DefaultDocumentIdToPathMapper mapper) {
         // assert mapper != null;
@@ -262,7 +243,6 @@
     }
     /**
      * Returns the path mapper.
-     * 
      * @return a <code>DocumentIdToPathMapper</code>
      */
     public DocumentIdToPathMapper getPathMapper() {
@@ -270,9 +250,7 @@
     }
     /**
      * Returns if a given string is a valid area name.
-     * 
-     * @param area
-     *            The area string to test.
+     * @param area The area string to test.
      * @return A boolean value.
      */
     public static boolean isValidArea(String area) {
@@ -280,7 +258,6 @@
     }
     /**
      * Get the default language
-     * 
      * @return the default language
      */
     public String getDefaultLanguage() {
@@ -288,72 +265,51 @@
     }
     /**
      * Set the default language
-     * 
-     * @param language
-     *            the default language
+     * @param language the default language
      */
     public void setDefaultLanguage(String language) {
         defaultLanguage = language;
     }
     /**
      * Get all available languages for this publication
-     * 
      * @return an <code>Array</code> of languages
      */
     public String[] getLanguages() {
         return (String[]) languages.toArray(new String[languages.size()]);
     }
     /**
-     * Get the breadcrumb prefix. It can be used as a prefix if a publication is
-     * part of a larger site
-     * 
+     * Get the breadcrumb prefix. It can be used as a prefix if a publication is part of a larger site
      * @return the breadcrumb prefix
      */
     public String getBreadcrumbPrefix() {
         return breadcrumbprefix;
     }
     /**
-     * Get the SSL prefix. If you want to serve SSL-protected pages through a
-     * special site, use this prefix. This can come in handy if you have
-     * multiple sites that need SSL protection and you want to share one SSL
-     * certificate.
-     * 
+     * Get the SSL prefix. If you want to serve SSL-protected pages through a special site, use this prefix. This can come in handy if you have multiple sites that need SSL protection and you want to share one SSL certificate.
      * @return the SSL prefix
      */
     public String getSSLPrefix() {
         return sslprefix;
     }
     /**
-     * Get the Live mount point. The live mount point is used to rewrite links
-     * that are of the form /contextprefix/publication/area/documentid to
-     * /livemountpoint/documentid
-     * 
-     * This is useful if you serve your live area through mod_proxy. to enable
-     * this functionality, set the Live mount point to / or something else. An
-     * empty mount point disables the feature.
-     * 
+     * Get the Live mount point. The live mount point is used to rewrite links that are of the form /contextprefix/publication/area/documentid to /livemountpoint/documentid This is useful if you serve your live area through mod_proxy. to enable this functionality, set the Live mount point to / or something else. An empty mount point disables the feature.
      * @return the Live mount point
      */
     public String getLiveMountPoint() {
         return livemountpoint;
     }
     /**
-     * Get the sitetree for a specific area of this publication. Sitetrees are
-     * created on demand and are cached.
-     * 
-     * @param area
-     *            the area
+     * Get the sitetree for a specific area of this publication. Sitetrees are created on demand and are cached.
+     * @param area the area
      * @return the sitetree for the specified area
-     * 
-     * @throws SiteTreeException
-     *             if an error occurs
+     * @throws SiteTreeException if an error occurs
      */
     public SiteTree getTree(String area) throws SiteTreeException {
         SiteTree sitetree = null;
-        if (hasSitetree) {
-            if (siteTrees.containsKey(area)) {
+        if(hasSitetree){
+            if(siteTrees.containsKey(area)){
                 sitetree = (SiteTree) siteTrees.get(area);
-            } else {
+            }else{
                 sitetree = new DefaultSiteTree(getDirectory(), area);
                 siteTrees.put(area, sitetree);
             }
@@ -361,26 +317,19 @@
         return sitetree;
     }
     /**
-     * Get the sitetree for a specific area of this publication. Sitetrees are
-     * created on demand and are cached.
-     * 
-     * @deprecated Please use getTree() because this method returns the
-     *             interface and not a specific implementation
+     * Get the sitetree for a specific area of this publication. Sitetrees are created on demand and are cached.
+     * @deprecated Please use getTree() because this method returns the interface and not a specific implementation
      * @see getTree()
-     * 
-     * @param area
-     *            the area
+     * @param area the area
      * @return the sitetree for the specified area
-     * 
-     * @throws SiteTreeException
-     *             if an error occurs
+     * @throws SiteTreeException if an error occurs
      */
     public DefaultSiteTree getSiteTree(String area) throws SiteTreeException {
         DefaultSiteTree sitetree = null;
-        if (hasSitetree) {
-            if (siteTrees.containsKey(area)) {
+        if(hasSitetree){
+            if(siteTrees.containsKey(area)){
                 sitetree = (DefaultSiteTree) siteTrees.get(area);
-            } else {
+            }else{
                 sitetree = new DefaultSiteTree(getDirectory(), area);
                 siteTrees.put(area, sitetree);
             }
@@ -390,25 +339,18 @@
     private DocumentBuilder documentBuilder;
     /**
      * Returns the document builder of this instance.
-     * 
      * @return A document builder.
      */
     public DocumentBuilder getDocumentBuilder() {
-        if (documentBuilder == null) {
-            throw new IllegalStateException("The document builder was not defined in publication.xconf!");
-        }
+        if(documentBuilder == null){ throw new IllegalStateException("The document builder was not defined in publication.xconf!"); }
         return documentBuilder;
     }
     /**
      * Creates a version of the document object in another area.
-     * 
-     * @param document
-     *            The document to clone.
-     * @param area
-     *            The destination area.
+     * @param document The document to clone.
+     * @param area The destination area.
      * @return A document.
-     * @throws PublicationException
-     *             when an error occurs.
+     * @throws PublicationException when an error occurs.
      */
     public Document getAreaVersion(Document document, String area) throws PublicationException {
         DocumentBuilder builder = getDocumentBuilder();
@@ -421,7 +363,7 @@
      */
     public boolean equals(Object object) {
         boolean equals = false;
-        if (getClass().isInstance(object)) {
+        if(getClass().isInstance(object)){
             Publication publication = (Publication) object;
             equals = getId().equals(publication.getId()) && getServletContext().equals(publication.getServletContext());
         }
@@ -435,12 +377,8 @@
         return key.hashCode();
     }
     /**
-     * Template method to copy a document. Override
-     * {@link #copyDocumentSource(Document, Document)} to implement access to a
-     * custom repository.
-     * 
-     * @see org.apache.lenya.cms.publication.Publication#copyDocument(org.apache.lenya.cms.publication.Document,
-     *      org.apache.lenya.cms.publication.Document)
+     * Template method to copy a document. Override {@link #copyDocumentSource(Document, Document)} to implement access to a custom repository.
+     * @see org.apache.lenya.cms.publication.Publication#copyDocument(org.apache.lenya.cms.publication.Document, org.apache.lenya.cms.publication.Document)
      */
     public void copyDocument(Document sourceDocument, Document destinationDocument) throws PublicationException {
         copyDocumentSource(sourceDocument, destinationDocument);
@@ -448,53 +386,47 @@
     }
     /**
      * Copies a document in the site structure.
-     * 
-     * @param sourceDocument
-     *            The source document.
-     * @param destinationDocument
-     *            The destination document.
-     * @throws PublicationException
-     *             when something went wrong.
+     * @param sourceDocument The source document.
+     * @param destinationDocument The destination document.
+     * @throws PublicationException when something went wrong.
      */
     protected void copySiteStructure(Document sourceDocument, Document destinationDocument) throws PublicationException {
-        if (hasSitetree) {
-            try {
+        if(hasSitetree){
+            try{
                 SiteTree sourceTree = getSiteTree(sourceDocument.getArea());
                 SiteTree destinationTree = getSiteTree(destinationDocument.getArea());
                 SiteTreeNode sourceNode = sourceTree.getNode(sourceDocument.getId());
-                if (sourceNode == null) {
-                    throw new PublicationException("The node for source document [" + sourceDocument.getId() + "] doesn't exist!");
-                }
+                if(sourceNode == null){ throw new PublicationException("The node for source document [" + sourceDocument.getId() + "] doesn't exist!"); }
                 SiteTreeNode[] siblings = sourceNode.getNextSiblings();
                 String parentId = sourceNode.getAbsoluteParentId();
                 SiteTreeNode sibling = null;
                 String siblingDocId = null;
                 // same document ID -> insert at the same position
-                if (sourceDocument.getId().equals(destinationDocument.getId())) {
-                    for (int i = 0; i < siblings.length; i++) {
+                if(sourceDocument.getId().equals(destinationDocument.getId())){
+                    for(int i = 0; i < siblings.length; i++){
                         String docId = parentId + "/" + siblings[i].getId();
                         sibling = destinationTree.getNode(docId);
-                        if (sibling != null) {
+                        if(sibling != null){
                             siblingDocId = docId;
                             break;
                         }
                     }
                 }
                 Label label = sourceNode.getLabel(sourceDocument.getLanguage());
-                if (label == null) {
+                if(label == null){
                     // the node that we're trying to publish
                     // doesn't have this language
                     throw new PublicationException("The node " + sourceDocument.getId() + " doesn't contain a label for language " + sourceDocument.getLanguage());
                 }
                 SiteTreeNode destinationNode = destinationTree.getNode(destinationDocument.getId());
-                if (destinationNode == null) {
-                    Label[] labels = { label };
-                    if (siblingDocId == null) {
+                if(destinationNode == null){
+                    Label[] labels = {label };
+                    if(siblingDocId == null){
                         destinationTree.addNode(destinationDocument.getId(), labels, sourceNode.visibleInNav(), sourceNode.getHref(), sourceNode.getSuffix(), sourceNode.hasLink());
-                    } else {
+                    }else{
                         destinationTree.addNode(destinationDocument.getId(), labels, sourceNode.visibleInNav(), sourceNode.getHref(), sourceNode.getSuffix(), sourceNode.hasLink(), siblingDocId);
                     }
-                } else {
+                }else{
                     // if the node already exists in the live
                     // tree simply insert the label in the
                     // live tree
@@ -502,92 +434,72 @@
                     // and synchronize visibilityinnav attribute with the one in
                     // the source area
                     String visibility = "true";
-                    if (!sourceNode.visibleInNav())
-                        visibility = "false";
+                    if(!sourceNode.visibleInNav()) visibility = "false";
                     destinationNode.setNodeAttribute(SiteTreeNodeImpl.VISIBLEINNAV_ATTRIBUTE_NAME, visibility);
                     // also update the link attribute if necessary
-                    if (sourceNode.hasLink() != destinationNode.hasLink()) {
+                    if(sourceNode.hasLink() != destinationNode.hasLink()){
                         String link = (sourceNode.hasLink() ? "true" : "false");
                         destinationNode.setNodeAttribute(SiteTreeNodeImpl.LINK_ATTRIBUTE_NAME, link);
                     }
                 }
                 destinationTree.save();
-            } catch (SiteTreeException e) {
+            }catch(SiteTreeException e){
                 throw new PublicationException(e);
             }
         }
     }
     /**
      * Copies a document source.
-     * 
-     * @param sourceDocument
-     *            The source document.
-     * @param destinationDocument
-     *            The destination document.
-     * @throws PublicationException
-     *             when something went wrong.
+     * @param sourceDocument The source document.
+     * @param destinationDocument The destination document.
+     * @throws PublicationException when something went wrong.
      */
     protected abstract void copyDocumentSource(Document sourceDocument, Document destinationDocument) throws PublicationException;
     /**
      * @see org.apache.lenya.cms.publication.Publication#deleteDocument(org.apache.lenya.cms.publication.Document)
      */
     public void deleteDocument(Document document) throws PublicationException {
-        if (!document.exists()) {
-            throw new PublicationException("Document [" + document + "] does not exist!");
-        }
+        if(!document.exists()){ throw new PublicationException("Document [" + document + "] does not exist!"); }
         deleteFromSiteStructure(document);
         deleteDocumentSource(document);
     }
     /**
      * Deletes a document from the site structure.
-     * 
-     * @param document
-     *            The document to remove.
-     * @throws PublicationException
-     *             when something went wrong.
+     * @param document The document to remove.
+     * @throws PublicationException when something went wrong.
      */
     protected void deleteFromSiteStructure(Document document) throws PublicationException {
-        if (hasSitetree) {
+        if(hasSitetree){
             SiteTree tree;
-            try {
+            try{
                 tree = getSiteTree(document.getArea());
-            } catch (SiteTreeException e) {
+            }catch(SiteTreeException e){
                 throw new PublicationException(e);
             }
             SiteTreeNode node = tree.getNode(document.getId());
-            if (node == null) {
-                throw new PublicationException("Sitetree node for document [" + document + "] does not exist!");
-            }
+            if(node == null){ throw new PublicationException("Sitetree node for document [" + document + "] does not exist!"); }
             Label label = node.getLabel(document.getLanguage());
-            if (label == null) {
-                throw new PublicationException("Sitetree label for document [" + document + "] in language [" + document.getLanguage() + "]does not exist!");
-            }
-            if (node.getLabels().length == 1 && node.getChildren().length > 0) {
-                throw new PublicationException("Cannot delete last language version of document [" + document + "] because this node has children.");
-            }
+            if(label == null){ throw new PublicationException("Sitetree label for document [" + document + "] in language [" + document.getLanguage() + "]does not exist!"); }
+            if(node.getLabels().length == 1 && node.getChildren().length > 0){ throw new PublicationException("Cannot delete last language version of document [" + document + "] because this node has children."); }
             node.removeLabel(label);
-            try {
-                if (node.getLabels().length == 0) {
+            try{
+                if(node.getLabels().length == 0){
                     tree.deleteNode(document.getId());
                 }
                 tree.save();
-            } catch (SiteTreeException e) {
+            }catch(SiteTreeException e){
                 throw new PublicationException(e);
             }
         }
     }
     /**
      * Deletes the source of a document.
-     * 
-     * @param document
-     *            The document to delete.
-     * @throws PublicationException
-     *             when something went wrong.
+     * @param document The document to delete.
+     * @throws PublicationException when something went wrong.
      */
     protected abstract void deleteDocumentSource(Document document) throws PublicationException;
     /**
-     * @see org.apache.lenya.cms.publication.Publication#moveDocument(org.apache.lenya.cms.publication.Document,
-     *      org.apache.lenya.cms.publication.Document)
+     * @see org.apache.lenya.cms.publication.Publication#moveDocument(org.apache.lenya.cms.publication.Document, org.apache.lenya.cms.publication.Document)
      */
     public void moveDocument(Document sourceDocument, Document destinationDocument) throws PublicationException {
         copyDocument(sourceDocument, destinationDocument);
@@ -596,24 +508,20 @@
     private Map areaSsl2proxy = new HashMap();
     /**
      * Generates a hash key for a area-SSL combination.
-     * 
-     * @param area
-     *            The area.
-     * @param isSslProtected
-     *            If the proxy is assigned for SSL-protected pages.
+     * @param area The area.
+     * @param isSslProtected If the proxy is assigned for SSL-protected pages.
      * @return An object.
      */
     protected Object getProxyKey(String area, boolean isSslProtected) {
         return area + ":" + isSslProtected;
     }
     /**
-     * @see org.apache.lenya.cms.publication.Publication#getProxy(org.apache.lenya.cms.publication.Document,
-     *      boolean)
+     * @see org.apache.lenya.cms.publication.Publication#getProxy(org.apache.lenya.cms.publication.Document, boolean)
      */
     public Proxy getProxy(Document document, boolean isSslProtected) {
         Object key = getProxyKey(document.getArea(), isSslProtected);
         Proxy proxy = (Proxy) this.areaSsl2proxy.get(key);
-        if (log.isDebugEnabled()) {
+        if(log.isDebugEnabled()){
             log.debug("Resolving proxy for [" + document + "] SSL=[" + isSslProtected + "]");
             log.debug("Resolved proxy: [" + proxy + "]");
         }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DefaultDocument.java?rev=575290&r1=575289&r2=575290&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DefaultDocument.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DefaultDocument.java Thu Sep 13 05:37:05 2007
@@ -30,43 +30,27 @@
     private DublinCore dublincore;
     /**
      * Creates a new instance of DefaultDocument.
-     * 
-     * @param publication
-     *            The publication the document belongs to.
-     * @param id
-     *            The document ID (starting with a slash).
+     * @param publication The publication the document belongs to.
+     * @param id The document ID (starting with a slash).
      * @deprecated Use {@link DefaultDocumentBuilder} instead.
      */
     public DefaultDocument(Publication publication, String id) {
-        if (id == null) {
-            throw new IllegalArgumentException("The document ID must not be null!");
-        }
-        if (!id.startsWith("/")) {
-            throw new IllegalArgumentException("The document ID must start with a slash!");
-        }
+        if(id == null){ throw new IllegalArgumentException("The document ID must not be null!"); }
+        if(!id.startsWith("/")){ throw new IllegalArgumentException("The document ID must start with a slash!"); }
         this.id = id;
         // assert(publication != null) && !"".equals(publication.getId());
         this.publication = publication;
         this.dublincore = new DublinCoreProxy(this);
     }
     /**
-     * Creates a new instance of DefaultDocument. The language of the document
-     * is the default language of the publication.
-     * 
-     * @param publication
-     *            The publication the document belongs to.
-     * @param id
-     *            The document ID (starting with a slash).
-     * @param area
-     *            The area.
+     * Creates a new instance of DefaultDocument. The language of the document is the default language of the publication.
+     * @param publication The publication the document belongs to.
+     * @param id The document ID (starting with a slash).
+     * @param area The area.
      */
     protected DefaultDocument(Publication publication, String id, String area) {
-        if (id == null) {
-            throw new IllegalArgumentException("The document ID must not be null!");
-        }
-        if (!id.startsWith("/")) {
-            throw new IllegalArgumentException("The document ID must start with a slash!");
-        }
+        if(id == null){ throw new IllegalArgumentException("The document ID must not be null!"); }
+        if(!id.startsWith("/")){ throw new IllegalArgumentException("The document ID must start with a slash!"); }
         this.id = id;
         // assert(publication != null) && !"".equals(publication.getId());
         this.publication = publication;
@@ -76,23 +60,14 @@
     }
     /**
      * Creates a new instance of DefaultDocument.
-     * 
-     * @param publication
-     *            The publication the document belongs to.
-     * @param id
-     *            The document ID (starting with a slash).
-     * @param area
-     *            The area.
-     * @param language
-     *            the language
+     * @param publication The publication the document belongs to.
+     * @param id The document ID (starting with a slash).
+     * @param area The area.
+     * @param language the language
      */
     protected DefaultDocument(Publication publication, String id, String area, String language) {
-        if (id == null) {
-            throw new IllegalArgumentException("The document ID must not be null!");
-        }
-        if (!id.startsWith("/")) {
-            throw new IllegalArgumentException("The document ID must start with a slash!");
-        }
+        if(id == null){ throw new IllegalArgumentException("The document ID must not be null!"); }
+        if(!id.startsWith("/")){ throw new IllegalArgumentException("The document ID must start with a slash!"); }
         this.id = id;
         // assert(publication != null) && !"".equals(publication.getId());
         this.publication = publication;
@@ -141,7 +116,6 @@
     }
     /**
      * Returns the file for this document.
-     * 
      * @return A file object.
      */
     public File getFile() {
@@ -160,29 +134,27 @@
     public String[] getLanguages() throws DocumentException {
         ArrayList languages = new ArrayList();
         SiteTree sitetree;
-        try {
+        try{
             sitetree = getPublication().getTree(getArea());
-            if (sitetree != null) {
+            if(sitetree != null){
                 SiteTreeNode node = sitetree.getNode(getId());
-                if (node != null) {
+                if(node != null){
                     Label[] labels = node.getLabels();
-                    for (int i = 0; i < labels.length; i++) {
+                    for(int i = 0; i < labels.length; i++){
                         languages.add(labels[i].getLanguage());
                     }
                 }
-            } else {
+            }else{
                 languages.add(getLanguage());
             }
-        } catch (SiteTreeException e) {
+        }catch(SiteTreeException e){
             throw new DocumentException(e);
         }
         return (String[]) languages.toArray(new String[languages.size()]);
     }
     /**
      * Sets the language of this document.
-     * 
-     * @param language
-     *            The language.
+     * @param language The language.
      */
     public void setLanguage(String language) {
         // /// language != null;
@@ -193,12 +165,12 @@
      */
     public String getLabel() throws DocumentException {
         String label = "";
-        try {
+        try{
             SiteTree siteTree = getPublication().getTree(getArea());
-            if (siteTree != null) {
+            if(siteTree != null){
                 label = siteTree.getNode(getId()).getLabel(getLanguage()).getLabel();
             }
-        } catch (SiteTreeException e) {
+        }catch(SiteTreeException e){
             throw new DocumentException(e);
         }
         return label;
@@ -231,15 +203,13 @@
     }
     /**
      * Sets the area.
-     * 
-     * @param area
-     *            A string.
+     * @param area A string.
      */
     // LENYA1.3 BEGIN - Area as Module cannot error, so assume "live".
     protected void setArea(String area) {
-        if (!AbstractPublication.isValidArea(area)) {
+        if(!AbstractPublication.isValidArea(area)){
             this.area = Publication.LIVE_AREA;
-        } else {
+        }else{
             this.area = area;
         }
     }
@@ -253,9 +223,7 @@
     }
     /**
      * Sets the extension of the file in the URL.
-     * 
-     * @param extension
-     *            A string.
+     * @param extension A string.
      */
     protected void setExtension(String extension) {
         // assert extension != null;
@@ -264,9 +232,7 @@
     private String documentURL;
     /**
      * Sets the document URL.
-     * 
-     * @param url
-     *            The document URL (without publication ID and area).
+     * @param url The document URL (without publication ID and area).
      */
     public void setDocumentURL(String url) {
         // assert url != null;
@@ -280,40 +246,38 @@
     }
     /**
      * (non-Javadoc)
-     * 
      * @see org.apache.lenya.cms.publication.Document#exists()
      */
     public boolean exists() throws DocumentException {
         boolean exists;
-        try {
+        try{
             SiteTree sitetree = getPublication().getTree(getArea());
-            if (sitetree != null) {
+            if(sitetree != null){
                 SiteTreeNode node = sitetree.getNode(getId());
                 exists = (node != null) && (node.getLabel(getLanguage()) != null);
-            } else {
+            }else{
                 exists = getFile().exists();
             }
-        } catch (SiteTreeException e) {
+        }catch(SiteTreeException e){
             throw new DocumentException(e);
         }
         return exists;
     }
     /**
      * (non-Javadoc)
-     * 
      * @see org.apache.lenya.cms.publication.Document#existsInAnyLanguage()
      */
     public boolean existsInAnyLanguage() throws DocumentException {
         boolean exists = false;
-        try {
+        try{
             SiteTree sitetree = getPublication().getTree(getArea());
-            if (sitetree != null) {
+            if(sitetree != null){
                 SiteTreeNode node = sitetree.getNode(getId());
                 exists = node != null;
-            } else {
+            }else{
                 exists = getFile().exists();
             }
-        } catch (SiteTreeException e) {
+        }catch(SiteTreeException e){
             throw new DocumentException(e);
         }
         return exists;
@@ -323,7 +287,7 @@
      */
     public boolean equals(Object object) {
         boolean equals = false;
-        if (getClass().isInstance(object)) {
+        if(getClass().isInstance(object)){
             Document document = (Document) object;
             equals = getPublication().equals(document.getPublication()) && getId().equals(document.getId()) && getArea().equals(document.getArea()) && getLanguage().equals(document.getLanguage());
         }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.