protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    super.doPost(request, response);

    try {
      if (!ServletFileUpload.isMultipartContent(request)) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
      }

      ServletFileUpload sfU = new ServletFileUpload();
      FileItemIterator items = sfU.getItemIterator(request);
      while (items.hasNext()) {
        FileItemStream item = items.next();
        if (!item.isFormField()) {
          InputStream stream = item.openStream();
          Document doc = editor.toDocument(stream);
          stream.close();
          handleDocument(request, response, doc);
          return;
        }
      }

      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No XML uploaded");
    } catch (FileUploadException fuE) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, fuE.getMessage());
    } catch (JDOMException jE) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, jE.getMessage());
    }
  }
예제 #2
0
  public String SqlExcute(String xmlStr) {
    String outstr = "false";
    Document doc;
    Element rootNode;
    String intStr = Basic.decode(xmlStr);

    try {
      Reader reader = new StringReader(intStr);
      SAXBuilder ss = new SAXBuilder();
      doc = ss.build(reader);

      rootNode = doc.getRootElement();

      List list = rootNode.getChildren();

      DBTable datatable = new DBTable();

      for (int i = 0; i < list.size(); i++) {
        Element childRoot = (Element) list.get(i);
        // System.out.print(childRoot.getText());
        outstr = String.valueOf(datatable.SaveDateStr(childRoot.getText()));
      }

    } catch (JDOMException ex) {
      System.out.print(ex.getMessage());
    }
    return outstr;
  }
예제 #3
0
  public ParseDoc(Object xmlFile, String rootId, TreeMap prevIdMap) {

    SAXBuilder saxBuilder = new SAXBuilder();

    try {
      if (xmlFile instanceof String) {
        document = saxBuilder.build((String) xmlFile);
      } else if (xmlFile instanceof URL) {
        document = saxBuilder.build((URL) xmlFile);
      }
      root = ParseUtils.parseRoot(document, rootId);
      objects = new TreeMap();

      // Build description string (but not for the snippets.xml file)
      if (xmlFile instanceof String) {
        List authorL = root.getChildren("author");
        String author = "<unknown>";
        if (root.getAttributeValue("name") != null) {
          author = root.getAttributeValue("name");
        } else if (authorL.size() > 0) {
          author = ((Element) authorL.get(0)).getValue();
        }
        String description =
            "from file "
                + xmlFile.toString()
                + " (author: "
                + author
                + ") on "
                + new Date().toString();
        HasIdentifiers.addGlobalIdentifier("_description_", description);
      }

      // Get all macro definitions, and remove them from document
      TreeMap macroMap = ParseUtils.getMacroDefs(root);

      // Process all macro expansions; replace macro expansion request with result
      ParseUtils.expandMacros(root, macroMap);

      // Get all elements in document, and assign identifiers to them;
      idMap = ParseUtils.parseId(root, prevIdMap);

      // Rewriting done; output debug XML code
      if (root.getAttributeValue("debug") != null) {
        XMLOutputter outputter = new XMLOutputter();
        FileOutputStream fos = new FileOutputStream(xmlFile + ".debug");
        outputter.output(document, fos);
        fos.close();
      }

    } catch (JDOMException e) { // indicates a well-formedness or other error

      throw new Error("JDOMException: " + e.getMessage());

    } catch (IOException e) { // indicates an IO problem

      throw new Error("IOException: " + e.getMessage());
    }
  }
예제 #4
0
 /** Create a new step from an in-line XML string. */
 public static Step createStep(Resolver resolver, String str)
     throws InvalidScriptException, IOException {
   StringReader reader = new StringReader(str);
   try {
     SAXBuilder builder = new SAXBuilder();
     Document doc = builder.build(reader);
     Element el = doc.getRootElement();
     return createStep(resolver, el);
   } catch (JDOMException e) {
     throw new InvalidScriptException(e.getMessage());
   }
 }
 private Document getXMLDocument(InputStream is) {
   SAXBuilder builder = new SAXBuilder();
   builder.setValidation(false);
   builder.setIgnoringElementContentWhitespace(true);
   Document doc = null;
   try {
     doc = builder.build(is);
   } catch (JDOMException e) {
     e.printStackTrace();
     System.exit(-1);
   } catch (IOException e) {
     e.printStackTrace();
     System.exit(-1);
   }
   return doc;
 }
예제 #6
0
  private void openFileMenuItemWidgetSelected(SelectionEvent evt) {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
    String filename = dialog.open();
    if (filename != null) {
      getShell().setText(filename);
      File file = new File(filename);
      XML.load(file);
      try {
        XML.Match();
        setStatus(XML.Output);
      } catch (JDOMException e) {

        e.printStackTrace();
      }
    }
  }
예제 #7
0
	/**
	 * 
	 * @param 普通版list	参数列表
	 */
	public void writeptParaList(ArrayList list)
	{
		
		try {
			String sCaseName="";
			String sItem="";
			String sCycName="";
			HashMap map=null;
			Document doc = builder.build(xmlFileName);
			Element root = doc.getRootElement();
			Element element = root;
			Element cycNode=null;
			
			map=(HashMap)list.get(0);	//参数文件map
			sItem="Description";
			sCaseName=(String)map.get(sItem);
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, "Description=" + sCaseName );
		
			sItem="CysName";
			sCycName=(String)map.get(sItem);
			
			map=(HashMap)list.get(1);	//public 参数map
			cycNode=writeptPublicNode(element,map,sCycName);
			
			if( writeCycNode(cycNode,list)==false)	//循环 参数
			  System.err.println(" write cyc node fail");
			
			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();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
예제 #8
0
  public String QuerySQL(String xmlStr) {
    String outstr = "";
    Document doc;
    Element rootNode;
    String intStr = Basic.decode(xmlStr);

    try {
      Reader reader = new StringReader(intStr);
      SAXBuilder ss = new SAXBuilder();
      doc = ss.build(reader);

      rootNode = doc.getRootElement();

      String SqlStr = "select " + rootNode.getAttributeValue("fieldStr");
      SqlStr = SqlStr + "  from  " + rootNode.getAttributeValue("tableStr");
      SqlStr = SqlStr + "  where (1=1) " + rootNode.getAttributeValue("whereStr");

      DBTable datatable = new DBTable();

      RecordSet rs = datatable.queryData(SqlStr);
      String[] fieldArr = rootNode.getAttributeValue("fieldStr").split(",");

      outstr = "<queryDataS success=\"true\">";
      while (rs.next()) {
        outstr = outstr + "<queryData";
        for (int i = 0; i < fieldArr.length; i++) {
          outstr =
              outstr + "  " + fieldArr[i].trim() + "=\"" + rs.getString(fieldArr[i].trim()) + "\"";
        }
        outstr = outstr + "/>";
      }
      outstr = outstr + "</queryDataS>";

    } catch (JDOMException ex) {
      outstr = "<queryDataS success=false>";
      outstr = outstr + ex.getMessage() + "</queryDataS>";
    }
    return Basic.encode(outstr);
  }
예제 #9
0
 /**
  * Notifies the registered {@link ErrorHandler SAX error handler} (if any) of an input processing
  * error. The error handler can choose to absorb the error and let the processing continue.
  *
  * @param exception <code>JDOMException</code> containing the error information; will be wrapped
  *     in a {@link SAXParseException} when reported to the SAX error handler.
  * @throws JDOMException if no error handler has been registered or if the error handler fired a
  *     {@link SAXException}.
  */
 private void handleError(JDOMException exception) throws JDOMException {
   if (errorHandler != null) {
     try {
       errorHandler.error(new SAXParseException(exception.getMessage(), null, exception));
     } catch (SAXException se) {
       if (se.getException() instanceof JDOMException) {
         throw (JDOMException) (se.getException());
       }
       throw new JDOMException(se.getMessage(), se);
     }
   } else {
     throw exception;
   }
 }
예제 #10
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");

		}

	}
예제 #11
0
  public String getDataTableXML(String xmlStr) {
    String outstr = "";
    Document doc;
    Element rootNode, child;

    ConnectionManager cm = ConnectionManager.getInstance();

    try {
      cm.get();

      Reader reader = new StringReader(xmlStr);
      SAXBuilder ss = new SAXBuilder();
      doc = ss.build(reader);

      rootNode = doc.getRootElement();

      List list = rootNode.getChildren();

      Element childRoot = (Element) list.get(0);

      DBGrid dbGrid = new DBGrid();
      dbGrid.setGridID(childRoot.getAttributeValue("id"));
      dbGrid.setGridType(childRoot.getAttributeValue("gridType"));
      dbGrid.setfieldSQL(childRoot.getAttributeValue("SQLStr"));
      dbGrid.setfieldcn(childRoot.getAttributeValue("fieldCN"));
      dbGrid.setenumType(childRoot.getAttributeValue("enumType"));
      dbGrid.setvisible(childRoot.getAttributeValue("visible"));
      dbGrid.setfieldName(childRoot.getAttributeValue("fieldname"));
      dbGrid.setfieldWidth(childRoot.getAttributeValue("fieldwidth"));
      dbGrid.setfieldType(childRoot.getAttributeValue("fieldtype"));
      dbGrid.setfieldCheck(childRoot.getAttributeValue("fieldCheck"));
      dbGrid.setcountSQL(childRoot.getAttributeValue("countSQL"));

      dbGrid.setpagesize(Integer.parseInt(childRoot.getAttributeValue("pageSize")));
      dbGrid.setAbsolutePage(Integer.parseInt(childRoot.getAttributeValue("AbsolutePage")));
      dbGrid.setRecordCount(Integer.parseInt(childRoot.getAttributeValue("RecordCount")));
      dbGrid.setCheck(childRoot.getAttributeValue("checkbl").toLowerCase().trim().equals("true"));
      dbGrid.setAlign(childRoot.getAttributeValue("tralign"));

      /*
            if (childRoot.getAttributeValue("bottomVisible").toLowerCase().equals("true"))
              dbGrid.setGridBottomVisible(true);
            else
              dbGrid.setGridBottomVisible(false);
      */
      // zr
      if (childRoot.getAttributeValue("bottomVisible").toLowerCase().equals("true")) {
        dbGrid.setGridBottomVisible(true);
        //            dbGrid.setSumfield(childRoot.getAttributeValue("sumfield"));
      } else dbGrid.setGridBottomVisible(false);

      dbGrid.setWhereStr(Basic.decode(childRoot.getAttributeValue("whereStr")));

      outstr = dbGrid.getEditDataTable();
      // System.out.println(outstr);

    } catch (JDOMException ex) {
      System.out.print(ex.getMessage());

    } finally {
      cm.release();
    }
    return outstr;
  }
예제 #12
0
  public String doExcelHou(String xmlStr, WritableWorkbook wwb) {
    String outstr = "";
    Document doc;
    Element rootNode, child;
    // System.out.println(xmlStr);

    try {
      Reader reader = new StringReader(xmlStr);
      SAXBuilder ss = new SAXBuilder();
      doc = ss.build(reader);

      rootNode = doc.getRootElement();

      if (rootNode.getAttributeValue("type").equals("lp")) {
        return getloadspell(rootNode.getText());
      }

      if (rootNode.getAttributeValue("type").equals("lm")) {
        return getLoadName(rootNode.getText());
      }

      List list = rootNode.getChildren();

      Element childRoot = (Element) list.get(0);
      String fieldTitle = childRoot.getAttributeValue("fieldTitle");

      if (rootNode.getAttributeValue("type").equals("enum")) {
        String enumType = childRoot.getAttributeValue("enumType");

        return getEnumType(enumType, fieldTitle);
      }
      if (rootNode.getAttributeValue("type").equals("sql")) {
        String SqlStr = childRoot.getAttributeValue("SqlStr");
        DBTable datatable = new DBTable();
        return datatable.getDropDownStr(SqlStr, fieldTitle);
      }

      if (rootNode.getAttributeValue("type").equals("excel")) {
        String SqlStr = childRoot.getAttributeValue("SQLStr");
        // System.out.println(SqlStr);

        String whereStr = Basic.decode(childRoot.getAttributeValue("whereStr"));
        // System.out.println(whereStr);
        DBTable datatable = new DBTable();
        return datatable.getExcel(SqlStr, whereStr);
      }

      // !
      if (rootNode.getAttributeValue("type").equals("excelhou")) {
        String SqlStr = childRoot.getAttributeValue("SQLStr");
        String fieldCN = childRoot.getAttributeValue("fieldCN");
        String fieldType = childRoot.getAttributeValue("fieldType");
        String fieldWidth = childRoot.getAttributeValue("fieldWidth");
        String visible = childRoot.getAttributeValue("visible");
        String enumType = childRoot.getAttributeValue("enumType");
        String whereStr = Basic.decode(childRoot.getAttributeValue("whereStr"));

        DBTable datatable = new DBTable();
        return datatable.writeExcel_new(
            wwb, SqlStr, whereStr, fieldCN, fieldType, fieldWidth, visible, enumType);
      }
      if (rootNode.getAttributeValue("type").equals("comboBox")) {

        String comboBoxID = childRoot.getAttributeValue("comboBoxID");

        JOption jOption = new JOption(comboBoxID);

        String enumType = childRoot.getAttributeValue("enumType");
        String titleStr = childRoot.getAttributeValue("titleStr");
        String sqlStr = childRoot.getAttributeValue("sqlStr");
        String defaultoption = childRoot.getAttributeValue("defaultOption");

        String titleVisible = childRoot.getAttributeValue("titleVisible");
        String keyVisible = childRoot.getAttributeValue("keyVisible");

        if (defaultoption != null) {
          String[] options = defaultoption.split(",", -2);

          if (options.length == 2) {
            jOption.addOption(options[0], options[1]);
          }
        }
        if (titleVisible.toLowerCase().trim().equals("false")) jOption.setTitleVisible(false);
        if (keyVisible.toLowerCase().trim().equals("false")) jOption.setKeyVisible(false);

        jOption.setEnumType(enumType);
        jOption.setSQlStr(sqlStr);
        jOption.setTitleStr(titleStr);
        return jOption.getDropHtml();
      }

    } catch (JDOMException ex) {
      System.out.print(ex.getMessage());
    }

    return outstr;
  }