Author: ssmiweve
Date: 2007-06-16 22:19:48 +0200 (Sat, 16 Jun 2007)
New Revision: 5341

Modified:
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/view/ImportPublish.java
   
trunk/core-api/src/main/java/no/schibstedsok/searchportal/view/velocity/PublishDirective.java
   
trunk/war/src/main/java/no/schibstedsok/searchportal/view/taglib/ImportPublishingPageTag.java
   trunk/war/src/webapp/WEB-INF/SearchPortal.tld
Log:
SEARCH-2525 - ImportPublish to import xml instead of html fragments


Modified: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/view/ImportPublish.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/view/ImportPublish.java
   2007-06-16 18:57:01 UTC (rev 5340)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/view/ImportPublish.java
   2007-06-16 20:19:48 UTC (rev 5341)
@@ -11,12 +11,16 @@
 import com.opensymphony.oscache.general.GeneralCacheAdministrator;
 import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.Writer;
 import java.net.URL;
 import java.util.Properties;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import no.schibstedsok.searchportal.datamodel.DataModel;
 import no.schibstedsok.searchportal.http.HTTPClient;
 import no.schibstedsok.searchportal.site.config.SiteConfiguration;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
 
 /**
  * General support to import page fragments from publishing system.
@@ -43,10 +47,9 @@
      * @param out 
      * @throws java.io.IOException 
      */
-    public static void importPage(
+    public static String importPage(
             final String page, 
-            final DataModel datamodel, 
-            final Writer out) throws IOException{
+            final DataModel datamodel) throws IOException{
         
         final Properties props = 
datamodel.getSite().getSiteConfiguration().getProperties();
 
@@ -84,12 +87,26 @@
                     CACHE.cancelUpdate(cacheKey);
                 }
             }
-        }finally{
-            out.write(content);
         }
+        return content;
     }
-    
-    
+         
+    /**
+     * 
+     * @param page 
+     * @param datamodel 
+     * @param out 
+     * @throws java.io.IOException 
+     */
+    public static Document importXml(
+            final String page, 
+            final DataModel datamodel) throws IOException, 
ParserConfigurationException, SAXException{ 
+        
+        final DocumentBuilderFactory factory = 
DocumentBuilderFactory.newInstance();
+        final DocumentBuilder builder = factory.newDocumentBuilder();
+        return builder.parse(importPage(page, datamodel));
+       
+    }   
     // Constructors --------------------------------------------------
     
     /** Creates a new instance of NewClass */

Modified: 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/view/velocity/PublishDirective.java
===================================================================
--- 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/view/velocity/PublishDirective.java
       2007-06-16 18:57:01 UTC (rev 5340)
+++ 
trunk/core-api/src/main/java/no/schibstedsok/searchportal/view/velocity/PublishDirective.java
       2007-06-16 20:19:48 UTC (rev 5341)
@@ -10,14 +10,12 @@
 import java.io.IOException;
 import java.io.Writer;
 import java.net.SocketTimeoutException;
-import no.schibstedsok.searchportal.datamodel.DataModel;
 import no.schibstedsok.searchportal.view.ImportPublish;
 import org.apache.log4j.Logger;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.runtime.directive.Directive;
 import org.apache.velocity.runtime.parser.node.Node;
 
 /**
@@ -66,16 +64,22 @@
 
         // The argument gets url encoded on the way in. Make sure to decode 
the / characters.
         final String url = getArgument(context, node, 0).replaceAll("%2F", 
"/");
-
+            
         try{
-            ImportPublish.importPage(url, getDataModel(context), writer);
+                            
+            if(1 == node.jjtGetNumChildren()) {
+                writer.write(ImportPublish.importPage(url, 
getDataModel(context)));
+            }else{
+                context.put("document", ImportPublish.importXml(url, 
getDataModel(context)));
+                rsvc.getTemplate(getArgument(context, node, 1)).merge(context, 
writer);
+            }
             return true;
 
         } catch (SocketTimeoutException ste) {
             LOG.error(ERR_NETWORK_DOWN + url + " --> " + ste.getMessage());
-
-        }catch(IOException se){
-            LOG.error(ERR_NETWORK_DOWN + url, se);
+ 
+        }catch(Exception e){
+            LOG.error(ERR_NETWORK_DOWN + url , e);
         }
 
         return false;

Modified: 
trunk/war/src/main/java/no/schibstedsok/searchportal/view/taglib/ImportPublishingPageTag.java
===================================================================
--- 
trunk/war/src/main/java/no/schibstedsok/searchportal/view/taglib/ImportPublishingPageTag.java
       2007-06-16 18:57:01 UTC (rev 5340)
+++ 
trunk/war/src/main/java/no/schibstedsok/searchportal/view/taglib/ImportPublishingPageTag.java
       2007-06-16 20:19:48 UTC (rev 5341)
@@ -8,14 +8,17 @@
 package no.schibstedsok.searchportal.view.taglib;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 import javax.servlet.jsp.JspWriter;
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.PageContext;
 import javax.servlet.jsp.tagext.JspFragment;
-import javax.servlet.jsp.tagext.SimpleTagSupport;
+import javax.xml.parsers.ParserConfigurationException;
 import no.schibstedsok.searchportal.datamodel.DataModel;
 import no.schibstedsok.searchportal.view.ImportPublish;
 import org.apache.log4j.Logger;
+import org.xml.sax.SAXException;
 
 /**
  *
@@ -23,14 +26,13 @@
  * @version $Id$
  */
 
-public final class ImportPublishingPageTag extends SimpleTagSupport {
+public final class ImportPublishingPageTag extends 
AbstractImportVelocityTemplateTag {
 
     private static final Logger LOG = 
Logger.getLogger(ImportPublishingPageTag.class);
 
-    /**
-     * Initialization of page property.
-     */
     private String page;
+    
+    private String template;
 
     /**Called by the container to invoke this tag.
      * The implementation of this method is provided by the tag library 
developer,
@@ -49,10 +51,27 @@
             }
 
             final DataModel datamodel = (DataModel) 
cxt.findAttribute(DataModel.KEY);
-            ImportPublish.importPage(page, datamodel, out);
             
+            if(null == template){
+                out.write(ImportPublish.importPage(page, datamodel));
+                
+            }else{
+                
+                try {
+                    
+                    final Map<String,Object> map = new 
HashMap<String,Object>();
+                    map.put("document", ImportPublish.importXml(page, 
datamodel));
+                    importTemplate(template, map);
+
+                } catch (ParserConfigurationException e) {
+                    LOG.error("Failed to import " + page + ".html");
+                } catch (SAXException e) {
+                    LOG.error("Failed to import " + page + ".html");
+                }
+            }
+            
         }catch(IOException e){
-            LOG.error("Failed to import pub" + page + ".html");
+            LOG.error("Failed to import " + page + ".html");
         }
 
     }
@@ -63,4 +82,9 @@
     public void setPage(final String value) {
         this.page = value;
     }
+    
+    /** Setter for template to parse **/
+    public void setTemplate(final String template){
+        this.template = template;
+    }
 }


Property changes on: 
trunk/war/src/main/java/no/schibstedsok/searchportal/view/taglib/ImportPublishingPageTag.java
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/war/src/webapp/WEB-INF/SearchPortal.tld
===================================================================
--- trunk/war/src/webapp/WEB-INF/SearchPortal.tld       2007-06-16 18:57:01 UTC 
(rev 5340)
+++ trunk/war/src/webapp/WEB-INF/SearchPortal.tld       2007-06-16 20:19:48 UTC 
(rev 5341)
@@ -40,6 +40,12 @@
       <rtexprvalue>true</rtexprvalue>
       <type>java.lang.String</type>
     </attribute>
+    <attribute>
+      <name>template</name>
+      <required>false</required>
+      <rtexprvalue>true</rtexprvalue>
+      <type>java.lang.String</type>
+    </attribute>
   </tag>
   <tag>
     <name>boomerang</name>

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to