From: Julio G. <ju...@us...> - 2004-03-17 15:10:57
|
Update of /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26122/smartfrog/src/org/smartfrog/sfcore/parser Modified Files: Parser.java SFParser.java Log Message: REF: new utitity methods for - create a Component description from a resource URL - load Parser using a resource URL. ADD: methods to merge DefaultProcessDescriptions with ProcessDescription. We need to refactor ProcessCompound to make use of it. Therefore, the call is commented. Index: SFParser.java =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/parser/SFParser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SFParser.java 30 Jan 2004 00:11:03 -0000 1.1.1.1 --- SFParser.java 17 Mar 2004 15:01:30 -0000 1.2 *************** *** 92,101 **** * Constructor for an instance of the parser for the given language. * ! * @param language the name of the language to use * * @throws SmartFrogException error crearing instance of parser */ ! public SFParser(String language) throws SmartFrogException { ! theLanguage = language; parser = getParser(); } --- 92,102 ---- * Constructor for an instance of the parser for the given language. * ! * @param String languageOrUrl the name of the language to use or the url ! * with suffixed by language extension. * * @throws SmartFrogException error crearing instance of parser */ ! public SFParser(String languageOrUrl) throws SmartFrogException { ! theLanguage = this.getLanguageFromUrl(language); parser = getParser(); } *************** *** 105,109 **** /** * Referebce to parser class. ! */ Class parserClass; --- 106,110 ---- /** * Referebce to parser class. ! */ Class parserClass; *************** *** 146,149 **** --- 147,173 ---- } + + /** + * Parses component(s) from an resource url. Returns a root component which + * contains the parsed components. Includes should be handled by some + * default include handler. + * + * @param String url to resource to parse and compile from + * + * @return Phases root component containing parsed component(s) + * + * @exception SmartFrogParseException error parsing stream + */ + + public Phases sfParseResource(String url) throws SmartFrogParseException { + InputStream is = SFClassLoader.getResourceAsStream(url); + if (is == null) { + throw new SmartFrogParseException(MessageUtil.formatMessage( + MSG_INPUTSTREAM_NULL)); + } + return sfParse(is); + } + + /** * Parses component(s) from a string. Returns the root component. This is a *************** *** 188,190 **** --- 212,239 ---- return parser.sfParseReference(new ByteArrayInputStream(txt.getBytes())); } + + + /** + * Gets language from the URL + * + * @param url URL passed to application + * + * @return Language string + * + * @throws SmartFrogException In case any error while getting the + * language string + */ + public static String getLanguageFromUrl(String url) + throws SmartFrogParseException { + if (url == null) { + throw new SmartFrogParseException (MessageUtil.formatMessage( + MSG_NULL_URL)); + } + + int i = url.lastIndexOf('.'); + + return url.substring(i + 1).trim(); + + } + } Index: Parser.java =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/parser/Parser.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Parser.java 30 Jan 2004 00:11:02 -0000 1.1.1.1 --- Parser.java 17 Mar 2004 15:01:25 -0000 1.2 *************** *** 21,25 **** package org.smartfrog.sfcore.parser; ! import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.reference.Reference; --- 21,25 ---- package org.smartfrog.sfcore.parser; ! import org.smartfrog.sfcore.common.SmartFrogParseException; import org.smartfrog.sfcore.reference.Reference; *************** *** 41,45 **** * @exception SmartFrogException error parsing string */ ! public Phases sfParse(String str) throws SmartFrogException; /** --- 41,59 ---- * @exception SmartFrogException error parsing string */ ! public Phases sfParse(String str) throws SmartFrogParseException; ! ! /** ! * Parses component(s) from an resource url. Returns a root component which ! * contains the parsed components. Includes should be handled by some ! * default include handler. ! * ! * @param is url to resource to parse and compile from ! * ! * @return root component containing parsed component(s) ! * ! * @exception SmartFrogParseException error parsing stream ! */ ! public Phases sfParseResource(String url) throws SmartFrogParseException; ! /** *************** *** 53,56 **** * @exception SmartFrogException failed to parse reference */ ! public Reference sfParseReference(String txt) throws SmartFrogException; } --- 67,70 ---- * @exception SmartFrogException failed to parse reference */ ! public Reference sfParseReference(String txt) throws SmartFrogParseException; } |