示例#1
0
	public boolean read(String strRoute, String strElement, int flag) {
		//SAXBuilder builder=new SAXBuilder();
		strText = null;
		try {
			String[] route = new String[4];

			String str = null;
			Document doc = builder.build(xmlFileName);
			Element root = doc.getRootElement();
			Element element = root;

			//创建一个拆分字符串内容的对象,每次返回一项
			StringTokenizer st = new StringTokenizer(strRoute, ":");
			str = st.nextToken();

			while (st.hasMoreTokens()) {
				str = st.nextToken();
				element = element.getChild(str);
			}

			//mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,str);
			element = (Element) element.getParent();
			/*
			 * while(flag!=1) { if(element.removeChild(str))
			 * mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"deleted "+str);
			 * else mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"not
			 * deleted");
			 * 
			 * flag--; }
			 */
			//	mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,element.getName());
			strText = element.getChild(str).getChild(strElement).getText();

		} catch (JDOMException jdome) {
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, xmlFileName
					+ " is not well-formed");

		} catch (IOException ioe) {
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, ioe);

		} catch (NullPointerException nullpe) {
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, "not founded"
					+ "\n" + nullpe);

		} catch (Exception e) {
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, "read no succeed"
					+ "\n" + e);

		}

		if (strText == null) {
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, "not founded");
			return false;
		} else {
			//	mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"strText="+strText);
			return true;
		}

	}
示例#2
0
  // createericlist with a String signature is used to process a String
  // containing a sequence of GAIGS structures
  // createericlist creates the list of graphics primitives for these snapshot(s).
  // After creating these lists, that are then appended to l, the list of snapshots,
  // Also must return the number of snapshots loaded from the string
  public /*synchronized*/ int createericlist(String structString) {
    int numsnaps = 0;
    if (debug) System.out.println("In create eric " + structString);
    StringTokenizer st = new StringTokenizer(structString, "\r\n");
    while (st.hasMoreTokens()) {
      numsnaps++; // ??
      String tempString;
      LinkedList tempList = new LinkedList();
      StructureType strct;
      tempString = st.nextToken();
      try {
        boolean headers = true;
        while (headers) {
          headers = false;
          if (tempString.toUpperCase().startsWith("VIEW")) {
            tempString = HandleViewParams(tempString, tempList, st);
            headers = true;
          }
          if (tempString.toUpperCase().startsWith("FIBQUESTION ")
              || tempString.toUpperCase().startsWith("MCQUESTION ")
              || tempString.toUpperCase().startsWith("MSQUESTION ")
              || tempString.toUpperCase().startsWith("TFQUESTION ")) {
            tempString = add_a_question(tempString, st);
            headers = true;
          }
        }

        if (tempString.toUpperCase().equals("STARTQUESTIONS")) {
          numsnaps--; // questions don't count as snapshots
          readQuestions(st);
          break;
        }
        // After returning from HandleViewParams, tempString should now contain
        // the line with the structure type and possible additional text height info
        StringTokenizer structLine = new StringTokenizer(tempString, " \t");
        String structType = structLine.nextToken();
        if (debug) System.out.println("About to assign structure" + structType);
        strct = assignStructureType(structType);
        strct.loadTextHeights(structLine, tempList, this);
        strct.loadLinesPerNodeInfo(st, tempList, this);

        strct.loadTitle(st, tempList, this);
        strct.loadStructure(st, tempList, this);
        strct.calcDimsAndStartPts(tempList, this);
        strct.drawTitle(tempList, this);
        strct.drawStructure(tempList, this);
      } catch (VisualizerLoadException e) {
        System.out.println(e.toString());
      }
      //             // You've just created a snapshot.  Need to insure that "**" is appended
      //             // to the URLList for this snapshot IF no VIEW ALGO line was parsed in the
      //             // string for the snapshot.  This could probably best be done in the
      //             // HandleViewParams method
      list_of_snapshots.append(tempList);
      Snaps++;
    }
    return (numsnaps);
  } // createericlist(string)
示例#3
0
  /**
   * Processes the command with text
   *
   * @param command
   * @param message
   */
  private boolean processMessageCommandText(String command, String message) {
    boolean processed = false;
    String args[] = new String[MAXARGC];
    int counter = 0;

    StringTokenizer st = new StringTokenizer(message, " ");
    while (st.hasMoreTokens() && counter < MAXARGC - 1) {
      args[counter] = st.nextToken();
      counter++;
    }

    // do the proccessing
    if (command.equalsIgnoreCase("MESSAGE")) {
      String toSend = message.substring(command.length() + args[1].length() + 2, message.length());
      //	    System.out.println("::" + toSend + "::");
      sendServerMessage(
          "<mobber><message><recipient>"
              + args[1]
              + "</recipient><mesg>"
              + toSend
              + "</mesg></message></mobber>");
      processed = true;
    } else if (command.equalsIgnoreCase("GROUPMESSAGE")) {
      String toSend = message.substring(command.length() + 2, message.length());
      //	    System.out.println("::" + toSend + "::");
      sendServerMessage(
          "<mobber><groupmessage><group>"
              + _group
              + "</group><mesg>"
              + toSend
              + "</mesg></groupmessage></mobber>");
      processed = true;
    } else if (command.equalsIgnoreCase("WALL")) {
      String toSend = message.substring(command.length() + 2, message.length());
      System.out.println("::" + toSend + "::");
      sendServerMessage("<mobber><wall><mesg>" + toSend + "</mesg></wall></mobber>");
      processed = true;
    } else if (command.equalsIgnoreCase("CREATEGROUP")) {
      String toSend = message.substring(command.length() + args[1].length() + 2, message.length());
      sendServerMessage(
          "<mobber><creategroup><group>"
              + args[1]
              + "</group><desc>"
              + toSend
              + "</desc></creategroup></mobber>");
      processed = true;
    }

    return processed;
  }
示例#4
0
  private /*synchronized*/ void readQuestions(StringTokenizer st) throws VisualizerLoadException {
    String tmpStr =
        "STARTQUESTIONS\n"; // When CG's QuestionFactory parses from a string, it looks for
    // a line with STARTQUESTIONS -- hence we add it artificially here
    try { // Build the string for the QuestionFactory
      while (st.hasMoreTokens()) {
        tmpStr += st.nextToken() + "\n";
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new VisualizerLoadException("Ooof!  bad question format");
    }

    try {
      // System.out.println(tmpStr);
      // Problem -- must make this be line oriented
      GaigsAV.questionCollection = QuestionFactory.parseScript(tmpStr);
    } catch (QuestionParseException e) {
      e.printStackTrace();
      System.out.println("Error parsing questions.");
      throw new VisualizerLoadException("Ooof!  bad question format");
      // throw new IOException();
    }
  } // readQuestions(st)
示例#5
0
	//改写XML文件的某一元素的值
	//strRoute为XML文件从根元素开始到该元素的父元素的路径
	//strElement为需要读取的元素
	//flag为当XML含有多个同名元素时,需要改写元素所处的序号
	public void write(String strRoute, String strElement, String strSet,
			int flag) {
		//SAXBuilder builder=new SAXBuilder();
		try {
			String str = null;
			Document doc = builder.build(xmlFileName);
			Element root = doc.getRootElement();
			Element element = root;

			StringTokenizer st = new StringTokenizer(strRoute, ":");
			str = st.nextToken();

			while (st.hasMoreTokens()) {
				str = st.nextToken();
				//mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,str);
				element = element.getChild(str);

			}

			//	mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"test :"+str);
			element = (Element) element.getParent();

			//若需要改写的不是XML文件的第一个同名元素,则获取该元素
			//方法为:将之前的元素依次移到后面,需要改写的元素前移至第一个
			/*
			 * if(flag>1) { int j=flag; while(j!=1) {
			 * 
			 * Element tmp=element.getChild(str);
			 * element.addContent(tmp.detach()); j--; } }
			 */
			element = element.getChild(str).getChild(strElement);

			//	mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"gettxt
			// "+element.getText());

			element.setText(strSet);

			//若需要改写的不是XML文件的第一个同名元素
			//上面改变了次序,需要在成功改写后恢复原有次序
			/*
			 * if(flag!=1) {
			 * 
			 * java.util.List children=element.getChildren(); Iterator
			 * iterator=children.iterator(); int count=0;
			 * while(iterator.hasNext()) { Element
			 * child=(Element)iterator.next(); count++; }
			 * 
			 * System.out.println("count"+count);
			 * 
			 * k=(count+1-flag)%count;
			 * 
			 * while(k!=0) { Element tmp=element.getChild(str);
			 * element.addContent(tmp.detach()); k--; } }
			 *  
			 */
			XMLOutputter outputter = new XMLOutputter("", false, "GB2312");
			PrintWriter out = new PrintWriter(new BufferedWriter(
					new FileWriter(xmlFileName)));

			Document myDocument = root.getDocument();

			outputter.output(myDocument, out);
			out.close();

		} catch (JDOMException jdome) {
			jdome.printStackTrace();
//			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, xmlFileName
//					+ " is not well-formed\n");

		} catch (IOException ioe) {
			ioe.printStackTrace();
//			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, ioe);

		} catch (Exception e) {
			e.printStackTrace();
//			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,
//					"write not succeed\n");

		}

	}
示例#6
0
  /**
   * Processes the other commands
   *
   * @param command
   * @param message
   */
  private boolean processMessageCommand(String command, String message) {
    boolean processed = false;

    String args[] = new String[MAXARGC];
    int counter = 0;

    StringTokenizer st = new StringTokenizer(message, " ");
    while (st.hasMoreTokens() && counter < MAXARGC - 1) {
      args[counter] = st.nextToken();
      counter++;
    }

    // do the proccessing
    if (command.equalsIgnoreCase("NAME")) {
      _user = args[1];
      processed = true;
    } else if (command.equalsIgnoreCase("PASS")) {
      _pass = args[1];
      processed = true;
    } else if (command.equalsIgnoreCase("LOGIN")) {
      sendServerMessage(
          "<mobber><login><name>"
              + _user
              + "</name><password>"
              + _pass
              + "</password></login></mobber>");
      processed = true;
    } else if (command.equalsIgnoreCase("LOGOUT")) {
      sendServerMessage("<mobber><logout /></mobber>");
      _status = NOTCONNECTED;
      processed = true;
    } else if (command.equalsIgnoreCase("EXIT")) {
      _mr.exit();
      processed = true;
    } else if (command.equalsIgnoreCase("CONNECT")) {
      connect(args[1], (new Integer(args[2])).intValue());
      sendMessage(CLIENT, "try to connect");
      if (_status == CONNECTED) sendMessage(CLIENT, "connected to:" + args[1] + ":" + args[2]);
      processed = true;
    } else if (command.equalsIgnoreCase("JOINGROUP")) {
      sendServerMessage("<mobber><joingroup><group>" + args[1] + "</group></joingroup></mobber>");
      processed = true;
    } else if (command.equalsIgnoreCase("PARTGROUP")) {
      sendServerMessage("<mobber><partgroup><group>" + args[1] + "</group></partgroup></mobber>");
      processed = true;
    } else if (command.equalsIgnoreCase("KICK")) {
      sendServerMessage(
          "<mobber><kick><group>"
              + _group
              + "</group><user>"
              + args[1]
              + "</user></kick></mobber>");
      processed = true;
    } else if (command.equalsIgnoreCase("LISTUSER")) {
      sendServerMessage("<mobber><listuser /></mobber>");
      processed = true;
    } else if (command.equalsIgnoreCase("LISTGROUP")) {
      sendServerMessage("<mobber><listgroup /></mobber>");
      processed = true;
    }
    return processed;
  }