001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018: package org.apache.lenya.cms.site.usecases;
019:
020: import org.apache.lenya.ac.impl.AbstractAccessControlTest;
021: import org.apache.lenya.cms.cocoon.source.SourceUtil;
022: import org.apache.lenya.cms.publication.Document;
023: import org.apache.lenya.cms.publication.DocumentLocator;
024: import org.apache.lenya.cms.publication.DocumentManager;
025: import org.apache.lenya.cms.publication.Publication;
026: import org.apache.lenya.cms.publication.PublicationUtil;
027: import org.apache.lenya.cms.site.SiteUtil;
028: import org.apache.lenya.xml.DocumentHelper;
029: import org.apache.xpath.XPathAPI;
030: import org.w3c.dom.Attr;
031: import org.w3c.dom.NodeList;
032:
033: /**
034: * Link rewriter test.
035: */
036: public class LinkRewriterTest extends AbstractAccessControlTest {
037:
038: protected static final String DOCUMENT_ID = "/index";
039: protected static final String SOURCE_DOCUMENT_ID = "/concepts";
040: protected static final String TARGET_DOCUMENT_ID = "/copied";
041:
042: /**
043: * Test method.
044: * @throws Exception
045: */
046: public void testLinkRewriter() throws Exception {
047: /*
048: Publication pub = PublicationUtil.getPublication(getManager(), "test");
049:
050: Document document = getIdentityMap().get(pub, Publication.AUTHORING_AREA, DOCUMENT_ID, "en");
051: org.w3c.dom.Document xml = DocumentHelper.readDocument(getClass().getResourceAsStream("index_en.xml"));
052: document.getRepositoryNode().lock();
053: SourceUtil.writeDOM(xml, document.getSourceURI(), getManager());
054:
055: LinkRewriter rewriter = null;
056: DocumentManager docManager = null;
057: Document target = null;
058: try {
059: docManager = (DocumentManager) getManager().lookup(DocumentManager.ROLE);
060:
061: Document source = getIdentityMap().get(pub,
062: Publication.AUTHORING_AREA,
063: SOURCE_DOCUMENT_ID,
064: "en");
065: source.getRepositoryNode().lock();
066:
067: DocumentLocator targetLoc = DocumentLocator.getLocator(pub.getId(),
068: Publication.AUTHORING_AREA,
069: TARGET_DOCUMENT_ID,
070: "en");
071:
072: SiteUtil.getSiteStructure(getManager(),
073: source.getFactory(),
074: source.getPublication(),
075: source.getArea()).getRepositoryNode().lock();
076:
077: docManager.move(source, targetLoc);
078: target = source.getFactory().get(targetLoc);
079:
080: rewriter = (LinkRewriter) getManager().lookup(LinkRewriter.ROLE);
081: rewriter.rewriteLinks(source, target);
082:
083: } finally {
084: if (docManager != null) {
085: getManager().release(docManager);
086: }
087: if (rewriter != null) {
088: getManager().release(rewriter);
089: }
090: }
091:
092: String[] xPaths = document.getResourceType().getLinkAttributeXPaths();
093: assertTrue(xPaths.length > 0);
094:
095: org.w3c.dom.Document xmlDoc = SourceUtil.readDOM(document.getSourceURI(), getManager());
096: boolean matched = false;
097:
098: for (int i = 0; i < xPaths.length; i++) {
099: NodeList nodes = XPathAPI.selectNodeList(xmlDoc, xPaths[i]);
100: for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
101: Attr attribute = (Attr) nodes.item(nodeIndex);
102: String targetUrl = attribute.getValue();
103: Document targetDoc = getIdentityMap().getFromURL(targetUrl);
104: if (targetDoc.equals(target)) {
105: matched = true;
106: }
107: }
108: }
109: assertTrue(matched);
110: */
111: }
112:
113: }
|