Package org.htmlparser.tags

Examples of org.htmlparser.tags.ImageTag


      Node[] images = parser.extractAllNodesThatMatch(HtmlNodeFilters.imageFilter).toNodeArray();
      for(int i=0;images!=null&&i<images.length;i++){
        int start_pos = images[i].getStartPosition();
        content.append(desc.substring(last_pos, start_pos));
        last_pos = images[i].getEndPosition();
        ImageTag img = (ImageTag)images[i];
        String img_url = img.getImageURL();
        if(!img_url.startsWith("http://")&&!img_url.startsWith("https://")){       
          if(img_url.startsWith("/")){
            int idx = link.indexOf("/", 7);
            img.setImageURL(link.substring(0, idx) + img_url);
          }
          else{
            int idx = link.lastIndexOf('/');
            img.setImageURL(link.substring(0, idx) + '/' + img_url);
          }
        }
        content.append(img.toHtml());
        //System.out.println(img.getImageURL());
      }
    }catch(Exception e){}
    content.append(desc.substring(last_pos));
    return content.toString();
View Full Code Here


                  Parser parser = new Parser();
                  parser.setInputHTML(new String(mailContent.getBytes(), ISO8859_1));
                    //Parser parser = Parser.createParser(new String(mailContent.getBytes(), ISO8859_1));
                    Node[] images = parser.extractAllNodesThatMatch(HtmlNodeFilters.imageFilter).toNodeArray();
                    for(int i=0;i<images.length;i++) {
                        ImageTag imgTag = (ImageTag) images[i];
                        if(!imgTag.getImageURL().toLowerCase().startsWith("http://"))
                            arrayList1.add(imgTag.getImageURL());
                    }
                } catch (UnsupportedEncodingException e1) {
                } catch (ParserException e) {}
                String afterReplaceStr = mailContent;
                //��html�ļ�����"cid:"+Content-ID���滻ԭ����ͼƬ����
View Full Code Here

    int nImgs = oCollectionList.size();

    if (DebugFile.trace) DebugFile.writeln("Images NodeList.size() = " + String.valueOf(nImgs));

    for (int i=0; i<nImgs; i++) {
    ImageTag oImgTag = (ImageTag) oCollectionList.elementAt(i);
     
        sSrc = oImgTag.extractImageLocn().replace('\\','/');
   
    if (DebugFile.trace) DebugFile.writeln("Processing image location "+sSrc);
   
        // Keep a reference to every related image name so that the same image is not included twice in the message
        if (!oImgs.containsKey(sSrc)) {

          // Find last slash from image url
          iSlash = sSrc.lastIndexOf('/');
     
          // Take image name
          if (iSlash>=0) {
            while (sSrc.charAt(iSlash)=='/') { if (++iSlash==sSrc.length()) break; }
              sCid = sSrc.substring(iSlash);
          }
          else {
            sCid = sSrc;
          }
          if (DebugFile.trace) DebugFile.writeln("HashMap.put("+sSrc+","+sCid+")");

          oImgs.put(sSrc, sCid);
        } // fi (!oImgs.containsKey(sSrc))
       
        sBodyCid = doSubstitution (sBodyCid, "Src", Gadgets.replace(Gadgets.replace(oImgTag.extractImageLocn(),'\\',"\\\\"),'.',"\\x2E"), sPreffix+oImgs.get(sSrc));
    } // next

  // **********************************************************************
  // Replace <TABLE BACKGROUND="..." >
   
View Full Code Here

    Pattern oPattern;
    String sTag, sCid;
    int iSlash;

    if (oNode instanceof ImageTag) {
      ImageTag oImgNode = (ImageTag) oNode;
      String sSrc = oImgNode.extractImageLocn();

      try {
        oPattern = oCompiler.compile(sSrc);
      } catch (MalformedPatternException neverthrown) {
        if (DebugFile.trace) DebugFile.writeln("MalformedPatternException "+sSrc);
        oPattern=null;
      }

      iSlash = sSrc.lastIndexOf('/');
      if (iSlash>=0) {
        while (sSrc.charAt(iSlash)=='/') { if (++iSlash==sSrc.length()) break; }
        sCid = sSrc.substring(iSlash);
      } else {
        sCid = sSrc;
      } // fi
   
      if (!oDocumentImages.containsKey(sCid)) {

       if (DebugFile.trace) DebugFile.writeln("HashMap.put(" + sSrc + "," + sCid + ")");

        oDocumentImages.put(sCid, sSrc);
      } // fi (oDocumentImages.containsKey(sCid))

    sTag = oImgNode.toHtml(true);

    if (DebugFile.trace) DebugFile.writeln("Util.substitute([Perl5Matcher], "+oPattern.getPattern()+", new Perl5Substitution(cid:"+oDocumentImages.get(sCid)+", Perl5Substitution.INTERPOLATE_ALL)"+", "+sTag+ ", Util.SUBSTITUTE_ALL)");

    oBuffer.append(Util.substitute(oMatcher, oPattern,
                                   new Perl5Substitution("cid:"+sCid,
View Full Code Here

                    }
                } catch (MalformedURLException e1) {
                    throw new HTMLParseException(e1);
                }
            } else if (tag instanceof ImageTag) {
                ImageTag image = (ImageTag) tag;
                binUrlStr = image.getImageURL();
            } else if (tag instanceof AppletTag) {
                // look for applets

                // This will only work with an Applet .class file.
                // Ideally, this should be upgraded to work with Objects (IE)
                // and archives (.jar and .zip) files as well.
                AppletTag applet = (AppletTag) tag;
                binUrlStr = applet.getAppletClass();
            } else if (tag instanceof InputTag) {
                // we check the input tag type for image
                if (ATT_IS_IMAGE.equalsIgnoreCase(tag.getAttribute(ATT_TYPE))) {
                    // then we need to download the binary
                    binUrlStr = tag.getAttribute(ATT_SRC);
                }
            } else if (tag instanceof LinkTag) {
                LinkTag link = (LinkTag) tag;
                if (link.getChild(0) instanceof ImageTag) {
                    ImageTag img = (ImageTag) link.getChild(0);
                    binUrlStr = img.getImageURL();
                }
            } else if (tag instanceof ScriptTag) {
                binUrlStr = tag.getAttribute(ATT_SRC);
                // Bug 51750
            } else if (tag instanceof FrameTag || tagname.equalsIgnoreCase(TAG_IFRAME)) {
View Full Code Here

                        throw new HTMLParseException(e1);
                    }
                }
                else if (node instanceof ImageTag)
                {
                    ImageTag image= (ImageTag)node;
                    binUrlStr= image.getImageURL();
                }
                else if (node instanceof AppletTag)
                {
                    AppletTag applet= (AppletTag)node;
                    binUrlStr= applet.getAppletClass();
                }
                else if (node instanceof InputTag)
                {
                    InputTag input= (InputTag)node;
                    // we check the input tag type for image
                    String strType= input.getAttribute("type");
                    if (strType != null && strType.equalsIgnoreCase("image"))
                    {
                        // then we need to download the binary
                        binUrlStr= input.getAttribute("src");
                    }
        } else if (node instanceof LinkTag){
          LinkTag link = (LinkTag)node;
          if (link.getChild(0) instanceof ImageTag){
            ImageTag img = (ImageTag)link.getChild(0);
            binUrlStr = img.getImageURL();
          }
        } else if (node instanceof ScriptTag){
          ScriptTag script = (ScriptTag)node;
          binUrlStr = script.getAttribute("src");
        } else if (node instanceof LinkTagTag){
View Full Code Here

        assertTrue(
            "Second data node shouls be a String Node",
            dataNode[1] instanceof StringNode);

        // Check the contents of each data node
        ImageTag imageTag = (ImageTag) dataNode[0];
        assertEquals(
            "Image URL",
            "http://www.yahoo.com/abcd.jpg",
            imageTag.getImageURL());
        StringNode stringNode = (StringNode) dataNode[1];
        assertEquals("String Contents", "Hello World", stringNode.getText());
    }
View Full Code Here

        }
        assertEquals("There should be 5 contained nodes in the link tag", 5, i);
        assertTrue(
            "First contained node should be an image tag",
            containedNodes[0] instanceof ImageTag);
        ImageTag imageTag = (ImageTag) containedNodes[0];
        assertEquals(
            "Image Location",
            "http://ad.abcnews.com/ad/sponsors/buena_vista_pictures/bvpi-ban0003.gif",
            imageTag.getImageURL());
        assertEquals("Image Height", "60", imageTag.getAttribute("HEIGHT"));
        assertEquals("Image Width", "468", imageTag.getAttribute("WIDTH"));
        assertEquals("Image Border", "0", imageTag.getAttribute("BORDER"));
        assertEquals(
            "Image Alt",
            "See Signs in Theaters 8-2 - Starring Mel Gibson",
            imageTag.getAttribute("ALT"));
        assertTrue(
            "Second contained node should be Tag",
            containedNodes[1] instanceof Tag);
        Tag tag1 = (Tag) containedNodes[1];
        assertEquals(
View Full Code Here

        {
            insideNodes[j++] = (Node) e.nextNode();
        }
        assertEquals("Number of contained internal nodes", 1, j);
        assertTrue(insideNodes[0] instanceof ImageTag);
        ImageTag imageTag = (ImageTag) insideNodes[0];
        assertEquals(
            "Image Tag Location",
            "http://www.fedpage.com/images\\register.gif",
            imageTag.getImageURL());
    }
View Full Code Here

    protected Tag createTag(TagData tagData, Tag tag, String url)
        throws ParserException
    {
        String link = extractImageLocn(tag, url);
        return new ImageTag(tagData, link);
    }
View Full Code Here

TOP

Related Classes of org.htmlparser.tags.ImageTag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.