| ||
![]() |
DeepestSourceFactory | |
|
This article provides the code for the DeepestSourceFactory.
Download Java code (DeepestSourceFactory.java). Download Java Class file (DeepestSourceFactory.class). ConfigurationAdd this line to webapp/WEB-INF/cocoon.xconf within the<component-instance class="com.solprovider.cocoon.DeepestSourceFactory" name="deep"/> ExamplesThis SourceFactory finds deepest file by incrementally removing directories.Example 1: deep:/C:\temp1\temp2\myfile.txt Tries: C:/temp1/temp2/myfile.txt, C:/temp1/myfile.txt, C:/myfile.txt Example 2: deep:/http://example.com/temp1/temp2/myfile.html Tries: http://example.com/temp1/temp2/myfile.html, http://example.com/temp1/myfile.html,http://example.com/myfile.html, http://myfile.html The starting level can be specified as the first parameter. Example 3: deep:/2/C:\temp1\temp2\temp3\temp4\myfile.txt checks for the same files as Example 1. Any valid protocol should be usable: Example 4: deep:/2/ftp://example.com/test1/test2/myfile.zip Tries: ftp://example.com/test1/myfile.zip, ftp://example.com/myfile.zip, ftp://myfile.zip Server names are considered a level as this class is indifferent to protocols. Relevant paths should also be usable: Example 4: deep:/2/test1/test2/myfile.xmap Tries: {currentPath}/test1/test2/myfile.zip, {currentPath}/test1/myfile.zip, {currentPath}/myfile.zip, Note the Excalibur FileSourceFactory does not allow the file: protocol to find relevant paths. The URLSourceFactory bypasses this bug by creating a FileSource without using the Factory. This example works because the URLSourceFactory is Cocoon's default when no protocol is specified. This class can be used to pass control to the deepest XMAP in a directory tree. <map:match pattern="**/*"/> <map:select type="resource-exists"> <map:when test="deep:/{1}/sitemap.xmap"> <map:mount uri-prefix="" src="deep:/{1}/sitemap.xmap"/> <map:serialize type="xml"/> </map:when> </map:select> <./map:match> Deeper XMAPs could contain code to find a higher XMAP using the deepest level parameter. If this XMAP was in the fourth directory from the root XMAP, this example specifies "3" levels so an XMAP in a higher directory is found. <map:match pattern="**/*"/> <!-- Do something special for this directory here. --> <!-- If nothing specific for this directory is needed, pass up to the next deepest XMAP. --> <map:select type="resource-exists"> <map:when test="deep:/3/{1}/sitemap.xmap"> <map:mount uri-prefix="" src="deep:/3/{1}/sitemap.xmap"/> <map:serialize type="xml"/> </map:when> </map:select> <./map:match>
|