@Override
 public void endNonterminal(String name, int end) {
   try {
     builder.closeElem();
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
 @Override
 public void startNonterminal(String name, int begin) {
   try {
     builder.openElem(Token.token(name), atts, nsp);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
示例#3
0
  @Override
  public void prepare() throws QueryException {
    // build data with all documents, to prevent dirty reads
    md = new MemData(data);
    for (final Item d : docs) {
      final MemData docData;
      if (d.node()) {
        // adding a document node
        final ANode doc = (ANode) d;
        if (doc.ndType() != NodeType.DOC) UPDOCTYPE.thrw(input, doc);
        docData = new MemData(data);
        new DataBuilder(docData).build(doc);
      } else if (d.str()) {
        // adding file(s) from a path
        final String docpath = string(d.atom(input));
        final String nm = ctx.mprop.random(data.meta.name);
        final DirParser p = new DirParser(IO.get(docpath), ctx.prop);
        final MemBuilder b = new MemBuilder(nm, p, ctx.prop);
        try {
          docData = b.build();
        } catch (final IOException e) {
          throw DOCERR.thrw(input, docpath);
        }
      } else {
        throw STRNODTYPE.thrw(input, this, d.type);
      }
      md.insert(md.meta.size, -1, docData);
    }

    // set new names, if needed
    final IntList pres = md.doc();
    if (pres.size() == 1 && name != null) {
      // name is specified and a single document is added: set the name
      final byte[] nm = path == null ? name : concat(path, SLASH, name);
      md.update(pres.get(0), Data.DOC, nm);
    } else if (path != null) {
      // path is specified: replace the path of each new document
      for (int i = 0, is = pres.size(); i < is; i++) {
        final int d = pres.get(i);
        final byte[] old = md.text(d, true);
        final int p = lastIndexOf(old, '/');
        final byte[] nm = p < 0 ? old : subtoken(old, p + 1);
        md.update(d, Data.DOC, concat(path, SLASH, nm));
      }
    }
  }
示例#4
0
 @Override
 public Document parse(final InputSource is) throws IOException {
   final String id = is.getSystemId();
   final SAXSource ss = new SAXSource(parser, is);
   final SAXWrapper sw = new SAXWrapper(ss, ctx.prop);
   final Data data = MemBuilder.build(id == null ? "" : id, sw);
   return new BXDoc(new DBNode(data));
 }
 public ANode call(Str str) throws IOException {
   String input = str.toJava();
   SingleParser singleParser =
       new SingleParser(new IOContent(""), MainOptions.get()) {
         @Override
         protected void parse() throws IOException {}
       };
   MemBuilder memBuilder = new MemBuilder(input, singleParser);
   memBuilder.init();
   BaseXTreeBuilder treeBuilder = new BaseXTreeBuilder(memBuilder);
   Parse_XQDocComments parser = new Parse_XQDocComments();
   parser.initialize(input, treeBuilder);
   try {
     execute(parser);
   } catch (ParseException pe) {
     memBuilder = new MemBuilder(input, singleParser);
     memBuilder.init();
     Atts atts = new Atts();
     atts.add(Token.token("b"), Token.token(pe.getBegin() + 1));
     atts.add(Token.token("e"), Token.token(pe.getEnd() + 1));
     if (pe.getOffending() < 0) {
       atts.add(Token.token("s"), Token.token(pe.getState()));
     } else {
       atts.add(Token.token("o"), Token.token(pe.getOffending()));
       atts.add(Token.token("x"), Token.token(pe.getExpected()));
     }
     memBuilder.openElem(Token.token("ERROR"), atts, new Atts());
     memBuilder.text(Token.token(parser.getErrorMessage(pe)));
     memBuilder.closeElem();
   }
   return new DBNode(memBuilder.data());
 }
 private void characters(int begin, int end) {
   if (begin < end) {
     try {
       builder.text(Token.token(input.subSequence(begin, end).toString()));
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
 }
示例#7
0
文件: Geo.java 项目: runeengh/basex
  /**
   * Writes an geometry and returns a string representation of the geometry.
   *
   * @param geometry geometry
   * @return DBNode database node
   * @throws QueryException exception
   */
  private DBNode gmlWriter(final Geometry geometry) throws QueryException {
    final String geo;
    try {
      // write geometry and add namespace declaration
      geo =
          new GMLWriter()
              .write(geometry)
              .replaceAll("^<gml:(.*?)>", "<gml:$1 xmlns:gml='" + string(URI) + "'>");
    } catch (final Exception ex) {
      throw GeoErrors.gmlWriterErr(ex);
    }

    try {
      final IO io = new IOContent(geo);
      return new DBNode(MemBuilder.build(new XMLParser(io, queryContext.context.options)));
    } catch (final IOException ex) {
      throw IOERR_X.get(null, ex);
    }
  }