// If there is a <title> element on the start page, use that as our AU
 // name.
 String recomputeRegName() {
   if (!isStarted()) {
     // This can get invoked (seveeral times, mostly from logging) before
     // enough mechanism has started to make it possible to resolve the CuUrl
     // below.
     return null;
   }
   try {
     CachedUrl cu = makeCachedUrl(m_registryUrl);
     if (cu == null) return null;
     URL cuUrl = CuUrl.fromCu(cu);
     Parser parser = new Parser(cuUrl.toString());
     NodeList nodelst = parser.extractAllNodesThatMatch(new NodeClassFilter(TitleTag.class));
     Node nodes[] = nodelst.toNodeArray();
     recomputeRegName = false;
     if (nodes.length < 1) return null;
     // Get the first title found
     TitleTag tag = (TitleTag) nodes[0];
     if (tag == null) return null;
     return tag.getTitle();
   } catch (MalformedURLException e) {
     log.warning("recomputeRegName", e);
     return null;
   } catch (ParserException e) {
     if (e.getThrowable() instanceof FileNotFoundException) {
       log.warning("recomputeRegName: " + e.getThrowable().toString());
     } else {
       log.warning("recomputeRegName", e);
     }
     return null;
   }
 }
Example #2
0
 @Test
 public void testTapParserException4() {
   exception = new ParserException("Null", new NullPointerException()); // NOPMD
   assertNotNull(exception);
   assertEquals(exception.getMessage(), "Null");
   assertTrue(exception.getCause() instanceof NullPointerException);
 }
 @NotNull
 @Override
 public Pair<R, State> parse(@NotNull List<Token<T>> tokens, @NotNull State state)
     throws ParserException {
   try {
     return myFirst.parse(tokens, state);
   } catch (ParserException e) {
     return mySecond.parse(tokens, new State(state, state.getPos(), e.getState().getMax()));
   }
 }
  /**
   * Returns a table listing the output parameters of this algorithm (usually just labels used to
   * obtain output image names later).
   *
   * @return A parameter table listing the outputs of this algorithm.
   */
  public ParameterTable createOutputParameters() {
    final ParameterTable table = new ParameterTable();

    try {
      table.put(new ParameterImage(AlgorithmParameters.RESULT_IMAGE));
    } catch (final ParserException e) {
      // this shouldn't really happen since there isn't any real parsing going on...
      e.printStackTrace();
    }

    return table;
  }
  /**
   * Returns a table listing the input parameters of this algorithm (which should match up with the
   * scripting parameters used in {@link #setGUIFromParams()}).
   *
   * @return A parameter table listing the inputs of this algorithm.
   */
  public ParameterTable createInputParameters() {
    final ParameterTable table = new ParameterTable();

    try {

      table.put(new ParameterExternalImage(AlgorithmParameters.getInputImageLabel(1)));
      table.put(new ParameterBoolean(AlgorithmParameters.DO_OUTPUT_NEW_IMAGE, true));
    } catch (final ParserException e) {
      // this shouldn't really happen since there isn't any real parsing going on...
      e.printStackTrace();
    }

    return table;
  }
Example #6
0
 public static void work(BufferedReader ir) {
   TestParser testParser = new TestParser();
   try {
     PushbackReader r = new PushbackReader(ir, 1024);
     Parser parser = new Parser(new Lexer(r));
     Node syntaxTree = parser.parse();
     syntaxTree.apply(testParser);
   } catch (LexerException e) {
     System.out.println(e.getMessage() + ".");
   } catch (ParserException e) {
     System.out.println(e.getMessage() + ".");
   } catch (IOException e) {
     System.out.println(e.getMessage() + ".");
     System.exit(1);
   }
 }
 @NotNull
 @Override
 public Pair<List<R>, State> parse(@NotNull List<Token<T>> tokens, @NotNull State state)
     throws ParserException {
   final List<R> list = new ArrayList<R>();
   try {
     //noinspection InfiniteLoopStatement
     while (true) {
       final Pair<R, State> result = myParser.parse(tokens, state);
       state = result.getSecond();
       list.add(result.getFirst());
     }
   } catch (ParserException e) {
     return Pair.create(list, new State(state, state.getPos(), e.getState().getMax()));
   }
 }
    @Override
    public void run() {
      final Collection<cgCache> caches;
      try {
        caches = doImport();

        importStepHandler.sendMessage(
            importStepHandler.obtainMessage(
                IMPORT_STEP_STORE_CACHES, R.string.gpx_import_storing, caches.size()));
        cgSearch search = storeParsedCaches(caches);
        Log.i(Settings.tag, "Imported successfully " + caches.size() + " caches.");

        importStepHandler.sendMessage(
            importStepHandler.obtainMessage(
                IMPORT_STEP_FINISHED, cgeoapplication.getCount(search), 0, search));
      } catch (IOException e) {
        Log.i(Settings.tag, "Importing caches failed - error reading data: " + e.getMessage());
        importStepHandler.sendMessage(
            importStepHandler.obtainMessage(
                IMPORT_STEP_FINISHED_WITH_ERROR,
                R.string.gpx_import_error_io,
                0,
                e.getLocalizedMessage()));
      } catch (ParserException e) {
        Log.i(Settings.tag, "Importing caches failed - data format error" + e.getMessage());
        importStepHandler.sendMessage(
            importStepHandler.obtainMessage(
                IMPORT_STEP_FINISHED_WITH_ERROR,
                R.string.gpx_import_error_parser,
                0,
                e.getLocalizedMessage()));
      } catch (CancellationException e) {
        Log.i(Settings.tag, "Importing caches canceled");
        importStepHandler.sendMessage(importStepHandler.obtainMessage(IMPORT_STEP_CANCELED));
      } catch (Exception e) {
        Log.e(Settings.tag, "Importing caches failed - unknown error: ", e);
        importStepHandler.sendMessage(
            importStepHandler.obtainMessage(
                IMPORT_STEP_FINISHED_WITH_ERROR,
                R.string.gpx_import_error_unexpected,
                0,
                e.getLocalizedMessage()));
      }
    }
  /**
   * Returns a table listing the input parameters of this algorithm (which should match up with the
   * scripting parameters used in {@link #setGUIFromParams()}).
   *
   * @return A parameter table listing the inputs of this algorithm.
   */
  public ParameterTable createInputParameters() {
    final ParameterTable table = new ParameterTable();

    try {
      table.put(new ParameterExternalImage(AlgorithmParameters.getInputImageLabel(1)));
      table.put(new ParameterBoolean(AlgorithmParameters.DO_OUTPUT_NEW_IMAGE, true));
      table.put(new ParameterBoolean(AlgorithmParameters.DO_PROCESS_WHOLE_IMAGE, true));
      table.put(new ParameterBoolean(AlgorithmParameters.DO_PROCESS_3D_AS_25D, false));
      table.put(new ParameterInt("search_window_side", 15));
      table.put(new ParameterInt("similarity_window_side", 7));
      table.put(new ParameterFloat("noise_standard_deviation", 10f));
      table.put(new ParameterFloat("degree_of_filtering", 1.414f));
      table.put(new ParameterBoolean("do_rician", false));
    } catch (final ParserException e) {
      // this shouldn't really happen since there isn't any real parsing going on...
      e.printStackTrace();
    }

    return table;
  }
Example #10
0
 // private utility method to create exception
 private ParserException createException(Message message, Object... params) {
   final String description = message.getText(params);
   return ParserException.create(description, this.line);
 }
Example #11
0
  // 获取一个网站上的链接,filter 用来过滤链接
  public static Set<String> extracLinks(String url, NodeFilter filter) {
    Set<String> links = new HashSet<String>();
    try {
      Parser parser = new Parser(url);
      parser.setEncoding("UTF-8");

      @SuppressWarnings("serial")
      NodeFilter frameFilter =
          new NodeFilter() {
            public boolean accept(Node node) {
              if (node.getText().startsWith("frame src=")) {
                return true;
              } else {
                return false;
              }
            }
          };

      OrFilter linkFilter = new OrFilter(new NodeClassFilter(LinkTag.class), frameFilter);

      NodeList list = parser.extractAllNodesThatMatch(linkFilter);

      System.out.println("length=" + list.size());

      for (int i = 0; i < list.size(); i++) {
        Node tag = list.elementAt(i);

        if (tag instanceof LinkTag) { // <a> 标签
          LinkTag link = (LinkTag) tag;
          String linkUrl = link.getLink(); // URL

          /*
           * if (filter.accept(linkUrl)) { links.add(linkUrl); }
           */

          System.out.println("linkUrl=" + linkUrl);

          if (filter.accept(tag)) {
            links.add(linkUrl);
          }
        } else { // <frame> 标签
          // 提取 frame 里 src 属性的链接,如 <frame src="test.html"/>
          String frame = tag.getText();
          int start = frame.indexOf("src=");
          frame = frame.substring(start);
          int end = frame.indexOf(" ");

          if (end == -1) {
            end = frame.indexOf(">");
          }

          String frameUrl = frame.substring(5, end - 1);
          // if (filter.accept(frameUrl)) {
          // links.add(frameUrl);
          // }

          System.out.println("frameUrl=" + frameUrl);

          if (filter.accept(tag)) {
            links.add(frameUrl);
          }
        }
      }

      /*
       * NodeFilter filter = new TagNameFilter("DIV"); NodeList nodes =
       * parser.extractAllNodesThatMatch(filter); if(nodes!=null) { for
       * (int i = 0; i < nodes.size(); i++) { Node textnode = (Node)
       * nodes.elementAt(i);
       * System.out.println("getText:"+textnode.getText());
       * System.out.println
       * ("================================================="); } }
       */
      /*
       * for(NodeIterator i = parser.elements (); i.hasMoreNodes(); ) {
       * Node node = i.nextNode();
       * System.out.println("getText:"+node.getText());
       * System.out.println("getPlainText:"+node.toPlainTextString());
       * System.out.println("toHtml:"+node.toHtml());
       * System.out.println("toHtml(true):"+node.toHtml(true));
       * System.out.println("toHtml(false):"+node.toHtml(false));
       * System.out.println("toString:"+node.toString());
       * System.out.println
       * ("================================================="); }
       */

      /*
       * TextExtractingVisitor visitor = new TextExtractingVisitor();
       * parser.visitAllNodesWith(visitor); String textInPage =
       * visitor.getExtractedText(); System.out.println(textInPage);
       */

    } catch (ParserException e) {
      e.printStackTrace();
    }
    return links;
  }
Example #12
0
 @Test
 public void testTapParserException3() {
   exception = new ParserException(new NullPointerException("Null TAP Stream")); // NOPMD
   assertNotNull(exception);
   assertTrue(exception.getCause() instanceof NullPointerException);
 }
Example #13
0
 @Test
 public void testTapParserException2() {
   exception = new ParserException("Error parsing document");
   assertNotNull(exception);
   assertEquals(exception.getMessage(), "Error parsing document");
 }