From 56b705aa35ad3662a8eb35f67a2259735986f30f Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 24 Oct 2001 16:30:24 +0000 Subject: [PATCH] added bits necessary for XmlConfigurator.addRequiredTag(String xmlPath) --- source/mir/xml/SaxContext.java | 54 +++++++++++++++++++++++++++ source/mir/xml/XmlConfigurator.java | 73 +++++++++++++++++++++++++++++++++---- source/mir/xml/XmlMatch.java | 45 +++++++++++++++++++++++ 3 files changed, 165 insertions(+), 7 deletions(-) create mode 100755 source/mir/xml/SaxContext.java create mode 100755 source/mir/xml/XmlMatch.java diff --git a/source/mir/xml/SaxContext.java b/source/mir/xml/SaxContext.java new file mode 100755 index 00000000..b67c4895 --- /dev/null +++ b/source/mir/xml/SaxContext.java @@ -0,0 +1,54 @@ +package mir.xml; + + +// XXX this interface is not final, but a prototype. + +/** SAX Context - used to match and perform actions + * provide access to the current stack and XML elements. + * + * Inspired by Tomcat's SAX context, although our's is + * implemented and used slightly differently. + * + * @author + */ +public class SaxContext { + + private String tagStack[]; + private int pos; + + // -------------------- Konstruktor + + public SaxContext() { + pos=0; + tagStack = new String[256]; + } + + // -------------------- Access to parsing context + + /** Depth of the tag stack. + */ + public int getTagCount() { + return pos; + } + + /** Access a particular tag + */ + public String getTag( int pos ) { + return tagStack[pos]; + } + + // ------------------- Adjusting the parsing context + public void push(String tag) { + tagStack[pos] = tag; + pos++; + } + + public void pop() { + if(pos > 1) + tagStack[pos]=null; + + pos--; + } + +} + diff --git a/source/mir/xml/XmlConfigurator.java b/source/mir/xml/XmlConfigurator.java index a67a7c4a..c82f2231 100755 --- a/source/mir/xml/XmlConfigurator.java +++ b/source/mir/xml/XmlConfigurator.java @@ -37,21 +37,37 @@ public class XmlConfigurator { private File configFileParent; private Locator locator; - //private SaxContext saxContext; + private SaxContext saxContext; + + XmlMatch requiredXmlMatch[]=new XmlMatch[256]; //maximum amount of rules + int requiredXmlMatchCount=0; + boolean matched[] = new boolean[256]; + int matchedCount=0; + + private static XmlConfigurator instance = new XmlConfigurator(); + public static XmlConfigurator getInstance() { return instance; } /** * Configures the Project with the contents of the specified XML file. */ - public static void configure(File configFile) throws ConfigException { - new XmlConfigurator(configFile).parse(); + public void configure(File configFile) throws ConfigException { + setConfigFile(configFile); + parse(); } /** + * konstruktor. private so no one calls "new" on us. + */ + private XmlConfigurator() {} + + + /** * Constructs a new Ant parser for the specified XML file. */ - private XmlConfigurator(File configFile) { + private void setConfigFile(File configFile) { this.configFile = new File(configFile.getAbsolutePath()); configFileParent = new File(this.configFile.getParent()); + saxContext = new SaxContext(); } /** @@ -74,6 +90,12 @@ public class XmlConfigurator { inputSource = new InputSource(inputStream); inputSource.setSystemId(uri); saxParser.parse(inputSource, new RootHandler()); + if(matchedCount < requiredXmlMatchCount) { + for( int i=0; i=0; j--) { + if( depth<1) { + // System.out.println("Pattern too long "); + return false; + } + String tag=ctx.getTag(depth-1); + if( ! names[j].equals( tag ) ) { + // System.out.println("XXX" + names[j] + " " + tag); + return false; + } + depth--; + } + + + return true; + } + + public String toString() { + return "Tag("+names+")"; + } + +} + -- 2.11.0