AnsweredAssumed Answered

Error con extractor de metadatos para OpenOffice

Question asked by durdy48 on Nov 26, 2007
Hola a todos!

He realizado un extractor de metadatos personalizado para archivos OpenOffice para ello he realizado lo siguiente:
En el custom-metadata-extractors-context.xml me declaro el bean:
<beans>

    <bean id="extracter.OpenOffice" class="es.juntadeandalucia.ceh.dgsief.metadata.SPOpenOfficeMetadataExtracter" parent="baseMetadataExtracter" >
        <property name="inheritDefaultMapping">
            <value>true</value>
        </property>
        <property name="mappingProperties">
            <props>
                <prop key="namespace.prefix.sp">http://www.juntadeandalucia.es/economiayhacienda/sief/sp</prop>
                <prop key="SP_AREA">sp:area</prop>
                <prop key="SP_ASUNTO">sp:asunto</prop>
                <prop key="SP_AUTOR">sp:autor</prop>
                <prop key="SP_CATEGORIA">sp:categoria</prop>
                <prop key="SP_COMGENERALES">sp:comgenerales</prop>
                <prop key="SP_DIRIGIDOA">sp:dirigidoa</prop>
                <prop key="SP_DUENO">sp:dueno</prop>
                <prop key="SP_FORMATODOC">sp:formatodoc</prop>
                <prop key="SP_IDLENGUA">sp:idlengua</prop>
                <prop key="SP_IDVERSION">sp:idversion</prop>
                <prop key="SP_LOCALIZACION">sp:localizacion</prop>
                <prop key="SP_NIVELDESEGURIDAD">sp:niveldeseguridad</prop>
                <prop key="SP_PALABRASCLAVES">sp:palabrasclaves</prop>
                <prop key="SP_PROCEDEDE">sp:procedede</prop>
                <prop key="SP_PROYECTO">sp:proyecto</prop>
                <prop key="SP_RESUMEN">sp:resumen</prop>
                <prop key="SP_SO">sp:so</prop>
                <prop key="SP_SOFTCREACION">sp:softcreacion</prop>
                <prop key="SP_SUBAREA">sp:subarea</prop>
                <prop key="SP_SUBCATEGORIA">sp:subcategoria</prop>
                <prop key="SP_SUBPROYECTO">sp:subproyecto</prop>
                <prop key="SP_TIPODOC">sp:tipodoc</prop>
                <prop key="SP_TITULO">sp:titulo</prop>
                <prop key="SP_VERSO">sp:verso</prop>
                <prop key="SP_VERSOFTCREACION">sp:versoftcreacion</prop>
                <prop key="SP_CONSEJERIA">sp:consejeria</prop>
                <prop key="SP_DG">sp:dg</prop>
                <prop key="SP_SERVICIO">sp:servicio</prop>
                <prop key="SP_REVISION">sp:revision</prop>
                <prop key="SP_CLASIFICACION">sp:clasificacion</prop>
            </props>
        </property>
    </bean>

</beans>

Tengo mi propio modelo de datos en mi metadatosModel.xml

En el metadatos-model-context.xml indico donde está el nuevo modelo.

En el web-client-config-custom.xml indico lo que quiero mostrar en mi interfaz.

<config evaluator="aspect-name" condition="sp:metadatosSP">
      <property-sheet>
         <show-property name="sp:area"/>
         <show-property name="sp:asunto"/>
      <!– Se usa el aspecto Author para esta propiedad –>
      <!–
         <show-property name="sp:autor"/>
      –>
         <show-property name="sp:categoria"/>
         <show-property name="sp:comgenerales"/>
         <show-property name="sp:dirigidoa"/>
         <show-property name="sp:dueno"/>
         <show-property name="sp:formatodoc"/>
         <show-property name="sp:idlengua"/>
         <show-property name="sp:idversion"/>
         <show-property name="sp:localizacion"/>
         <show-property name="sp:niveldeseguridad"/>
         <show-property name="sp:palabrasclaves"/>
         <show-property name="sp:procedede"/>
         <show-property name="sp:proyecto"/>
         <show-property name="sp:resumen"/>
         <show-property name="sp:so"/>
         <show-property name="sp:softcreacion"/>
         <show-property name="sp:subarea"/>
         <show-property name="sp:subcategoria"/>
         <show-property name="sp:subproyecto"/>
         <show-property name="sp:tipodoc"/>
         <!– Se usa el aspecto Titled para esta propiedad –>
      <!–
         <show-property name="sp:titulo"/>
      –>
         <show-property name="sp:verso"/>
         <show-property name="sp:versoftcreacion"/>
         <show-property name="sp:consejeria"/>
         <show-property name="sp:dg"/>
         <show-property name="sp:servicio"/>
         <show-property name="sp:revision"/>
         <show-property name="sp:clasificacion"/>
      </property-sheet>
   </config>

Y finalmente tengo el bean siguiente:


package es.juntadeandalucia.ceh.dgsief.metadata;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.Serializable;
import java.net.ConnectException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;

import net.sf.jooreports.openoffice.connection.OpenOfficeConnection;

import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.util.PropertyCheck;
import org.alfresco.util.TempFileProvider;

import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.document.XDocumentInfoSupplier;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.ucb.XFileIdentifierConverter;
import com.sun.star.uno.UnoRuntime;

/**
* Extracts values from Star Office documents into the following:
* <pre>
*   <b>author:</b>                 –      cm:author
*   <b>title:</b>                  –      cm:title
*   <b>description:</b>            –      cm:description
* </pre>
*
* @author Jesper Steen MíƒÂ¸ller
*/
public class SPOpenOfficeMetadataExtracter extends AbstractMappingMetadataExtracter
{
    private static final String KEY_AUTHOR = "author";
    private static final String KEY_TITLE = "title";
    private static final String KEY_DESCRIPTION = "description";

    public static String[] SUPPORTED_MIMETYPES = new String[] {
        MimetypeMap.MIMETYPE_STAROFFICE5_WRITER,
        MimetypeMap.MIMETYPE_STAROFFICE5_IMPRESS,
        MimetypeMap.MIMETYPE_OPENOFFICE1_WRITER,
        MimetypeMap.MIMETYPE_OPENOFFICE1_IMPRESS,
    // Add the other OpenOffice.org stuff here
        MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT_TEMPLATE,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_GRAPHICS,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_GRAPHICS_TEMPLATE,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_PRESENTATION,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_PRESENTATION_TEMPLATE,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_SPREADSHEET,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_SPREADSHEET_TEMPLATE,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_CHART,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_CHART_TEMPLATE,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_IMAGE,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_IMAGE_TEMPLATE,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_FORMULA,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_FORMULA_TEMPLATE,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT_MASTER,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT_WEB,
        MimetypeMap.MIMETYPE_OPENDOCUMENT_DATABASE
    // In fact, other types may apply as well, but should be counted as lower
    // quality since they involve conversion.
    };

    private OpenOfficeConnection connection;

    public SPOpenOfficeMetadataExtracter()
    {
        super(new HashSet<String>(Arrays.asList(SUPPORTED_MIMETYPES)));
    }

    public void setConnection(OpenOfficeConnection connection)
    {
        this.connection = connection;
    }
   
    private synchronized void connect()
    {
        if (isConnected())
        {
            // just leave it
        }
        else
        {
            try
            {
                connection.connect();
            }
            catch (ConnectException e)
            {
                logger.warn(e.getMessage());
            }
        }
    }

    /**
     * Initialises the bean by establishing an UNO connection
     */
    @Override
    public synchronized void init()
    {
        PropertyCheck.mandatory("OpenOfficeMetadataExtracter", "connection", connection);
       
        // Base initialization
        super.init();

        // attempt a connection
        connect();
        // Only allow registration if the connection is good
        if (!isConnected())
        {
            // Reconnections are only supported if the server is able to connection initially.
            super.setRegistry(null);
        }
    }

    /**
     * @return Returns true if a connection to the Uno server could be
     *         established
     */
    public boolean isConnected()
    {
        return connection.isConnected();
    }

    @Override
    public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
    {
        Map<String, Serializable> rawProperties = newRawMap();

        String sourceMimetype = reader.getMimetype();

        // create temporary files to convert from and to
        File tempFromFile = TempFileProvider.createTempFile(
                "OpenOfficeMetadataExtracter-", "."
                + getMimetypeService().getExtension(sourceMimetype));
        // download the content from the source reader
        reader.getContent(tempFromFile);

        String sourceUrl = toUrl(tempFromFile, connection);

        // UNO Interprocess Bridge *should* be thread-safe, but…
        synchronized (connection)
        {
            XComponentLoader desktop = connection.getDesktop();
            XComponent document = desktop.loadComponentFromURL(
                    sourceUrl,
                    "_blank",
                    0,
                    new PropertyValue[] { property("Hidden", Boolean.TRUE) });
            if (document == null)
            {
                throw new FileNotFoundException("could not open source document: " + sourceUrl);
            }
            try
            {
                XDocumentInfoSupplier infoSupplier = (XDocumentInfoSupplier) UnoRuntime.queryInterface(
                        XDocumentInfoSupplier.class, document);
                XPropertySet propSet = (XPropertySet) UnoRuntime.queryInterface(
                        XPropertySet.class,
                        infoSupplier
                        .getDocumentInfo());

                putRawValue(KEY_TITLE, propSet.getPropertyValue("Title").toString(), rawProperties);
                putRawValue(KEY_DESCRIPTION, propSet.getPropertyValue("Subject").toString(), rawProperties);
                putRawValue(KEY_AUTHOR, propSet.getPropertyValue("Author").toString(), rawProperties);
            }
            finally
            {
                document.dispose();
            }
        }
        // Done
        return rawProperties;
    }

    public String toUrl(File file, OpenOfficeConnection connection) throws ConnectException
    {
        Object fcp = connection.getFileContentProvider();
        XFileIdentifierConverter fic = (XFileIdentifierConverter) UnoRuntime.queryInterface(
                XFileIdentifierConverter.class, fcp);
        return fic.getFileURLFromSystemPath("", file.getAbsolutePath());
    }

    public double getReliability(String sourceMimetype)
    {
        if (isConnected())
            return super.getReliability(sourceMimetype);
        else
            return 0.0;
    }

    private static PropertyValue property(String name, Object value)
    {
        PropertyValue property = new PropertyValue();
        property.Name = name;
        property.Value = value;
        return property;
    }
}


Pero al ejecutar me da el siguiente error:

09:45:05,495 ERROR [[Catalina].[localhost].[/alfresco]] Excepción enviando evento inicializado de contexto a instancia de escuchador de clase org.alfresco.web.app.ContextListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'extracter.OpenOffice' defined in file [C:\alfrescoTomcat2.1\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension\custom-metadata-extractors-context.xml]: Invocation of init method failed; nested exception is org.alfresco.error.AlfrescoRuntimeException: La Propiedad 'connection' no se ha establecido: SPOpenOfficeMetadataExtracter
Caused by:
org.alfresco.error.AlfrescoRuntimeException: La Propiedad 'connection' no se ha establecido: SPOpenOfficeMetadataExtracter
   at org.alfresco.util.PropertyCheck.mandatory(PropertyCheck.java:50)
   at es.juntadeandalucia.ceh.dgsief.metadata.SPOpenOfficeMetadataExtracter.init(SPOpenOfficeMetadataExtracter.java:129)
   at org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter.register(AbstractMappingMetadataExtracter.java:432)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1160)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1122)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1085)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:273)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
   at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
   at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
   at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
   at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
   at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:825)
   at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:714)
   at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
   at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
   at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
   at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
   at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
   at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
   at org.apache.catalina.core.StandardService.start(StandardService.java:448)
   at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
   at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
   at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
26-nov-2007 9:45:05 org.apache.catalina.core.StandardContext start

ALGUNA AYUDA POR FAVOR?

Outcomes