PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/saxonB/net/sf/saxon/event/XQueryEmitter.java

https://bitbucket.org/dmwelch/phdxnat_pipeline
Java | 77 lines | 40 code | 8 blank | 29 comment | 15 complexity | 993e2310f504d887a2904540834c4ff6 MD5 | raw file
  1. package net.sf.saxon.event;
  2. import net.sf.saxon.trans.XPathException;
  3. import net.sf.saxon.om.FastStringBuffer;
  4. import java.io.IOException;
  5. /**
  6. * The XQueryEmitter is designed to serialize an XQuery that was originally embedded in an
  7. * XML document. It is a variant of the XMLEmitter, and differs in that the operators <, >, <=, >=, <<, and <<
  8. * are output without escaping. They are recognized by virtue of the fact that they appear in text or attribute
  9. * content between curly braces but not in quotes.
  10. */
  11. public class XQueryEmitter extends XMLEmitter {
  12. /**
  13. * Write contents of array to current writer, after escaping special characters.
  14. * This method converts the XML special characters (such as < and &) into their
  15. * predefined entities.
  16. *
  17. * @param chars The character sequence containing the string
  18. * @param inAttribute Set to true if the text is in an attribute value
  19. */
  20. protected void writeEscape(final CharSequence chars, final boolean inAttribute) throws IOException, XPathException {
  21. boolean inBraces = false;
  22. FastStringBuffer buff = new FastStringBuffer(chars.length());
  23. for (int i=0; i<chars.length(); i++) {
  24. char c = chars.charAt(i);
  25. if (!inBraces && c=='{' && chars.charAt(i+1)!='{') {
  26. inBraces = true;
  27. buff.append((char)0); // switch disable-output-escaping on
  28. } else if (inBraces && c=='}') {
  29. inBraces = false;
  30. buff.append((char)0); // switch disable-output-escaping off
  31. } else if (inBraces && c=='"') {
  32. buff.append((char)0);
  33. i++;
  34. do {
  35. buff.append(c);
  36. c = chars.charAt(i++);
  37. } while (c != '"');
  38. buff.append((char)0);
  39. i--;
  40. } else if (inBraces && c=='\'') {
  41. buff.append((char)0);
  42. i++;
  43. do {
  44. buff.append(c);
  45. c = chars.charAt(i++);
  46. } while (c != '\'');
  47. buff.append((char)0);
  48. i--;
  49. }
  50. buff.append(c);
  51. }
  52. super.writeEscape(buff, inAttribute);
  53. }
  54. }
  55. //
  56. // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
  57. // you may not use this file except in compliance with the License. You may obtain a copy of the
  58. // License at http://www.mozilla.org/MPL/
  59. //
  60. // Software distributed under the License is distributed on an "AS IS" basis,
  61. // WITHOUT WARRANTY OF ANY KIND, either express or implied.
  62. // See the License for the specific language governing rights and limitations under the License.
  63. //
  64. // The Original Code is: all this file
  65. //
  66. // The Initial Developer of the Original Code is Michael H. Kay.
  67. //
  68. // Contributor(s):
  69. //