package edu.jhu.library.dspace.app.xmlui.aspect.general; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer; import org.dspace.app.xmlui.utils.UIException; import org.dspace.app.xmlui.wing.WingException; import org.dspace.app.xmlui.wing.element.Body; import org.dspace.app.xmlui.wing.element.PageMeta; import org.dspace.authorize.AuthorizeException; import org.xml.sax.SAXException; import java.io.IOException; import java.io.InputStream; import java.sql.SQLException; import java.util.Enumeration; import java.util.Properties; /** - Emits Subversion revision information of JScholarship found in the resource 'svnbuild.properties' to the DRI.
*/ public class JscholarshipVersionTransformer extends AbstractDSpaceTransformer { private static final Log log = LogFactory.getLog( JscholarshipVersionTransformer.class ); private final static String buildResource = "/svnbuild.properties"; private final static String metadataElementProperty = "meta.element"; private final static String defaultMetadataElementPropertyValue = "svn"; private final static Properties buildInfo = new Properties(); private static boolean available = false; static { InputStream is = JscholarshipVersionTransformer.class.getResourceAsStream( buildResource ); if ( is != null ) { try { buildInfo.load( is ); if ( buildInfo.size() > 0 ) { available = true; } } catch ( IOException e ) { log.warn( "Unable to load Subversion build information: " + e.getMessage() ); System.err.println( "Unable to load Subversion build information: " + e.getMessage() ); } } else { log.info( "Build information will not be availible. Resource " + buildResource + " not found." ); } }
public void addBody(Body body) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException { // To avoid an empty body. body.addDivision( "buildinfo" ).addPara( " " ); } public void addPageMeta( PageMeta pageMeta ) throws SAXException, WingException, UIException, SQLException, IOException, AuthorizeException { String element = buildInfo.getProperty( metadataElementProperty, defaultMetadataElementPropertyValue ); if ( available ) { pageMeta.addMetadata( element, "enabled" ).addContent( "true" ); Enumeration props = buildInfo.propertyNames(); while ( props.hasMoreElements() ) { String qualifier = (String)props.nextElement(); String metadataValue = buildInfo.getProperty( qualifier, "" ); pageMeta.addMetadata( element, qualifier ).addContent( metadataValue ); } } else { pageMeta.addMetadata( element, "enabled" ).addContent( "false" ); } } } |