In this session, we will look first at the rich metadata that documents in your repository have, how to control the mapping of this on to your content model, and some of the interesting things this can deliver. We'll then move on to the content transformation and rendition services, and see how you can easily and powerfully generate a wide range of media from the content you already have.
55. Calling Apache Tika 13 // Get a content detector, and an auto-selecting Parser TikaConfigconfig = TikaConfig.getDefaultConfig(); ContainerAwareDetector detector = new ContainerAwareDetector( config.getMimeRepository() ); Parser parser = new AutoDetectParser(detector); // We’ll only want the plain text contents ContentHandler handler = new BodyContentHandler(); // Tell the parser what we have Metadata metadata = new Metadata(); metadata.set(Metadata.RESOURCE_NAME_KEY, filename); // Have it processed parser.parse(input, handler, metadata, new ParseContext());
57. Metadata Extractor – JavaScript Use 15 JavaScript var action = actions.create("extract-metadata"); action.execute(document); Full access is not directly available You can’t get at the raw properties You can, however, trigger extraction and saving to the node easily Available via an action
70. Content Transformer – JavaScript Use 23 JavaScript var action = actions.create("transform"); // Transform into the same folder action.parameters["destination-folder"] = document.parent; action.parameters["assoc-type"] = "{http://www.alfresco.org/model/content/1.0}contains"; action.parameters["assoc-name"] = document.name + "transformed"; action.parameters["mime-type"] = "text/html"; // Execute action.execute(document); Full access is not directly available You can’t control which property is transformed, it’s always Content You can control where the transformed version goes Triggering the transformation is easier than in Java Available via an action
71. Custom Tika Parsers - Interface 24 Interface public interface Parser { Set<MediaType> getSupportedTypes(ParseContext context); void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException; } The Tika Parser interface is quite simple Need to provide a list of supported mime types, so that auto-detection can work Accept an input stream, populate the Metadata object, and fire SAX events to the supplied handler That’s it!
72. Custom Tika Parser – Hello World Parser 25 public class HelloWorldParser implements Parser { public Set<MediaType> getSupportedTypes(ParseContext context) { Set<MediaType> types = new HashSet<MediaType>(); types.add(MediaType.parse("hello/world")); return types; } public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws SAXException { XHTMLContentHandlerxhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); xhtml.startElement("h1"); xhtml.characters("Hello, World!"); xhtml.endElement("h1"); xhtml.endDocument(); metadata.set("hello","world"); metadata.set("title","Hello World!"); } }
115. Learn More 40 wiki.alfresco.com forums.alfresco.com blogs.alfresco.com/wp/nickb/ twitter: @AlfrescoECM @Gagravarr
Hinweis der Redaktion
Use devconf-files/geotagged.jpgAKA quickGEO.jpg from projects/repository/source/test-resources/quick/Upload it into ShareGo to the details page, and show the EXIF and GEO bits
Create a script with the code shown, also available as devconf-js/contentTransformHellowWorld.jsCreate a simple .txt entry in explorerRun the script against itShow that we get a .bin with content type of hello/worldMaybe view the contents of thisRun the script againShow that we get a new plain text file, with the simple contents
Use quick.xls or similar from projects/repository/source/test-resources/quick/Upload it into ExplorerRun a custom action which is a scriptvarnameBase = document.name.substring(0, document.name.lastIndexOf("."));var action = actions.create("transform");action.parameters["destination-folder"] = document.parent;action.parameters["assoc-type"] = "{http://www.alfresco.org/model/content/1.0}contains";action.parameters["assoc-name"] = nameBase + ".txt";action.parameters["mime-type"] = "text/plain";action.execute(document);action.parameters["assoc-name"] = nameBase + ".csv";action.parameters["mime-type"] = "text/csv";action.execute(document);action.parameters["assoc-name"] = nameBase + ".html";action.parameters["mime-type"] = "text/xml";action.execute(document);
In Share, create a rule on a folder to execute the script belowEnsure the folder that the script writes to isn’t a child!Upload an image, at least 600x400 big into the folderIn share, use the repo browser to get to the special folder, and show the smaller cropped versionvarrenditionDef = renditionService.createRenditionDefinition("Test", "htmlRenderingEngine");renditionDef.parameters["destination-path-template"] = "/Company Home/Test/${name}.html";renditionDef.execute(document);renditionDef.parameters["destination-path-template"] = "/Company Home/Test/BodyOnly/${name}.html";renditionDef.parameters["bodyContentsOnly"] = true;
In share, create a Video folder, and a Video Drop subfolderOn the subfolder, create a ruleRule is copy + transformTarget mimetype is flash videoTarget directory is the parent (Videos)Don’t run in the backgroundUpload devconf-files/Video.mp4WaitHopefully show the thumbnail of the .mp4 (refresh if needed)Go to the videos directoryShow the large preview image of the new .flv image
Upload a .docx (including images) to a Web Quick Start folder with .docx extraction enabled via ShareView in Share the HTML, to show what it looks likeFlip to the WCM site, and show it with imagesBACKUP – Create a script based on devconf-files/renderTest.jsIn share, create a folder with a rule of execute scriptPick the scriptUpload devconf-files/word3imgs.docxGo to Company Home/TestShow the htmlShow the images(You can’t show the two together without WCM, sorry....)