コード例 #1
0
  /** If the LINK refers to a stylesheet document, this method loads and parses it. */
  protected void processLink() {
    this.styleSheet = null;
    String rel = this.getAttribute(HtmlAttributeProperties.REL);
    if (rel != null) {
      String cleanRel = rel.trim().toLowerCase();
      boolean isStyleSheet = cleanRel.equals("stylesheet");
      boolean isAltStyleSheet = cleanRel.equals("alternate stylesheet");
      boolean isAppendixStyleSheet = cleanRel.equals("appendix stylesheet");
      if (isStyleSheet || isAltStyleSheet || isAppendixStyleSheet) {
        UserAgentContext uacontext = this.getUserAgentContext();
        if (uacontext.isExternalCSSEnabled()) {
          String media = this.getMedia();
          if (CSSUtilities.matchesMedia(media, uacontext)) {
            HTMLDocumentImpl doc = (HTMLDocumentImpl) this.getOwnerDocument();
            try {

              CSSStyleSheet sheet = CSSUtilities.parse(this.getHref(), doc);
              CSSStyleSheetImpl sheetImpl = null;
              if (sheet != null) {
                doc.addStyleSheet(sheet);
                this.styleSheet = sheet;
                if (sheet instanceof CSSStyleSheetImpl) {
                  sheetImpl = (CSSStyleSheetImpl) sheet;
                  if (isAltStyleSheet) {
                    sheetImpl.setDisabled(true);
                  } else {
                    sheetImpl.setDisabled(disabled);
                  }

                  URL baseURL = new URL(doc.getBaseURI());
                  URL scriptURL = Urls.createURL(baseURL, getHref());
                  if (scriptURL != null) sheetImpl.setHref(scriptURL.toString());
                  doc.addStyleSheet(sheetImpl);
                } else {
                  if (isAltStyleSheet) {
                    sheet.setDisabled(true);
                  } else {
                    sheet.setDisabled(this.disabled);
                  }
                  doc.addStyleSheet(sheet);
                }
              }

            } catch (MalformedURLException mfe) {
              this.warn(
                  "Will not parse CSS. URI=["
                      + this.getHref()
                      + "] with BaseURI=["
                      + doc.getBaseURI()
                      + "] does not appear to be a valid URI.");
            } catch (Throwable err) {
              this.warn("Unable to parse CSS. URI=[" + this.getHref() + "].", err);
            }
          }
        }
      }
    }
  }
コード例 #2
0
ファイル: CSSOMParser.java プロジェクト: rolfdeboer/navajo
    public void startDocument(InputSource source) throws CSSException {
      if (_nodeStack.empty()) {
        CSSStyleSheetImpl ss = new CSSStyleSheetImpl();
        _parentStyleSheet = ss;

        // Create the rule list
        CSSRuleListImpl rules = new CSSRuleListImpl();
        ss.setRuleList(rules);
        _nodeStack.push(ss);
        _nodeStack.push(rules);
      } else {
        // Error
      }
    }