Lab 9 - Configure a new link definition with extractor/interceptor

During the lab, you will be configuring a link definition with a link extractor and interceptor for XHTML hyperlinks and images.

  1. In the lab folder, create a new Spring context file named context.xml.
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
    </beans>
  2. Open the context.xml file in your favorite editor.
  3. Create a new Document Type bean for the XHTML DOCTYPE.
    <bean id="samples.dtd.xhtml" parent="xml.schema.dtd.abstract">
      <property name="label" value="XHTML" />
      <property name="id" value="html" />
      <property name="publicId" value="-//W3C//DTD XHTML 1.0 Transitional//EN" />
      <property name="systemId" value="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
    </bean>
  4. Create a new Link Definition bean for XHTML hyperlinks.
  5. Add the following properties to the Link Definition bean as required:
    Property Type Mandatory Description
    role String Required Used to categorize and filter the links in the Manage Links dialog.
    elements Set <String> Optional List of elements that define the link. If the property is undefined, then the link can be defined by any element. The elements property must be defined if the attributes property is not.
    attributes Set <String> Optional List of attributes (if any) that define the link. The attributes property must be defined if the elements property is not.
    attributeMappings Map <String,QName> Optional Defines how the link element attributes (all attributes on the matched link element) should be mapped to predicates. By default, the href attribute is mapped to the qname.xlink.href predicate. One of the attributes must be mapped to the qname.xlink.href predicate in order for the link to be validated. Use a fully-qualified name with Clark notation as the key of the entry.
    <bean id="xhtml.linkDefinition.href" parent="xlink.rdf.linkDefinition.abstract">
      <property name="role" value="hyperlink" />
      <property name="attribute" value="href" />
      <property name="attributeMappings">
        <map>
          <entry key="href" value="{http://www.w3.org/1999/xlink}href" />
        </map>
      </property>
    </bean>
  6. Create another Link Definition bean for XHTML img links to images.
    <bean id="xhtml.linkDefinition.img" parent="xlink.rdf.linkDefinition.abstract">
      <property name="role" value="image" />
      <property name="element" value="{http://www.w3.org/1999/xhtml}img" />
      <property name="attribute" value="src" />
      <property name="attributeMappings">
        <map>
          <entry key="alt" value="{http://www.w3.org/1999/xlink}title" />
          <entry key="src" value="{http://www.w3.org/1999/xlink}href" />
        </map>
      </property>
    </bean>
  7. Create an XLink Extractor bean for the XHTML hyperlink and img links.
  8. Add the following properties to the XLink Extractor bean as required:
    Property Type Mandatory Description
    xmlSchemaFilter XmlSchemaFilter Required A filter for which the bean applies.
    linkDefinitions List < LinkDefinition > Required A list of Link Definitions.
    <bean id="xhtml.xlink.extractor" parent="xlink.rdf.extractor.link.abstract">
      <property name="xmlSchemaFilter" ref="samples.dtd.xhtml" />
      <property name="linkDefinitions">
        <list>
          <ref bean="xhtml.linkDefinition.href" />
          <ref bean="xhtml.linkDefinition.img" />
        </list>
      </property>
    </bean>
  9. Create an XLink Interceptor bean for the XHTML hyperlink and img links.
  10. Add the following properties to the XLink Interceptor bean as required:
    Property Type Mandatory Description
    xmlSchemaFilter XmlSchemaFilter Required A filter for which the bean applies.
    linkDefinitions List < LinkDefinition > Required A list of Link Definitions.
    <bean id="xhtml.xlink.interceptor" parent="xlink.rdf.interceptor.link.abstract">
      <property name="xmlSchemaFilter" ref="samples.dtd.xhtml" />
      <property name="linkDefinitions">
        <list>
          <ref bean="xhtml.linkDefinition.href" />
          <ref bean="xhtml.linkDefinition.img" />
        </list>
      </property>
    </bean>
  11. Save your changes.
  12. Test your Link Definition beans, XLink Extractor and XLink Interceptor with the XHtmlLinkExtractorTest and XHtmlLinkExtractorAlfrescoTest unit tests in com.componize.samples.lab09.
  13. Deploy your files to the application server.
  14. Once the application server has started, connect to the Alfresco Share interface.
  15. Add the Metadata & Link Management aspect to the XHTML sample files.
  16. Use the Where Used action to view and browse the extracted links.
  17. Move or rename the sample files and check the link paths are updated automatically.
The XHTML hyperlinks and image links should be extracted and automatically managed by Componize.