From: <wol...@us...> - 2009-11-29 10:02:48
|
Revision: 10664 http://exist.svn.sourceforge.net/exist/?rev=10664&view=rev Author: wolfgang_m Date: 2009-11-29 10:02:42 +0000 (Sun, 29 Nov 2009) Log Message: ----------- [feature] XQDoc module: changed scan function to extract a short name for the scanned module URI; remove leading "declare function " from function signatures. Port of rev 10663 Revision Links: -------------- http://exist.svn.sourceforge.net/exist/?rev=10663&view=rev Modified Paths: -------------- stable/eXist-1.4.x/extensions/xqdoc/src/org/exist/xqdoc/xquery/Scan.java Added Paths: ----------- stable/eXist-1.4.x/extensions/xqdoc/src/org/exist/xqdoc/xquery/normalize.xql Property Changed: ---------------- stable/eXist-1.4.x/extensions/modules/src/org/exist/xquery/modules/jfreechart/JFreeCharting.java Property changes on: stable/eXist-1.4.x/extensions/modules/src/org/exist/xquery/modules/jfreechart/JFreeCharting.java ___________________________________________________________________ Modified: svn:mergeinfo - /trunk/eXist/extensions/modules/src/org/exist/xquery/modules/jfreechart/JFreeCharting.java:10520-10526,10529-10532,10537,10539-10540,10551-10552,10576,10583-10586,10589,10653 + /trunk/eXist/extensions/modules/src/org/exist/xquery/modules/jfreechart/JFreeCharting.java:10520-10526,10529-10532,10537,10539-10540,10551-10552,10576,10583-10586,10589,10653,10663 Modified: stable/eXist-1.4.x/extensions/xqdoc/src/org/exist/xqdoc/xquery/Scan.java =================================================================== --- stable/eXist-1.4.x/extensions/xqdoc/src/org/exist/xqdoc/xquery/Scan.java 2009-11-29 09:59:26 UTC (rev 10663) +++ stable/eXist-1.4.x/extensions/xqdoc/src/org/exist/xqdoc/xquery/Scan.java 2009-11-29 10:02:42 UTC (rev 10664) @@ -5,10 +5,8 @@ import org.exist.dom.DocumentImpl; import org.exist.dom.QName; import org.exist.security.PermissionDeniedException; -import org.exist.source.BinarySource; -import org.exist.source.DBSource; -import org.exist.source.Source; -import org.exist.source.SourceFactory; +import org.exist.security.xacml.AccessContext; +import org.exist.source.*; import org.exist.storage.lock.Lock; import org.exist.util.LockException; import org.exist.xmldb.XmldbURI; @@ -22,6 +20,8 @@ import java.io.IOException; import java.net.URISyntaxException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class Scan extends BasicFunction { @@ -56,6 +56,12 @@ ) }; + private final static Pattern NAME_PATTERN = Pattern.compile("([^/\\.]+)\\.?[^\\.]*$"); + + private final static String NORMALIZE_XQUERY = "resource:org/exist/xqdoc/xquery/normalize.xql"; + + private CompiledXQuery normalizeXQuery = null; + public Scan(XQueryContext context, FunctionSignature signature) { super(context, signature); } @@ -107,7 +113,7 @@ uri = location; try { source = SourceFactory.getSource(context.getBroker(), context.getModuleLoadPath(), uri, false); - name = source.getKey().toString(); + name = extractName(uri); } catch (IOException e) { throw new XPathException(this, "failed to read module " + uri, e); } catch (PermissionDeniedException e) { @@ -121,7 +127,7 @@ NodeValue root = ModuleUtils.stringToXML(context, xml); if (root == null) return Sequence.EMPTY_SEQUENCE; - return (NodeValue) ((Document) root).getDocumentElement(); + return normalize((NodeValue) ((Document) root).getDocumentElement()); } catch (XQDocException e) { throw new XPathException(this, "error while scanning module: " + e.getMessage(), e); } catch (IOException e) { @@ -130,4 +136,23 @@ throw new XPathException(this, "error while scanning module: " + e.getMessage(), e); } } + + private String extractName(String uri) { + Matcher matcher = NAME_PATTERN.matcher(uri); + if (matcher.find()) { + return matcher.group(1); + } + return uri; + } + + private Sequence normalize(NodeValue input) throws IOException, XPathException { + XQuery xquery = context.getBroker().getXQueryService(); + if (normalizeXQuery == null) { + Source source = new ClassLoaderSource(NORMALIZE_XQUERY); + XQueryContext xc = xquery.newContext(AccessContext.INITIALIZE); + normalizeXQuery = xquery.compile(xc, source); + } + normalizeXQuery.getContext().declareVariable("xqdoc:doc", input); + return xquery.execute(normalizeXQuery, Sequence.EMPTY_SEQUENCE); + } } \ No newline at end of file Copied: stable/eXist-1.4.x/extensions/xqdoc/src/org/exist/xqdoc/xquery/normalize.xql (from rev 10663, trunk/eXist/extensions/xqdoc/src/org/exist/xqdoc/xquery/normalize.xql) =================================================================== --- stable/eXist-1.4.x/extensions/xqdoc/src/org/exist/xqdoc/xquery/normalize.xql (rev 0) +++ stable/eXist-1.4.x/extensions/xqdoc/src/org/exist/xqdoc/xquery/normalize.xql 2009-11-29 10:02:42 UTC (rev 10664) @@ -0,0 +1,21 @@ +xquery version "1.0"; + +declare namespace xqdoc="http://www.xqdoc.org/1.0"; + +declare variable $xqdoc:doc external; + +declare function xqdoc:normalize($node as node()) { + typeswitch ($node) + case element(xqdoc:signature) return + element xqdoc:signature { + $node/@*, replace($node/string(), "\s*declare function\s+", "") + } + case element() return + element { node-name($node) } { + $node/@*, for $child in $node/node() return xqdoc:normalize($child) + } + default return + $node +}; + +xqdoc:normalize($xqdoc:doc) \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |