// --------------------------------------------- // get def node // --------------------------------------------- public VRMLNode getDefNode(String defName) { Map<String, VRMLNodeType> m = handler.getDefMap(); VRMLNode node = (VRMLNode) m.get(defName); return node; }
// ---------------------------------------------------------- // parse // ---------------------------------------------------------- public boolean parse(String fname) { File f = new File(fname); if (!f.exists()) { System.err.println("*** [ERROR] " + fname + " not exists! ***"); return false; } FileInputStream stream = null; try { stream = new FileInputStream(fname); } catch (Exception excep) { System.out.println(excep.toString()); return false; } // InputSource is = new InputSource(f); InputSource is = new InputSource("file://" + fname, stream); VRMLParserFactory parser_fac = null; try { parser_fac = VRMLParserFactory.newVRMLParserFactory(); } catch (Exception fce) { throw new RuntimeException("Failed to load factory"); } VRMLReader reader = parser_fac.newVRMLReader(); scene = new CRVRMLScene(2, 0); handler = new X3DParseEventHandler(scene); handler.debugMode(false); // handler.debugMode(true); reader.setHeaderIgnore(true); reader.setContentHandler(handler); reader.setScriptHandler(handler); reader.setProtoHandler(handler); reader.setRouteHandler(handler); reader.setErrorReporter(DefaultErrorReporter.getDefaultReporter()); try { reader.parse(is); } catch (Exception excep) { excep.printStackTrace(); return false; } // VRMLNode root = scene.getRootNode(); // printNode(root); return true; }
// --------------------------------------------- // get all def names // --------------------------------------------- public String[] getDefNames() { Map<String, VRMLNodeType> m = handler.getDefMap(); Set<String> strSet = m.keySet(); String[] ret = new String[strSet.size()]; int i = 0; Iterator<String> itr = strSet.iterator(); while (itr.hasNext()) { String defName = itr.next(); ret[i] = defName; i++; } return ret; }