Hi, new to the mailing list.  I've been working on adapting JSPWiki for my 
organization, and I wanted to put out some of the code that I've been 
working on to see if it might be worthy of a patch.  I have added several 
methods to the XML-RPC interface in RPCHandler.java.

Here they are:

/**
  * Sets the wiki markup of the specified wiki page to the specified text.
  *
  * @param pageName name of the wiki page whose text will be set
  * @param text     text the wiki page will be set to
  *
  * @return an empty string
  *
  * @author Rob Leslie
  */
  public String setPage( String pageName, String text )
      throws XmlRpcException
  { 
      try
      {
          WikiPage page = new WikiPage( m_engine, pageName );

          WikiContext context = new WikiContext( m_engine, page );

          m_engine.saveText( context, text );
      } 
      catch( Exception e )
      {
          log.error( "Failed to set page", e );
          throw new XmlRpcException( 0, "Failed to set page: " + 
e.getMessage() );
      }
 
      return "";
  }
 
/**
  * Attaches the specified file to the specified wiki page under the 
specified file
  * name.  File must be in Base 64.
  *
  * @param pageName name of the wiki page to which the file will be 
attached
  * @param file     file in Base 64 which will be attached
  * @param fileName name under which the file will be attached
  *
  * @return an empty string
  *
  * @author Rob Leslie
  */
  public String addAttachment( String pageName, String encodedString, 
String fileName )
      throws XmlRpcException, FileNotFoundException, IOException
  { 
      encodedString = encodedString.replaceAll( "\n", "" );
      encodedString = encodedString.replaceAll( "\r", "" );
 
      byte[] encodedBytes = encodedString.getBytes();
 
        org.apache.commons.codec.binary.Base64 decoder = new Base64();
 
        byte[] decodedBytes = decoder.decode( encodedBytes );
 
        try
        {
            m_engine.getAttachmentManager().storeAttachment( new 
Attachment( m_engine, pageName, fileName ), new ByteArrayInputStream( 
decodedBytes ) ); 
        }
        catch( Exception e )
        {
            log.error( "Failed to add attachment", e );
            throw new XmlRpcException( 0, "Failed to add attachment: " + 
e.getMessage() );
        }
 
        return "";
  }
 
/**
  * Attaches the specified file to the specified wiki page under the 
specified file
  * name.  File must be in Base 64.
  *
  * @param pageName name of the wiki page to which the file will be 
attached
  * @param file     file in Base 64 which will be attached
  * @param fileName name under which the file will be attached
  *
  * @return list of names of attachments on the specified wiki page
  *
  * @author Rob Leslie
  */ 
  public Vector getAttachments( String pageName )
      throws XmlRpcException
  {
      Collection coll;
 
        Vector result = new Vector();
 
        Attachment a;
 
        WikiPage page = new WikiPage( m_engine, pageName ); 
 
      try
        {
            coll = m_engine.getAttachmentManager().listAttachments( page 
); 
 
            for( Iterator i = coll.iterator(); i.hasNext(); )
            {
                a = (Attachment) i.next();
                result.add( a.getFileName() );
            } 
      }
        catch( Exception e )
        {
            log.error( "Failed to get attachments", e );
            throw new XmlRpcException( 0, "Failed to get attachments: " + 
e.getMessage() );
        }
 
        return result;
  }
***IMPORTANT NOTICE: This communication, including any attachment, contains 
information that may be confidential or privileged, and is intended solely for 
the entity or individual to whom it is addressed.  If you are not the intended 
recipient, you should delete this message and are hereby notified that any 
disclosure, copying, or distribution of this message is strictly prohibited.  
Nothing in this email, including any attachment, is intended to be a legally 
binding signature.***

Reply via email to