/* vc_model.js:  model-related functions for VC filter

   Copyright (C) 2009 Black Mesa Technologies LLC

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program, in the Licenses subdirectory, in file
   GNU_GPL.
   
   If the license was not provided, or is missing, see 
   <http://www.gnu.org/licenses/>.

*/

/* Revisions:
   2009-05-02 : CMSMcQ : made first version (empty) of this file
*/

/* We want browser-independent ways to perform various basic
   operations.

   DomFromXmluri(uri) : dereferences a URI and returns a DOM
   representation of the XML there.  In browsers, suffers from
   the same-source rule.

   DomFromXmlstring(s) : parses a string as XML and returns a
   DOM representation of the XML.

   DomFromTransformXmlXslt(domXml, domXslt) : applies an 
   XSLT stylesheet (represented in a DOM) to an XML document
   (in a DOM) and returns the result as a DOM.

   StringFromTransformXmlXslt(domXml, domXslt) : applies an 
   XSLT stylesheet (represented in a DOM) to an XML document
   (in a DOM) and returns the result as a string with angle
   brackets.
*/

function DomFromXmluri(uri) {
  // standard DOM here
  var x = document.implementation.createDocument("","",null);
  // and non-standardized Mozilla ...
  x.async = false;
  x.load(uri);
  return x;
}

function DomFromXmlstring(s) {
  // nonstandard Mozilla here, I think

  // do I need to add this line for Sarissa?
  x = Sarissa.getDomDocument();
  var dp = new DOMParser();
  var x = dp.parseFromString(s,"text/xml");
  return x;
}

function DomFromTransformXmlXslt(instance, stylesheet) {
  var xp = new XSLTProcessor();
  xp.importStylesheet(stylesheet);
  return xp.transformToDocument(instance);
}

function DomFromTransformXmlXsltParams(instance, stylesheet, params) {
  var xp = new XSLTProcessor();
  xp.importStylesheet(stylesheet);
  for (param in params) {
    xp.setParameter(null,param,params[param]);
  }
  return xp.transformToDocument(instance);
}

// NCName = NameStartChar NameChar+ (minus colon)
// NameStartChar = [A-Z] 
//   | "_" 
//   | [a-z] 
//   | [#xC0-#xD6] 
//   | [#xD8-#xF6] 
//   | [#xF8-#x2FF] 
//   | [#x370-#x37D] 
//   | [#x37F-#x1FFF] 
//   | [#x200C-#x200D] 
//   | [#x2070-#x218F] 
//   | [#x2C00-#x2FEF] 
//   | [#x3001-#xD7FF] 
//   | [#xF900-#xFDCF] 
//   | [#xFDF0-#xFFFD] 
//   | [#x10000-#xEFFFF]
// 
// NameChar = NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]

mp_NT_Regex['NCName'] = /^([A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]|([\uD800-\uD87F][\uDC00-\uDFFF]))([A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]|([\uD800-\uD87F][\uDC00-\uDFFF])|[\u002D.0-9\u00B7\u0300-\u036F\u203F-\u2040])+$/;
