1 23 24 package org.apache.slide.extractor; 25 26 import java.io.ByteArrayInputStream ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 30 import org.apache.slide.common.PropertyName; 31 import org.apache.slide.content.NodeRevisionContent; 32 import org.apache.slide.content.NodeRevisionDescriptor; 33 import org.apache.slide.content.NodeRevisionDescriptors; 34 import org.apache.slide.event.ContentAdapter; 35 import org.apache.slide.event.ContentEvent; 36 import org.apache.slide.event.VetoException; 37 38 41 public class PropertyExtractorTrigger extends ContentAdapter { 42 public void create(ContentEvent event) throws VetoException { 43 store(event); 44 } 45 46 public void store(ContentEvent event) throws VetoException { 47 try { 48 String namespaceName = event.getNamespace() == null ? null : event.getNamespace().getName(); 49 NodeRevisionDescriptors descriptors = event.getRevisionDescriptors(); 50 NodeRevisionDescriptor descriptor = event.getRevisionDescriptor(); 51 NodeRevisionContent content = event.getRevisionContent(); 52 if ( content != null && descriptor != null ) { 53 PropertyExtractor[] extractor = ExtractorManager.getInstance().getPropertyExtractors(namespaceName, descriptors, descriptor); 54 for ( int i = 0; i < extractor.length; i++ ) { 55 Map extractedProperties = extractor[i].extract(new ByteArrayInputStream (content.getContentBytes())); 56 for ( Iterator j = extractedProperties.entrySet().iterator(); j.hasNext(); ) { 57 Map.Entry entry = (Map.Entry ) j.next(); 58 final Object key = entry.getKey(); 59 if (key instanceof PropertyName) { 60 final String name = ((PropertyName) key).getName(); 61 final String namespace = ((PropertyName) key).getNamespace(); 62 descriptor.setProperty(name, namespace, entry.getValue()); 63 } 64 else { 65 descriptor.setProperty((String ) entry.getKey(), entry.getValue()); 66 } 67 } 68 } 69 } 70 } catch ( ExtractorException e ) { 71 throw new VetoException(e.getMessage()); 72 } 73 } 74 } | Popular Tags |