示例#1
0
 private NodeImpl getFrameSet(final NodeImpl node) {
   final NodeImpl[] children = node.getChildrenArray();
   if (children == null) {
     return null;
   }
   final int length = children.length;
   NodeImpl frameSet = null;
   for (int i = 0; i < length; i++) {
     final NodeImpl child = children[i];
     if (child instanceof Text) {
       // Ignore
     } else if (child instanceof ElementImpl) {
       final String tagName = child.getNodeName();
       if ("HEAD".equalsIgnoreCase(tagName)
           || "NOFRAMES".equalsIgnoreCase(tagName)
           || "TITLE".equalsIgnoreCase(tagName)
           || "META".equalsIgnoreCase(tagName)
           || "SCRIPT".equalsIgnoreCase(tagName)
           || "NOSCRIPT".equalsIgnoreCase(tagName)) {
         // ignore it
       } else if ("FRAMESET".equalsIgnoreCase(tagName)) {
         frameSet = child;
         break;
       } else {
         if (this.hasSomeHtml((ElementImpl) child)) {
           return null;
         }
       }
     }
   }
   return frameSet;
 }
  public void ___testGetFonts() {
    NRC_HTMLDocumentByCobra doc = null;
    try {
      doc = new NRC_HTMLDocumentByCobra("http://localhost/tests/testfonts.html");
      HTMLDocumentImpl document = doc.getDocument();
      doc.close();
      NodeImpl el = (NodeImpl) document.getElementById("tnunacom");
      el = (NodeImpl) el.getFirstChild();
      String fs[] = NRC_HTMLDocumentByCobra.getFonts(el);
      String fsS = Arrays.toString(fs);
      assertEquals(
          "Les polices retournées ne correspondent pas aux polices escomptées",
          "[nunacom, Verdana, Arial, Helvetica, sans-serif]",
          fsS);

      el = (NodeImpl) document.getElementById("tnaamajut");
      el = (NodeImpl) el.getFirstChild();
      fs = NRC_HTMLDocumentByCobra.getFonts(el);
      fsS = Arrays.toString(fs);
      assertEquals(
          "Les polices retournées ne correspondent pas aux polices escomptées",
          "[Naamajut, Verdana, Arial, Helvetica, sans-serif]",
          fsS);

      el = (NodeImpl) document.getElementById("ttimes");
      el = (NodeImpl) el.getFirstChild();
      fs = NRC_HTMLDocumentByCobra.getFonts(el);
      fsS = Arrays.toString(fs);
      assertEquals(
          "Les polices retournées ne correspondent pas aux polices escomptées",
          "[Times New Roman, Helvetica]",
          fsS);

      el = (NodeImpl) document.getElementById("tgeorgia");
      el = (NodeImpl) el.getFirstChild();
      fs = NRC_HTMLDocumentByCobra.getFonts(el);
      fsS = Arrays.toString(fs);
      assertEquals(
          "Les polices retournées ne correspondent pas aux polices escomptées", "[georgia]", fsS);

      el = (NodeImpl) document.getElementById("tprosyl");
      el = (NodeImpl) el.getFirstChild();
      fs = NRC_HTMLDocumentByCobra.getFonts(el);
      fsS = Arrays.toString(fs);
      assertEquals(
          "Les polices retournées ne correspondent pas aux polices escomptées",
          "[PROSYL, Verdana, Arial, Helvetica, sans-serif]",
          fsS);

    } catch (Exception e) {
      e.printStackTrace();
      if (doc != null) doc.close();
      fail();
    }
  }