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.linking;
019:
020: import java.net.MalformedURLException;
021:
022: import org.apache.lenya.cms.publication.Document;
023: import org.apache.lenya.cms.publication.DocumentFactory;
024:
025: /**
026: * <p>
027: * Resolve a link from a document to another document using it's
028: * </p>
029: * <ul>
030: * <li>publication ID</li>
031: * <li>area</li>
032: * <li>UUID</li>
033: * <li>language</li>
034: * <li>revision number</li>
035: * </ul>
036: * <p>
037: * All of these parameters are optional and default to the attributes of the
038: * document which contains the link.
039: * </p>
040: * <p>
041: * Syntax (square brackets denote optional parts):
042: * </p>
043: * <code>lenya-document:<uuid>[,lang=...][,area=...][,rev=...][,pub=...]</code>
044: * <p>
045: * The fallback mode determines the behaviour if the target language is omitted
046: * and the target document doesn't exist in the language of the source document.
047: * The default fallback mode is {@link #MODE_DEFAULT_LANGUAGE}.
048: * <p>
049: */
050: public interface LinkResolver {
051:
052: /**
053: * The Avalon role.
054: */
055: String ROLE = LinkResolver.class.getName();
056:
057: /**
058: * The link URI scheme.
059: */
060: String SCHEME = "lenya-document";
061:
062: /**
063: * Fail if the target document doesn't exist in the source language.
064: */
065: int MODE_FAIL = 0;
066:
067: /**
068: * Try to fall back to the default language.
069: */
070: int MODE_DEFAULT_LANGUAGE = 1;
071:
072: /**
073: * Sets the fallback mode.
074: * @param mode one of {@link #MODE_FAIL} and {@link #MODE_DEFAULT_LANGUAGE}.
075: */
076: void setFallbackMode(int mode);
077:
078: /**
079: * @return the fallback mode.
080: */
081: int getFallbackMode();
082:
083: /**
084: * Resolve a link.
085: *
086: * @param currentDocument The document which contains the link.
087: * @param linkUri The link URI.
088: * @return A link target.
089: * @throws MalformedURLException if the URI is invalid.
090: */
091: LinkTarget resolve(Document currentDocument, String linkUri)
092: throws MalformedURLException;
093:
094: /**
095: * Resolve a link. The link URI has to contain the UUID, language, area and publication ID.
096: * @param factory The document factory to use.
097: * @param linkUri The link URI.
098: * @return A link target.
099: * @throws MalformedURLException if the URI is invalid.
100: */
101: LinkTarget resolve(DocumentFactory factory, String linkUri)
102: throws MalformedURLException;
103:
104: }
|