Skip to content
This repository
Browse code

Fixed a problem with link processing and added a test case for it.

  • Loading branch information...
commit 17a5cc48f1fb8be48c2dfdcbbfd38a36d2f7eaf0 1 parent 8928a63
gWestenberger gWestenberger authored
29 src/org/opencms/staticexport/CmsDefaultLinkSubstitutionHandler.java
@@ -30,6 +30,7 @@
30 30 import org.opencms.ade.detailpage.I_CmsDetailPageFinder;
31 31 import org.opencms.file.CmsObject;
32 32 import org.opencms.file.CmsResource;
  33 +import org.opencms.file.CmsResourceFilter;
33 34 import org.opencms.file.CmsVfsException;
34 35 import org.opencms.file.CmsVfsResourceNotFoundException;
35 36 import org.opencms.file.types.CmsResourceTypeImage;
@@ -384,14 +385,26 @@ public String getRootPath(CmsObject cms, String targetUri, String basePath) {
384 385 if (path.startsWith(OpenCms.getSystemInfo().getOpenCmsContext())) {
385 386 path = path.substring(OpenCms.getSystemInfo().getOpenCmsContext().length());
386 387 }
387   - String ignoreWorkplaceStr = (String)cms.getRequestContext().getAttribute(
388   - DONT_USE_CURRENT_SITE_FOR_WORKPLACE_REQUESTS);
389   - boolean ignoreWorkplace = Boolean.parseBoolean(ignoreWorkplaceStr);
390   - cms.getRequestContext().setAttribute(DONT_USE_CURRENT_SITE_FOR_WORKPLACE_REQUESTS, "false");
391   - if (OpenCms.getSiteManager().isWorkplaceRequest(matcher) && !ignoreWorkplace) {
392   - // workplace URL, use current site root
393   - // this is required since the workplace site does not have a site root to set
394   - return cms.getRequestContext().addSiteRoot(path + suffix);
  388 + boolean isWorkplaceServer = OpenCms.getSiteManager().isWorkplaceRequest(matcher);
  389 + if (isWorkplaceServer) {
  390 + String pathForCurrentSite = cms.getRequestContext().addSiteRoot(path);
  391 + String pathForMatchedSite = cms.getRequestContext().addSiteRoot(
  392 + OpenCms.getSiteManager().matchSite(matcher).getSiteRoot(),
  393 + path);
  394 + String originalSiteRoot = cms.getRequestContext().getSiteRoot();
  395 + String selectedPath = pathForCurrentSite;
  396 + try {
  397 + cms.getRequestContext().setSiteRoot("");
  398 + // the path for the current site normally is preferred, but if it doesn't exist and the path for the matched site
  399 + // does exist, then use the path for the matched site
  400 + if (!cms.existsResource(pathForCurrentSite, CmsResourceFilter.ALL)
  401 + && cms.existsResource(pathForMatchedSite, CmsResourceFilter.ALL)) {
  402 + selectedPath = pathForMatchedSite;
  403 + }
  404 + } finally {
  405 + cms.getRequestContext().setSiteRoot(originalSiteRoot);
  406 + }
  407 + return selectedPath + suffix;
395 408 } else {
396 409 // add the site root of the matching site
397 410 return cms.getRequestContext().addSiteRoot(
3  test/data/WEB-INF/base/opencms-system.xml
@@ -39,7 +39,8 @@
39 39 <sites>
40 40 <workplace-server>http://localhost:8080</workplace-server>
41 41 <default-uri>/sites/default/</default-uri>
42   - <site server="http://localhost:8080" uri="/sites/default/">
  42 + <shared-folder>/shared/</shared-folder>
  43 + <site server="http://localhost:8080" uri="/sites/default/">
43 44 <secure server="https://localhost:443"/>
44 45 </site>
45 46 <site server="http://localhost:8081" uri="/sites/default/folder1/" />
1  test/data/scripts/script_default_folders.txt
@@ -8,6 +8,7 @@ setSiteRoot "/"
8 8 createFolder "/" "sites/"
9 9 createFolder "/sites/" "default/"
10 10 createFolder "/system/" "lost-found/"
  11 +createFolder "/" "shared/"
11 12
12 13 # Apply folder permissions
13 14 chacc "/" "user" "ALL_OTHERS" "+v+r+i"
324 test/org/opencms/xml/content/TestCmsXmlContentLinks.java
@@ -27,9 +27,12 @@
@@ -44,6 +47,7 @@
@@ -155,6 +159,7 @@ public static Test suite() {
@@ -257,6 +262,98 @@ private static void updateLink(CmsObject cms, CmsLink link, CmsResource resource
@@ -688,6 +785,120 @@ public void testRemoveParent() throws Exception {
@@ -814,94 +1025,51 @@ public void testUpdatePath() throws Exception {
19 test/org/opencms/xml/content/xmlcontent-15.xml
... ... @@ -0,0 +1,19 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +
  3 +<Test2Links
  4 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5 + xsi:noNamespaceSchemaLocation="http://www.opencms.org/test14.xsd">
  6 +
  7 + <Test2Link language="en">
  8 + <Html>
  9 + <links>
  10 + </links>
  11 + <content><![CDATA[<img src="${TARGET}">]]></content>
  12 + </Html>
  13 + <VfsLink>
  14 + <link>
  15 + <target><![CDATA[${TARGET2}]]></target>
  16 + </link>
  17 + </VfsLink>
  18 + </Test2Link>
  19 +</Test2Links>

0 comments on commit 17a5cc4

Please sign in to comment.
Something went wrong with that request. Please try again.