portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raph...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager CastorPsmlManagerService.java
Date Sun, 02 Mar 2003 19:35:21 GMT
raphael     2003/03/02 11:35:21

  Modified:    src/java/org/apache/jetspeed/services/psmlmanager
                        CastorPsmlManagerService.java
  Log:
  Fix for bug 13286 - Jetspeed always used system encoding for saving PSML
  
  Changed this behavior to use content.defaultencoding property in
  JR.p
  
  thanks to Shinsuke SUGAYA <shinsuke@yahoo.co.jp> for the patch
  
  Revision  Changes    Path
  1.37      +34 -11    jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java
  
  Index: CastorPsmlManagerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- CastorPsmlManagerService.java	2 Mar 2003 15:45:08 -0000	1.36
  +++ CastorPsmlManagerService.java	2 Mar 2003 19:35:21 -0000	1.37
  @@ -62,6 +62,7 @@
   import org.apache.jetspeed.services.Profiler;
   import org.apache.jetspeed.services.JetspeedSecurity;
   import org.apache.jetspeed.services.security.UserException;
  +import org.apache.jetspeed.services.resources.JetspeedResources;
   
   //Castor defined API
   import org.apache.jetspeed.om.profile.Portlets;
  @@ -94,6 +95,9 @@
   import org.exolab.castor.mapping.Mapping;
   import org.exolab.castor.mapping.MappingException;
   import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Node;
   
   // serialization support
   import org.apache.xml.serialize.Serializer;
  @@ -105,7 +109,8 @@
   import java.io.Reader;
   import java.io.FileReader;
   import java.io.Writer;
  -import java.io.FileWriter;
  +import java.io.FileOutputStream;
  +import java.io.OutputStreamWriter;
   import java.io.IOException;
   import java.net.URL;
   import java.util.Date;
  @@ -115,6 +120,9 @@
   import java.util.Map;
   import java.util.HashMap;
   import javax.servlet.ServletConfig;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.parsers.ParserConfigurationException;
   
   import org.apache.jetspeed.cache.FileCache;
   import org.apache.jetspeed.cache.FileCacheEventListener;
  @@ -181,6 +189,9 @@
       /** the Castor mapping file name */
       protected Mapping mapping = null;
   
  +    /** The default encoding used to serialize PSML files to disk */
  +    protected String defaultEncoding = JetspeedResources.getString(JetspeedResources.CONTENT_ENCODING_KEY,
"utf-8");
  +
       /**
        * This is the early initialization method called by the
        * Turbine <code>Service</code> framework
  @@ -431,12 +442,15 @@
   
               // now that we have a file reference, try to load the serialized PSML
               Portlets portlets = null;
  -            FileReader reader = null;
               try
               {
  -                reader = new FileReader(f);
  +                DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
  +                DocumentBuilder builder = dbfactory.newDocumentBuilder();
  +
  +                Document d = builder.parse(f);
   
  -                portlets = load(reader);
  +                Unmarshaller unmarshaller = new Unmarshaller(this.mapping);
  +                portlets = (Portlets)unmarshaller.unmarshal((Node) d);
   
                   doc.setPortlets(portlets);
   
  @@ -461,9 +475,15 @@
                   Log.error("PSMLManager: document "+f.getAbsolutePath()+" is not valid",
e);
                   doc = null;
               }
  -            finally
  +            catch (ParserConfigurationException e)
  +            {
  +                Log.error("PSMLManager: Could not load the file "+f.getAbsolutePath(),
e);
  +                doc = null;
  +            }
  +            catch (SAXException e)
               {
  -                try { reader.close(); } catch (IOException e) {}
  +                Log.error("PSMLManager: Could not load the file "+f.getAbsolutePath(),
e);
  +                doc = null;
               }
           }
   
  @@ -538,12 +558,12 @@
               f = new File(fileOrUrl);
           }
   
  -
  -        FileWriter writer = null;
  -
  +        OutputStreamWriter writer = null;
           try
           {
  -            writer = new FileWriter(f);
  +            String encoding = this.defaultEncoding;
  +            writer = new OutputStreamWriter(new FileOutputStream(f), encoding);
  +
               save(writer, doc.getPortlets());
               success = true;
           }
  @@ -632,8 +652,11 @@
       protected void save(Writer writer, Portlets portlets)
           throws IOException, MarshalException, ValidationException, MappingException
       {
  +        String encoding = this.defaultEncoding;
  +
           if (portlets != null)
           {
  +            format.setEncoding(encoding);
               Serializer serializer = new XMLSerializer(writer, format);
               Marshaller marshaller = new Marshaller(serializer.asDocumentHandler());
               marshaller.setMapping(this.mapping);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message