2 * This file is part of the XSL implementation.
4 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #include "XSLImportRule.h"
27 #include "CachedXSLStyleSheet.h"
28 #include "CachedResourceLoader.h"
30 #include "XSLStyleSheet.h"
34 XSLImportRule::XSLImportRule(XSLStyleSheet* parent, const String& href)
42 XSLImportRule::~XSLImportRule()
45 m_styleSheet->setParent(0);
48 m_cachedSheet->removeClient(this);
51 XSLStyleSheet* XSLImportRule::parentStyleSheet() const
53 return (parent() && parent()->isXSLStyleSheet()) ? static_cast<XSLStyleSheet*>(parent()) : 0;
56 void XSLImportRule::setXSLStyleSheet(const String& href, const KURL& baseURL, const String& sheet)
59 m_styleSheet->setParent(0);
61 m_styleSheet = XSLStyleSheet::create(this, href, baseURL);
63 XSLStyleSheet* parent = parentStyleSheet();
65 m_styleSheet->setParentStyleSheet(parent);
67 m_styleSheet->parseString(sheet);
71 parent->checkLoaded();
74 bool XSLImportRule::isLoading()
76 return (m_loading || (m_styleSheet && m_styleSheet->isLoading()));
79 void XSLImportRule::loadSheet()
81 CachedResourceLoader* cachedResourceLoader = 0;
82 StyleBase* root = this;
84 while ((parent = root->parent()))
86 if (root->isXSLStyleSheet())
87 cachedResourceLoader = static_cast<XSLStyleSheet*>(root)->cachedResourceLoader();
89 String absHref = m_strHref;
90 XSLStyleSheet* parentSheet = parentStyleSheet();
91 if (!parentSheet->finalURL().isNull())
92 // use parent styleheet's URL as the base URL
93 absHref = KURL(parentSheet->finalURL(), m_strHref).string();
95 // Check for a cycle in our import chain. If we encounter a stylesheet
96 // in our parent chain with the same URL, then just bail.
97 for (parent = this->parent(); parent; parent = parent->parent()) {
98 if (parent->isXSLStyleSheet() && absHref == static_cast<XSLStyleSheet*>(parent)->finalURL().string())
102 ResourceRequest request(cachedResourceLoader->document()->completeURL(absHref));
103 m_cachedSheet = cachedResourceLoader->requestXSLStyleSheet(request);
106 m_cachedSheet->addClient(this);
108 // If the imported sheet is in the cache, then setXSLStyleSheet gets called,
109 // and the sheet even gets parsed (via parseString). In this case we have
110 // loaded (even if our subresources haven't), so if we have a stylesheet after
111 // checking the cache, then we've clearly loaded.
117 } // namespace WebCore
119 #endif // ENABLE(XSLT)