示例#1
0
  public Struct validate(InputSource xml) throws PageException {
    CFMLEngine engine = CFMLEngineFactory.getInstance();
    warnings = engine.getCreationUtil().createArray();
    errors = engine.getCreationUtil().createArray();
    fatals = engine.getCreationUtil().createArray();

    try {
      XMLReader parser = new XMLUtilImpl().createXMLReader("org.apache.xerces.parsers.SAXParser");
      parser.setContentHandler(this);
      parser.setErrorHandler(this);
      parser.setEntityResolver(this);
      parser.setFeature("http://xml.org/sax/features/validation", true);
      parser.setFeature("http://apache.org/xml/features/validation/schema", true);
      parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
      // if(!validateNamespace)
      if (!Util.isEmpty(strSchema))
        parser.setProperty(
            "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
            strSchema);
      parser.parse(xml);
    } catch (SAXException e) {
    } catch (IOException e) {
      throw engine.getExceptionUtil().createXMLException(e.getMessage());
    }

    // result
    Struct result = engine.getCreationUtil().createStruct();
    result.setEL("warnings", warnings);
    result.setEL("errors", errors);
    result.setEL("fatalerrors", fatals);
    result.setEL("status", engine.getCastUtil().toBoolean(!hasErrors));
    release();
    return result;
  }
  @Override
  public final Query getCollectionsAsQuery() {
    final String v = "VARCHAR";
    Query query = null;
    String[] cols =
        new String[] {
          "external",
          "language",
          "mapped",
          "name",
          "online",
          "path",
          "registered",
          "lastmodified",
          "categories",
          "charset",
          "created",
          "size",
          "doccount"
        };
    String[] types =
        new String[] {
          "BOOLEAN", v, "BOOLEAN", v, "BOOLEAN", v, v, "DATE", "BOOLEAN", v, "OBJECT", "DOUBLE",
          "DOUBLE"
        };
    try {
      query = engine.getCreationUtil().createQuery(cols, types, collections.size(), "query");
    } catch (PageException e) {
      query = engine.getCreationUtil().createQuery(cols, collections.size(), "query");
    }

    // Collection.Key[] keys = collections.keys();
    Iterator<Object> it = collections.valueIterator();
    int i = -1;
    while (it.hasNext()) {
      i++;
      try {
        SearchCollection coll = (SearchCollection) it.next();
        query.setAt("external", i + 1, Boolean.FALSE);
        query.setAt("charset", i + 1, "UTF-8");
        query.setAt("created", i + 1, coll.created());

        query.setAt("categories", i + 1, Boolean.TRUE);
        query.setAt("language", i + 1, coll.getLanguage());
        query.setAt("mapped", i + 1, Boolean.FALSE);
        query.setAt("name", i + 1, coll.getName());
        query.setAt("online", i + 1, Boolean.TRUE);
        query.setAt("path", i + 1, coll.getPath().getAbsolutePath());
        query.setAt("registered", i + 1, "CF");
        query.setAt("lastmodified", i + 1, coll.getLastUpdate());
        query.setAt("size", i + 1, new Double(coll.getSize()));
        query.setAt("doccount", i + 1, new Double(coll.getDocumentCount()));
      } catch (PageException pe) {
      }
    }
    return query;
  }
  /**
   * read in a single collection element
   *
   * @param config
   * @param el
   * @throws SearchException
   */
  private final void readCollection(Config config, Element el) throws SearchException {
    SearchCollection sc;
    // try {
    // Collection
    DateTime last =
        engine
            .getCastUtil()
            .toDateTime(el.getAttribute("lastUpdate"), engine.getThreadTimeZone(), null);
    if (last == null) last = engine.getCreationUtil().now();
    DateTime cre =
        engine
            .getCastUtil()
            .toDateTime(el.getAttribute("created"), engine.getThreadTimeZone(), null);
    if (cre == null) cre = engine.getCreationUtil().now();
    ResourceProvider frp = engine.getResourceUtil().getFileResourceProvider();
    sc =
        _readCollection(
            el.getAttribute("name"),
            frp.getResource(el.getAttribute("path")),
            el.getAttribute("language"),
            last,
            cre);
    collections.setEL((sc.getName()), sc);

    // Indexes
    NodeList children = el.getChildNodes();
    int len = children.getLength();
    for (int i = 0; i < len; i++) {
      Node n = children.item(i);
      if (n instanceof Element && n.getNodeName().equals("index")) {
        readIndex(sc, (Element) n);
      }
    }
    /*}
    catch (PageException e) {
        throw new SearchException(e);
    }*/
  }
示例#4
0
  @Override
  public void init(GatewayEngine engine, String id, String cfcPath, Map config)
      throws GatewayException {
    this.engine = engine;
    cfmlEngine = CFMLEngineFactory.getInstance();
    caster = cfmlEngine.getCastUtil();
    creator = cfmlEngine.getCreationUtil();
    this.cfcPath = cfcPath;
    this.id = id;

    // config
    Object oPort = config.get("port");
    port = caster.toIntValue(oPort, 1225);

    Object oWM = config.get("welcomeMessage");
    String strWM = caster.toString(oWM, "").trim();
    if (strWM.length() > 0) welcomeMessage = strWM;
  }
 public SearchEngineSupport() {
   engine = CFMLEngineFactory.getInstance();
   collections = engine.getCreationUtil().createStruct();
 }