Exemplo n.º 1
0
 /** Generates a simple <add><doc>... XML String with no options */
 public String adoc(SolrInputDocument sdoc) {
   List<String> fields = new ArrayList<String>();
   for (SolrInputField sf : sdoc) {
     for (Object o : sf.getValues()) {
       fields.add(sf.getName());
       fields.add(o.toString());
     }
   }
   return adoc(fields.toArray(new String[fields.size()]));
 }
Exemplo n.º 2
0
 /** Return true if all is ok, no errors */
 protected boolean antlr(
     String fileName, String grammarFileName, String grammarStr, boolean debug) {
   boolean allIsWell = true;
   mkdir(tmpdir);
   writeFile(tmpdir, fileName, grammarStr);
   try {
     final List options = new ArrayList();
     if (debug) {
       options.add("-debug");
     }
     options.add("-o");
     options.add(tmpdir);
     options.add("-lib");
     options.add(tmpdir);
     options.add(new File(tmpdir, grammarFileName).toString());
     final String[] optionsA = new String[options.size()];
     options.toArray(optionsA);
     ErrorQueue equeue = new ErrorQueue();
     Tool antlr = newTool(optionsA);
     antlr.addListener(equeue);
     antlr.processGrammarsOnCommandLine();
     if (equeue.errors.size() > 0) {
       allIsWell = false;
       System.err.println("antlr reports errors from " + options);
       for (int i = 0; i < equeue.errors.size(); i++) {
         ANTLRMessage msg = (ANTLRMessage) equeue.errors.get(i);
         System.err.println(msg);
       }
       System.out.println("!!!\ngrammar:");
       System.out.println(grammarStr);
       System.out.println("###");
     }
   } catch (Exception e) {
     allIsWell = false;
     System.err.println("problems building grammar: " + e);
     e.printStackTrace(System.err);
   }
   return allIsWell;
 }