Пример #1
0
  @SuppressWarnings({"unchecked", "resource"})
  private ElementScript getClassName(Node node, String normailzator) {
    String value = XMLUtil.getTextContent(node, ".", true);
    ValueSourceType qsSourceType =
        ValueSourceType.valueOf(XMLUtil.getTextContent(node, "@source", true, "STATIC", true));
    try {
      if (qsSourceType == ValueSourceType.GROOVY_FILE
          || qsSourceType == ValueSourceType.FILE
          || qsSourceType == ValueSourceType.JAVA_CLASS) {
        return new ElementScript(qsSourceType, value);
      } else {
        AppEnv.logger.errorLogEntry(
            "Included script did not implemented, form rule="
                + parentRule.getID()
                + ", node="
                + node.getBaseURI());
      }

    } catch (MultipleCompilationErrorsException e) {
      AppEnv.logger.errorLogEntry(
          "Script compilation error at form rule compiling="
              + parentRule.getID()
              + ", node="
              + node.getBaseURI());
      AppEnv.logger.errorLogEntry(e.getMessage());
    }
    return null;
  }
Пример #2
0
  protected Rule(AppEnv env, File docFile) throws RuleException {
    try {
      this.env = env;
      DocumentBuilderFactory pageFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder pageBuilder = pageFactory.newDocumentBuilder();
      Document xmlFileDoc = pageBuilder.parse(docFile.toString());
      doc = xmlFileDoc;
      filePath = docFile.getAbsolutePath();
      parentDirPath = docFile.getParentFile().getAbsolutePath();
      scriptDirPath =
          "rule"
              + File.separator
              + env.appName
              + File.separator
              + "Resources"
              + File.separator
              + "scripts";
      id = XMLUtil.getTextContent(doc, "/rule/@id", true);
      if (id.equals("")) {
        id = FilenameUtils.removeExtension(docFile.getName());
      }
      AppEnv.logger.debugLogEntry("Load rule: " + this.getClass().getSimpleName() + ", id=" + id);
      if (XMLUtil.getTextContent(doc, "/rule/@mode").equalsIgnoreCase("off")) {
        isOn = RunMode.OFF;
        isValid = false;
      }

      if (XMLUtil.getTextContent(doc, "/rule/@anonymous").equalsIgnoreCase("on")) {
        allowAnonymousAccess = true;
      }

      if (XMLUtil.getTextContent(doc, "/rule/@security").equalsIgnoreCase("on")) {
        isSecured = true;
      }

      description = XMLUtil.getTextContent(doc, "/rule/description");

      NodeList captionList = XMLUtil.getNodeList(doc, "/rule/caption");
      for (int i = 0; i < captionList.getLength(); i++) {
        Caption c = new Caption(captionList.item(i));
        if (c.isOn == RunMode.ON) {
          captions.add(c);
        }
      }

    } catch (SAXParseException spe) {
      AppEnv.logger.errorLogEntry("XML-file structure error (" + docFile.getAbsolutePath() + ")");
      AppEnv.logger.errorLogEntry(spe);
    } catch (FileNotFoundException e) {
      throw new RuleException("Rule \"" + docFile.getAbsolutePath() + "\" has not found");
    } catch (ParserConfigurationException e) {
      AppEnv.logger.errorLogEntry(e);
    } catch (IOException e) {
      AppEnv.logger.errorLogEntry(e);
    } catch (SAXException se) {
      AppEnv.logger.errorLogEntry(se);
    }
  }
Пример #3
0
  public ElementRule(Node node, IElement parent) {
    parentRule = parent;
    try {
      name = XMLUtil.getTextContent(node, "name", false);
      if (!name.equals("")) {
        hasElementName = true;
      }
      String mode = XMLUtil.getTextContent(node, "@mode", false);
      if (mode.equalsIgnoreCase("off")) {
        isOn = RunMode.OFF;
        return;
      }

      type = ElementType.valueOf(XMLUtil.getTextContent(node, "@type", true, "UNKNOWN", false));
      switch (type) {
        case SCRIPT:
          Node qoNode = XMLUtil.getNode(node, "events/doscript", false);
          doClassName = getClassName(qoNode, "doscript");
          if (doClassName == null) {
            isValid = false;
          }

          break;

        case INCLUDED_PAGE:
          value = XMLUtil.getTextContent(node, "value", false);
          break;

        default:
          break;
      }

    } catch (Exception e) {
      AppEnv.logger.errorLogEntry(e);
      isValid = false;
    }
  }
Пример #4
0
  private void message(String text, HttpServletResponse response, PublishAsType publishAs) {
    ServletOutputStream out;
    String xmlText;
    Server.logger.errorLogEntry(text);
    try {

      xmlText =
          "<?xml version = \"1.0\" encoding=\"utf-8\"?><request><error type=\""
              + type
              + "\">"
              + "<message><version>"
              + Server.serverVersion
              + "</version><errortext>"
              + XMLUtil.getAsTagValue(text)
              + "</errortext></message></error></request>";
      //		System.out.println("xml text = "+xmlText);
      response.setHeader(
          "Cache-Control", "no-cache, must-revalidate, private, no-store, s-maxage=0, max-age=0");
      response.setHeader("Pragma", "no-cache");
      response.setDateHeader("Expires", 0);

      if (publishAs == PublishAsType.HTML) {
        response.setContentType("text/html;charset=utf-8");
        out = response.getOutputStream();
        Source xmlSource = new StreamSource(new StringReader(xmlText));
        Result result = new StreamResult(out);
        TransformerFactory transFact = TransformerFactory.newInstance();
        Transformer trans = transFact.newTransformer(xsltSource);
        // System.out.println(PortalEnv.appID+": xsl transformation="+PortalEnv.errorXSL);
        trans.transform(xmlSource, result);
      } else {
        response.setContentType("text/xml;charset=utf-8");
        // response.sendError(550);
        out = response.getOutputStream();
        out.println(xmlText);
      }
    } catch (IOException ioe) {
      System.out.println(ioe);
      ioe.printStackTrace();
    } catch (TransformerConfigurationException tce) {
      System.out.println(tce);
      tce.printStackTrace();
    } catch (TransformerException te) {
      System.out.println(te);
      te.printStackTrace();
    }
  }