public void startElement(QName element, XMLAttributes attrs, Augmentations augs)
     throws XNIException {
   if (this.baseUrl != null) {
     try {
       int attrCount = attrs != null ? attrs.getLength() : 0;
       for (int i = 0; i < attrCount; i++) {
         String aname = attrs.getQName(i);
         /** update by jiangjun 2011-5-24 补全file的相对地址 */
         if (aname.matches("href|src|action|lsrc|real_src|dynamic-src|file")) {
           String avalue = attrs.getValue(i);
           if (null != avalue & !"".equals(avalue) & avalue.indexOf("javascript:") < 0) {
             attrs.setValue(i, UrlUtil.guessURL(baseUrl, avalue));
           }
         }
       }
     } catch (MalformedURLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
   String depth = String.valueOf(fElementDepth);
   attrs.addAttribute(
       new QName(element.localpart, DEPTH_NAME, DEPTH_NAME, element.uri), "String", depth);
   if (baseUrl != null
       && baseUrl.toString().indexOf("app.wumii.com") == -1
       && STYLE.equalsIgnoreCase(element.rawname)) {
     if (attrs.getValue("media") != null && !"screen".equalsIgnoreCase(attrs.getValue("media"))) {
       notCollectCss = 1;
     }
     styleBuffer = new StringBuffer();
   } else {
     super.startElement(element, attrs, augs);
     fElementDepth++;
   }
 }
  public void characters(XMLString text, Augmentations augs) throws XNIException {

    if (styleBuffer != null && notCollectCss == 0) {
      styleBuffer.append(text.ch, text.offset, text.length);
      return;
    }
    if (notCollectCss != 1) {
      super.characters(text, augs);
    }
  }
  @Override
  public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
      throws XNIException {
    if ("base".equalsIgnoreCase(element.rawname)) {
      String hrefValue = attributes.getValue("href");
      if (hrefValue != null) {
        try {
          this.baseUrl = new URL(hrefValue);
        } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    } else if (this.baseUrl != null) {
      try {
        int attrCount = attributes != null ? attributes.getLength() : 0;
        for (int i = 0; i < attrCount; i++) {
          String aname = attributes.getQName(i);
          /** update by jiangjun 2011-5-24 补全file的相对地址 */
          if (aname.matches("href|src|action|lsrc|real_src|dynamic-src|file")) {
            String avalue = attributes.getValue(i);
            if (null != avalue & !"".equals(avalue) & avalue.indexOf("javascript:") < 0) {
              // 朱磊改,例如:http://www.qiushibaike.net/页面中图片相对地址为
              // ../../aaa.jpg 目前已经是根目录了,上一级不存在
              if (avalue.indexOf(baseUrl.getHost()) == -1 && avalue.startsWith("..")) {
                avalue = avalue.substring(avalue.lastIndexOf("../") + 3);
              }

              attributes.setValue(i, UrlUtil.guessURL(baseUrl, avalue));
            }
          }
        }
      } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    if ("link".equalsIgnoreCase(element.rawname)) {
      String typeValue = attributes.getValue("type");
      if (typeValue != null) {
        if (typeValue.indexOf("css") >= 0) {
          return;
        }
      } else {
        return;
      }
    }
    if (delMark == 1) {
      delMark = 0;
      return;
    }
    String depth = String.valueOf(fElementDepth);
    attributes.addAttribute(new QName(null, DEPTH_NAME, DEPTH_NAME, null), "String", depth);
    super.emptyElement(element, attributes, augs);
  }
 public void endElement(QName element, Augmentations augs) throws XNIException {
   try {
     if (STYLE.equalsIgnoreCase(element.rawname) && styleBuffer != null) {
       styleList.add(styleBuffer);
       return;
     }
     notCollectCss = 0;
     super.endElement(element, augs);
     fElementDepth--;
   } catch (Exception e) {
     // TODO: handle exception
   } finally {
     styleBuffer = null;
   }
 }
示例#5
0
 public void startElement(QName element, XMLAttributes attrs, Augmentations augs)
     throws XNIException {
   if (element.rawname.equalsIgnoreCase("script") && attrs != null) {
     String value = attrs.getValue("type");
     if (value != null && value.equalsIgnoreCase(SCRIPT_TYPE)) {
       String src = attrs.getValue("src");
       if (src != null && src.indexOf("/dojo/dojo.js") != -1) {
         scriptURL = src;
         scriptURLPrefix = scriptURL.substring(0, scriptURL.indexOf("/dojo/dojo.js"));
         dojoLoaderPath = scriptURL.substring(0, scriptURL.lastIndexOf('/') + 1);
         configScriptTag = configScriptTag.replace("__URLPREFIX__", scriptURLPrefix);
       }
     }
   }
   super.startElement(element, attrs, augs);
 }
示例#6
0
 public void startDocument(XMLLocator locator, String encoding, Augmentations augs)
     throws XNIException {
   super.startDocument(locator, encoding, augs);
 }
 /** Start document. */
 public void startDocument(
     XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs)
     throws XNIException {
   fElementDepth = 0;
   super.startDocument(locator, encoding, nscontext, augs);
 }