gt:             + "indent='yes'  " + LINE_SEP
context: /*
  // This software is subject to the terms of the Eclipse Public License v1.0
  // Agreement, available at the following URL:
  // http://www.eclipse.org/legal/epl-v10.html.
  // You must accept the terms of that agreement to use this software.
  //
  // Copyright (C) 2005-2014 Pentaho and others
  // All Rights Reserved.
  */
  package mondrian.tui;
  
  import mondrian.olap.Util;
  
  import org.apache.xerces.dom.DocumentImpl;
  import org.apache.xerces.impl.Constants;
  import org.apache.xerces.parsers.DOMParser;
  import org.apache.xml.serialize.OutputFormat;
  import org.apache.xml.serialize.XMLSerializer;
  import org.apache.xpath.domapi.XPathEvaluatorImpl;
  
  import org.w3c.dom.*;
  import org.w3c.dom.xpath.*;
  import org.xml.sax.*;
  
  import java.io.*;
  import java.util.ArrayList;
  import java.util.List;
  import javax.xml.parsers.*;
  import javax.xml.transform.*;
  import javax.xml.transform.dom.DOMResult;
  import javax.xml.transform.dom.DOMSource;
  
  /**
   * Some XML parsing, validation and transform utility methods used
   * to valiate XMLA responses.
   *
   * @author Richard M. Emberson
   */
  public class XmlUtil {
  
      public static final String LINE_SEP =
          System.getProperty("line.separator", "\n");
  
      public static final String SOAP_PREFIX = "SOAP-ENV";
      public static final String XSD_PREFIX = "xsd";
  
      public static final String XMLNS = "xmlns";
  
      public static final String NAMESPACES_FEATURE_ID =
          "http://xml.org/sax/features/namespaces";
      public static final String VALIDATION_FEATURE_ID =
          "http://xml.org/sax/features/validation";
  
      public static final String SCHEMA_VALIDATION_FEATURE_ID =
          "http://apache.org/xml/features/validation/schema";
      public static final String FULL_SCHEMA_VALIDATION_FEATURE_ID =
          "http://apache.org/xml/features/validation/schema-full-checking";
  
      public static final String DEFER_NODE_EXPANSION =
          "http://apache.org/xml/features/dom/defer-node-expansion";
  
      public static final String SCHEMA_LOCATION =
          Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION;
  
      /**
       * This is the xslt that can extract the "data" part of a SOAP
       * XMLA response.
       */
      public static final String getSoapXmlaXds2xd(String xmlaPrefix) {
          return
              "<?xml version='1.0'?>" + LINE_SEP
              + "<xsl:stylesheet " + LINE_SEP
              + "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " + LINE_SEP
              + "xmlns:xalan='http://xml.apache.org/xslt' " + LINE_SEP
              + "xmlns:xsd='http://www.w3.org/2001/XMLSchema' " + LINE_SEP
              + "xmlns:ROW='urn:schemas-microsoft-com:xml-analysis:rowset' "
              + LINE_SEP
              + "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' "
              + LINE_SEP
              + "xmlns:xmla='urn:schemas-microsoft-com:xml-analysis' " + LINE_SEP
              + "version='1.0' " + LINE_SEP
              + "> " + LINE_SEP
              + "<xsl:output method='xml'  " + LINE_SEP
              + "encoding='UTF-8' " + LINE_SEP
              + "indent='yes'  " + LINE_SEP
              + "xalan:indent-amount='2'/> " + LINE_SEP
              + "  " + LINE_SEP
              + "<!-- consume '/' and apply --> " + LINE_SEP
              + "<xsl:template match='/'> " + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'Envelope' and apply --> " + LINE_SEP
              + "<xsl:template match='SOAP-ENV:Envelope'> " + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'Header' --> " + LINE_SEP
              + "<xsl:template match='SOAP-ENV:Header'> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'Body' and apply --> " + LINE_SEP
              + "<xsl:template match='SOAP-ENV:Body'> " + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'DiscoverResponse' and apply --> " + LINE_SEP
              + "<xsl:template match='" + xmlaPrefix + ":DiscoverResponse'> "
              + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'return' and apply --> " + LINE_SEP
              + "<xsl:template match='" + xmlaPrefix + ":return'> " + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'xsd:schema' --> " + LINE_SEP
              + "<xsl:template match='xsd:schema'> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- copy everything else --> " + LINE_SEP
              + "<xsl:template match='*|@*'> " + LINE_SEP
              + "<xsl:copy> " + LINE_SEP
              + "<xsl:apply-templates select='@*|node()'/> " + LINE_SEP
              + "</xsl:copy> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "</xsl:stylesheet>";
      }
  
      /**
       * This is the xslt that can extract the "schema" part of a SOAP
       * XMLA response.
       */
      public static final String getSoapXmlaXds2xs(String xmlaPrefix) {
          return
              "<?xml version='1.0'?> " + LINE_SEP
              + "<xsl:stylesheet  " + LINE_SEP
              + "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'  " + LINE_SEP
              + "xmlns:xalan='http://xml.apache.org/xslt' " + LINE_SEP
              + "xmlns:xsd='http://www.w3.org/2001/XMLSchema' " + LINE_SEP
              + "xmlns:ROW='urn:schemas-microsoft-com:xml-analysis:rowset' "
              + LINE_SEP
              + "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'  "
              + LINE_SEP
              + "xmlns:xmla='urn:schemas-microsoft-com:xml-analysis' " + LINE_SEP
              + "version='1.0' " + LINE_SEP
              + "> " + LINE_SEP
              + "<xsl:output method='xml'  " + LINE_SEP
              + "encoding='UTF-8' " + LINE_SEP
              + "indent='yes'  " + LINE_SEP
              + "xalan:indent-amount='2'/> " + LINE_SEP
              + "<!-- consume '/' and apply --> " + LINE_SEP
              + "<xsl:template match='/'> " + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'Envelope' and apply --> " + LINE_SEP
              + "<xsl:template match='SOAP-ENV:Envelope'> " + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'Header' --> " + LINE_SEP
              + "<xsl:template match='SOAP-ENV:Header'> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'Body' and apply --> " + LINE_SEP
              + "<xsl:template match='SOAP-ENV:Body'> " + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'DiscoverResponse' and apply --> " + LINE_SEP
              + "<xsl:template match='" + xmlaPrefix + ":DiscoverResponse'> "
              + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'return' and apply --> " + LINE_SEP
              + "<xsl:template match='" + xmlaPrefix + ":return'> " + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'root' and apply --> " + LINE_SEP
              + "<xsl:template match='ROW:root'> " + LINE_SEP
              + "<xsl:apply-templates/> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- consume 'row' --> " + LINE_SEP
              + "<xsl:template match='ROW:row'> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "<!-- copy everything else --> " + LINE_SEP
              + "<xsl:template match='*|@*'> " + LINE_SEP
              + "<xsl:copy> " + LINE_SEP
              + "<xsl:apply-templates select='@*|node()'/> " + LINE_SEP
              + "</xsl:copy> " + LINE_SEP
              + "</xsl:template> " + LINE_SEP
              + "</xsl:stylesheet>";
      }
  
      /**
       * This is the xslt that can extract the "data" part of a XMLA response.
       */
      public static final String getXmlaXds2xd(String ns) {
          String xmlaPrefix = (ns == null) ? "" : (ns + ":");
          return
              "<?xml version='1.0'?>" + LINE_SEP
              + "<xsl:stylesheet " + LINE_SEP
              + "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " + LINE_SEP
              + "xmlns:xalan='http://xml.apache.org/xslt' " + LINE_SEP
              + "xmlns:xsd='http://www.w3.org/2001/XMLSchema' " + LINE_SEP
              + "xmlns:ROW='urn:schemas-microsoft-com:xml-analysis:rowset' "
              + LINE_SEP
              + "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' "
              + LINE_SEP
              + "xmlns:xmla='urn:schemas-microsoft-com:xml-analysis' " + LINE_SEP
              + "version='1.0' " + LINE_SEP
              + "> " + LINE_SEP
              + "<xsl:output method='xml'  " + LINE_SEP
              + "encoding='UTF-8' " + LINE_SEP
  