1

server.xml (tomcat) から SSL 構成のコメントを外し、いくつかの属性を追加する必要がある場合のシナリオがあります。SSL 構成が既に利用可能な場合に 2 つの属性を追加することに成功しましたが、私のテンプレートはコメントを外した部分では機能しません。何か案が?

<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet type="text/xsl" href="new2.xsl"?>

<Server port="8005" shutdown="SHUTDOWN">

  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>


  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->

    <Connector port="8080" URIEncoding="UTF-8" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

    <!--NEED TO UNCOMMENT AND ADD ATTRIBUTES IN THE FOLLOWING ELEMENT--> 

    <!--<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" /> -->


    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">         
    -->
    <Engine name="Catalina" defaultHost="localhost">


      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
      </Host>
    </Engine>
  </Service>
</Server>

パーツのコメントを解除する xslt が続きます。パーツのコメントが既に解除されている場合は、2 つの属性を追加します。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="@* | node()" name="Copy">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="@* | node()" mode="insertConnector">
    <xsl:call-template name="Copy" />
  </xsl:template>
<!--If the SSL configuration doesn't exist but availabe in comments, uncomment it-->
  <xsl:template match="comment()[not(../Connector[@scheme = 'https']) and
                                 contains(., 'Connector') and
                                 (contains(., 'scheme=https') or
                                  contains(., scheme='https'))]">

    <xsl:value-of select="." disable-output-escaping="yes"/> <!--This line uncomments the comment-->
  </xsl:template>

  <xsl:template match = "Connector[@scheme = 'https']" name="AddAttributes">
    <Connector keystoreFile="${user.home}/.keystore">
    <xsl:apply-templates select="@* | node()"/>
  </Connector>
  </xsl:template>
</xsl:stylesheet>

コメント部分に属性を追加する方法、またはコメントを外した直後に要素に属性を追加する方法を教えてください。上記の XSLT は、SSL 構成部分のコメントを外しているだけです。ありがとうございました。

4

2 に答える 2

3

コメントの内容をXMLパーサーに渡すには、独自の拡張関数を作成するか、XSLT 3.0でparse-xml()として標準化されているXSLTプロセッサーによって提供されるsaxon:parse()などの拡張機能を呼び出します。 。または、@ JLRicheによって提案されているように、disable-output-escapingを使用して2フェーズパイプラインを使用します。

于 2013-03-20T09:29:59.150 に答える
1

これが最終的に行ったアプローチであるため、ここに私のコメントを回答として追加するだけです。

少なくとも XSLT 1.0 では、これを行う方法はないと思います。コメント解除プロセスは、コメントのコンテンツをエスケープされていないテキストとして出力するだけで、それを XML データとして認識しません。XSLT を介して XML を 1 回実行してその部分のコメントを解除し、もう一度コメントを追加する 2 パス アプローチを実行することは可能でしょうか?

于 2013-03-20T16:07:35.537 に答える