Package org.exist.atom.modules

Examples of org.exist.atom.modules.Query


                      + ex.getMessage(), ex);
            }

          } else {
            // no class means query
            final Query query = new Query();
            modules.put(name, query);

            final String allowQueryPost = moduleConf.getAttribute("query-by-post");
            if ("true".equals(allowQueryPost)) {
              query.setQueryByPost(true);
            }

            final NodeList methodList = moduleConf.getElementsByTagNameNS(CONF_NS, "method");

            for (int m = 0; m < methodList.getLength(); m++) {
              final Element methodConf = (Element) methodList.item(m);
              final String type = methodConf.getAttribute("type");
              if (type == null) {
                getLog().warn(
                    "No type specified for method in module "
                        + name);
                continue;
              }

              // What I want but can't have because of JDK 1.4
              // URI baseURI =
              // URI.create(methodConf.getBaseURI());
              final URI baseURI = docBaseURI;
              final String queryRef = methodConf.getAttribute("query");
              if (queryRef == null) {
                getLog().warn(
                    "No query specified for method " + type
                        + " in module " + name);
                continue;
              }

              final boolean fromClasspath = "true".equals(methodConf.getAttribute("from-classpath"));
              final Query.MethodConfiguration mconf = query
                  .getMethodConfiguration(type);
              if (mconf == null) {
                getLog().warn(
                    "Unknown method " + type
                        + " in module " + name);
                continue;
              }

              final String responseContentType = methodConf.getAttribute("content-type");
              if (responseContentType != null
                  && responseContentType.trim().length() != 0) {
                mconf.setContentType(responseContentType);
              }

              URL queryURI = null;
              if (fromClasspath) {
                getLog().debug(
                    "Nope. Attempting to get resource "
                        + queryRef + " from "
                        + Atom.class.getName());
                queryURI = Atom.class.getResource(queryRef);

              } else {
                queryURI = baseURI.resolve(queryRef).toURL();
              }

              getLog().debug(
                  "Loading from module " + name + " method "
                      + type + " from resource "
                      + queryURI + " via classpath("
                      + fromClasspath + ") and ref ("
                      + queryRef + ")");

              if (queryURI == null) {
                throw new ServletException(
                    "Cannot find resource " + queryRef
                        + " for module " + name);
              }
              mconf.setQuerySource(queryURI);
            }
            query.init(new ModuleContext(config, name, atomConf
                .getParent()));

          }
        }

      } catch (final IOException e) {
        getLog().warn(e);
        throw new ServletException(e.getMessage());
      } catch (final SAXException e) {
        getLog().warn(e);
        throw new ServletException(e.getMessage());
      } catch (final ParserConfigurationException e) {
        getLog().warn(e);
        throw new ServletException(e.getMessage());
      } catch (final EXistException e) {
        getLog().warn(e);
        throw new ServletException(e.getMessage());
      } finally {
        if (is != null) {
          try {
            is.close();
          } catch (final IOException ex) {
          }
        }
      }

    } else {
      try {
        final AtomProtocol protocol = new AtomProtocol();
        modules.put("edit", protocol);
        protocol.init(new ModuleContext(config, "edit", dbHome.getAbsolutePath()));

        final AtomFeeds feeds = new AtomFeeds();
        modules.put("content", feeds);
        feeds.init(new ModuleContext(config, "content", dbHome.getAbsolutePath()));

        final Query query = new Query();
        query.setQueryByPost(true);
        modules.put("query", query);
        query.init(new ModuleContext(config, "query", dbHome.getAbsolutePath()));

        final Query topics = new Query();
        modules.put("topic", topics);
        topics.getMethodConfiguration("GET").setQuerySource(
            topics.getClass().getResource("topic.xq"));
        topics.init(new ModuleContext(config, "topic", dbHome.getAbsolutePath()));

        final Query introspect = new Query();
        modules.put("introspect", introspect);
        introspect.getMethodConfiguration("GET").setQuerySource(
            introspect.getClass().getResource("introspect.xq"));
        introspect.init(new ModuleContext(config, "introspect", dbHome.getAbsolutePath()));

      } catch (final EXistException ex) {
        throw new ServletException("Exception during module init(): "
            + ex.getMessage(), ex);
      }
View Full Code Here

TOP

Related Classes of org.exist.atom.modules.Query

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.