Example #1
0
 public String toString() {
   StringBuffer buffer = new StringBuffer("<" + ROW_TAG_NAME + ">");
   for (int i = 0; i < columnDescription.length; i++) {
     String colIdentifier = columnDescription[i].getIdentifier();
     buffer.append("<").append(colIdentifier).append(">");
     buffer.append(CommonUtil.escapeXml(CommonUtil.nvl(data[i], "")));
     buffer.append("</").append(colIdentifier).append(">");
   }
   buffer.append("</").append(ROW_TAG_NAME).append(">");
   return buffer.toString();
 }
Example #2
0
    public void execute() {
      if (!isEditable() || !isEnabled()) {
        return;
      }

      try {
        int position = lastClickPoint != null ? viewToModel(lastClickPoint) : getCaretPosition();
        lastClickPoint = null;
        Document document = getDocument();
        String selectedText = getSelectedText();
        if (selectedText != null && !CommonUtil.isEmpty(selectedText)) {
          final int selectionEnd = getSelectionEnd();
          document.insertString(selectionEnd, selectedText, null);
          select(selectionEnd, selectionEnd + selectedText.length());
        } else {
          final int docLen = document.getLength();
          int fromIndex = Math.max(0, getText(0, position).lastIndexOf('\n'));
          int toIndex = getText(fromIndex + 1, docLen - fromIndex).indexOf('\n');
          toIndex = toIndex < 0 ? docLen : fromIndex + toIndex;
          String textToDuplicate = getText(fromIndex, toIndex - fromIndex + 1);
          if (!textToDuplicate.startsWith("\n")) {
            textToDuplicate = "\n" + textToDuplicate;
          }
          if (textToDuplicate.endsWith("\n")) {
            textToDuplicate = textToDuplicate.substring(0, textToDuplicate.length() - 1);
          }
          document.insertString(Math.min(docLen, toIndex + 1), textToDuplicate, null);
          setCaretPosition(position + textToDuplicate.length());
        }
      } catch (BadLocationException e1) {
        e1.printStackTrace();
      }
    }
Example #3
0
 public Variable get(Object var) {
   String s = var.toString();
   int index = CommonUtil.getIntValue(s, -1);
   if (index > 0) {
     return get(index - 1);
   } else {
     return get(s);
   }
 }
Example #4
0
  /**
   * Constructor.
   *
   * @param configuration
   * @param workingDir
   */
  public Scraper(ScraperConfiguration configuration, String workingDir) {
    this.configuration = configuration;
    this.runtimeConfig = new RuntimeConfig();
    this.workingDir = CommonUtil.adaptFilename(workingDir);

    this.httpClientManager = new HttpClientManager();

    this.context = new ScraperContext(this);
    this.scriptEngine = configuration.createScriptEngine(this.context);
    this.usedScriptEngines.put(configuration.getDefaultScriptEngine(), this.scriptEngine);
  }
Example #5
0
    public void execute() {
      if (!isEditable() || !isEnabled()) {
        return;
      }
      int position = lastClickPoint != null ? viewToModel(lastClickPoint) : getCaretPosition();
      lastClickPoint = null;
      Document document = getDocument();
      String selectedText = getSelectedText();

      try {
        if (selectedText != null && !CommonUtil.isEmpty(selectedText)) {
          String trimmed = selectedText.trim();
          if (trimmed.startsWith("<!--") && trimmed.endsWith("-->")) {
            StringBuffer buffer = new StringBuffer(selectedText);
            int pos = buffer.indexOf("<!--");
            buffer.delete(pos, pos + 4);
            pos = buffer.lastIndexOf("-->");
            buffer.delete(pos, pos + 3);
            replaceSelection(buffer.toString());
          } else {
            String newSelection = "<!--" + selectedText + "-->";
            replaceSelection(newSelection);
          }
        } else {
          final int docLen = document.getLength();
          int fromIndex = Math.max(0, getText(0, position).lastIndexOf('\n'));
          int toIndex = getText(fromIndex + 1, docLen - position).indexOf('\n');
          toIndex = toIndex < 0 ? docLen : fromIndex + toIndex;
          String textToComment = getText(fromIndex, toIndex - fromIndex + 1);

          if (textToComment.startsWith("\n")) {
            textToComment = textToComment.substring(1);
            fromIndex++;
          }
          if (textToComment.endsWith("\n")) {
            textToComment = textToComment.substring(0, textToComment.length() - 1);
            toIndex--;
          }
          String trimmed = textToComment.trim();
          if (trimmed.startsWith("<!--") && trimmed.endsWith("-->")) {
            int pos = textToComment.lastIndexOf("-->");
            document.remove(fromIndex + pos, 3);
            pos = textToComment.indexOf("<!--");
            document.remove(fromIndex + pos, 4);
          } else {
            document.insertString(Math.min(toIndex + 1, docLen), "-->", null);
            document.insertString(fromIndex, "<!--", null);
          }
        }
      } catch (BadLocationException e1) {
        e1.printStackTrace();
      }
    }
Example #6
0
  public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
    if (node == null) {
      return;
    }

    Object userObject = node.getUserObject();
    if (userObject instanceof TopicInfo) {
      TopicInfo topicInfo = (TopicInfo) userObject;
      try {
        if (topicInfo.subtopicCount > 0) {
          htmlPane.setText(
              "<div style='font-family:Verdana,Tahoma;font-size:10px;'>Please choose a topic</div>");
          return;
        }

        URL helpFileUrl = ResourceManager.getHelpFileUrl(topicInfo.id);
        if (helpFileUrl == null) {
          throw new RuntimeException();
        }
        String content = CommonUtil.readStringFromUrl(helpFileUrl);
        content =
            "<html><body style=\"font-family:Verdana,Tahoma;font-size:10px;\">"
                + "<h2>"
                + topicInfo.title
                + "</h2>"
                + content
                + "</body></html>";
        ((HTMLDocument) htmlPane.getDocument()).setBase(helpFileUrl);
        htmlPane.setText(content);
        htmlPane.setCaretPosition(0);
      } catch (Exception e1) {
        htmlPane.setText(
            "<div style='color:#FF0000;font-family:Verdana,Tahoma;font-size:10px;'>Cannot read help for \""
                + topicInfo.title
                + "\"!</div>");
      }
    }
  }
Example #7
0
  /** Constructor - creates layout. */
  public HelpFrame() {
    setTitle("Web-Harvest Help");
    setIconImage(((ImageIcon) ResourceManager.HELP32_ICON).getImage());

    this.topNode = new DefaultMutableTreeNode();
    this.treeModel = new DefaultTreeModel(this.topNode);
    try {
      String helpContent = CommonUtil.readStringFromUrl(ResourceManager.getHelpContentUrl());
      XmlNode xmlNode = XmlParser.parse(new InputSource(new StringReader(helpContent)));
      createNodes(topNode, xmlNode);
    } catch (Exception e) {
      e.printStackTrace();
      GuiUtils.showErrorMessage("Error reading help content!");
    }

    tree = new JTree(topNode);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setBorder(new EmptyBorder(5, 5, 5, 5));
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            DefaultTreeCellRenderer renderer =
                (DefaultTreeCellRenderer)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) value;
              Object userObject = defaultMutableTreeNode.getUserObject();
              if (userObject instanceof TopicInfo) {
                TopicInfo topicInfo = (TopicInfo) userObject;
                renderer.setIcon(
                    topicInfo.subtopicCount == 0
                        ? ResourceManager.HELPTOPIC_ICON
                        : ResourceManager.HELPDIR_ICON);
              }
            }
            return renderer;
          }
        });
    tree.addTreeSelectionListener(this);

    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    htmlPane.setContentType("text/html");
    htmlPane.setEditorKit(new HTMLEditorKit());
    htmlPane.setBorder(new EmptyBorder(5, 5, 5, 5));

    JSplitPane splitPane = new ProportionalSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setResizeWeight(0.0d);
    splitPane.setBorder(null);

    JScrollPane treeScrollPane = new WHScrollPane(tree);
    treeScrollPane.getViewport().setBackground(Color.white);
    treeScrollPane.setBackground(Color.white);
    splitPane.setLeftComponent(treeScrollPane);
    splitPane.setRightComponent(new WHScrollPane(htmlPane));
    splitPane.setDividerLocation(0.3d);

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(splitPane, BorderLayout.CENTER);

    pack();
  }