ASF Bugzilla – Attachment 20268 Details for
Bug 42050
proxying does not work
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
version 3 fixing error when no proxy config is used
all-in-one.diff (text/plain), 29.29 KB, created by
Thorsten Scherler
on 2007-05-24 05:52:06 UTC
(
hide
)
Description:
version 3 fixing error when no proxy config is used
Filename:
MIME Type:
Creator:
Thorsten Scherler
Created:
2007-05-24 05:52:06 UTC
Size:
29.29 KB
patch
obsolete
>Index: src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java >=================================================================== >--- src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java (revision 540982) >+++ src/impl/java/org/apache/lenya/cms/publication/PublicationConfiguration.java (working copy) >@@ -83,6 +83,7 @@ > private static final String ELEMENT_CONTENT_DIR = "content-dir"; > private static final String ATTRIBUTE_SRC = "src"; > private static final String ELEMENT_PROXIES = "proxies"; >+ private static final String ATTRIBUTE_ROOT = "root"; > private static final String ELEMENT_PROXY = "proxy"; > private static final String ATTRIBUTE_AREA = "area"; > private static final String ATTRIBUTE_URL = "url"; >@@ -179,6 +180,16 @@ > > Configuration proxyConfig = config.getChild(ELEMENT_PROXIES); > if (proxyConfig != null) { >+ // root/global proxy >+ String urlRoot=proxyConfig.getAttribute(ATTRIBUTE_ROOT,null); >+ String sslRoot = proxyConfig.getAttribute(ATTRIBUTE_SSL,null); >+ if (urlRoot!=null & sslRoot!=null){ >+ Proxy rootProxy = new Proxy(); >+ rootProxy.setUrl(urlRoot); >+ Object rootKey = getProxyKey(ATTRIBUTE_ROOT, Boolean.valueOf(sslRoot).booleanValue()); >+ this.areaSsl2proxy.put(rootKey, rootProxy); >+ } >+ // Area proxies > Configuration[] proxyConfigs = proxyConfig.getChildren(ELEMENT_PROXY); > for (int i = 0; i < proxyConfigs.length; i++) { > String url = proxyConfigs[i].getAttribute(ATTRIBUTE_URL); >Index: src/modules/sitetree/sitemap.xmap >=================================================================== >--- src/modules/sitetree/sitemap.xmap (revision 540982) >+++ src/modules/sitetree/sitemap.xmap (working copy) >@@ -52,13 +52,12 @@ > <map:pipeline type="caching"> > > <!-- sitetree --> >- <!-- pattern: sitetree/{pub-id}/{area}/{default-language}/{language}/{url}.xml --> >+ <!-- pattern: sitetree/{pub-id}/{area}/{default-language}/{language}/{path}.xml --> > <map:match pattern="sitetree/*/*/*/*/**.xml"> > <map:generate src="lenya://lenya/pubs/{1}/content/{2}/sitetree.xml"/> > <map:transform src="fallback://lenya/modules/sitetree/xslt/navigation/sitetree2nav.xsl"> >- <map:parameter name="url" value="/{5}"/> >+ <map:parameter name="currentPath" value="/{5}"/> > <map:parameter name="area" value="{2}"/> >- <map:parameter name="root" value="{request:contextPath}/{1}/{2}/"/> > <map:parameter name="chosenlanguage" value="{4}"/> > <map:parameter name="defaultlanguage" value="{3}"/> > </map:transform> >Index: src/modules/sitetree/xslt/navigation/sitetree2nav.xsl >=================================================================== >--- src/modules/sitetree/xslt/navigation/sitetree2nav.xsl (revision 540982) >+++ src/modules/sitetree/xslt/navigation/sitetree2nav.xsl (working copy) >@@ -25,39 +25,11 @@ > xmlns:nav="http://apache.org/cocoon/lenya/navigation/1.0" > exclude-result-prefixes="tree"> > >- <xsl:param name="url"/> <!-- the links will be relative to this url (must start with slash)--> > <xsl:param name="chosenlanguage"/> > <xsl:param name="defaultlanguage"/> >+ <xsl:param name="currentPath"/> > >- <xsl:variable name="relative"> >- <xsl:choose> >- <xsl:when test="$url != '' and starts-with($url, '/')">true</xsl:when> >- <xsl:otherwise>false</xsl:otherwise> >- </xsl:choose> >- </xsl:variable> > >- <xsl:variable name="root"> >- <xsl:if test="$relative = 'true'"> >- <xsl:call-template name="create-path-to-context"> >- <xsl:with-param name="local-url" select="substring-after($url, '/')"/> >- </xsl:call-template> >- </xsl:if> >- </xsl:variable> >- >- <xsl:template name="create-path-to-context"> >- <xsl:param name="local-url"/> >- <xsl:if test="contains($local-url, '/')"> >- <xsl:variable name="tail" select="substring-after($local-url, '/')"/> >- <xsl:text>..</xsl:text> >- <xsl:if test="contains($tail, '/')"> >- <xsl:text>/</xsl:text> >- </xsl:if> >- <xsl:call-template name="create-path-to-context"> >- <xsl:with-param name="local-url" select="$tail"/> >- </xsl:call-template> >- </xsl:if> >- </xsl:template> >- > <xsl:template match="tree:fragment"> > <nav:fragment> > <xsl:copy-of select="@*"/> >@@ -76,12 +48,10 @@ > > > <xsl:template match="tree:site"> >- >- <nav:site url="{$root}{$url}" request-url="{$url}"> >+ <nav:site> > <xsl:copy-of select="@*"/> > <xsl:apply-templates/> > </nav:site> >- > </xsl:template> > > >@@ -109,8 +79,8 @@ > --> > <xsl:template match="tree:node[not(@visible = 'false')]"> > >- <!-- basic url of parent node --> >- <xsl:param name="previous-url" select="''"/> >+ <!-- base path of parent node --> >+ <xsl:param name="parentPath" select="''"/> > > <xsl:variable name="existinglanguage"> > <xsl:call-template name="resolve-existing-language"/> >@@ -124,70 +94,20 @@ > <xsl:copy-of select="@folder"/> > <xsl:copy-of select="@uuid"/> > >- <!-- basic url - for all nodes --> >+ <!-- base path - for all nodes --> > >- <xsl:variable name="basic-url"> >- <xsl:text/> >- <xsl:choose> >- <xsl:when test="@href"> >- <xsl:value-of select="@href"/> >- </xsl:when> >- <xsl:otherwise> >- <xsl:value-of select="concat($previous-url, '/', @id)"/> >- </xsl:otherwise> >- </xsl:choose> >- </xsl:variable> >+ <xsl:variable name="path" select="concat($parentPath, '/', @id)"/> > >- <xsl:variable name="language-suffix"> >- <xsl:text>_</xsl:text> >- <xsl:value-of select="$existinglanguage"/> >- </xsl:variable> >+ <!-- suffix - only when @href is not present --> > >- <xsl:variable name="canonical-language-suffix"> >- <xsl:choose> >- <xsl:when test="$existinglanguage != '' and $defaultlanguage != $existinglanguage"> >- <xsl:value-of select="$language-suffix"/> >- </xsl:when> >- <xsl:otherwise> >- <!-- no suffix for default language --></xsl:otherwise> >- </xsl:choose> >- </xsl:variable> >- >- <!-- suffix - only when @href is not present --> >- >- <xsl:variable name="suffix"> >- <xsl:if test="not(@href)"> >- <xsl:text>.</xsl:text> >- <xsl:choose> >- <xsl:when test="@suffix"> >- <xsl:value-of select="@suffix"/> >- </xsl:when> >- <xsl:otherwise> >- <xsl:text>html</xsl:text> >- </xsl:otherwise> >- </xsl:choose> >+ <xsl:variable name="extensionParam"> >+ <xsl:if test="@suffix"> >+ <xsl:text>?uuid2url.extension=</xsl:text> >+ <xsl:value-of select="@suffix"/> > </xsl:if> > </xsl:variable> > >- <xsl:attribute name="suffix"> >- <xsl:value-of select="$suffix"/> >- </xsl:attribute> >- <xsl:attribute name="basic-url"> >- <xsl:value-of select="concat($previous-url, '/', @id)"/> >- </xsl:attribute> >- <xsl:attribute name="language-suffix"> >- <xsl:value-of select="$canonical-language-suffix"/> >- </xsl:attribute> >- >- <xsl:variable name="canonical-url"> >- <xsl:value-of select="concat($basic-url, $canonical-language-suffix, $suffix)"/> >- </xsl:variable> >- >- <xsl:variable name="non-canonical-url"> >- <xsl:value-of select="concat($basic-url, $language-suffix, $suffix)"/> >- </xsl:variable> >- >- <xsl:if test="$url = $canonical-url or $url = $non-canonical-url"> >+ <xsl:if test="$currentPath = $path"> > <xsl:attribute name="current">true</xsl:attribute> > </xsl:if> > >@@ -196,12 +116,11 @@ > <xsl:when test="@href"> > <xsl:value-of select="@href"/> > </xsl:when> >- <xsl:when test="$relative = 'true' and $root = ''"> >- <xsl:value-of select="substring-after($canonical-url, '/')"/> >+ <xsl:when test="@uuid"> >+ <xsl:text>lenya-document:</xsl:text> >+ <xsl:value-of select="@uuid"/> >+ <xsl:value-of select="$extensionParam"/> > </xsl:when> >- <xsl:otherwise> >- <xsl:value-of select="concat($root, $canonical-url)"/> >- </xsl:otherwise> > </xsl:choose> > </xsl:attribute> > >@@ -221,7 +140,7 @@ > </xsl:choose> > > <xsl:apply-templates select="tree:node"> >- <xsl:with-param name="previous-url" select="$basic-url"/> >+ <xsl:with-param name="parentPath" select="$path"/> > </xsl:apply-templates> > > </nav:node> >Index: src/pubs/default/config/publication.xml >=================================================================== >--- src/pubs/default/config/publication.xml (revision 541229) >+++ src/pubs/default/config/publication.xml (working copy) >@@ -102,7 +102,7 @@ > <!-- Lenya can rewrite the links to cater to special proxy setups. > For information about these settings, read http://lenya.apache.org/1_2_x/components/deployment/proxying.html > (yes, this needs some updating... sorry.) >- <proxies> >+ <proxies ssl="false" root="https://www.host.com/ssl/"> > <proxy area="live" ssl="true" url="https://www.host.com/ssl/default"/> > <proxy area="live" ssl="false" url="http://www.host.com/default"/> > <proxy area="authoring" ssl="true" url="https://www.host.com/lenya/default/authoring"/> >Index: src/pubs/default/sitemap.xmap >=================================================================== >--- src/pubs/default/sitemap.xmap (revision 541229) >+++ src/pubs/default/sitemap.xmap (working copy) >@@ -23,6 +23,7 @@ > <map:components> > <map:transformers default="xslt"> > <map:transformer name="metaData" logger="lenya.sitemap.transformer.metaData" src="org.apache.lenya.cms.cocoon.transformation.MetaDataTransformer"/> >+ <map:transformer name="proxy" logger="lenya.sitemap.transformer.proxy" src="org.apache.lenya.cms.cocoon.transformation.ProxyTransformer"/> > </map:transformers> > <map:serializers default="xhtml"> > <map:serializer logger="sitemap.serializer.links" name="links" src="org.apache.lenya.cms.cocoon.serialization.LinkSerializer"/> >@@ -130,13 +131,13 @@ > <map:serialize type="xml"/> > </map:match> > >- <!-- navigation/{1:nav-element}/{2:pub-id}/{3:default-language}/{4:language}/{5:area}/{6:url} --> >+ <!-- navigation/{1:nav-element}/{2:pub-id}/{3:default-language}/{4:language}/{5:area}/{6:path} --> > <map:match pattern="navigation-element/*/*/*/*/*/**"> > <map:generate src="cocoon://modules/sitetree/{1}/{2}/{3}/{4}/{5}/{6}.xml"/> > <map:serialize type="xml"/> > </map:match> > >- <!-- /lenyabody-{1:rendertype}/{2:publication-id}/{3:area}/{4:doctype}/{5:default-language}/{6:language}/{7:url} --> >+ <!-- /lenyabody-{1:rendertype}/{2:publication-id}/{3:area}/{4:doctype}/{5:default-language}/{6:language}/{7:path} --> > <map:match pattern="lenyabody-raw-*/*/*/*/*/*/**"> > <map:aggregate element="cmsbody"> > <map:part src="cocoon:/navigation-element/breadcrumb/{2}/{3}/{5}/{6}/{7}"/> >@@ -173,16 +174,15 @@ > the navigational elements (breadcrumb, tabs, menu) with the actual > content of the document. --> > <map:pipeline type="noncaching"> >- <!-- /lenyabody-{1:rendertype}/{2:publication-id}/{3:area}/{4:doctype}/{5:url} --> >+ <!-- /lenyabody-{1:rendertype}/{2:publication-id}/{3:area}/{4:doctype}/{5:path} --> > <map:match pattern="lenyabody-*/*/*/*/**"> > <map:generate src="cocoon:/lenyabody-raw-{1}/{2}/{3}/{4}/{page-envelope:default-language}/{page-envelope:document-language}/{5}"/> >- <map:transform type="uuid2url"/> > <map:transform src="fallback://lenya/modules/svg/xslt/image2svg.xsl"/> > <map:transform src="cocoon:/getDoctypeXSLT/{4}"> > <map:parameter name="root" value="{base-url:{2}:{3}:{access-control:ssl}}"/> > <map:parameter name="publication-id" value="{2}"/> > <map:parameter name="area" value="{3}"/> >- <map:parameter name="url" value="{5}"/> >+ <map:parameter name="url" value="{page-envelope:document-url}"/> > <map:parameter name="document-path" value="{page-envelope:document-path}"/> > <map:parameter name="document-type" value="{4}"/> > <map:parameter name="language" value="{page-envelope:document-language}"/> >@@ -228,7 +228,7 @@ > <map:pipeline> > > <map:match pattern="**.bxe.html"> >- <map:generate src="cocoon:/lenyabody-edit/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-url}"/> >+ <map:generate src="cocoon:/lenyabody-edit/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-path}"/> > <map:serialize type="xml"/> > </map:match> > >@@ -259,10 +259,10 @@ > <map:select type="parameter"> > <map:parameter name="parameter-selector-test" value="{request-param:rendertype}"/> > <map:when test="edit"> >- <map:generate src="cocoon:/lenyabody-edit/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-url}"/> >+ <map:generate src="cocoon:/lenyabody-edit/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-path}"/> > </map:when> > <map:otherwise> >- <map:generate src="cocoon:/lenyabody-view/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-url}"/> >+ <map:generate src="cocoon:/lenyabody-view/{page-envelope:publication-id}/{page-envelope:area}/{page-envelope:document-type}{page-envelope:document-path}"/> > </map:otherwise> > </map:select> > >@@ -307,6 +307,7 @@ > </map:select> > <!-- pretty-print output for easier debugging and for the benefit of new users --> > <map:transform src="fallback://lenya/modules/prettyprinting/xslt/xml2nicexml.xsl"/> >+ <map:transform type="proxy"/> > <map:serialize type="xhtml"/> > </map:otherwise> > </map:select> >Index: src/resources/build/publication.rng >=================================================================== >--- src/resources/build/publication.rng (revision 540982) >+++ src/resources/build/publication.rng (working copy) >@@ -189,6 +189,10 @@ > </optional> > <optional> > <element name="proxies"> >+ <optional> >+ <attribute name="root"><data type="anyURI"/></attribute> >+ <attribute name="ssl"><ref name="booleanString"/></attribute> >+ </optional> > <oneOrMore> > <element name="proxy"> > <attribute name="area"><ref name="lenyaAreaName"/></attribute> >Index: src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/UuidToUrlTransformer.java >=================================================================== >--- src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/UuidToUrlTransformer.java (revision 541260) >+++ src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/UuidToUrlTransformer.java (working copy) >@@ -18,14 +18,10 @@ > package org.apache.lenya.cms.cocoon.transformation; > > import java.io.IOException; >-import java.util.ArrayList; > import java.util.Arrays; >-import java.util.List; > import java.util.Map; > > import org.apache.avalon.framework.activity.Disposable; >-import org.apache.avalon.framework.configuration.Configuration; >-import org.apache.avalon.framework.configuration.ConfigurationException; > import org.apache.avalon.framework.parameters.Parameters; > import org.apache.avalon.framework.service.ServiceException; > import org.apache.avalon.framework.service.ServiceSelector; >@@ -51,7 +47,6 @@ > import org.apache.lenya.cms.repository.Session; > import org.apache.lenya.util.Query; > import org.apache.lenya.util.ServletHelper; >-import org.apache.lenya.util.StringUtil; > import org.xml.sax.Attributes; > import org.xml.sax.SAXException; > import org.xml.sax.helpers.AttributesImpl; >@@ -114,8 +109,6 @@ > private DocumentFactory factory; > private LinkResolver linkResolver; > private String contextPath; >- >- private boolean relativeUrls = false; > > /** > * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, >@@ -125,15 +118,11 @@ > public void setup(SourceResolver _resolver, Map _objectModel, String _source, > Parameters _parameters) throws ProcessingException, SAXException, IOException { > super.setup(_resolver, _objectModel, _source, _parameters); >- >+ > Request _request = ObjectModelHelper.getRequest(_objectModel); > this.contextPath = _request.getContextPath(); > > try { >- if (_parameters.isParameter("urls")) { >- setUrlType(_parameters.getParameter("urls")); >- } >- > Session session = RepositoryUtil.getSession(this.manager, _request); > this.factory = DocumentUtil.createDocumentFactory(this.manager, session); > String url = ServletHelper.getWebappURI(_request); >@@ -176,28 +165,6 @@ > } > } > >- public void configure(Configuration config) throws ConfigurationException { >- super.configure(config); >- Configuration urlConfig = config.getChild("urls", false); >- if (urlConfig != null) { >- String value = urlConfig.getAttribute("type"); >- setUrlType(value); >- } >- } >- >- protected void setUrlType(String value) throws ConfigurationException { >- if (value.equals("relative")) { >- this.relativeUrls = true; >- } >- else if (value.equals("absolute")) { >- this.relativeUrls = false; >- } >- else { >- throw new ConfigurationException("Invalid URL type [" + value >- + "], must be relative or absolute."); >- } >- } >- > /** > * Returns the currently processed document. > * >@@ -373,27 +340,17 @@ > throws AccessControlException { > > String webappUrl = targetDocument.getCanonicalWebappURL(); >- >+ Policy policy = this.policyManager.getPolicy(this.accreditableManager, webappUrl); >+ >+ Proxy proxy = targetDocument.getPublication().getProxy(targetDocument, >+ policy.isSSLProtected()); >+ > String rewrittenURL; >- if (this.relativeUrls) { >- rewrittenURL = getRelativeUrlTo(webappUrl); >+ if (proxy == null) { >+ rewrittenURL = this.request.getContextPath() + webappUrl; >+ } else { >+ rewrittenURL = proxy.getURL(targetDocument); > } >- else { >- Policy policy = this.policyManager.getPolicy(this.accreditableManager, webappUrl); >- >- Proxy proxy = targetDocument.getPublication().getProxy(targetDocument, >- policy.isSSLProtected()); >- >- if (proxy == null) { >- rewrittenURL = this.request.getContextPath() + webappUrl; >- } else { >- rewrittenURL = proxy.getURL(targetDocument); >- } >- if (getLogger().isDebugEnabled()) { >- getLogger().debug(this.indent + "SSL protection: [" + policy.isSSLProtected() + "]"); >- getLogger().debug(this.indent + "Resolved proxy: [" + proxy + "]"); >- } >- } > > int lastDotIndex = rewrittenURL.lastIndexOf("."); > if (lastDotIndex > -1) { >@@ -409,42 +366,14 @@ > } > > if (getLogger().isDebugEnabled()) { >+ getLogger().debug(this.indent + "SSL protection: [" + policy.isSSLProtected() + "]"); >+ getLogger().debug(this.indent + "Resolved proxy: [" + proxy + "]"); > getLogger().debug(this.indent + "Rewriting URL to: [" + rewrittenURL + "]"); > } > > setAttribute(newAttrs, attributeName, rewrittenURL); > } > >- private String getRelativeUrlTo(String webappUrl) { >- String currentUrl = this.currentDocument.getCanonicalWebappURL(); >- List sourceSteps = toList(currentUrl); >- List targetSteps = toList(webappUrl); >- >- while (!sourceSteps.isEmpty() && !targetSteps.isEmpty() >- && sourceSteps.get(0).equals(targetSteps.get(0))) { >- sourceSteps.remove(0); >- targetSteps.remove(0); >- } >- >- String upDots = ""; >- if (sourceSteps.size() > 1) { >- String[] upDotsArray = new String[sourceSteps.size() - 1]; >- Arrays.fill(upDotsArray, ".."); >- upDots = StringUtil.join(upDotsArray, "/") + "/"; >- } >- >- String[] targetArray = (String[]) targetSteps.toArray(new String[targetSteps.size()]); >- String targetPath = StringUtil.join(targetArray, "/"); >- >- String relativeUrl = upDots + targetPath; >- return relativeUrl; >- >- } >- >- protected List toList(String url) { >- return new ArrayList(Arrays.asList(url.substring(1).split("/"))); >- } >- > /** > * Sets the value of the href attribute. > * >Index: src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/ProxyTransformer.java >=================================================================== >--- src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/ProxyTransformer.java (revision 0) >+++ src/modules-core/linking/java/src/org/apache/lenya/cms/cocoon/transformation/ProxyTransformer.java (revision 0) >@@ -0,0 +1,212 @@ >+package org.apache.lenya.cms.cocoon.transformation; >+ >+import java.io.IOException; >+import java.util.Arrays; >+import java.util.Map; >+ >+import org.apache.avalon.framework.parameters.Parameters; >+import org.apache.avalon.framework.service.ServiceSelector; >+import org.apache.cocoon.ProcessingException; >+import org.apache.cocoon.environment.ObjectModelHelper; >+import org.apache.cocoon.environment.Request; >+import org.apache.cocoon.environment.SourceResolver; >+import org.apache.cocoon.transformation.AbstractSAXTransformer; >+import org.apache.lenya.ac.AccessControlException; >+import org.apache.lenya.ac.AccessController; >+import org.apache.lenya.ac.AccessControllerResolver; >+import org.apache.lenya.ac.AccreditableManager; >+import org.apache.lenya.ac.Policy; >+import org.apache.lenya.ac.PolicyManager; >+import org.apache.lenya.cms.publication.DocumentBuildException; >+import org.apache.lenya.cms.publication.DocumentFactory; >+import org.apache.lenya.cms.publication.DocumentUtil; >+import org.apache.lenya.cms.publication.Proxy; >+import org.apache.lenya.cms.publication.Publication; >+import org.apache.lenya.cms.publication.PublicationUtil; >+import org.apache.lenya.cms.repository.RepositoryUtil; >+import org.apache.lenya.cms.repository.Session; >+import org.apache.lenya.util.ServletHelper; >+import org.xml.sax.Attributes; >+import org.xml.sax.SAXException; >+import org.xml.sax.helpers.AttributesImpl; >+ >+public class ProxyTransformer extends AbstractSAXTransformer { >+ protected static final String[] elementNames = { "a", "object", "img", >+ "link", "form" , "script" }; >+ >+ protected static final String[] attributeNames = { "href", "src", "data", >+ "action" }; >+ >+ private boolean ignoreLinkElement = false; >+ >+ private String indent = ""; >+ >+ private DocumentFactory factory; >+ >+ private Publication publication; >+ >+ private String url; >+ >+ private ServiceSelector serviceSelector; >+ >+ private AccessControllerResolver acResolver; >+ >+ private AccreditableManager accreditableManager; >+ >+ private PolicyManager policyManager; >+ >+ protected static final String PARAMETER_FACTORY = "private.factory"; >+ >+ private static final String ATTRIBUTE_ROOT = "root"; >+ >+ public void setup(SourceResolver _resolver, Map _objectModel, String _source, >+ Parameters _parameters) throws ProcessingException, SAXException, >+ IOException { >+ super.setup(_resolver, _objectModel, _source, _parameters); >+ Request _request = ObjectModelHelper.getRequest(_objectModel); >+ >+ try { >+ Session session = RepositoryUtil.getSession(this.manager, _request); >+ this.factory = DocumentUtil.createDocumentFactory(this.manager, session); >+ this.url = ServletHelper.getWebappURI(_request); >+ this.publication = PublicationUtil.getPublicationFromUrl(this.manager, >+ factory, url); >+ } catch (final Exception e) { >+ throw new RuntimeException(e); >+ } >+ this.serviceSelector = null; >+ try { >+ this.serviceSelector = (ServiceSelector) this.manager >+ .lookup(AccessControllerResolver.ROLE + "Selector"); >+ this.acResolver = (AccessControllerResolver) this.serviceSelector >+ .select(AccessControllerResolver.DEFAULT_RESOLVER); >+ AccessController accessController = this.acResolver >+ .resolveAccessController(url); >+ this.accreditableManager = accessController.getAccreditableManager(); >+ this.policyManager = accessController.getPolicyManager(); >+ } catch (final Exception e) { >+ throw new RuntimeException(e); >+ } >+ >+ } >+ >+ public void startElement(String uri, String name, String qname, >+ Attributes attrs) throws SAXException { >+ if (getLogger().isDebugEnabled()) { >+ getLogger().debug( >+ this.indent + "<" + qname + "> (ignoreAElement = " >+ + this.ignoreLinkElement + ")"); >+ this.indent += " "; >+ } >+ AttributesImpl newAttrs = null; >+ if (lookingAtLinkElement(name)) { >+ >+ for (int i = 0; i < attributeNames.length; i++) { >+ String linkUrl = attrs.getValue(attributeNames[i]); >+ if (linkUrl != null) { >+ if (linkUrl.startsWith("/")) { >+ try { >+ newAttrs = new AttributesImpl(attrs); >+ rewriteLink(newAttrs, attributeNames[i], linkUrl); >+ if (getLogger().isDebugEnabled()) { >+ getLogger().debug(this.indent + "link URL: [" + linkUrl + "]"); >+ } >+ } catch (final Exception e) { >+ getLogger().error("startElement failed: ", e); >+ throw new SAXException(e); >+ } >+ } >+ } >+ } >+ if (newAttrs == null) >+ super.startElement(uri, name, qname, attrs); >+ else >+ super.startElement(uri, name, qname, newAttrs); >+ } else >+ super.startElement(uri, name, qname, attrs); >+ >+ } >+ >+ public void endElement(String uri, String name, String qname) >+ throws SAXException { >+ if (getLogger().isDebugEnabled()) { >+ this.indent = this.indent.substring(2); >+ getLogger().debug(this.indent + "</" + qname + ">"); >+ } >+ if (getLogger().isDebugEnabled()) { >+ getLogger().debug(this.indent + "</" + qname + "> sent"); >+ } >+ super.endElement(uri, name, qname); >+ } >+ >+ private void rewriteLink(AttributesImpl newAttrs, String attributeName, >+ String linkUrl) throws AccessControlException, DocumentBuildException { >+ String rewrittenURL = ""; >+ Policy policy; >+ policy = this.policyManager.getPolicy(this.accreditableManager, linkUrl); >+ String area = ""; >+ if(factory.isDocument(linkUrl)){ >+ area = factory.getFromURL(linkUrl).getArea(); >+ } >+ if (PublicationUtil.isValidArea(area)) { >+ Proxy proxy = this.publication.getProxy(area, policy.isSSLProtected()); >+ if (proxy == null) { >+ rewrittenURL = this.request.getContextPath() + linkUrl; >+ } else { >+ String prefix = "/" + publication.getId() + "/" + area; >+ if (linkUrl.startsWith(prefix)) >+ rewrittenURL = proxy.getUrl() + linkUrl.substring(prefix.length()); >+ else >+ rewrittenURL = proxy.getUrl() + linkUrl; >+ } >+ if (getLogger().isDebugEnabled()) { >+ getLogger().debug( >+ this.indent + "SSL protection: [" + policy.isSSLProtected() + "]"); >+ getLogger().debug(this.indent + "Resolved proxy: [" + proxy + "]"); >+ } >+ >+ if (getLogger().isDebugEnabled()) { >+ getLogger().debug( >+ this.indent + "Rewriting URL to: [" + rewrittenURL + "]"); >+ } >+ } else { >+ // Since we came here the link is not covered by the area proxies. >+ // Now we try the global proxy for the pub of our initial request. >+ Proxy proxy = this.publication.getProxy(ATTRIBUTE_ROOT, policy.isSSLProtected()); >+ if (proxy == null) { >+ rewrittenURL = this.request.getContextPath() + linkUrl; >+ } else { >+ rewrittenURL = proxy.getUrl() + linkUrl.substring(1); >+ } >+ if (getLogger().isDebugEnabled()) { >+ getLogger().debug( >+ this.indent + "Rewriting URL to: [" + rewrittenURL + "]"); >+ } >+ } >+ setAttribute(newAttrs, attributeName, rewrittenURL); >+ } >+ >+ private boolean lookingAtLinkElement(String name) { >+ return Arrays.asList(elementNames).contains(name); >+ } >+ >+ /** >+ * Sets the value of the href attribute. >+ * >+ * @param attr >+ * The attributes. >+ * @param name >+ * The attribute name. >+ * @param value >+ * The value. >+ * @throws IllegalArgumentException >+ * if the href attribute is not contained in this attributes. >+ */ >+ protected void setAttribute(AttributesImpl attr, String name, String value) { >+ int position = attr.getIndex(name); >+ if (position == -1) { >+ throw new IllegalArgumentException("The href attribute is not available!"); >+ } >+ attr.setValue(position, value); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 42050
:
20139
|
20170
|
20201
|
20240
|
20241
|
20246
|
20268
|
20280
|
20282