Skip to content

Commit

Permalink
Version 1.0.0: Initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
coledarr authored and vim-scripts committed Oct 7, 2012
0 parents commit e18f2fc
Show file tree
Hide file tree
Showing 6 changed files with 460 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README
@@ -0,0 +1,14 @@
This is a mirror of http://www.vim.org/scripts/script.php?script_id=4255

Vim filetype plugin enables you to run xquery files against a MarkLogic server, it displays the results in a separate window.

Source: https://github.com/coledarr/vim-xqmarklogic

Requirements

vim (obviously), MarkLogic (probably obvious), and curl (not so obvious)
Any recent vintage vim should work.
MarkLogic6 works, but probably both older and newer versions will as well.
curl needs to be available on the local machine


53 changes: 53 additions & 0 deletions README.md
@@ -0,0 +1,53 @@
xqmarklogic
===========

Vim filetype plugin enables you to run xqueries files against a MarkLogic
server, it displays the results in a separate window.

* [See](http://www.vim.org)
* [Source](github.com/coledarr/vim-xqmarklogic)

Requirements
------------

vim (obviously), MarkLogic (probably obvious), and curl (not so obvious)

Installation
------------

Can be broken into two steps. Setup vim and to setup MarkLogic

For setting up vim I'd suggest either

* [pathogen.vim](http://www.vim.org/scripts/script.php?script_id=2332)
([pathogen.vim source](http://github.com/tpope/vim-pathogen))

or

* [vundle](http://www.vim.org/scripts/script.php?script_id=3458)
([vundle source](https://github.com/gmarik/vundle))

Both have good documentation and make it far easier to setup plugins.

For pathogen put the plugin in your bundle directory and in vim run

:Helptags

For vundle add this line to your vimrc

Bundle 'coledarr/vim-xqmarklogic'

To manually install:

1. copy vim-xqmarklogic/ftplugin/xquery.vim to ~/.vim/ftplugin (or ~\vimfiles\ftplugin)
1. copy vim-xqmarklogic/doc/xqmarklogic.txt to ~/.vim/ftplugin (or ~\vimfiles\ftplugin)
1. In vim run:

:helptags

For more details and setting up MarkLogic run this in vim once you've done the above:

:help xqmarklogic-install


It works well with [xqyeryvim](http://www.vim.org/scripts/script.php?script_id=3611)
184 changes: 184 additions & 0 deletions doc/xqmarklogic.txt
@@ -0,0 +1,184 @@
xqmarklogic Documentation *xqmarklogic*
*xqmarklogic.txt*

Author: Darren Cole http://github.com/coledarr/vim-xqmarklogic

Integrating MarkLogic xqueries into vim, and displays the result in another
window. This is a filetype plugin that is only available when in an xquery
file.

1. Introduction |xqmarklogic-intro|
2 Installation |xqmarklogic-install|
MarkLogic configuration |xqmarklogic-config-marklogic|
vimrc configuration |xqmarklogic-config-vimrc|
3. Security Considerations |xqmarklogic-security|
4. Commands |xqmarklogic-commands|
5. Customization:
Options and Settings |xqmarklogic-options|

==============================================================================
INTRODUCTION *xqmarklogic-intro*

xqmarklogic maps <LEADER>B and <C-CR> (CTRL-RETURN like QueryConsole) to run a
xquery against MarkLogic server using curl and a custom App Server running a
short xquery file. It displays the results in a new window. It was inspired
by this webpage:
http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic

Git repository at: http://github.com/coledarr/vim-xqmarklogic

==============================================================================
INSTALLATION *xqmarklogic-install*

This plugin will need to be installed.
Couple ways to do this:
1. copy the doc/* and ftplugin/* to your cooresponding ~/.vim/
directories
2. pathogen.vim https://github.com/tpope/vim-pathogen
3. vundle https://github.com/gmarik/vundle

See pathogen.vim's documentation to set it up (it's easy). Then put the
xqmarklogic directory in your ~/.vim/bundle directory, and run :Helptags

Vundle has even more features (can update plugins automatically) See the
documentation from the link above.

MARKLOGIC CONFIGURATION *xqmarklogic-config-marklogic*
You will need MarkLogic running, a MarkLogic App Server setup to run a xquery,
curl, and this xqmarklogic file type plugin. MarkLogic provides an XML
database, and even has a free version called MarkLogic Express.
See: http://www.marklogic.com/

This plugin was developed and used with MarkLogic6, but should work with
earlier and probably later versions.

Script is in the file xqmarklogic/xq.xqry. This script takes text input
and runs it against the database using xdmp:eval. This opens up your whole
MarkLogic server to have arbitrary xquery run against any database by whoever
is authorized to access this App Server. Read the |xqmarklogic-security|
section. This probably shouldn't be on the production server, and should be
protected.

In MarkLogic Admin interface go to Group->Default->App Servers, then the
"Create HTTP" tab. Then fill in a few fields.
"server name" - Can be whatever you want.
"root" - Is somewhere accessible by MarkLogic server to read the
xq.xqy file. I have put it in /opt/MarkLogic.local/
"port" - whatever port this App Server should listen on

Make sure the xq.xqy file has been copied and is readable by the MarkLogic
server.

curl can support SSL, but the plugin isn't setup to support this. Patches
welcome. wget doesn't work, again patches welcome.

VIMRC CONFIGURATION *xqmarklogic-config-vimrc*
There are a few settings needed in your |vimrc| file

Use the port number you set when configuring the App Server, not the
default 8002 >
let g:xqmarklogic_defaultPort='8002'
<

Use the user and password needed to access the App Server you setup >
let g:xqmarklogic_defaultUser='admin'
let g:xqmarklogic_defaultPassword='password'
<

If MakrLogic isn't running on the localhost, you'll need to add the host as
well >
let g:xqmarklogic_defaultHost='marklogichost'
<

For more details and other options and setting see |xqmarklogic-options|
These settings can be set differently in different buffers.

SECURITY CONSIDERATIONS *xqmarklogic-security*

As mentioned above xq.xqy has some security considerations. It can run any
xquery against any of the MarkLogic databases. It is only as protected as the
App Server (password in the clear with http by default). xqmarklogic
doesn't support ssl now, but that could be added (patches welcome). So be
aware.

Second issue is less obvious and has the potential to expose the MarkLogic
password to everyone who can login into the local machine. Vim stores command
history in ~/.viminfo. If you set and |xqmarklogic-options| below (particularly
the one for the MarkLogic password) from command mode, those commands are
stored in the viminfo file. Pull requests with fixes for this are welcome.


==============================================================================
3. Commands *xqmarklogic-commands*

<leader>B Run current buffer as an xquery against the MarkLogic
App Server you setup earlier. This mapping runs XQmlquery, so
it is easy to remap this if needed.

XQtoggleShowCurlCmd toggles showing curl command used in the output
window in an XML comment. It is off by default since
the command contains "--" and thus can't be in a valid
XML comment.

XQtoggleShowDuration toggle showing the duration of the query. On by
default.

XQsetUser sets the user to use for login to the string argument

XQsetPassword sets the password to use for login to the string
argument
XQsetURI sets the URI to use to the string argument

XQsetHost sets the host to use to the string argument

XQsetPort sets the port to use to the argument

XQsetScript sets the script to use to the string argument

XQsetDatabase sets the database to query against to the string
argument.

XQdisplaySettings Displays what the current buffer settings are.

XQmlquery Run the current buffer against the MarkLogic server


==============================================================================
4. Customization: Options and Settings *xqmarklogic-options*

Global default values can be set in you |vimrc| file.

g:xqmarklogic_defaultHost - the default Host name to use, if not set
uses 'localhost'
g:xqmarklogic_defaultURI - the default URI, if not set uses 'http://'
g:xqmarklogic_defaultPort - the default Port, if not set uses 8002
(which is used by MarkLogic by default and
wont work)
g:xqmarklogic_defaultUser - the default User, if not set uses 'admin'
g:xqmarklogic_defaultPassword - the default password to use, if not set
you will probably have problems.
g:xqmarklogic_defaultScript - the default name of the xq.xqy, if not set
uses '/xq.xqy'
g:xqmarklogic_defaultDb - the default Database to query against, if
not set uses 'Documents'

g:xqmarklogic_noMappings - if set \B and <C-CR> wont be mapped
Example: >
let g:xqmarklogic_defaultUser='labarbara_conrad'
<

Several of these values can be set on a per buffer basis, here are
the corresponding

b:xqmarklogic_host corresponds to: g:xqmarklogic_defaultHost
b:xqmarklogic_uri corresponds to: g:xqmarklogic_defaultURI
b:xqmarklogic_port corresponds to: g:xqmarklogic_defaultPort
b:xqmarklogic_user corresponds to: g:xqmarklogic_defaultUser
b:xqmarklogic_password corresponds to: g:xqmarklogic_defaultPassword
b:xqmarklogic_script corresponds to: g:xqmarklogic_defaultScript
b:xqmarklogic_db corresponds to: g:xqmarklogic_defaultDb
Example run when the cursor is in the xquery file you want it set to: >
:let b:xqmarklogic_password='flexo_is_the_greatest'
<

vim:tw=78:ts=8:ft=help:norl:

0 comments on commit e18f2fc

Please sign in to comment.