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());
    }
  }
Exemple #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;
  }
Exemple #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());
    }
  }
Exemple #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());
   }
 }
 /**
  * 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;
   }
 }
Exemple #6
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);
  }
Exemple #7
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;
  }
Exemple #8
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;
  }