Beispiel #1
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);
 }
Beispiel #2
0
 public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
     throws SAXException {
   try {
     if (!pushedContext) namespaceContext.pushContext();
     else pushedContext = false;
     for (int i = 0, len = atts.getLength(); i < len; i++)
       attributes.addAttribute(
           makeQName(atts.getURI(i), atts.getLocalName(i), atts.getQName(i)),
           symbolTable.addSymbol(atts.getType(i)),
           atts.getValue(i));
     schemaValidator.startElement(makeQName(namespaceURI, localName, qName), attributes, null);
     attributes.removeAllAttributes();
   } catch (XNIException e) {
     throw toSAXException(e);
   }
 }
 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++;
   }
 }
Beispiel #4
0
 protected void printStartElement(QName element, XMLAttributes attrs) 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.equals(scriptURL)) {
         attrs.setValue(attrs.getIndex("src"), zazlPath);
         String dojoDataConfigStr = attrs.getValue(attrs.getIndex("data-dojo-config"));
         configScriptTag =
             configScriptTag.replace("__DOJOCONFIG__", "{" + dojoDataConfigStr + "}");
         attrs.removeAttributeAt(attrs.getIndex("data-dojo-config"));
         Matcher m = packagesRegex.matcher(dojoDataConfigStr);
         if (m.find()) {
           String packagesString = m.group(0);
           if (packagesString != null) {
             StringBuffer sb = new StringBuffer();
             try {
               Map<String, Object> packages =
                   (Map<String, Object>)
                       JSONParser.parse(new StringReader('{' + packagesString + '}'));
               List<Map<String, Object>> packageList =
                   (List<Map<String, Object>>) packages.get("packages");
               for (Map<String, Object> pkg : packageList) {
                 String name = (String) pkg.get("name");
                 if (name.equals("zazl")) {
                   continue;
                 }
                 String location = (String) pkg.get("location");
                 location = normalize(dojoLoaderPath + location);
                 sb.append("		'");
                 sb.append(name);
                 sb.append("' : '");
                 sb.append(location);
                 sb.append("',\n");
               }
               sb.deleteCharAt(sb.length() - 1);
               sb.deleteCharAt(sb.length() - 1);
               configScriptTag = configScriptTag.replace("__PATHS__", sb.toString());
             } catch (IOException e) {
               e.printStackTrace();
             }
           }
         }
       }
       super.printStartElement(element, attrs);
     } else {
       super.printStartElement(element, attrs);
     }
   } else {
     super.printStartElement(element, attrs);
   }
 }
 protected void scanAttribute(XMLAttributes paramXMLAttributes) throws IOException, XNIException {
   if (this.fNamespaces) {
     this.fEntityScanner.scanQName(this.fAttributeQName);
   } else {
     String str = this.fEntityScanner.scanName();
     this.fAttributeQName.setValues(null, str, str, null);
   }
   this.fEntityScanner.skipSpaces();
   if (!this.fEntityScanner.skipChar(61)) {
     reportFatalError(
         "EqRequiredInAttribute",
         new Object[] {this.fCurrentElement.rawname, this.fAttributeQName.rawname});
   }
   this.fEntityScanner.skipSpaces();
   int i = paramXMLAttributes.getLength();
   int j = paramXMLAttributes.addAttribute(this.fAttributeQName, XMLSymbols.fCDATASymbol, null);
   if (i == paramXMLAttributes.getLength()) {
     reportFatalError(
         "AttributeNotUnique",
         new Object[] {this.fCurrentElement.rawname, this.fAttributeQName.rawname});
   }
   boolean bool =
       scanAttributeValue(
           this.fTempString,
           this.fTempString2,
           this.fAttributeQName.rawname,
           this.fIsEntityDeclaredVC,
           this.fCurrentElement.rawname);
   paramXMLAttributes.setValue(j, this.fTempString.toString());
   if (!bool) {
     paramXMLAttributes.setNonNormalizedValue(j, this.fTempString2.toString());
   }
   paramXMLAttributes.setSpecified(j, true);
 }
  @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);
  }
  /** Binds namespaces. */
  protected void bindNamespaces(QName element, XMLAttributes attrs) {

    // split element qname
    splitQName(element);

    // declare namespace prefixes
    int attrCount = attrs != null ? attrs.getLength() : 0;
    for (int i = attrCount - 1; i >= 0; i--) {
      attrs.getName(i, fQName);
      String aname = fQName.rawname;
      String ANAME = aname.toUpperCase();
      if (ANAME.startsWith("XMLNS:") || ANAME.equals("XMLNS")) {
        int anamelen = aname.length();

        // get parts
        String aprefix = anamelen > 5 ? aname.substring(0, 5) : null;
        String alocal = anamelen > 5 ? aname.substring(6) : aname;
        String avalue = attrs.getValue(i);

        // re-case parts and set them back into attributes
        if (anamelen > 5) {
          aprefix = modifyName(aprefix, NAMES_LOWERCASE);
          alocal = modifyName(alocal, fNamesElems);
          aname = aprefix + ':' + alocal;
        } else {
          alocal = modifyName(alocal, NAMES_LOWERCASE);
          aname = alocal;
        }
        fQName.setValues(aprefix, alocal, aname, null);
        attrs.setName(i, fQName);

        // declare prefix
        String prefix = alocal != aname ? alocal : "";
        String uri = avalue.length() > 0 ? avalue : null;
        if (fOverrideNamespaces
            && prefix.equals(element.prefix)
            && HTMLElements.getElement(element.localpart, null) != null) {
          uri = fNamespacesURI;
        }
        fNamespaceContext.declarePrefix(prefix, uri);
      }
    }

    // bind element
    String prefix = element.prefix != null ? element.prefix : "";
    element.uri = fNamespaceContext.getURI(prefix);
    // REVISIT: The prefix of a qualified element name that is
    // bound to a namespace is passed (as recent as
    // Xerces 2.4.0) as "" for start elements and null
    // for end elements. Why? One of them is a bug,
    // clearly. -Ac
    if (element.uri != null && element.prefix == null) {
      element.prefix = "";
    }

    // do we need to insert namespace bindings?
    if (fInsertNamespaces
        && attrs != null
        && HTMLElements.getElement(element.localpart, null) != null) {
      if (element.prefix == null || fNamespaceContext.getURI(element.prefix) == null) {
        String xmlns = "xmlns" + ((element.prefix != null) ? ":" + element.prefix : "");
        fQName.setValues(null, xmlns, xmlns, null);
        attrs.addAttribute(fQName, "CDATA", fNamespacesURI);
        bindNamespaces(element, attrs);
        return;
      }
    }

    // bind attributes
    attrCount = attrs != null ? attrs.getLength() : 0;
    for (int i = 0; i < attrCount; i++) {
      attrs.getName(i, fQName);
      splitQName(fQName);
      prefix =
          !fQName.rawname.equals("xmlns") ? (fQName.prefix != null ? fQName.prefix : "") : "xmlns";
      // PATCH: Joseph Walton
      if (!prefix.equals("")) {
        fQName.uri = prefix.equals("xml") ? XML_URI : fNamespaceContext.getURI(prefix);
      }
      // NOTE: You would think the xmlns namespace would be handled
      // by NamespaceSupport but it's not. -Ac
      if (prefix.equals("xmlns") && fQName.uri == null) {
        fQName.uri = XMLNS_URI;
      }
      attrs.setName(i, fQName);
    }
  } // bindNamespaces(QName,XMLAttributes)