I have an XProc script that currently hardcodes document hrefs like this:
<p:xslt>
<p:input port="source"/>
<p:input port="stylesheet">
<p:document href="/path/to/stylesheet.xsl"/>
</p:input>
</p:xslt>
I would like to pass /path/to/stylesheet.xsl as an option to the xproc script, so in my declare-step I put:
<p:option name="stylePath" required="true"/>
but I still can't figure out how to replace the hardcoded href in p:document with the option value.
I'll be most grateful for your help.
Here's what eventually worked for me:
Create a step to load the document with the option passed to it:
<p:load name="getStylesheetSource">
<p:with-option name="href" select="$stylePath" />
</p:load>
Then, in the XSLT step, pipe the loaded stylesheet
<p:xslt name="transform">
<p:input port="source">
<!-- etc. -->
</p:input>
<p:input port="stylesheet">
<p:pipe step="getStylesheetSource" port="result" />
</p:input>
</p:xslt>
With this setup, one can pass the stylePath option when invoking the XProc script without having to hard code the path.
Related
I has been breaking my head trying with regular expresions. I want to extract the sslconnector in a tomcat service.xml file.
this is the imput from my file.
<?xml version='1.0' encoding='utf-8'?>
<Server port="${shutdown.port}" shutdown="5ijXSyVl4Y9r">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<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">
<Connector port="${http.port}" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="${https.port}" />
<Connector port="${https.port}" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
keystoreFile="/opt/ais/install/tomcat/security/ais.jks" keystorePass="a1ss3cr3t"
clientAuth="false" sslEnabledProtocols="TLSv1.1,TLSv1.2" />
<Connector port="${ajp.port}" protocol="AJP/1.3" redirectPort="${https.port}" connectionTimeout="20000"/>
<Connector port="${ajp.port}" protocol="AJP/1.3" redirectPort="${https.port}" connectionTimeout="20000"/>
<Engine name="Catalina" defaultHost="localhost" jvmRoute="${tomcat.node.name}">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="access_log" pattern="%h %l %u %t %r %s %b %D %I %{JSESSIONID}c" resolveHosts="false" rotatable="false"/>
</Host>
</Engine>
</Service>
</Server>
I was trying with this sed sentence. "sed -n '/<.[Cc]onnector./>/p'" but not look, I'm only able to get the ajp connector.
some ideas?
The following (GNU) sed might work :
sed -n '/<Connector /,/\/>/p'
It prints from the line containing <Connector up to the line containing the next /> (which can be the same line).
It works with your sample data but could fail under many conditions, such as the tag having children and being closed by a </Connector> rather than self-closing. If your data has enough variation you'll probably want to use an XML selection language such as XPath, in which //Connector would be enough to get you all the Connector nodes whatever their format is.
I'm setting up an application that uses Struts 2.3 and Tiles 2. Some pages will be heavily Struts driven (e.g. lots of CRUD) while others will be simple, static HTML/JSP pages. I want to set up some actions that handle specific functionality and send all other URLs to a default action, which will check to see if the appropriate static page exists based on the supplied path. If not, a 404 error or some such will be generated instead.
In struts.xml, I have applied a basic configuration that appears like it should work; however, Struts seems to ignore the wildcard action. The non-wildcard actions work just fine.
Here's the struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!--
You could also set the constants in the struts.properties file
placed in the same directory as struts.xml
-->
<constant name="struts.devMode" value="true" />
<!-- <constant name="struts.mapper.class" value="rest" /> -->
<constant name="struts.action.extension" value="," />
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="regex" />
<!--
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>
<constant name="struts.convention.package.locators" value="rest"/>
-->
<package name="base" extends="tiles-default" abstract="yes">
<result-types>
<result-type name="tiles" default="true" class="org.apache.struts2.views.tiles.TilesResult" />
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
<!-- <interceptor name="requestConstants" class="com.ibm.gbs.vdp.constants.ConstantsInterceptor" /> -->
<interceptor-stack name="mainStack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="json" />
<!-- <interceptor-ref name="session" /> -->
<!-- <interceptor-ref name="requestConstants" /> -->
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="mainStack" />
<global-results>
<result name="login" type="tiles">login</result>
</global-results>
</package>
<!-- package start -->
<package name="main" extends="base" namespace="/">
<action name="login">
<result type="tiles">login</result>
</action>
<action name="logout" class="com.gswt.common.action.LogoutAction">
<result name="success">login</result>
</action>
<action name="*" class="com.installation.action.PageAction">
<result type="tiles">standard-page</result>
</action>
</package>
<!-- package end -->
<!-- package start -->
<package name="licenses" extends="base" namespace="/licenses">
</package>
<!-- package end -->
<!-- package start -->
<package name="checklists" extends="base" namespace="/checklists">
</package>
<!-- package end -->
<!-- package start -->
<package name="error" extends="base" namespace="/error">
<action name="404">
<result type="tiles">error-404</result>
</action>
</package>
<!-- package end -->
</struts>
And here's an example of the error I receive:
There is no Action mapped for namespace [/] and action name [page] associated with context path []. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:553)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:125)
com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:80)
com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908)
com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:997)
com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.invokeFilters(DefaultExtensionProcessor.java:1079)
com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java:999)
com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3954)
com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:945)
com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:191)
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:277)
com.ibm.ws.ssl.channel.impl.SSLConnectionLink.determineNextChannel(SSLConnectionLink.java:1049)
com.ibm.ws.ssl.channel.impl.SSLConnectionLink$MyReadCompletedCallback.complete(SSLConnectionLink.java:643)
com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1784)
com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1656)
What am I missing or doing wrong?
Since you are using advanced wildcards then your action name should be a valid regex expression to match the configuration.
Like so
<action name="{.*}" class="com.installation.action.PageAction">
<result type="tiles">standard-page</result>
</action>
I would like to filter the ELMAH results declaratively in my web.config. I'm not getting it to successfully filter out some of the exceptions I would like. HttpStatusCode is succesfully filtering, but I'm still getting ViewStateExceptions through. There are lots of posts about how to configure it, however I'm not sure how to put several filters into the configuration section and documentation seems to be a little thin on this point. Currently I have the below configuration in my web.config. I wondering, can someone point out:
If I have things defined correctly to filter out ViewStateExceptions and
How exactly to define the node structure to process all the filters correctly.
<errorFilter>
<test>
<equal binding="HttpStatusCode" value="404" type="Int32" />
<test>
<test>
<and>
<is-type binding="Exception" type="System.Web.HttpException" />
<regex binding='Exception.Message' pattern='invalid\s+viewstate' caseSensitive='false' />
</and>
</test>
<test>
<and>
<is-type binding="Exception" type="System.Web.UI.ViewStateException" />
<regex binding='Exception.Message' pattern='invalid\s+viewstate' caseSensitive='false' />
</and>
</test>
</errorFilter>
In your last test try binding to BaseException, not Exception.
Re your structure try something like:
<test>
<or>
<regex binding="BaseException.Message" pattern="Request timed out."/>
<and>
<equal binding="Context.Request.ServerVariables['REMOTE_ADDR']" value="::1" type="String"/>
<regex binding="Exception" pattern="hello"/>
</and>
<regex binding="BaseException.Message" pattern="The remote host closed the connection."/>
</or>
</test>
Should work. Wrap all the tests in an <or>, then any tests that must both be true, wrap in an <and>.
In Eclipse CDT Indigo, there is a new feature that allows you to add new C/C++ template projects to the new project wizard. I've figured out how to do this successfully up to a point. I can create a basic project that just depends on simple source files but now I'd like to create a CPPUnit project to which I'd like to automatically add the CPPUnit library. For the life of me, I can't figure out how to achieve this end. Does anyone know how?
Sorry I am late, but I just had the very same question for the very same problem. I have figured out a solution. It works for me, but I am well aware that it is probably not as general as hoped for. In your template.xml, you may want to add the following process:
<process type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringListOptionValues">
<simple name="projectName" value= "$(projectName)"/>
<complex-array name="resourcePaths">
<element>
<simple name="id" value="gnu.cpp.link.option.libs" />
<simple-array name="values">
<element value="dl" />
<element value="cppunit" />
</simple-array>
<simple name="path" value="" />
</element>
</complex-array>
</process>
The crucial part is to know where to put the two libraries dl and cppunit. The key gnu.cpp.link.option.libs is the correct one for the GNU compiler tool chain which is active on most Linux computers.
I have extracted the key name from the Eclipse plugin org.eclipse.cdt.managedbuilder.gnu.ui_XXXXXXX. You can find it at Eclipse's plugins folder. If you need the key for another toolset, I recommend opening the plugin.xml file. Here, you should search for the attribute valueType="libs". The corresponding id is the key you need to manipulate in your process file.
If you also need to manipulate the library search path, search for valueType="libPaths". This will lead you to the key gnu.cpp.link.option.paths. You can add additional entries to the list with a process similar to the one shown above.
It is AMAZING how hard this stuff is to find. In addition to plugin.xml browsing, all the templates provide efficient ramp up on implementing these options:
Source Reference
manual download: Eclipse CDT Source Download
Templates to Browse
plugins/org.eclipse.cdt.managedbuilder.gnu.ui_X.X.X.xxxxx.jar/templates/projecttemplates/
and then in each proj dir (e.g. 'HeloWorldCAnsiProject') locate template.xml
GNU C Options to Browse
plugins/org.eclipse.cdt.managedbuilder.gnu.ui_X.X.X.xxxxx.jar/plugin.xml
Example Implementation By Reverse-Engineering
Goal - set 'Cross GCC Compiler' -> Optimization -> 'Other optimization flags'
create a dummy C project with no customization
open properties. set the target field manually. I set 'Other optimization flags' to 'COME_FIND_ME'
open the .cproject file in an editor. search for COME_FIND_ME. here is what I found:
<option id="gnu.c.compiler.option.optimization.flags.1380831355" superClass="gnu.c.compiler.option.optimization.flags" value="COME_FIND_ME" valueType="string"/>
it is then of type 'string' and 'id' gnu.c.compiler.option.optimization.flags.
Search in the plugin.xml listed above for 'gnu.c.compiler.option.optimization.flags'. Here's what i found (on line 1120):
<option
name="%Option.Posix.Optimize.Flags"
category="gnu.c.compiler.category.optimization"
id="gnu.c.compiler.option.optimization.flags"
valueType="string">
</option>
get outta this example project, and go back to your template.xml you want to add this to. we want to append here to default value, so lets do that. add:
<process type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringOptionValue">
<simple name="projectName" value="$(projectName)" />
<complex-array name="resourcePaths">
<element>
<simple name="id" value="gnu.c.compiler.option.optimization.flags" />
<simple name="value" value="-Omg_eclipse" />
<simple name="path" value="" />
</element>
</complex-array>
</process>
and that's it.
Useful Links
Help - Eclipse Platform - How to register a project template with CDT
Help - Eclipse Platform - Example template
Notes
Here are where the MBS append/set functions live:
org.eclipse.cdt.managedbuilder.core.source_X.X.X.xxxxx.jar/org/eclipse/cdt/managedbuilder/templateengine/processes
Full Template File Example
finally, here's a code snippet that may save you hours of scouring the internet. this template.xml creates a new project by copying over main.c, and setting three build options.
<?xml version="1.0" encoding="ISO-8859-1"?>
<template type="ProjTempl" version="1.0" supplier="stack_overflow" revision="1.0" author="Justin Reina"
id="EXE" label="My C Project" description="set some stuff."help="help.html">
<process type="org.eclipse.cdt.core.CreateSourceFolder">
<simple name="projectName" value="$(projectName)"/>
<simple name="path" value="bsp"/>
</process>
<process type="org.eclipse.cdt.core.AddFiles">
<simple name="projectName" value="$(projectName)"/>
<complex-array name="files">
<element>
<simple name="source" value = "main.c"/>
<simple name="target" value = "main.c"/>
<simple name="replaceable" value = "true" />
</element>
</complex-array>
</process>
<process type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringListOptionValues">
<simple name="projectName" value= "$(projectName)"/>
<complex-array name="resourcePaths">
<element>
<simple name="id" value="gnu.c.link.option.libs" />
<simple-array name="values">
<element value="corestuff" />
<element value="utilstuff" />
</simple-array>
<simple name="path" value="" />
</element>
</complex-array>
</process>
<process type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringOptionValue">
<simple name="projectName" value="$(projectName)" />
<complex-array name="resourcePaths">
<element>
<simple name="id" value="gnu.c.compiler.option.optimization.flags" />
<simple name="value" value="-Omg_eclipse" />
<simple name="path" value="" />
</element>
</complex-array>
</process>
<process type="org.eclipse.cdt.managedbuilder.core.SetMBSBooleanOptionValue">
<simple name="projectName" value="$(projectName)" />
<complex-array name="resourcePaths">
<element>
<simple name="id" value="gnu.c.link.option.nostdlibs" />
<simple name="value" value="true" />
<simple name="path" value="" />
</element>
</complex-array>
</process>
</template>
To the Eclipse Foundation; next time can I just pay you a half-day's salary for you to give me this information???
In an Ant build.xml, I would like to be able to find any matches in all .html files using the following regex:
("|')((?!http://|#|mailto:|&|/)([^#\n\s\."])+?\.([^#\n\s"])+?)\1
Then, I want to list those matches of \2 in a file. Is this possible?
Final result, thanks to #bakoyaro:
<echo message="Collecting appcache files" />
<concat destFile="your_output_file">
<fileset dir="./${dir.publish}">
<include name="**/*.html"/>
</fileset>
<filterchain>
<linecontainsregexp>
<regexp pattern="(.)*?("|')((?!http://|\?|#|mailto:|\1)([^#\n\s\."'?])+?\.([^#\n\s"'?])+?)\2" />
</linecontainsregexp>
<tokenfilter>
<replaceregex pattern="(.)*?("|')((?!http://|\?|#|mailto:|\1)([^#\n\s\."'?])+?\.([^#\n\s"'?])+?)\2" flags="g" replace="\1\2\3\2${line.separator}" />
</tokenfilter>
<linecontainsregexp>
<regexp pattern="(.)*?("|')((?!http://|\?|#|mailto:|\1)([^#\n\s\."'?])+?\.([^#\n\s"'?])+?)\2" />
</linecontainsregexp>
<tokenfilter>
<replaceregex pattern="(.)*?("|')((?!http://|\?|#|mailto:|\1)([^#\n\s\."'?])+?\.([^#\n\s"'?])+?)\2" flags="g" replace="\3" />
</tokenfilter>
<linecontainsregexp>
<regexp pattern="((?!http://|\?|#|mailto:|\1)([^#\n\s\."'?])+?\.([^#\n\s"'?])+?)" />
</linecontainsregexp>
</filterchain>
</concat>
Here is a snippet that may help, it will create a .zip file containing any of the files that match your regex. I use it to examine my builds to ensure that all of the ant tokens were replaced.
<zip destfile="${your_file_name}" update="true" whenempty="skip">
<fileset dir="${your_search_directory}">
<!-- your file pattern -->
<include name="**/*.html" />
<!-- this will destroy an executable file. best to exclude them -->
<exclude name="**/*.jar" />
<containsregexp expression="your_regex_to_match" />
</fileset>
</zip>
You should be able to do this using the Concat task with a nested FilterChain.
Something like this:
<concat destFile="your_output_file">
<fileset dir="WebContent">
<include name="**/*.html"/>
</fileset>
<filterchain>
<linecontainsregexp>
<regexp pattern="your_pattern_to_match" />
</linecontainsregexp>
<tokenfilter>
<replaceregex pattern="your_pattern_to_extract" replace="output_required" />
</tokenfilter>
</filterchain>
</concat>