devdoc

Wednesday, October 19, 2005

RSS and XSLT

If you have a feed and want to display only a few elements and add an alternate backgournd color maybe this stylesheet can give you some ideas :)


<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">

<div id="bbcNews">
<h2 class="bbc">World News</h2>
<xsl:apply-templates/>
</div>
</xsl:template>



<xsl:template match="rss">
<xsl:apply-templates/>
</xsl:template>



<xsl:template match="item">
<xsl:variable name="numItem"><xsl:number count="item" level="multiple" format="1"></xsl:variable>
<xsl:if test="$numItem &lt; 10">
<xsl:if test="$numItem mod 2 = 0">
<p class="bbcNotShaded"><xsl:value-of select="title"> <a href="{link}"> ...more</a></p>
</xsl:if>
<xsl:if test="$numItem mod 2 = 1">
<p class="bbcShaded"><xsl:value-of select="title"> <a href="{link}"> ...more</a></p>
</xsl:if>
</xsl:if>

</xsl:template>




<xsl:template match="text()">


</xsl:stylesheet>

Tuesday, October 18, 2005

Images

It would be nice if we could set the height and width to any image withot knowing anything about the image....


/*
* Ivan Pedrazas, Created on 18-Oct-2005
*
* (c) SWORD-UK 18-Oct-2005
* FILE: ImageAnalizer.java
*
* */
package com.sword.intranet.documentum.job;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.documentum.fc.client.IDfSysObject;
import com.documentum.fc.common.DfException;


public class ImageAnalizer {


private static final long serialVersionUID = 1L;
/** Logger for this class and subclasses */
protected static final Log logger = LogFactory.getLog(ImageAnalizer.class);

public static void analize(IDfSysObject sysObj){

ByteArrayInputStream bias = null;

try {
bias = sysObj.getContent();
BufferedImage image = ImageIO.read(bias);
setData(image,sysObj);
bias.close();
} catch (IOException e) {
logger.error(e.getMessage());
}catch (DfException e) {
logger.error(e.getMessage());
}

}

private static void setData(BufferedImage image,IDfSysObject sysObj){
boolean fSave = false;
try {
if(sysObj.hasAttr("cs_width")){
int width = image.getWidth();
if(width>0){
sysObj.setString("cs_width",Integer.toString(width));
fSave = true;
}
}
if(sysObj.hasAttr("cs_height")){
int height = image.getHeight();
if(height>0){
sysObj.setString("cs_height",Integer.toString(height));
fSave = true;
}
}
if(fSave){
sysObj.save();
}
} catch (DfException e) {
logger.error(e.getMessage());
}

}
}