On DD4T Java version2, component link(dynamic linking) in rich text field(format area) doesn't resolved.
On rich text field, link to component can be added by clicking "Hyperlink" button, then selecting "Component" on Type dropdownlist and select a component. Following code is added to richtext field.
<a href="tcm:6-109">link</a>
But following error occurs when publishing by DD4T TBB(Version of TBB is 2.0.2-beta.).
This Component is not a Multimedia Component: tcm:64-109
So I modified TBB source code,BinaryPublisher class, PublishBinariesInRichTextField method, not to publish components which are not multimedia component.
My modified source code is following.
foreach (XmlElement elmt in xml.SelectNodes("//*[@xlink:href[starts-with(string(.),'tcm:')]]", xml.NamespaceManager))
{
log.Debug("found node " + elmt.OuterXml);
XmlAttribute link = (XmlAttribute)elmt.SelectSingleNode("@xlink:href", xml.NamespaceManager);
if(((Component)engine.GetObject(link.FirstChild.Value)).ComponentType!=ComponentType.Multimedia){
log.Debug("this is not multimedia component, so skip:" + link.FirstChild.Value);
continue;
}
Now publishing succeed and following content is published.
<a xlink:href="tcm:6-109">link</a>
On WEB application server,there is a XSLT file "resolveXhtmlWithLinks.xslt". This XSLT seems to resolve component link, but it causes compile error, because a class "LinkResolverFactory" specified on variable element is not existing.
<xsl:template match="*[@xlink:href]">
<xsl:variable name="factory"
select="java:org.dd4t.core.factories.impl.LinkResolverFactory.getInstance()"/>
<xsl:variable name="resolver"
select="java:getLinkResolver($factory)"/>
<xsl:variable name="resolved-link"
select="java:resolve($resolver, string(@xlink:href))"/>
I tried customize source code to make it work, but I couldn't.
What is "LinkResolverFactory"? Can I get it from somewhere? How can I make link to component in rich text field work?
Regards,
UPDATE
It works by following customizations
Add "getInstance" method to DefaultLinkResolver
private static final DefaultLinkResolver INSTANCE = new DefaultLinkResolver();
public static final DefaultLinkResolver getInstance() {
return INSTANCE;
}
Edit resolveXhtmlWithLinks.xslt.
<xsl:variable name="resolver"
select="java:org.dd4t.core.resolvers.impl.DefaultLinkResolver.getInstance()"/>
<xsl:variable name="resolved-link"
select="java:resolve($resolver, string(@xlink:href))"/>
In urlmapping.xml, add "factory-method" attribute to bean with id="LinkResolver".
<bean id="LinkResolver" class="org.dd4t.core.resolvers.impl.DefaultLinkResolver" factory-method="getInstance">