@Override
 protected void details(IndentedWriter out, SerializationContext sCxt) {
   out.println(Utils.className(this));
   out.incIndent();
   op.output(out, sCxt);
   out.decIndent();
 }
 private static void printBase(Prologue prologue, IndentedWriter out) {
   if (prologue.getBaseURI() != null && prologue.explicitlySetBaseURI()) {
     out.print("BASE    ");
     out.print("<" + prologue.getBaseURI() + ">");
     out.newline();
   }
 }
    private void visitDropClear(String name, UpdateDropClear update) {
      out.ensureStartOfLine();
      out.print(name);
      out.print(" ");
      if (update.isSilent()) out.print("SILENT ");

      printTarget(update.getTarget());
    }
 public static void outputPlain(IndentedWriter out, Triple triple, SerializationContext naming) {
   // No tag
   output(out, triple.getSubject(), naming);
   out.print(" ");
   output(out, triple.getPredicate(), naming);
   out.print(" ");
   output(out, triple.getObject(), naming);
 }
 private void printUpdate2(UpdateBinaryOp update, String name) {
   out.print(name);
   if (update.getSilent()) out.print(" SILENT");
   out.print(" ");
   printTargetUpdate2(update.getSrc());
   out.print(" TO ");
   printTargetUpdate2(update.getDest());
 }
    public void visit(UpdateCreate update) {
      out.ensureStartOfLine();
      out.print("CREATE");
      out.print(" ");
      if (update.isSilent()) out.print("SILENT ");

      String s = FmtUtils.stringForNode(update.getGraph(), sCxt);
      out.print(s);
    }
 private void outputQuadsBraced(List<Quad> quads) {
   if (quads.size() == 0) {
     out.print("{ }");
     return;
   }
   out.println("{");
   outputQuads(quads);
   out.print("}");
 }
 public static void outputPlain(IndentedWriter out, Quad qp, SerializationContext naming) {
   output(out, qp.getGraph(), naming);
   out.print(" ");
   output(out, qp.getSubject(), naming);
   out.print(" ");
   output(out, qp.getPredicate(), naming);
   out.print(" ");
   output(out, qp.getObject(), naming);
 }
 public static void output(IndentedWriter out, List<Node> nodeList, SerializationContext naming) {
   out.print("(");
   boolean first = true;
   for (Node node : nodeList) {
     if (!first) out.print(" ");
     out.print(FmtUtils.stringForNode(node, naming));
     first = false;
   }
   out.print(")");
 }
    private void outputTripleOfQuad(Quad quad) {
      String s = FmtUtils.stringForNode(quad.getSubject(), sCxt);
      String p = FmtUtils.stringForNode(quad.getPredicate(), sCxt);
      String o = FmtUtils.stringForNode(quad.getObject(), sCxt);

      out.print(s);
      out.print(" ");
      out.print(p);
      out.print(" ");
      out.print(o);
    }
    private void outputQuad(Quad quad) {
      String qs = FmtUtils.stringForQuad(quad, sCxt.getPrefixMapping());

      if (quad.getGraph() != null) {
        String g = FmtUtils.stringForNode(quad.getGraph(), sCxt);
        out.print(g);
        out.print(" ");
      }
      outputTripleOfQuad(quad);
      out.println(" .");
    }
 private void printTargetUpdate2(Target target) {
   if (target.isDefault()) {
     out.print("DEFAULT");
   } else if (target.isOneNamedGraph()) {
     // out.print("GRAPH ") ;
     String s = FmtUtils.stringForNode(target.getGraph(), sCxt);
     out.print(s);
   } else {
     out.print("Target BROKEN / Update2");
     throw new ARQException("Malformed Target / Update2");
   }
 }
    public void visit(UpdateLoad update) {
      out.ensureStartOfLine();
      out.print("LOAD");
      out.print(" ");
      if (update.getSilent()) out.print("SILENT ");

      outputStringAsURI(update.getSource());

      if (update.getDest() != null) {
        out.print(" INTO GRAPH ");
        output(update.getDest());
      }
    }
  // Do better
  @Override
  public void output(IndentedWriter out, SerializationContext sCxt) {
    // Linear form.
    getInput().output(out, sCxt);
    out.ensureStartOfLine();
    details(out, sCxt);
    out.ensureStartOfLine();

    //        details(out, sCxt) ;
    //        out.ensureStartOfLine() ;
    //        out.incIndent() ;
    //        getInput().output(out, sCxt) ;
    //        out.decIndent() ;
    //        out.ensureStartOfLine() ;
  }
 public static void output(Update update, IndentedWriter out, SerializationContext sCxt) {
   if (sCxt == null) sCxt = new SerializationContext();
   prologue(out, sCxt.getPrologue());
   outputUpdate(update, out, sCxt);
   // Update operations do not end in newline.
   out.flush();
 }
  public static void printPrefixes(Prologue prologue, IndentedWriter out) {
    if (prologue.getPrefixMapping() == null) return;

    Map<String, String> pmap = null;

    if (prologue.getPrefixMapping() instanceof PrefixMapping2) {
      PrefixMapping2 pm2 = (PrefixMapping2) prologue.getPrefixMapping();
      pmap = pm2.getNsPrefixMap(false);
    } else {
      Map<String, String> _pmap = prologue.getPrefixMapping().getNsPrefixMap();
      pmap = _pmap;
    }

    if (pmap.size() > 0) {
      // boolean first = true ;
      for (String k : pmap.keySet()) {
        String v = pmap.get(k);
        out.print("PREFIX  ");
        out.print(k);
        out.print(':');
        out.print(' ', 4 - k.length());
        // Include at least one space
        out.print(' ');
        out.print(FmtUtils.stringForURI(v));
        out.newline();
      }
    }
  }
  public static void output(UpdateRequest request, IndentedWriter out, SerializationContext sCxt) {
    if (sCxt == null) sCxt = new SerializationContext(request);
    prologue(out, sCxt.getPrologue());
    boolean addSeparator = (request.getOperations().size() > 1);
    boolean first = true;

    for (Update update : request.getOperations()) {
      out.ensureStartOfLine();
      if (!first) out.println();
      first = false;
      outputUpdate(update, out, sCxt);
      if (addSeparator) out.print(" ;");
    }

    // Update requests always end in newline.
    out.ensureStartOfLine();
    out.flush();
  }
    private void outputQuads(List<Quad> quads) {
      out.incIndent(BLOCK_INDENT);
      Node g = Quad.tripleInQuad;
      boolean inBlock = false;
      for (Quad q : quads) {
        if (q.getGraph() != g) {
          // New graph (default or named)
          if (inBlock) {
            // In named - end it.
            out.decIndent(BLOCK_INDENT);
            out.println("}");
            inBlock = false;
          }

          g = q.getGraph();

          // Start new block.
          // Two cases for no braces:
          // Quad.tripleInQuad and Quad.defaultGraphNodeGenerated ;
          if (!q.isTriple() && !q.isDefaultGraphGenerated()) {
            out.print("GRAPH ");
            output(g);
            out.println(" {");
            out.incIndent(BLOCK_INDENT);
            inBlock = true;
          }
        }

        outputTripleOfQuad(q);
        out.println(" .");
      }

      if (inBlock) {
        out.decIndent(BLOCK_INDENT);
        out.println("}");
        inBlock = false;
      }
      out.decIndent(BLOCK_INDENT);
    }
 public void printSSE(PrintStream ps) {
   IndentedWriter out = new IndentedWriter(ps);
   out.println("(stats");
   out.incIndent();
   for (Pattern p : patterns) {
     p.output(out);
     out.println();
   }
   out.decIndent();
   out.println(")");
   out.flush();
 }
 private void printTarget(Target target) {
   if (target.isAll()) {
     out.print("ALL");
   } else if (target.isAllNamed()) {
     out.print("NAMED");
   } else if (target.isDefault()) {
     out.print("DEFAULT");
   } else if (target.isOneNamedGraph()) {
     out.print("GRAPH ");
     String s = FmtUtils.stringForNode(target.getGraph(), sCxt);
     out.print(s);
   } else {
     out.print("Target BROKEN");
     throw new ARQException("Malformed Target");
   }
 }
 protected void details(IndentedWriter out, SerializationContext sCxt) {
   out.println(Utils.className(this));
 }
 public void apply(Printable item) {
   if (!first && sep != null) out.print(sep);
   first = false;
   item.output(out);
 }
Beispiel #23
0
 public static void output(IndentedWriter out, Node node, SerializationContext naming) {
   out.print(FmtUtils.stringForNode(node, naming));
 }
 private void outputStringAsURI(String uriStr) {
   String x = FmtUtils.stringForURI(uriStr, sCxt);
   out.print(x);
 }
 public void visit(UpdateDataInsert update) {
   out.ensureStartOfLine();
   out.print("INSERT DATA ");
   outputQuadsBraced(update.getQuads());
 }
 private static void prologue(IndentedWriter out, Prologue prologue) {
   int row1 = out.getRow();
   PrologueSerializer.output(out, prologue);
   int row2 = out.getRow();
   if (row1 != row2) out.newline();
 }
 public void visit(UpdateDataDelete update) {
   out.ensureStartOfLine();
   out.print("DELETE DATA ");
   outputQuadsBraced(update.getQuads());
 }
 private void output(Node node) {
   String $ = FmtUtils.stringForNode(node, sCxt);
   out.print($);
 }
    public void visit(UpdateModify update) {
      out.ensureStartOfLine();
      if (update.getWithIRI() != null) {
        // out.ensureStartOfLine() ;
        out.print("WITH ");
        output(update.getWithIRI());
      }

      if (update.hasDeleteClause()) {
        List<Quad> deleteQuads = update.getDeleteQuads();
        out.ensureStartOfLine();
        out.print("DELETE ");
        outputQuadsBraced(deleteQuads);
      }

      if (update.hasInsertClause()) {
        List<Quad> insertQuads = update.getInsertQuads();
        out.ensureStartOfLine();
        out.print("INSERT ");
        outputQuadsBraced(insertQuads);
      }

      if (!update.hasInsertClause() && !update.hasDeleteClause()) {
        // Fake a clause to make it legal syntax.
        out.ensureStartOfLine();
        out.println("INSERT { }");
      }

      for (Node x : update.getUsing()) {
        out.ensureStartOfLine();
        out.print("USING ");
        output(x);
      }

      for (Node x : update.getUsingNamed()) {
        out.ensureStartOfLine();
        out.print("USING NAMED ");
        output(x);
      }

      Element el = update.getWherePattern();
      out.ensureStartOfLine();
      out.print("WHERE");
      out.incIndent(BLOCK_INDENT);
      out.newline();

      if (el != null) {
        FormatterElement fmtElement = new FormatterElement(out, sCxt);
        fmtElement.visitAsGroup(el);
      } else out.print("{}");
      out.decIndent(BLOCK_INDENT);
    }
 public void visit(UpdateDeleteWhere update) {
   out.ensureStartOfLine();
   out.println("DELETE WHERE ");
   outputQuadsBraced(update.getQuads());
 }