KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > navigation > NavigationLookupResult


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.navigation;
17
18 import org.outerx.daisy.x10Navigationspec.NavigationLookupResultDocument;
19 import org.outerj.daisy.repository.VariantKey;
20
21 /**
22  * Encapsulates information about the result of a navigation tree lookup.
23  * Either the lookup matched a document node in which case the variantKey
24  * field will identify that document, and the navigationPath
25  * field will contain the corresponding path in the navigation tree (the
26  * same as the one provided when doing the lookup).
27  *
28  * <p>If the lookup matched
29  * a group node or the lookup didn't match but the path ended on a document
30  * ID and the document is found at another location in the tree of one
31  * of the lookup variants, the redirect field will be true, the navigationPath
32  * field will contain the path to where to redirect, and the lookupAlternativeName
33  * will contain the name of the lookupAlternative which matched.
34  *
35  * <p>If the lookup didn't match and the path ended on a document ID but
36  * the document ID does not occur in the tree, then the redirect field will
37  * be false, the navigationPath will contain an empty string and the variantKey
38  * field will contain a variant key with that document ID and the branch
39  * and language of the navigation tree document.
40  *
41  * <p>In all other cases, the notFound field will be true.
42  */

43 public class NavigationLookupResult {
44     private VariantKey variantKey = null;
45     private String JavaDoc lookupAlternativeName;
46     private String JavaDoc navigationPath;
47     private boolean redirect;
48     private boolean notFound;
49
50     private NavigationLookupResult() {
51     }
52
53     public static NavigationLookupResult createMatchResult(VariantKey variantKey, String JavaDoc navigationPath) {
54         NavigationLookupResult lookupResult = new NavigationLookupResult();
55         lookupResult.variantKey = variantKey;
56         lookupResult.navigationPath = navigationPath;
57         lookupResult.redirect = false;
58         return lookupResult;
59     }
60
61     public static NavigationLookupResult createRedirectResult(String JavaDoc lookupAlternativeName, String JavaDoc navigationPath, VariantKey variantKey) {
62         NavigationLookupResult lookupResult = new NavigationLookupResult();
63         lookupResult.lookupAlternativeName = lookupAlternativeName;
64         lookupResult.navigationPath = navigationPath;
65         lookupResult.redirect = true;
66         lookupResult.variantKey = variantKey;
67         return lookupResult;
68     }
69
70     public static NavigationLookupResult createNotFoundResult() {
71         NavigationLookupResult lookupResult = new NavigationLookupResult();
72         lookupResult.notFound = true;
73         return lookupResult;
74     }
75
76     public static NavigationLookupResult createFromXml(NavigationLookupResultDocument.NavigationLookupResult resultXml) {
77         NavigationLookupResult lookupResult = new NavigationLookupResult();
78         if (resultXml.isSetNotFound())
79             lookupResult.notFound = resultXml.getNotFound();
80         if (resultXml.isSetRedirect())
81             lookupResult.redirect = resultXml.getRedirect();
82         if (resultXml.isSetDocumentId()) {
83             lookupResult.variantKey = new VariantKey(resultXml.getDocumentId(), resultXml.getBranchId(), resultXml.getLanguageId());
84         }
85         if (resultXml.isSetPath())
86             lookupResult.navigationPath = resultXml.getPath();
87         if (resultXml.isSetLookupAlternativeName())
88             lookupResult.lookupAlternativeName = resultXml.getLookupAlternativeName();
89
90         return lookupResult;
91     }
92
93     public VariantKey getVariantKey() {
94         return variantKey;
95     }
96
97     public String JavaDoc getNavigationPath() {
98         return navigationPath;
99     }
100
101     public boolean isRedirect() {
102         return redirect;
103     }
104
105     public boolean isNotFound() {
106         return notFound;
107     }
108
109     public String JavaDoc getLookupAlternativeName() {
110         return lookupAlternativeName;
111     }
112
113     public NavigationLookupResultDocument getXml() {
114         NavigationLookupResultDocument resultDocument = NavigationLookupResultDocument.Factory.newInstance();
115         NavigationLookupResultDocument.NavigationLookupResult resultXml = resultDocument.addNewNavigationLookupResult();
116
117         if (notFound)
118             resultXml.setNotFound(true);
119         if (redirect)
120             resultXml.setRedirect(true);
121         if (variantKey != null) {
122             resultXml.setDocumentId(variantKey.getDocumentId());
123             resultXml.setBranchId(variantKey.getBranchId());
124             resultXml.setLanguageId(variantKey.getLanguageId());
125         }
126         if (navigationPath != null)
127             resultXml.setPath(navigationPath);
128         if (lookupAlternativeName != null)
129             resultXml.setLookupAlternativeName(lookupAlternativeName);
130
131         return resultDocument;
132     }
133 }
134
Popular Tags