http://wiki.alfresco.com/wiki/Metadata_Extraction
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"[]>
<!– Registrar nuevo extractor de metadato personalizado de office –>
<beans>
<bean id="extracter.CustomOpenOffice" class="org.alfresco.sample.CustomOpenOfficeMetadataExtracter" parent="baseMetadataExtracter">
<property name="inheritDefaultMapping">
<value>true</value>
</property>
<property name="mappingProperties">
<props>
<prop key="namespace.prefix.cds">http://www.cds.org/model/content/1.0</prop>
<prop key="category">cds:clasificacion</prop>
<prop key="template">cds:plantilla</prop>
</props>
</property>
</bean>
</beans>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<!– Registrar el nuevo extractor de metadato personalizado de office –>
<beans>
<bean id="extracter.CustomOpenOffice" class="org.alfresco.sample.CustomOpenOfficeMetadataExtracter" parent="baseMetadataExtracter" />
</beans>
package org.alfresco.sample;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Map;
import java.util.ArrayList;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.metadata.TikaPoweredMetadataExtracter;
import org.apache.log4j.Logger;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.Parser;
import org.apache.tika.parser.microsoft.OfficeParser;
import org.alfresco.service.cmr.repository.ContentReader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class CustomOpenOfficeMetadataExtracter extends TikaPoweredMetadataExtracter {
public static final String KEY_CATEGORY = "category";
public static final String KEY_TEMPLATE = "template";
public static ArrayList<String> SUPPORTED_MIMETYPES= buildSupportedMimetypes(new String[] {MimetypeMap.MIMETYPE_EXCEL}, new OfficeParser());
private static final String CUSTOM_PREFIX = "cds:";
protected static Log logger = LogFactory.getLog(CustomOpenOfficeMetadataExtracter.class);
public CustomOpenOfficeMetadataExtracter() {
super(SUPPORTED_MIMETYPES);
//logger.debug("Initializing CustomOpenOfficeMetadataExtracter logger constructor");
// TODO Auto-generated constructor stub
}
@Override
protected Parser getParser() {
// TODO Auto-generated method stub
return new OfficeParser();
}
@Override
public Map<String, Serializable> extractRaw(ContentReader reader) {
Map<String, Serializable> rawProperties = newRawMap();
Metadata metadatap=new Metadata();
putRawValue("category", metadatap.get(Metadata.CATEGORY), rawProperties);
putRawValue("template", metadatap.get(Metadata.TEMPLATE), rawProperties);
String metadataCategory= metadatap.get(Metadata.CATEGORY);
logger.info("\n\nPropiedad categoria:" + metadataCategory + "\n");
String metadataTemplate= metadatap.get(Metadata.TEMPLATE);
logger.info("\n\nPropiedad plantilla:" + metadataTemplate + "\n");
logger.info("Poniendo datos?");
logger.info("\n\nPropiedades de vuelta:" + rawProperties.toString() + "\n");
return rawProperties;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<model name = "cds:cdsmodel" xmlns = "http://www.alfresco.org/model/dictionary/1.0">
<!– Metadatos opcionales del modelo personalizado –>
<description>Modelo personalizado</description>
<author>Yaraiza</author>
<version>1.0</version>
<imports>
<!– Importamos definiciones de Alfresco, concretamente el dicionario y modelo de contenido –>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<!– Import Alfresco Content Domain Model Definitions –>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
</imports>
<!– Registramos el Nuevo namespaces que se utilizara en este modelo –>
<namespaces>
<namespace uri = "http://www.cds.org/model/content/1.0" prefix = "cds"/>
</namespaces>
<aspects>
<!– Definicion de los aspectos personalizados del modelo –>
<aspect name = "cds:aspectClasificacionDoc">
<title>Clasificacion de Documentos</title>
<properties>
<property name = "cds:clasificacion">
<title>Categoría</title>
<type>d:text</type>
</property>
<property name = "cds:validar">
<title>Validable</title>
<type>d:boolean</type>
<default>false</default>
</property>
<property name = "cds:plantilla">
<title>Plantilla</title>
<type>d:text</type>
</property>
</properties>
</aspect>
</aspects>
</model>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<!– Registro del modelo cdsModel –>
<bean id="extension.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
<property name="models">
<list>
<value>org/alfresco/sample/cdsModel.xml</value>
</list>
</property>
</bean>
</beans>
<alfresco-config>
<!– Si queremos que el nuevo aspecto aparezca como opción en el wizard de reglas de contenido–>
<config evaluator = "string-compare" condition = "Action Wizards">
<aspects>
<aspect name = "cds:aspectClasificacionDoc"/>
</aspects>
</config>
<!– Para poder editar las propiedades que hemos definido en el nuevo aspect–>
<config evaluator = "aspect-name" condition = "cds:aspectClasificacionDoc">
<property-sheet>
<show-property name="cds:clasificacion" displaylabelid="Categoría"/>
<show-property name="cds:validar" displaylabelid="Validable" readonly="true"/>
<show-property name="cds:plantilla" displaylabelid="Plantilla" readonly="true"/>
</property-sheet>
</config>
</alfresco-config>
15:10:10,593 DEBUG [org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter] Completed metadata extraction:
reader: ContentAccessor[ contentUrl=store://C:\Alfresco\tomcat\temp\Alfresco\alfresco1123639261342029096.upload, mimetype=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, size=8274, encoding=UTF-8, locale=en_US]
extracter: org.alfresco.sample.CustomOpenOfficeMetadataExtracter@21eb3f
changed: {{http://www.cds.org/model/content/1.0}plantilla=null, {http://www.cds.org/model/content/1.0}clasificacion=CDS}
<?xml version="1.0" encoding="UTF-8"?>
<model name = "cds:cdsmodel" xmlns = "http://www.alfresco.org/model/dictionary/1.0">
<!– Metadatos opcionales del modelo personalizado –>
<description>Modelo personalizado</description>
<author>Yaraiza</author>
<version>1.0</version>
<imports>
<!– Importamos definiciones de Alfresco, concretamente el dicionario y modelo de contenido –>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<!– Import Alfresco Content Domain Model Definitions –>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
</imports>
<!– Registramos el Nuevo namespaces que se utilizara en este modelo –>
<namespaces>
<namespace uri = "http://www.cds.org/model/content/1.0" prefix = "cds"/>
</namespaces>
<aspects>
<!– Definicion de los aspectos personalizados del modelo –>
<aspect name = "cds:aspectClasificacionDoc">
<title>Clasificacion de Documentos</title>
<properties>
<property name = "cds:clasificacion">
<title>Categoría</title>
<type>d:text</type>
</property>
<property name = "cds:validar">
<title>Validable</title>
<type>d:boolean</type>
<default>false</default>
</property>
<property name = "cds:plantilla">
<title>Plantilla</title>
<type>d:text</type>
</property>
</properties>
</aspect>
</aspects>
</model>
<alfresco-config>
<!– Si queremos que el nuevo aspecto aparezca como opción en el wizard de reglas de contenido–>
<config evaluator = "string-compare" condition = "Action Wizards">
<aspects>
<aspect name = "cds:aspectClasificacionDoc"/>
</aspects>
</config>
<!– Para poder editar las propiedades que hemos definido en el nuevo aspect–>
<config evaluator = "aspect-name" condition = "cds:aspectClasificacionDoc">
<property-sheet>
<show-property name="cds:clasificacion" displaylabelid="Categoría"/>
<show-property name="cds:validar" displaylabelid="Validable" readonly="true"/>
<show-property name="cds:plantilla" displaylabelid="Plantilla" readonly="true"/>
</property-sheet>
</config>
</alfresco-config>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"[]>
<!– Registrar nuevo extractor de metadato personalizado de office –>
<beans>
<bean id="extracter.CustomOpenOffice" class="org.alfresco.sample.CustomOpenOfficeMetadataExtracter" parent="baseMetadataExtracter">
<property name="inheritDefaultMapping">
<value>true</value>
</property>
<property name="mappingProperties">
<props>
<prop key="namespace.prefix.cds">http://www.cds.org/model/content/1.0</prop>
<prop key="category">cds:clasificacion</prop>
<prop key="template">cds:plantilla</prop>
</props>
</property>
</bean>
</beans>
protected Parser getParser() {
// TODO Auto-generated method stub
return new OOXMLParser();
}
public static ArrayList<String> SUPPORTED_MIMETYPES= buildSupportedMimetypes(new String[] {
MimetypeMap.MIMETYPE_EXCEL,
MimetypeMap.MIMETYPE_WORD,
MimetypeMap.MIMETYPE_PPT}, new OOXMLParser());
Content from pre 2016 and from language groups that have been closed.
Content is read-only.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.