}
/**
*/
public synchronized ConcreteElement postArticle( String provider, RunData rundata ) {
ElementContainer ec = new ElementContainer();
ParameterParser params = rundata.getParameters();
String topic = params.getString( "topic", "" );
String title = params.getString( "title", "" );
String link = params.getString( "link", "" );
String description = params.getString( "description", "" );
//create the JCM item
Item item = new Item();
item.setTopic( topic );
item.setTitle( title );
item.setLink( link );
item.setDescription( description );
Content content = null;
try {
content = this.getContentMarkup( this.getURL( provider ) ).getContent();
//BEGIN reorg of the item list so that the new entry begins at the top
Vector v = new Vector();
Item[] items = content.getChannel().getItem();
for ( int i = 0; i < items.length; ++i ) {
v.addElement( items[i] );
}
v.insertElementAt( item, 0 );
//now build this into a new array
Item[] newItems = new Item[ v.size() ];
v.copyInto( newItems );
content.getChannel().removeAllItem();
//now go through all the new items and add those
for ( int i = 0; i < newItems.length; ++i ) {
content.getChannel().addItem( newItems[i] );
}
//END reorg of the item list so that the new entry begins at the top
//save the portlet markup after you have made the changes.
this.getContentMarkup( this.getURL( provider ) ).save();
} catch ( Throwable t ) {
logger.error("Throwable", t);
return new StringElement( "Can't use this provider: " + t.getMessage() );
}
ec.addElement( "Your article '" + title + "' has been posted within '" + topic + "'" );
return ec;
}