KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > util > DaisyLinkUtil


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.frontend.util;
17
18 import org.outerj.daisy.frontend.components.siteconf.SiteConf;
19
20 import java.util.regex.Matcher JavaDoc;
21
22 public class DaisyLinkUtil {
23     /**
24      * Returns a suitable query string with branch and language parameters
25      * for a daisy: URL parsed with {@link org.outerj.daisy.util.Constants.DAISY_LINK_PATTERN}
26      * in the context of a certain site and document.
27      */

28     public static String JavaDoc getBranchLangQueryString(Matcher JavaDoc matcher, SiteConf siteConf, long documentBranchId, long documentLanguageId) {
29         String JavaDoc branch = matcher.group(3);
30         String JavaDoc language = matcher.group(5);
31
32         StringBuffer JavaDoc queryString = new StringBuffer JavaDoc();
33         if (branch != null && branch.length() > 0) {
34             queryString.append("?branch=").append(branch);
35         } else if (documentBranchId != siteConf.getBranchId()) {
36             queryString.append("?branch=").append(documentBranchId);
37         }
38         if (language != null && language.length() > 0) {
39             queryString.append(queryString.length() > 0 ? "&" : "?");
40             queryString.append("language=").append(language);
41         } else if (documentLanguageId != siteConf.getLanguageId()) {
42             queryString.append(queryString.length() > 0 ? "&" : "?");
43             queryString.append("language=").append(documentLanguageId);
44         }
45         return queryString.toString();
46     }
47 }
48
Popular Tags