The command line arguments may provide a pointer to a ‘scriptFile’ and a pointer to an algorithm ‘scriptMap’ for getting the script file name.
With and without ml2xml
<..scriptFile := entry script file name..>
if( scriptMap != null ){
try{
String f = FileInfo.searchFile( scriptMap );
if( f == null ){
throw new java.io.FileNotFoundException( scriptMap );
} else {
scriptMap = f;
}
<.get sax reader.>
saxReader.setContentHandler( new DefaultHandler(){
<.process script map.>
} );
InputStream inputStream =
(InputStream) (new File(scriptMap).toURI().toURL().openStream());
saxReader.parse( new InputSource(inputStream) );
saxReaderStack.push( saxReader );
} catch( java.io.FileNotFoundException e ){
instructionErr( null,
"File not found: " + e.getMessage()
+ "; command line option -i",
33 );
} catch( Exception e ){
instructionErr( null, e.toString(), e.getStackTrace(), 27 );
}
}
if( scriptFile == null ){
scriptFile = "xtpipes-default.4xt";
}
-_-_-
<..process script map..>
private Stack <Boolean> condition = new Stack <Boolean> ();
-_-_-
<..process script map..>+
public void startDocument () {
condition.push( new Boolean(true) );
}
-_-_-
<..process script map..>+
public void startElement(String ns, String sName,
String qName, Attributes atts) {
if( condition == null ){ return; }
<.trace start map element.>
boolean cond = ((Boolean) condition.peek()).booleanValue();
if( qName.equals("when") ){
if( cond ){ <.cond := when ....> }
}
else
if( qName.equals("command-line") ){
if( scriptFile != null ){
<.trace found script in map.>
condition = null;
return;
} }
else
if( qName.equals("processing-instruction") ){
if( cond ){
String s = inputObject.getXtpipes();
if( s != null ){
Xtpipes.scriptFile = s;
<.trace found script in map.>
condition = null;
return;
} } }
else
if( qName.equals("select") ){
if( cond ){
Xtpipes.scriptFile = atts.getValue("name");
<.trace found script in map.>
condition = null;
return;
} }
condition.push( new Boolean(cond) );
}
-_-_-
<..process script map..>+
public void endElement(String ns, String sName, String qName) {
if( condition == null ){ return; }
<.trace end map element.>
condition.pop();
}
-_-_-
<..cond := when .....>
String name = atts.getValue("name");
String value = atts.getValue("value");
if( name.equals("system-id") ){
cond = value.equals(inputObject.getSystemId());
}
else
if( name.equals("public-id") ){
cond = value.equals(inputObject.getPublicId());
}
else
if( name.equals("dtd-root") ){
cond = value.equals(inputObject.getDtdRoot());
}
else
if( name.equals("root") ){
cond = value.equals(inputObject.getRoot());
}
else
if( name.equals("ext") ){
cond = inputObject.getFilename().endsWith("." + value);
}
else
if( name.equals("prefix") ){
name = inputObject.getFilename();
if( name != null ){
int i = name.lastIndexOf(’/’);
if( (i != -1) && ((i+1) < name.length()) ){
name = name.substring(i+1);
}
i = name.lastIndexOf(’\\’);
if( (i != -1) && ((i+1) < name.length()) ){
name = name.substring(i+1);
}
cond = name.startsWith(value);
} }
else
if( name.equals("meta-type") ){
cond = value.equals(inputObject.getMetaType());
}
else
if( name.equals("content-type") ){
cond = value.equals(inputObject.getContentType());
}
-_-_-
<..trace found script in map..>
if( trace ){
Xtpipes.logWriter.println( " Found script file in map: "
+ Xtpipes.scriptFile );
}
-_-_-
<..trace start map element..>
if( Xtpipes.trace ){
String s = "<" + qName + "\n";
for(int i=0; i<atts.getLength(); i++ ){
String name = atts.getQName(i);
s += " " + name + "=\"" + atts.getValue(i) + "\"";
}
s += ">" ;
Xtpipes.logWriter.println( s );
}
-_-_-
<..trace end map element..>
if( Xtpipes.trace ){
String s = "</" + qName + ">";
Xtpipes.logWriter.println( s );
}
-_-_-