You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jspwiki.apache.org by Robert G Leslie <rg...@regence.com> on 2008/07/01 19:38:20 UTC
XML-RPC Patch
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.***
Re: XML-RPC Patch
Posted by Janne Jalkanen <Ja...@ecyrd.com>.
Hi!
Thanks heaps! To observe the process (that is, to make sure we don't
forget about this) I would recommend that you open a JIRA issue (at
https://issues.apache.org/jira/browse/JSPWIKI), and attach your patch
to that issue as a patch (that is, in Eclipse: Team->Create Patch, or
use the "diff" command line tool.)
In addition, you need to specify which version of JSPWiki the patch
is against.
To quickly review your patch: your code should observe the security
measures added in the current SVN trunk to the XML-RPC interface as
well. This is needed or else anyone can overwrite any protected
pages through the XML-RPC interface (which would make it inherently
unsafe).
/Janne
On 1 Jul 2008, at 20:38, Robert G Leslie wrote:
> 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.***