001: /*
002: * Copyright 2004 Outerthought bvba and Schaubroeck nv
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.outerj.daisy.navigation;
017:
018: import org.outerx.daisy.x10Navigationspec.NavigationLookupResultDocument;
019: import org.outerj.daisy.repository.VariantKey;
020:
021: /**
022: * Encapsulates information about the result of a navigation tree lookup.
023: * Either the lookup matched a document node in which case the variantKey
024: * field will identify that document, and the navigationPath
025: * field will contain the corresponding path in the navigation tree (the
026: * same as the one provided when doing the lookup).
027: *
028: * <p>If the lookup matched
029: * a group node or the lookup didn't match but the path ended on a document
030: * ID and the document is found at another location in the tree of one
031: * of the lookup variants, the redirect field will be true, the navigationPath
032: * field will contain the path to where to redirect, and the lookupAlternativeName
033: * will contain the name of the lookupAlternative which matched.
034: *
035: * <p>If the lookup didn't match and the path ended on a document ID but
036: * the document ID does not occur in the tree, then the redirect field will
037: * be false, the navigationPath will contain an empty string and the variantKey
038: * field will contain a variant key with that document ID and the branch
039: * and language of the navigation tree document.
040: *
041: * <p>In all other cases, the notFound field will be true.
042: */
043: public class NavigationLookupResult {
044: private VariantKey variantKey = null;
045: private String lookupAlternativeName;
046: private String navigationPath;
047: private boolean redirect;
048: private boolean notFound;
049:
050: private NavigationLookupResult() {
051: }
052:
053: public static NavigationLookupResult createMatchResult(
054: VariantKey variantKey, String navigationPath) {
055: NavigationLookupResult lookupResult = new NavigationLookupResult();
056: lookupResult.variantKey = variantKey;
057: lookupResult.navigationPath = navigationPath;
058: lookupResult.redirect = false;
059: return lookupResult;
060: }
061:
062: public static NavigationLookupResult createRedirectResult(
063: String lookupAlternativeName, String navigationPath,
064: VariantKey variantKey) {
065: NavigationLookupResult lookupResult = new NavigationLookupResult();
066: lookupResult.lookupAlternativeName = lookupAlternativeName;
067: lookupResult.navigationPath = navigationPath;
068: lookupResult.redirect = true;
069: lookupResult.variantKey = variantKey;
070: return lookupResult;
071: }
072:
073: public static NavigationLookupResult createNotFoundResult() {
074: NavigationLookupResult lookupResult = new NavigationLookupResult();
075: lookupResult.notFound = true;
076: return lookupResult;
077: }
078:
079: public static NavigationLookupResult createFromXml(
080: NavigationLookupResultDocument.NavigationLookupResult resultXml) {
081: NavigationLookupResult lookupResult = new NavigationLookupResult();
082: if (resultXml.isSetNotFound())
083: lookupResult.notFound = resultXml.getNotFound();
084: if (resultXml.isSetRedirect())
085: lookupResult.redirect = resultXml.getRedirect();
086: if (resultXml.isSetDocumentId()) {
087: lookupResult.variantKey = new VariantKey(resultXml
088: .getDocumentId(), resultXml.getBranchId(),
089: resultXml.getLanguageId());
090: }
091: if (resultXml.isSetPath())
092: lookupResult.navigationPath = resultXml.getPath();
093: if (resultXml.isSetLookupAlternativeName())
094: lookupResult.lookupAlternativeName = resultXml
095: .getLookupAlternativeName();
096:
097: return lookupResult;
098: }
099:
100: public VariantKey getVariantKey() {
101: return variantKey;
102: }
103:
104: public String getNavigationPath() {
105: return navigationPath;
106: }
107:
108: public boolean isRedirect() {
109: return redirect;
110: }
111:
112: public boolean isNotFound() {
113: return notFound;
114: }
115:
116: public String getLookupAlternativeName() {
117: return lookupAlternativeName;
118: }
119:
120: public NavigationLookupResultDocument getXml() {
121: NavigationLookupResultDocument resultDocument = NavigationLookupResultDocument.Factory
122: .newInstance();
123: NavigationLookupResultDocument.NavigationLookupResult resultXml = resultDocument
124: .addNewNavigationLookupResult();
125:
126: if (notFound)
127: resultXml.setNotFound(true);
128: if (redirect)
129: resultXml.setRedirect(true);
130: if (variantKey != null) {
131: resultXml.setDocumentId(variantKey.getDocumentId());
132: resultXml.setBranchId(variantKey.getBranchId());
133: resultXml.setLanguageId(variantKey.getLanguageId());
134: }
135: if (navigationPath != null)
136: resultXml.setPath(navigationPath);
137: if (lookupAlternativeName != null)
138: resultXml.setLookupAlternativeName(lookupAlternativeName);
139:
140: return resultDocument;
141: }
142: }
|