incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r161208 - incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/DocumentPortlet.java
Date Wed, 13 Apr 2005 20:55:24 GMT
Author: taylor
Date: Wed Apr 13 13:55:22 2005
New Revision: 161208

URL: http://svn.apache.org/viewcvs?view=rev&rev=161208
Log:
cleanup DocumentPortlet, added Print friendly link

Modified:
    incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/DocumentPortlet.java

Modified: incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/DocumentPortlet.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/DocumentPortlet.java?view=diff&r1=161207&r2=161208
==============================================================================
--- incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/DocumentPortlet.java
(original)
+++ incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/DocumentPortlet.java
Wed Apr 13 13:55:22 2005
@@ -78,19 +78,36 @@
         	try 
             {
 				Document doc = cms.getDocument(currentFile);
-				if ((doc.getContentType().indexOf("html") != -1)  || (doc.getContentType().indexOf("text")
!= -1))
-				{
-                    String title = doc.getProperty("title");
-                    if (title == null)
-                        title = doc.getName();
-					String currentDocument = "<div>Current Document: <b>" + title + "</b>
- "+ doc.getUri() + "</div>";
-	                String anchors = "<hr/>"; //createAnchors(doc);
-					response.getPortletOutputStream().write(currentDocument.getBytes());
-	                response.getPortletOutputStream().write(anchors.getBytes());           
    
-					response.getPortletOutputStream().write(DIV_START.getBytes());
-					drain(doc.getContent().getContentStream(), response.getPortletOutputStream());
-					response.getPortletOutputStream().write(DIV_END.getBytes());
-					
+                boolean isText = doc.getContentType().equals("text/plain");
+                String title = doc.getProperty("title");
+                if (title == null)
+                {
+                    title = doc.getName();
+                    int pos = title.lastIndexOf(".");
+                    if (pos != -1)
+                    {
+                        title = title.substring(0, pos);
+                    }
+                }                
+                
+				if ((doc.getContentType().indexOf("html") != -1) || isText)
+				{                    
+                    String contextPath = request.getContextPath();
+                    String linkage = "<a target='_new' href='" + 
+                                     contextPath + "/servlet/FileServlet?uri=" + currentFile
+ "'>Print</a>";                            
+                    String currentDocument = "<b>" + title + "</b>"; 
+                    String out = "<table width='100%'><tr><td align='left'
style='font-size:9pt'>" 
+                        + currentDocument + "</td><td align='left'>" + linkage
+ "</td></tr></table>";                     
+                    String anchors = "<hr/>"; //createAnchors(doc);
+                    response.getPortletOutputStream().write(out.getBytes());
+                    response.getPortletOutputStream().write(anchors.getBytes());
+                    response.getPortletOutputStream().write(DIV_START.getBytes());
+                    if (isText)
+                        response.getPortletOutputStream().write("<PRE>".getBytes());
+                    drain(doc.getContent().getContentStream(), response.getPortletOutputStream());
+                    if (isText)
+                        response.getPortletOutputStream().write("</PRE>".getBytes());
+                                                            				
 					int hash = currentFile.indexOf('#');
 					if(hash != -1)
 					{
@@ -101,12 +118,9 @@
 						response.getPortletOutputStream().write("');</script>".getBytes());
 					}
 				}
-                else if (doc.getContentType().indexOf("gif") != -1)
+                else if ((doc.getContentType().indexOf("image/") != -1))
                 {
-                    String title = doc.getProperty("title");
-                    if (title == null)
-                        title = doc.getName();
-                    String currentDocument = "<div>Current Document: <b>" + title
+ "</b> - "+ doc.getUri() + "</div>";
+                    String currentDocument = "<b>" + title + "</b>"; 
                     String anchors = "<hr/>"; //createAnchors(doc);
                     response.getPortletOutputStream().write(currentDocument.getBytes());
                     response.getPortletOutputStream().write(anchors.getBytes());        
       
@@ -114,8 +128,7 @@
                     String gif = "<IMG SRC='" + request.getContextPath() + "/FileServlet?uri="
+ doc.getUri() + "'/>";
                     response.getPortletOutputStream().write(gif.getBytes());
                     response.getPortletOutputStream().write(DIV_END.getBytes());        
           
-                }
-				
+                }				
 				else 
 				{
                     renderBinaryDoc(request, response, currentFile, doc);



Mime
View raw message