pjt / xml-server
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
XML-Server
Last updated: Thu 07 May 2009
Acts as a front-end to a SVN repository of XML & XSL files. Maintains up-to-date copies of the files as the repository changes, allows reading of XML files optionally passed through stylesheets, allows editing of XML files.
The primary entities the server knows about are the XML files; the XSL files simply act as filters on the former, & can't be accessed directly.
Installation
To install, check out a local copy of the repository. Record its location in the
app/xml_service/repos_config.clj
file, as well as the location of the remote repository against which commits are to be made.
To run the server, invoke
./run
(optionally with the -r option, to bring up a REPL). The server will listen on port 8080
(this can be changed in the boot.clj driver file).
API, by URI
/GET.
Returns human-readable listing of XML, XSL entries currently in the repository./listGET.
Returns JSON object with two keys:xml&xsl. The value ofxmlis an object containing all XML entries (keyed by full path in the repository); the value ofxslis an array of XSL entries./list/:xmlGET.
Returns JSON object containing one key: the full repository path for XML file, whose value is an array of explicitly declared (in the "spenser-stylesheets" processing instruction) XSL entries./xml/:xml(?xquery)GET.
Returns XML filed named, possibly filtered by an XQuery expression. If the result of evaluating the XQuery expression is a collection (of nodes or values), the collection is returned as a JSON array./style/:style/:xml(?xquery)GET.
Returns the XML file named, run through the stylesheet(s) named, possibly filtered by an XQuery expression. The XQuery expression is evaluated against the XML document; if its result is a collection, the stylesheet(s) are applied to each. If the result of stylesheet application is a collection, it's returned as a JSON array./edit/:style/:xmlGET. Requires login (authenticated against repository).
Returns XML file named, run through stylesheet(s) named. Makes XML file the currently-edited document for the session, thus making it the target for future edits./editPOST. Requires login.
PARAMETERS:select: XPath for node to be modifiedupdate: string representing new state ofselectnodeupdate-style: name of stylesheet(s) through which to runupdatebefore updatingpost-style: name of stylesheet(s) through which to run returned node (parent ofselect)
Replaces the node identified by
selectwith the value ofupdate(possibly run throughupdate-stylestylesheet(s)) in the session's currently-edited document. Returns the parent ofselect, or, ifselectis the root, the root./edit/diffGET. Requires login.
Returnssvn diffoutput reflecting changes from the repository for currently-edit document./edit/commitPOST. Requires login.
PARAMETERS:msg: log message for check-in
Commits edits made to session's currently-edited document back to the repository.
Naming XML, XSL entries
For the above URLs, the keywords :xml & :style represent holes in the paths where names of particular files go. The naming scheme is as follows:
for XML files:
the full path of the file in the repository, e.g.
This is the canonical name for the XML, & is what's returned by theworks/volOne/trunk/letters/letters.xml/listURLs.any substring of the above that uniquely identifies a file, e.g.
This is to support interactive use at a browser. If the susbstring doesn't uniquely identify a file, an HTTP 404 is returned whose body lists all the files matched.letters
for XSL files:
XSL files don't have canonical names; their names are simply filenames minus extension. They're resolved relative to the XML file they'll be applied to, in this resolution order:
If the name is a uniquely identifying substring of a stylesheet listed in the XML file's
spenser-stylesheetsprocessing instruction, the stylesheet in the processing-instruction is chosen. E.g.choicesis given in the URL,choices_fqexists in the XML's processing instruction,choices_fqis chosen.If 1. isn't true, all the stylesheets in the repository for which the name is a substring are collected. If the collection contains one stylesheet, it's chosen; if there's more than one, the stylesheet closest to the XML file is chosen, where distance equals number of directory steps between XML file & stylesheet (steps beneath the XML file's containing directory are weighted at half of steps outside containing directory). If there is a single closest stylesheet, it's chosen; if there's not, an HTTP 404 is returned whose body lists the closest sheets.
The rule of thumb, then, for arranging stylesheets in the repository is: put stylesheets meant for arbitrary XML input in a single "global" directory, & put stylesheets meant for particular files either in the same directory as, or in a directory beneath, the file (&, optionally, point directly to it in the processing instruction).
Finally, names of stylesheets can specify multiple sheets. Combine sheet names with the
+character. E.g., to apply a tokenizing sheet & an HTML-conversion sheet, hit the
URL. Sheets are applied in left-to-right order./style/tokenize+html/letters

