public boolean addProtoParameter(VRML97ProtoParameterList paramList, VRML97ProtoTokenizer stream) throws IOException { stream.nextToken(); if (stream.ttype != StreamTokenizer.TT_WORD) return false; String fieldName = stream.sval; stream.nextToken(); if (stream.ttype != StreamTokenizer.TT_WORD) return false; String name = stream.sval; String value = getParameterValue(fieldName, stream); if (name != null && value != null) { // Debug.message(" " + fieldName + " " + name + " = " + value); paramList.addParameter(fieldName, name, value); return true; } return false; }
public String getVRML97ProtoString(VRML97Proto proto, VRML97ProtoTokenizer stream) throws IOException { VRML97ProtoParameterList paramList = new VRML97ProtoParameterList(); int indent = 0; stream.nextToken(); while (stream.ttype != StreamTokenizer.TT_EOF) { if (stream.ttype == StreamTokenizer.TT_WORD) { if (stream.sval.compareTo("{") == 0) { indent++; break; } } stream.nextToken(); } if (stream.ttype == StreamTokenizer.TT_EOF) return null; stream.nextToken(); while (stream.ttype != StreamTokenizer.TT_EOF) { switch (stream.ttype) { case StreamTokenizer.TT_WORD: { String strToken = stream.sval; if (strToken.compareTo("{") == 0) indent++; else if (strToken.compareTo("}") == 0) { indent--; if (indent == 0) return proto.getString(paramList); } else { String name = strToken; VRML97ProtoParameter protoParam = proto.getParameter(name); if (protoParam != null) { String fieldTypeName = protoParam.getType(); String value = getParameterValue(fieldTypeName, stream); if (hasProto(proto, value) == true) { Debug.message("==== value ==== "); Debug.message(value); StringWriter strWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(strWriter); StringReader strReader = new StringReader(value); VRML97ProtoTokenizer valueStream = new VRML97ProtoTokenizer(strReader); try { replace(valueStream, printWriter); strWriter.flush(); strWriter.close(); } catch (IOException e) { } value = strWriter.toString(); Debug.message("==== New value ==== "); Debug.message(value); } paramList.addParameter(fieldTypeName, name, value); } } } break; case StreamTokenizer.TT_EOL: { } break; } stream.nextToken(); } return null; }