コード例 #1
0
 // 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;
   }
 }
コード例 #2
0
  public ArrayList<String> parseXML() throws Exception {
    ArrayList<String> ret = new ArrayList<String>();

    handshake();

    URL url =
        new URL(
            "http://mangaonweb.com/page.do?cdn="
                + cdn
                + "&cpn=book.xml&crcod="
                + crcod
                + "&rid="
                + (int) (Math.random() * 10000));
    String page = DownloaderUtils.getPage(url.toString(), "UTF-8", cookies);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(page));
    Document d = builder.parse(is);
    Element doc = d.getDocumentElement();

    NodeList pages = doc.getElementsByTagName("page");
    total = pages.getLength();
    for (int i = 0; i < pages.getLength(); i++) {
      Element e = (Element) pages.item(i);
      ret.add(e.getAttribute("path"));
    }

    return (ret);
  }
コード例 #3
0
 private Element getElement(String eltName) {
   NodeList nodeList = docElt.getElementsByTagName(eltName);
   if (nodeList.getLength() != 0) {
     Node node = nodeList.item(0);
     if (node instanceof Element) return (Element) node;
   }
   return null;
 }
コード例 #4
0
ファイル: DOMTreeView.java プロジェクト: ferryzhou/jweb
 void lookup(String text) {
   NodeList nl = DOMInfoExtractor.locateNodes(document, ".//text()[contains(.,'" + text + "')]");
   System.out.println("find " + nl.getLength() + " items");
   FoundItem[] fis = new FoundItem[nl.getLength()];
   for (int i = 0; i < nl.getLength(); i++) {
     fis[i] = getFoundItem(nl.item(i), text);
   }
   foundList.setListData(fis);
 }
コード例 #5
0
 private static Collection<Node> getNodeMatching(Node body, String regexp) {
   final Collection<Node> nodes = new ArrayList<>();
   if (body.getNodeName().matches(regexp)) nodes.add(body);
   if (body.getChildNodes().getLength() == 0) return nodes;
   NodeList returnList = body.getChildNodes();
   for (int k = 0; k < returnList.getLength(); k++) {
     final Node node = returnList.item(k);
     nodes.addAll(getNodeMatching(node, regexp));
   }
   return nodes;
 }
コード例 #6
0
ファイル: AppConfig.java プロジェクト: ramseylab/Dizzy
 public String getProperty(String pPropertyName) {
   String propertyValue = null;
   NodeList nodeList = mConfigFileDocument.getElementsByTagName(pPropertyName);
   int nodeListLength = nodeList.getLength();
   if (nodeListLength > 0) {
     Node firstChildNode = nodeList.item(nodeListLength - 1).getFirstChild();
     if (null != firstChildNode) {
       propertyValue = firstChildNode.getNodeValue();
     }
   }
   return (propertyValue);
 }
コード例 #7
0
 public void load(InputStream is) throws IOException, ParserConfigurationException, SAXException {
   doc = db.parse(is);
   docElt = doc.getDocumentElement();
   if (docElt.getTagName().equals(docElementName)) {
     NodeList nl = docElt.getElementsByTagName(trackElementName);
     for (int i = 0; i < nl.getLength(); i++) {
       Element elt = (Element) nl.item(i);
       Track track = new Track(elt);
       tracks.add(track);
       hash.put(track.getKey(), track);
     }
   }
 }
コード例 #8
0
ファイル: DOMTreeView.java プロジェクト: ferryzhou/jweb
 void lookupByXPath(String xpath) {
   NodeList nl = DOMInfoExtractor.locateNodes(document, xpath);
   System.out.println("lookupByXPath: " + xpath);
   if (nl == null) {
     JOptionPane.showMessageDialog(this, "error xpath: " + xpath);
   }
   System.out.println("find " + nl.getLength() + " items");
   FoundItem[] fis = new FoundItem[nl.getLength()];
   for (int i = 0; i < nl.getLength(); i++) {
     fis[i] = getFoundItem(nl.item(i), null);
   }
   foundList.setListData(fis);
 }
コード例 #9
0
  @Override
  public VPackage parse() {

    logger.debug("Starting parsing package: " + xmlFile.getAbsolutePath());

    long startParsing = System.currentTimeMillis();

    try {
      Document document = getDocument();
      Element root = document.getDocumentElement();

      _package = new VPackage(xmlFile);

      Node name = root.getElementsByTagName(EL_NAME).item(0);
      _package.setName(name.getTextContent());
      Node descr = root.getElementsByTagName(EL_DESCRIPTION).item(0);
      _package.setDescription(descr.getTextContent());

      NodeList list = root.getElementsByTagName(EL_CLASS);

      boolean initPainters = false;
      for (int i = 0; i < list.getLength(); i++) {
        PackageClass pc = parseClass((Element) list.item(i));
        if (pc.getPainterName() != null) {
          initPainters = true;
        }
      }

      if (initPainters) {
        _package.initPainters();
      }

      logger.info(
          "Parsing the package '{}' finished in {}ms.\n",
          _package.getName(),
          (System.currentTimeMillis() - startParsing));
    } catch (Exception e) {
      collector.collectDiagnostic(e.getMessage(), true);
      if (RuntimeProperties.isLogDebugEnabled()) {
        e.printStackTrace();
      }
    }

    try {
      checkProblems("Error parsing package file " + xmlFile.getName());
    } catch (Exception e) {
      return null;
    }

    return _package;
  }
コード例 #10
0
ファイル: Parameters.java プロジェクト: nagyist/jitsi
  /**
   * Retrieves default values from xml.
   *
   * @param list the configuration list
   */
  private static void parseDefaults(NodeList list) {
    for (int i = 0; i < list.getLength(); ++i) {
      NamedNodeMap mapping = list.item(i).getAttributes();
      String attribute = mapping.getNamedItem("attribute").getNodeValue();
      String value = mapping.getNamedItem("value").getNodeValue();

      try {
        Default field = Default.fromString(attribute);
        DEFAULTS.put(field, value);
      } catch (IllegalArgumentException exc) {
        logger.warn("Unrecognized default attribute: " + attribute);
      }
    }
  }
コード例 #11
0
ファイル: D4.java プロジェクト: sarekautowerke/D4
  public List parsePage(String pageCode) {
    List sections = new ArrayList();
    List folders = new ArrayList();
    List files = new ArrayList();
    int start = pageCode.indexOf("<div id=\"list-view\" class=\"view\"");
    int end = pageCode.indexOf("<div id=\"gallery-view\" class=\"view\"");
    String usefulSection = "";
    if (start != -1 && end != -1) {
      usefulSection = pageCode.substring(start, end);
    } else {
      debug("Could not parse page");
    }
    try {
      DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      InputSource is = new InputSource();
      is.setCharacterStream(new StringReader(usefulSection));
      Document doc = db.parse(is);

      NodeList divs = doc.getElementsByTagName("div");
      for (int i = 0; i < divs.getLength(); i++) {
        Element div = (Element) divs.item(i);
        boolean isFolder = false;
        if (div.getAttribute("class").equals("filename")) {
          NodeList imgs = div.getElementsByTagName("img");
          for (int j = 0; j < imgs.getLength(); j++) {
            Element img = (Element) imgs.item(j);
            if (img.getAttribute("class").indexOf("folder") > 0) {
              isFolder = true;
            } else {
              isFolder = false; // it's a file
            }
          }

          NodeList anchors = div.getElementsByTagName("a");
          Element anchor = (Element) anchors.item(0);
          String attr = anchor.getAttribute("href");
          String fileName = anchor.getAttribute("title");
          String fileURL;
          if (isFolder && !attr.equals("#")) {
            folders.add(attr);
            folders.add(fileName);
          } else if (!isFolder && !attr.equals("#")) {
            // Dropbox uses ajax to get the file for download, so the url isn't enough. We must be
            // sneaky here.
            fileURL = "https://dl.dropbox.com" + attr.substring(23) + "?dl=1";
            files.add(fileURL);
            files.add(fileName);
          }
        }
      }
    } catch (Exception e) {
      debug(e.toString());
    }

    sections.add(files);
    sections.add(folders);

    return sections;
  }
コード例 #12
0
ファイル: Parameters.java プロジェクト: nagyist/jitsi
 /**
  * Populates LOCALES list with contents of xml.
  *
  * @param list the configuration list
  */
 private static void parseLocales(NodeList list) {
   for (int i = 0; i < list.getLength(); ++i) {
     Node node = list.item(i);
     NamedNodeMap attributes = node.getAttributes();
     String label = ((Attr) attributes.getNamedItem("label")).getValue();
     String code = ((Attr) attributes.getNamedItem("isoCode")).getValue();
     String dictLocation = ((Attr) attributes.getNamedItem("dictionaryUrl")).getValue();
     try {
       LOCALES.add(new Locale(label, code, new URL(dictLocation)));
     } catch (MalformedURLException exc) {
       logger.warn(
           "Unable to parse dictionary location of " + label + " (" + dictLocation + ")", exc);
     }
   }
 }
コード例 #13
0
ファイル: Parameters.java プロジェクト: nagyist/jitsi
  static {
    try {
      URL url = SpellCheckActivator.bundleContext.getBundle().getResource(RESOURCE_LOC);

      InputStream stream = url.openStream();

      if (stream == null) throw new IOException();

      // strict parsing options
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

      factory.setValidating(false);
      factory.setIgnoringComments(true);
      factory.setIgnoringElementContentWhitespace(true);

      // parses configuration xml
      /*-
       * Warning: Felix is unable to import the com.sun.rowset.internal
       * package, meaning this can't use the XmlErrorHandler. This causes
       * a warning and a default handler to be attached. Otherwise this
       * should have: builder.setErrorHandler(new XmlErrorHandler());
       */
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse(stream);

      // iterates over nodes, parsing contents
      Node root = doc.getChildNodes().item(1);

      NodeList categories = root.getChildNodes();

      for (int i = 0; i < categories.getLength(); ++i) {
        Node node = categories.item(i);
        if (node.getNodeName().equals(NODE_DEFAULTS)) {
          parseDefaults(node.getChildNodes());
        } else if (node.getNodeName().equals(NODE_LOCALES)) {
          parseLocales(node.getChildNodes());
        } else {
          logger.warn("Unrecognized category: " + node.getNodeName());
        }
      }
    } catch (IOException exc) {
      logger.error("Unable to load spell checker parameters", exc);
    } catch (SAXException exc) {
      logger.error("Unable to parse spell checker parameters", exc);
    } catch (ParserConfigurationException exc) {
      logger.error("Unable to parse spell checker parameters", exc);
    }
  }
コード例 #14
0
ファイル: D4.java プロジェクト: sarekautowerke/D4
 public String getFolderName(String pageCode) {
   String usefulSection =
       pageCode.substring(
           pageCode.indexOf("<h3 id=\"breadcrumb\">"),
           pageCode.indexOf("<div id=\"list-view\" class=\"view\""));
   String folderName;
   try {
     DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
     InputSource is = new InputSource();
     is.setCharacterStream(new StringReader(usefulSection));
     Document doc = db.parse(is);
     NodeList divs = doc.getElementsByTagName("h3");
     for (int i = 0; i < divs.getLength(); i++) {
       Element div = (Element) divs.item(i);
       String a = div.getTextContent();
       folderName = a.substring(a.indexOf("/>") + 2).trim();
       return folderName;
     }
   } catch (Exception e) {
     debug(e.toString());
   }
   return "Error!";
 }
コード例 #15
0
  /**
   * Constructs an attribute designator element from an existing XML block.
   *
   * @param element representing a DOM tree element.
   * @exception SAMLException if that there is an error in the sender or in the element definition.
   */
  public AttributeDesignator(Element element) throws SAMLException {
    // make sure that the input xml block is not null
    if (element == null) {
      SAMLUtilsCommon.debug.message("AttributeDesignator: Input is null.");
      throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("nullInput"));
    }
    // Make sure this is an AttributeDesignator.
    String tag = null;
    tag = element.getLocalName();
    if ((tag == null) || (!tag.equals("AttributeDesignator"))) {
      SAMLUtilsCommon.debug.message("AttributeDesignator: wrong input");
      throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("wrongInput"));
    }

    // handle attributes
    int i = 0;
    NamedNodeMap atts = ((Node) element).getAttributes();
    int attrCount = atts.getLength();
    for (i = 0; i < attrCount; i++) {
      Node att = atts.item(i);
      if (att.getNodeType() == Node.ATTRIBUTE_NODE) {
        String attName = att.getLocalName();
        if (attName == null || attName.length() == 0) {
          if (SAMLUtilsCommon.debug.messageEnabled()) {
            SAMLUtilsCommon.debug.message(
                "AttributeDesignator:" + "Attribute Name is either null or empty.");
          }
          throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("nullInput"));
        }
        if (attName.equals("AttributeName")) {
          _attributeName = ((Attr) att).getValue().trim();
        } else if (attName.equals("AttributeNamespace")) {
          _attributeNameSpace = ((Attr) att).getValue().trim();
        }
      }
    }
    // AttributeName is required
    if (_attributeName == null || _attributeName.length() == 0) {
      if (SAMLUtilsCommon.debug.messageEnabled()) {
        SAMLUtilsCommon.debug.message(
            "AttributeDesignator: " + "AttributeName is required attribute");
      }
      throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("missingAttribute"));
    }

    // AttributeNamespace is required
    if (_attributeNameSpace == null || _attributeNameSpace.length() == 0) {
      if (SAMLUtilsCommon.debug.messageEnabled()) {
        SAMLUtilsCommon.debug.message(
            "AttributeDesignator: " + "AttributeNamespace is required attribute");
      }
      throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("missingAttribute"));
    }

    // handle the children of AttributeDesignator element
    // Since AttributeDesignator does not have any child element_node,
    // we will throw exception if we found any such child.
    NodeList nodes = element.getChildNodes();
    int nodeCount = nodes.getLength();
    if (nodeCount > 0) {
      for (i = 0; i < nodeCount; i++) {
        Node currentNode = nodes.item(i);
        if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
          if (SAMLUtilsCommon.debug.messageEnabled()) {
            SAMLUtilsCommon.debug.message("AttributeDesignator: illegal input!");
          }
          throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("wrongInput"));
        }
      }
    }
  }
コード例 #16
0
  private PackageClass parseClass(Element classNode) {
    PackageClass newClass = new PackageClass();
    _package.getClasses().add(newClass);

    newClass.setComponentType(PackageClass.ComponentType.getType(classNode.getAttribute(ATR_TYPE)));
    newClass.setStatic(Boolean.parseBoolean(classNode.getAttribute(ATR_STATIC)));
    newClass.setName(getElementByName(classNode, EL_NAME).getTextContent());
    final String source = getElementStringByName(classNode, EL_FILE);
    if (source != null) {
      newClass.setSource(source);
    }
    newClass.setTarget(getElementStringByName(classNode, EL_EXTENDS));
    newClass.setDescription(getElementByName(classNode, EL_DESCRIPTION).getTextContent());
    newClass.setIcon(getElementByName(classNode, EL_ICON).getTextContent());

    // parse all variables declared in the corresponding specification
    if (newClass.getComponentType().hasSpec()) {
      final String newClassName = newClass.getName();
      try {
        switch (RuntimeProperties.getSpecParserKind()) {
          case REGEXP:
            {
              ClassList classList = new ClassList();
              SpecParser.parseSpecClass(newClassName, getWorkingDir(), classList);
              newClass.setSpecFields(classList.getType(newClassName).getFields());
              break;
            }
          case ANTLR:
            {
              if (specificationLoader == null) {
                specificationLoader =
                    new SpecificationLoader(new PackageSpecSourceProvider(_package), null);
              }
              final AnnotatedClass annotatedClass =
                  specificationLoader.getSpecification(newClassName);
              newClass.setSpecFields(annotatedClass.getFields());
              break;
            }
          default:
            throw new IllegalStateException("Undefined specification language parser");
        }
      } catch (SpecParseException e) {
        final String msg = "Unable to parse the specification of class " + newClassName;
        logger.error(msg, e);
        collector.collectDiagnostic(msg + "\nReason: " + e.getMessage() + "\nLine: " + e.getLine());
      }
    }

    // Graphics
    Element grNode = getElementByName(classNode, EL_GRAPHICS);
    newClass.addGraphics(
        getGraphicsParser().parse(grNode/*, newClass.getComponentType() == ComponentType.REL*/ ));

    Element painter;
    if ((painter = getElementByName(grNode, EL_PAINTER)) != null) {
      newClass.setPainterName(painter.getTextContent());
    }

    // Ports
    NodeList ports = classNode.getElementsByTagName(EL_PORT);
    for (int i = 0; i < ports.getLength(); i++) {
      parsePort(newClass, (Element) ports.item(i));
    }

    // Fields
    NodeList fields = classNode.getElementsByTagName(EL_FIELD);
    for (int i = 0; i < fields.getLength(); i++) {
      parseField(newClass, (Element) fields.item(i));
    }

    return newClass;
  }
コード例 #17
0
ファイル: Main.java プロジェクト: damacode/MyTumblr
 private static NodeList getIFrames(NodeList node_list) {
   return node_list.extractAllNodesThatMatch(new TagNameFilter("iframe"), true);
 }
コード例 #18
0
ファイル: Main.java プロジェクト: damacode/MyTumblr
 private static NodeList getRemarks(NodeList node_list) {
   return node_list.extractAllNodesThatMatch(new NodeClassFilter(RemarkNode.class), true);
 }
コード例 #19
0
ファイル: Main.java プロジェクト: damacode/MyTumblr
 private static NodeList getPhotosetPosts(NodeList node_list) {
   return node_list.extractAllNodesThatMatch(
       new HasAttributeFilter("class", "my_photoset_post"), true);
 }
コード例 #20
0
ファイル: PathMonitor.java プロジェクト: krichter/pathmonitor
  public static void main(String[] args) {
    String specloc = System.getProperty("spec");
    if (specloc == null) {
      System.out.print("No spec file given, quitting");
      System.exit(0);
    }

    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z");
    java.util.Date date = new java.util.Date();
    String startstamp = dateFormat.format(date);

    boolean firstrun = true;

    while (true) {
      System.out.println("Loading XML Spec file: " + specloc);
      // BufferedWriter out = null;
      SocketAcceptor acceptor = null;
      SocketAcceptor statusacceptor = null;

      Vector<MonitorThread> monitorlist = new Vector<MonitorThread>();
      try {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        Document doc = docBuilder.parse(new File(specloc));

        doc.getDocumentElement().normalize();
        String heartbeatportString = doc.getDocumentElement().getAttribute("heartbeatport");
        String statusportString = doc.getDocumentElement().getAttribute("statusport");
        String logfiledir = doc.getDocumentElement().getAttribute("logfiledir");
        String masterlabel = doc.getDocumentElement().getAttribute("label");
        String nodeid = doc.getDocumentElement().getAttribute("id");
        String smtphost = doc.getDocumentElement().getAttribute("smtphost");
        String l1mailto = doc.getDocumentElement().getAttribute("l1mailto");
        String l2mailto = doc.getDocumentElement().getAttribute("l2mailto");
        String l2threshold = doc.getDocumentElement().getAttribute("l2threshold");

        if (heartbeatportString == null || heartbeatportString.equals("")) {
          System.out.println("No heartbeat specified in spec, quitting");
          System.exit(0);
        }
        if (statusportString == null || statusportString.equals("")) {
          System.out.println("No status port specified in spec, quitting");
          System.exit(0);
        }
        if (logfiledir == null || logfiledir.equals("")) {
          System.out.println("No logfile directory location specified in spec, quitting");
          System.exit(0);
        }

        int heartbeatport = Integer.valueOf(heartbeatportString).intValue();
        System.out.println("This Monitor is using port " + heartbeatport + " for heartbeat");

        int statusport = Integer.valueOf(statusportString).intValue();
        System.out.println("This Monitor is using port " + statusport + " for status updates");

        System.out.println("Logging to directory " + logfiledir);
        Log log = new Log(logfiledir);
        log.nodelabel = masterlabel;
        log.setMailer(smtphost, l1mailto, l2mailto, convertStringToInt(l2threshold));

        if (firstrun) {
          firstrun = false;
          log.logit("Monitor Node Started", "start", null);
        }
        log.logit("Logging started", "", null);

        ThreadPing threadping = new ThreadPing(log, false);
        Thread pinger = new Thread(threadping);
        threadping.thisThread = pinger;
        pinger.start();
        log.pinger = threadping;

        // ShutdownHook hook = new ShutdownHook(out);
        // Runtime.getRuntime().addShutdownHook(hook);

        // Starting Heartbeat server

        acceptor = new NioSocketAcceptor();
        acceptor.getSessionConfig().setReuseAddress(true);
        acceptor.getSessionConfig().setTcpNoDelay(true);
        acceptor.setReuseAddress(true);
        // acceptor.getFilterChain().addLast("logger", new LoggingFilter());
        acceptor
            .getFilterChain()
            .addLast(
                "codec",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
        acceptor.setReuseAddress(true);
        // acceptor.setCloseOnDeactivation(true);
        acceptor.getSessionConfig().setTcpNoDelay(true);

        acceptor.setDefaultLocalAddress(new InetSocketAddress(heartbeatport));
        Vector<IoSession> sessionlist = new Vector<IoSession>();
        acceptor.setHandler(new HeartBeatHandler(sessionlist));
        acceptor.bind();

        // Starting Path Monitoring
        NodeList listOfServers = doc.getElementsByTagName("check");
        int totalServers = listOfServers.getLength();
        System.out.println("Total # of checks: " + totalServers);

        // Vector<PingMonitorThread> pinglist = new Vector<PingMonitorThread>();
        // Vector<PortMonitorThread> portlist = new Vector<PortMonitorThread>();
        // Vector<HeartbeatMonitorThread> heartbeatlist = new Vector<HeartbeatMonitorThread>();

        System.out.println();
        for (int i = 0; i < totalServers; i++) {
          Node serverNode = listOfServers.item(i);

          Element serverNodeElement = (Element) serverNode;
          String checklabel = serverNodeElement.getAttribute("label");
          String host =
              serverNodeElement
                  .getElementsByTagName("host")
                  .item(0)
                  .getChildNodes()
                  .item(0)
                  .getNodeValue();
          String checktype =
              serverNodeElement
                  .getElementsByTagName("checktype")
                  .item(0)
                  .getChildNodes()
                  .item(0)
                  .getNodeValue();
          boolean enabled = true;
          if (serverNodeElement.getElementsByTagName("enabled").item(0) != null
              && serverNodeElement
                  .getElementsByTagName("enabled")
                  .item(0)
                  .getChildNodes()
                  .item(0)
                  .getNodeValue()
                  .toLowerCase()
                  .equals("false")) {
            enabled = false;
          }
          String successrateString =
              serverNodeElement
                  .getElementsByTagName("successrate")
                  .item(0)
                  .getChildNodes()
                  .item(0)
                  .getNodeValue();
          String retryrateString =
              serverNodeElement
                  .getElementsByTagName("retryrate")
                  .item(0)
                  .getChildNodes()
                  .item(0)
                  .getNodeValue();
          // String l2thresholdoverride =
          // serverNodeElement.getElementsByTagName("l2threshold").item(0).getChildNodes().item(0).getNodeValue();
          String l2thresholdoverride = getElementValue("l2threshold", serverNodeElement);
          // String l1mailtoadd =
          // serverNodeElement.getElementsByTagName("l1mailto").item(0).getChildNodes().item(0).getNodeValue();
          String l1mailtoadd = getElementValue("l1mailto", serverNodeElement);
          // String l2mailtoadd =
          // serverNodeElement.getElementsByTagName("l2mailto").item(0).getChildNodes().item(0).getNodeValue();
          String l2mailtoadd = getElementValue("l2mailto", serverNodeElement);

          int l2thresholdoverrideint = convertStringToInt(l2thresholdoverride);
          String[] l1mailtoaddarray = new String[0];
          String[] l2mailtoaddarray = new String[0];
          if (!l1mailtoadd.equals("")) {
            l1mailtoaddarray = l1mailtoadd.split(",");
          }
          if (!l2mailtoadd.equals("")) {
            l2mailtoaddarray = l2mailtoadd.split(",");
          }

          // System.out.println(l1mailtoaddarray.length + "-" + l2mailtoaddarray.length);

          int successrate = 30;
          int retryrate = 30;
          if (host == null || host.equals("")) {
            System.out.println("No Host, skipping this path");
            enabled = false;
          }

          if (successrateString == null || successrateString.equals("")) {
            System.out.println(
                "No Success Rate defined, using default (" + successrate + " seconds)");
          } else {
            successrate = Integer.valueOf(successrateString).intValue();
          }

          if (retryrateString == null || retryrateString.equals("")) {
            System.out.println("No retry rate defined, using default (" + retryrate + " seconds)");
          } else {
            retryrate = Integer.valueOf(retryrateString).intValue();
          }

          System.out.println(checklabel);

          if (checktype.equals("heartbeat")) {
            String portString =
                serverNodeElement
                    .getElementsByTagName("port")
                    .item(0)
                    .getChildNodes()
                    .item(0)
                    .getNodeValue();

            if (portString == null || portString.equals("")) {
              System.out.println("No Heartbeat, skipping this path");
            } else {
              int heartbeat = Integer.valueOf(portString).intValue();
              System.out.println("Starting Heartbeat Check:");
              System.out.println("Host: " + host);
              System.out.println("Port: " + heartbeat);
              System.out.println();
              HeartbeatMonitorThread m =
                  new HeartbeatMonitorThread(
                      host, heartbeat, log, successrate, retryrate, checklabel);
              m.setAlertOverride(l2thresholdoverrideint, l1mailtoaddarray, l2mailtoaddarray);
              Thread t = new Thread(m);
              m.thisthread = t;
              if (enabled) {
                t.start();
                log.logit(
                    "Starting Heartbeat Check - " + host + ":" + heartbeat,
                    "enable-" + successrate + "-" + retryrate,
                    m.getStatus());
              } else {
                log.logit(
                    "Heartbeat Check - " + host + ":" + heartbeat + " Disabled on start",
                    "disable",
                    m.getStatus());
              }
              monitorlist.add(m);
            }
          } else if (checktype.equals("ping")) {
            System.out.println("Starting Ping Check:");
            System.out.println("Host: " + host);
            System.out.println();
            PingMonitorThread m =
                new PingMonitorThread(host, log, successrate, retryrate, checklabel);
            m.setAlertOverride(l2thresholdoverrideint, l1mailtoaddarray, l2mailtoaddarray);
            Thread t = new Thread(m);
            m.thisthread = t;
            if (enabled) {
              t.start();
              log.logit(
                  "Starting Ping Check - " + host,
                  "enable-" + successrate + "-" + retryrate,
                  m.getStatus());
            } else {
              log.logit("Ping Check - " + host + " Disabled on start", "disable", m.getStatus());
            }
            monitorlist.add(m);
          } else if (checktype.equals("port")) {
            String portString =
                serverNodeElement
                    .getElementsByTagName("port")
                    .item(0)
                    .getChildNodes()
                    .item(0)
                    .getNodeValue();

            if (portString == null || portString.equals("")) {
              System.out.println("No Port Given, skipping");
            } else {
              int heartbeat = Integer.valueOf(portString).intValue();
              System.out.println("Starting Port Check:");
              System.out.println("Host: " + host);
              System.out.println("Port: " + heartbeat);
              System.out.println();

              PortMonitorThread m =
                  new PortMonitorThread(host, heartbeat, log, successrate, retryrate, checklabel);
              m.setAlertOverride(l2thresholdoverrideint, l1mailtoaddarray, l2mailtoaddarray);
              Thread t = new Thread(m);
              m.thisthread = t;
              if (enabled) {
                t.start();
                log.logit(
                    "Starting Port Check - " + host + ":" + heartbeat,
                    "enable-" + successrate + "-" + retryrate,
                    m.getStatus());
              } else {
                log.logit(
                    "Port Check - " + host + ":" + heartbeat + " Disabled on start",
                    "disable",
                    m.getStatus());
              }
              monitorlist.add(m);
            }
          }
        }

        statusacceptor = new NioSocketAcceptor();
        statusacceptor.setReuseAddress(true);
        // statusacceptor.getFilterChain().addLast("logger", new LoggingFilter());
        statusacceptor.getSessionConfig().setTcpNoDelay(true);
        statusacceptor.getSessionConfig().setKeepAlive(true);
        statusacceptor.getSessionConfig().setBothIdleTime(5);
        statusacceptor.getSessionConfig().setReaderIdleTime(5);
        statusacceptor.getSessionConfig().setWriteTimeout(5);
        // statusacceptor.setReuseAddress(true);
        statusacceptor.setCloseOnDeactivation(true);
        statusacceptor.setDefaultLocalAddress(new InetSocketAddress(statusport));
        statusacceptor.setHandler(
            new StatusHttpProtocolHandler(
                monitorlist,
                acceptor,
                statusacceptor,
                log,
                masterlabel,
                nodeid,
                sessionlist,
                startstamp));
        statusacceptor.bind();

        System.out.println("Status Listener activated...");
      } catch (Exception e) {
        e.printStackTrace();
        try {
          // out.flush();
          // out.close();
        } catch (Exception e2) {
        }

        try {
          Thread.sleep(30000);
        } catch (Exception e3) {
        }
      }

      for (int x = 0; x < monitorlist.size(); x++) {
        if (monitorlist.get(x).getThisThread() != null) {
          try {
            monitorlist.get(x).getThisThread().join();
          } catch (Exception e) {
          }
        }
      }

      if (acceptor != null) {
        while (acceptor.isActive() || !acceptor.isDisposed()) {
          try {
            Thread.sleep(1000);
          } catch (Exception e) {
          }
        }
      }

      if (statusacceptor != null) {
        while (statusacceptor.isActive() || !statusacceptor.isDisposed()) {
          try {
            Thread.sleep(1000);
          } catch (Exception e) {
          }
        }
      }
      System.out.println("Main thread has reached end, reloading...");
      /*
      try
      {
      	Thread.sleep(9999999);
      }
      catch (Exception e)
      {
      	e.printStackTrace();
      }
      */
    }
  }
コード例 #21
0
    private ClassGraphics parse(Element grNode /*, boolean isRelation*/) {
      ClassGraphics newGraphics = new ClassGraphics();
      newGraphics.setShowFields(Boolean.parseBoolean(grNode.getAttribute(ATR_SHOW_FIELDS)));
      // newGraphics.setRelation( isRelation );

      NodeList list = grNode.getChildNodes();
      for (int k = 0; k < list.getLength(); k++) {
        if (list.item(k).getNodeType() != Node.ELEMENT_NODE) continue;
        Element node = (Element) list.item(k);
        String nodeName = node.getNodeName();

        Shape shape = null;
        if (EL_BOUNDS.equals(nodeName)) {
          Dim dim = getDim(node);
          newGraphics.setBounds(dim.x, dim.y, dim.width, dim.height);
          continue;
        } else if (EL_LINE.equals(nodeName)) {

          shape = makeLine(node, newGraphics);

        } else if (EL_RECT.equals(nodeName)) {

          Dim dim = getDim(node);
          Lineprops lp = getLineProps(node);
          shape =
              new Rect(
                  dim.x,
                  dim.y,
                  dim.width,
                  dim.height,
                  getColor(node),
                  isShapeFilled(node),
                  lp.strokeWidth,
                  lp.lineType);

        } else if (EL_OVAL.equals(nodeName)) {

          Dim dim = getDim(node);
          Lineprops lp = getLineProps(node);
          shape =
              new Oval(
                  dim.x,
                  dim.y,
                  dim.width,
                  dim.height,
                  getColor(node),
                  isShapeFilled(node),
                  lp.strokeWidth,
                  lp.lineType);

        } else if (EL_ARC.equals(nodeName)) {

          Dim dim = getDim(node);
          Lineprops lp = getLineProps(node);
          int startAngle = Integer.parseInt(node.getAttribute(ATR_START_ANGLE));
          int arcAngle = Integer.parseInt(node.getAttribute(ATR_ARC_ANGLE));
          shape =
              new Arc(
                  dim.x,
                  dim.y,
                  dim.width,
                  dim.height,
                  startAngle,
                  arcAngle,
                  getColor(node),
                  isShapeFilled(node),
                  lp.strokeWidth,
                  lp.lineType);

        } else if (EL_POLYGON.equals(nodeName)) {
          Lineprops lp = getLineProps(node);

          Polygon polygon =
              new Polygon(getColor(node), isShapeFilled(node), lp.strokeWidth, lp.lineType);

          // points
          NodeList points = node.getElementsByTagName(EL_POINT);
          int pointCount = points.getLength();
          // arrays of polygon points
          int[] xs = new int[pointCount];
          int[] ys = new int[pointCount];
          // arrays of FIXED information about polygon points
          int[] fxs = new int[pointCount];
          int[] fys = new int[pointCount];
          int width = newGraphics.getBoundWidth();
          int height = newGraphics.getBoundHeight();

          for (int j = 0; j < pointCount; j++) {
            FixedCoords fc = getFixedCoords((Element) points.item(j), width, height, null);
            xs[j] = fc.x;
            fxs[j] = fc.fx;
            ys[j] = fc.y;
            fys[j] = fc.fy;
          }

          polygon.setPoints(xs, ys, fxs, fys);
          shape = polygon;

        } else if (EL_IMAGE.equals(nodeName)) {

          Dim dim = getDim(node);
          // image path should be relative to the package xml
          String imgPath = node.getAttribute(ATR_PATH);
          String fullPath = FileFuncs.preparePathOS(getWorkingDir() + imgPath);
          shape = new Image(dim.x, dim.y, fullPath, imgPath, isShapeFixed(node));

        } else if (EL_TEXT.equals(nodeName)) {
          shape = makeText(node, newGraphics);
          /*
           * if (str.equals("*self")) newText.name = "self"; else if
           * (str.equals("*selfWithName")) newText.name = "selfName";
           */
        }

        if (shape != null) newGraphics.addShape(shape);
      }

      return newGraphics;
    }
コード例 #22
0
  public void addPackageClass(PackageClass pClass) {

    Document doc;
    try {
      doc = getDocument();
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    String name = pClass.getName();

    // check if such class exists and remove duplicates
    Element rootEl = doc.getDocumentElement();
    NodeList classEls = rootEl.getElementsByTagName(EL_CLASS);
    for (int i = 0; i < classEls.getLength(); i++) {
      Element nameEl = getElementByName((Element) classEls.item(i), EL_NAME);
      if (name.equals(nameEl.getTextContent())) {
        rootEl.removeChild(classEls.item(i));
      }
    }

    Element classNode = doc.createElement(EL_CLASS);
    doc.getDocumentElement().appendChild(classNode);
    classNode.setAttribute(ATR_TYPE, PackageClass.ComponentType.SCHEME.getXmlName());
    classNode.setAttribute(ATR_STATIC, "false");

    Element className = doc.createElement(EL_NAME);
    className.setTextContent(name);
    classNode.appendChild(className);

    Element desrc = doc.createElement(EL_DESCRIPTION);
    desrc.setTextContent(pClass.getDescription());
    classNode.appendChild(desrc);

    Element icon = doc.createElement(EL_ICON);
    icon.setTextContent(pClass.getIcon());
    classNode.appendChild(icon);

    // graphics
    classNode.appendChild(generateGraphicsNode(doc, pClass.getGraphics()));

    // ports
    List<Port> ports = pClass.getPorts();
    if (!ports.isEmpty()) {
      Element portsEl = doc.createElement(EL_PORTS);
      classNode.appendChild(portsEl);

      for (Port port : ports) {
        portsEl.appendChild(generatePortNode(doc, port));
      }
    }

    // fields
    Collection<ClassField> fields = pClass.getFields();
    if (!fields.isEmpty()) {
      Element fieldsEl = doc.createElement(EL_FIELDS);
      classNode.appendChild(fieldsEl);

      for (ClassField cf : fields) {
        fieldsEl.appendChild(generateFieldNode(doc, cf));
      }
    }

    // write
    try {
      writeDocument(doc, new FileOutputStream(xmlFile));
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
コード例 #23
0
ファイル: Main.java プロジェクト: damacode/MyTumblr
 private static boolean handleURL(String address) {
   Main.status(String.format("Processing page \"%s\".", address));
   try {
     NodeList posts = getPosts(address);
     if (posts.toNodeArray().length == 0) {
       return false;
     }
     for (Node post_node : posts.toNodeArray()) {
       if (post_node instanceof TagNode) {
         TagNode post = (TagNode) post_node;
         Post new_post = new Post(Long.parseLong(post.getAttribute("id").substring(5)));
         if (!Main.post_post_hash.containsKey(new_post)) {
           NodeList photo_posts = getPhotoPosts(post.getChildren());
           NodeList remarks = getRemarks(photo_posts);
           for (Node node : remarks.toNodeArray()) {
             Matcher matcher = lores.matcher(node.getText());
             String media_url = "";
             if (matcher.find()) {
               media_url = matcher.group();
               media_url = media_url.substring(17, media_url.length() - 1);
             }
             String thumb =
                 media_url.replace(
                     media_url.substring(media_url.lastIndexOf("_"), media_url.lastIndexOf(".")),
                     "_75sq");
             URL thumb_url = new URL(thumb);
             new_post.pictures.add(new Picture(new URL(media_url), thumb_url));
           }
           NodeList photoset_posts = getPhotosetPosts(post.getChildren());
           NodeList iframes = getIFrames(photoset_posts);
           for (Node node : iframes.toNodeArray()) {
             if (node instanceof TagNode) {
               String iframe_url = ((TagNode) node).getAttribute("src");
               Parser parser2 = new Parser(iframe_url);
               NodeList a_list = parser2.extractAllNodesThatMatch(new TagNameFilter("a"));
               Node[] a_array = a_list.toNodeArray();
               Node[] img_array =
                   a_list.extractAllNodesThatMatch(new TagNameFilter("img"), true).toNodeArray();
               String media_url;
               for (int i = 0; i < a_array.length; i++) {
                 media_url = ((TagNode) img_array[i]).getAttribute("src");
                 String thumb =
                     media_url.replace(
                         media_url.substring(
                             media_url.lastIndexOf("_"), media_url.lastIndexOf(".")),
                         "_75sq");
                 URL thumb_url = new URL(thumb);
                 new_post.pictures.add(new Picture(new URL(media_url), thumb_url));
               }
             }
           }
           Main.handlePost(new_post);
         } else {
           new_post = post_post_hash.get(new_post);
           handleNonDownloadPost(new_post);
         }
       }
     }
   } catch (Exception ex) {
     ex.printStackTrace();
     Main.status("Error handling post.");
   }
   return true;
 }
コード例 #24
0
  @Override
  public HashSet<ScoredAnnotation> solveSa2W(String text) throws AnnotationException {
    HashSet<ScoredAnnotation> res;
    try {
      res = new HashSet<ScoredAnnotation>();
      lastTime = Calendar.getInstance().getTimeInMillis();

      URL wikiApi = new URL(url);
      String parameters =
          "references=true&repeatMode=all&minProbability=0.0&source="
              + URLEncoder.encode(text, "UTF-8");
      HttpURLConnection slConnection = (HttpURLConnection) wikiApi.openConnection();
      slConnection.setRequestProperty("accept", "text/xml");
      slConnection.setDoOutput(true);
      slConnection.setDoInput(true);
      slConnection.setRequestMethod("POST");
      slConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      slConnection.setRequestProperty("charset", "utf-8");
      slConnection.setRequestProperty(
          "Content-Length", "" + Integer.toString(parameters.getBytes().length));
      slConnection.setUseCaches(false);

      DataOutputStream wr = new DataOutputStream(slConnection.getOutputStream());
      wr.writeBytes(parameters);
      wr.flush();
      wr.close();
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse(slConnection.getInputStream());

      /*			URL wikiApi = new URL(url+"?references=true&repeatMode=all&minProbability=0.0&source="+URLEncoder.encode(text, "UTF-8"));
      			URLConnection wikiConnection = wikiApi.openConnection();
      			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      			DocumentBuilder builder = factory.newDocumentBuilder();
      			Document doc = builder.parse(wikiConnection.getInputStream());
      */

      lastTime = Calendar.getInstance().getTimeInMillis() - lastTime;

      XPathFactory xPathfactory = XPathFactory.newInstance();
      XPath xpath = xPathfactory.newXPath();
      XPathExpression idExpr = xpath.compile("//detectedTopic/@id");
      XPathExpression weightExpr = xpath.compile("//detectedTopic/@weight");
      XPathExpression referenceExpr = xpath.compile("//detectedTopic/references");

      NodeList ids = (NodeList) idExpr.evaluate(doc, XPathConstants.NODESET);
      NodeList weights = (NodeList) weightExpr.evaluate(doc, XPathConstants.NODESET);
      NodeList references = (NodeList) referenceExpr.evaluate(doc, XPathConstants.NODESET);

      for (int i = 0; i < weights.getLength(); i++) {
        if (weights.item(i).getNodeType() != Node.TEXT_NODE) {
          int id = Integer.parseInt(ids.item(i).getNodeValue());
          float weight = Float.parseFloat(weights.item(i).getNodeValue());
          //					System.out.println("ID="+ids.item(i).getNodeValue()+" weight="+weight);
          XPathExpression startExpr =
              xpath.compile("//detectedTopic[@id=" + id + "]/references/reference/@start");
          XPathExpression endExpr =
              xpath.compile("//detectedTopic[@id=" + id + "]/references/reference/@end");
          NodeList starts =
              (NodeList) startExpr.evaluate(references.item(i), XPathConstants.NODESET);
          NodeList ends = (NodeList) endExpr.evaluate(references.item(i), XPathConstants.NODESET);
          for (int j = 0; j < starts.getLength(); j++) {
            int start = Integer.parseInt(starts.item(j).getNodeValue());
            int end = Integer.parseInt(ends.item(j).getNodeValue());
            int len = end - start;
            res.add(new ScoredAnnotation(start, len, id, weight));
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new AnnotationException(
          "An error occurred while querying Wikipedia Miner API. Message: " + e.getMessage());
    }
    return res;
  }