Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add separate file for xq.xqy, add documentation

Add a file for xq.xqy needed for MarkLogic App Server (from:
<http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic> )
Added real documentation file
  • Loading branch information...
commit b62bbb1dfd77a8a4d6307e27ce51982a0aaacc67 1 parent 8c5e62e
Darren Cole authored

Showing 2 changed files with 163 additions and 0 deletions. Show diff stats Hide diff stats

  1. +151 0 doc/xqmarklogic.txt
  2. +12 0 xq.xqy
151 doc/xqmarklogic.txt
... ... @@ -0,0 +1,151 @@
  1 + xqmarklogic.vim Documentation *xqmarklogic*
  2 +
  3 +Integrating MarkLogic xqueries into vim, and displays the result in another
  4 +window
  5 +
  6 +1. Introduction |xqmarklogic-intro|
  7 +2.1 Installation |xqmarklogic-install|
  8 +2.2 Security Considerations |xqmarklogic-security|
  9 +3. Commands |xqmarklogic-commands|
  10 +4. Customization:
  11 + Options and Settings |xqmarklogic-options|
  12 +
  13 +==============================================================================
  14 +1. Introduction *xqmarklogic-inro*
  15 +
  16 +xqmarklogic.vim maps <LEADER>B to run a xquery against MarkLogic
  17 +server using curl and a custom App Server running a short xquery file. It
  18 +displays the results in a new window. It was inspired by this webpage:
  19 +http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic
  20 +
  21 +Git repository at: github.com/coledarr/vim-xqmarklogic
  22 +
  23 +==============================================================================
  24 +2.1. Installation *xqmarklogic-install*
  25 +
  26 +You will need MarkLogic running, a MarkLogic App Server setup to run a xquery,
  27 +curl, and this xqmarklogic.vim plugin. MarkLogic provides an XML database,
  28 +and even has a free version called MarkLogic Express.
  29 + See: <http://www.marklogic.com/>
  30 +
  31 +This plugin was developed and used with MarkLogic6, but should work with
  32 +ealier and probably later versions.
  33 +
  34 +Script is in the file vim-xqmarklogic/xq.xqry. This script takes text input
  35 +and runs it agains the database using xdmp:eval. This opens up your whole
  36 +MarkLogic server to have arbitrary xquery run against any database. This
  37 +probably shouldn't be on the production server, and should be protected. See
  38 +MarkLogic documentation on how to do this.
  39 +
  40 +In MarkLogic Admin interface go to Group->Default->App Servers, then the
  41 +"Create HTTP" tab. Then fill in a few fields.
  42 + "server name" - Can be whatever you want.
  43 + "root" - Is somewhere accessible by MarkLogic server to read the
  44 + xq.xqy file. I have put it in /opt/MarkLogic.local/
  45 + "port" - whatever port this App Server should listen on
  46 +
  47 +Make sure the xq.xqy file has been copied and is readable by the MarkLogic
  48 +server.
  49 +
  50 +curl can support SSL, but the plugin isn't setup to support this. Patches
  51 +welcome. wget doesn't work, again patches welcome.
  52 +
  53 +This plugin will need to be installed.
  54 +Couple ways to do this:
  55 + 1. copy the doc/* and plugin/* to your cooresponding ~/.vim/
  56 + directories
  57 + 2. pathogen.vim <https://github.com/tpope/vim-pathogen>
  58 + 3. vundle <https://github.com/gmarik/vundle>
  59 +
  60 +See pathogen.vim's documentation to set it up (it's easy). Then put the
  61 +vim-xqmarklogic directory in your ~/.vim/bundle directory, and run :Helptags
  62 +
  63 +Vundle has even more features (can update plugins), but takes a little more
  64 +setup. See the documentation from the link above.
  65 +
  66 +Then a few settings will need to be added to your |.vimrc| file:
  67 +
  68 +Use the port number you set when configuring the App Server, not 8002
  69 + let g:xqmarklogic_defaultPort='8002'
  70 +Use the user and password needed to access the App Server you setup
  71 + let g:xqmarklogic_defaultUser='admin'
  72 + let g:xqmarklogic_defaultPassword='password'
  73 +If MakrLogic isn't running on the localhost, you'll need to add the host as
  74 +well
  75 + let g:xqmarklogic_defaultHost='marklogichost'
  76 +
  77 +For more details and other options and setting see |xqmarklogic-options|
  78 +These settings can be set differently in different buffers.
  79 +
  80 +=======================================
  81 +2.2 Security Considerations *xqmarklogic-security*
  82 +
  83 +As mentioned above xq.xqy has some security considerations. It can run any
  84 +xquery against any of the MarkLogic databases. It is only as protected as the
  85 +App Server (password in the clear with http by default). The xqmarklogic.vim
  86 +doesn't support ssl now, but that could be added. So be aware.
  87 +
  88 +Second issue is less obvious and has the potential to expose the MarkLogic
  89 +password to everyone who can login into the local machine. Vim stores command
  90 +history in ~/.viminfo. If you set and |xqmarklogic-options| below (particularlly
  91 +the one for the MarkLogic password) from command mode, those commands are
  92 +stored in the viminfo file. Pull requests with fixes for this are welcome.
  93 +
  94 +
  95 +==============================================================================
  96 +3. Commands *xqmarklogic-commands*
  97 +
  98 +<leader>B Run current buffer as an xquery against the MarkLogic
  99 + Appserver you setup earlier. This mapping runs XQmlquery, so
  100 + it is easy to remap this if needed.
  101 +
  102 +XQtoggleShowCurlCmd toggles showing curl command used in the output
  103 + window in an XML comment. It is off by default since
  104 + the command contains "--" and thus can't be in valid
  105 + XML comment.
  106 +
  107 +XQtoggleShowDuration toggle showing the duration of the query. On by
  108 + default.
  109 +
  110 +XQsetDatabase sets the database to query against to the string
  111 + argument.
  112 +
  113 +XQdisplaySettings Displays what the current buffer settings are, they
  114 + are currentlyt NOT initialized until after the first
  115 + query.
  116 +
  117 +==============================================================================
  118 +4. Customization: Options and Settings *xqmarklogic-options*
  119 +
  120 + Global default values can be set in you |.vimrc| file.
  121 +
  122 +g:xqmarklogic_defaultHost - the default Host name to use, if not set
  123 + uses 'localhost'
  124 +g:xqmarklogic_defaultURI - the default URI, if not set uses 'http://'
  125 +g:xqmarklogic_defaultPort - the default Port, if not set uses 8002
  126 + (which is used by MarkLogic by default and
  127 + wont work)
  128 +g:xqmarklogic_defaultUser - the default User, if not set uses 'admin'
  129 +g:xqmarklogic_defaultPassword - the default password to use, if not set
  130 + you will probably have problems.
  131 +g:xqmarklogic_defaultXq - the default name of the xq.xqy, if not set
  132 + uses '/xq.xqy'
  133 +g:xqmarklogic_defaultDb - the default Database to query against, if
  134 + not set uses 'Documents'
  135 + Example:
  136 + let g:xqmarklogic_defaultUser='labarbara_conrad'
  137 +
  138 + Several of these values can be set on a per buffer basis, here are
  139 +the corresponding
  140 +
  141 +b:xqmarklogic_host corresponds to: g:xqmarklogic_defaultHost
  142 +b:xqmarklogic_uri corresponds to: g:xqmarklogic_defaultURI
  143 +b:xqmarklogic_port corresponds to: g:xqmarklogic_defaultPort
  144 +b:xqmarklogic_user corresponds to: g:xqmarklogic_defaultUser
  145 +b:xqmarklogic_password corresponds to: g:xqmarklogic_defaultPassword
  146 +b:xqmarklogic_xq corresponds to: g:xqmarklogic_defaultXq
  147 +b:xqmarklogic_db corresponds to: g:xqmarklogic_defaultDb
  148 + Example run when the cursor is in the xquery file you want it set to
  149 + :let b:xqmarklogic_password='flexo_is_the_greatest'
  150 +
  151 +# vim: textwidth=78 noexpandtab softtabstop=8 shiftwidth=8 syntax=help
12 xq.xqy
... ... @@ -0,0 +1,12 @@
  1 +xquery version "1.0-ml";
  2 +
  3 +let
  4 + $db := xdmp:get-request-field("db", "Documents"),
  5 + $xquery := xdmp:get-request-body("text")
  6 +return
  7 + try {
  8 + xdmp:eval($xquery, (), <options xmlns="xdmp:eval"><database>{xdmp:database($db)}</database></options>)
  9 + }
  10 + catch($e) {
  11 + $e
  12 + }

0 comments on commit b62bbb1

Please sign in to comment.
Something went wrong with that request. Please try again.