KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > PublicationHelper


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
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  */

17
18 /* $Id: PublicationHelper.java 42625 2004-03-04 15:45:03Z egli $ */
19
20 package org.apache.lenya.cms;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.apache.lenya.cms.publication.Publication;
26 import org.apache.lenya.cms.publication.PublicationException;
27 import org.apache.lenya.cms.publication.PublicationFactory;
28
29 public class PublicationHelper {
30     
31     /**
32      * Constructor for PublicationHelper.
33      *
34      */

35     protected PublicationHelper() {}
36     
37     /**
38      * Initializes the object with the first parameters from the command line arguments
39      * <code>args</code>. The remainder of the array is returned.
40      *
41      * @param args The command line arguments of the test.
42      * @return The remainder of the arguments after the publication parameters are extracted.
43      *
44      */

45     public static String JavaDoc[] extractPublicationArguments(String JavaDoc[] args) {
46         String JavaDoc servletContextPath = args[0];
47         String JavaDoc publicationId = args[1];
48         try {
49             publication =
50                 PublicationFactory.getPublication(
51                     publicationId,
52                     servletContextPath);
53         } catch (PublicationException e) {
54             e.printStackTrace();
55         }
56
57         List JavaDoc subList = Arrays.asList(args).subList(2, args.length);
58         String JavaDoc[] remainder =
59             (String JavaDoc[])subList.toArray(new String JavaDoc[subList.size()]);
60
61         return remainder;
62     }
63
64     private static Publication publication;
65
66     /**
67      * Returns the publication.
68      * @return A publication object.
69      */

70     public static Publication getPublication() {
71         return publication;
72     }
73 }
74
Popular Tags