KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > books > publisher > impl > BookInstanceLayout


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.books.publisher.impl;
17
18 import org.outerj.daisy.books.store.BookInstance;
19
20 /**
21  * Helper class to determine the location of resources within a book instance.
22  */

23 public class BookInstanceLayout {
24     public static String JavaDoc getDocumentStorePath(BookInstance bookInstance, long documentId, long branchId, long languageId) {
25         String JavaDoc storeBasePath = "/data/documents/" + documentId + "_" + branchId + "_" + languageId;
26         String JavaDoc storePath = storeBasePath + ".xml";
27         int counter = 0;
28         while (bookInstance.exists(storePath)) {
29             counter++;
30             storePath = storeBasePath + "_" + counter + ".xml";
31         }
32         return storePath;
33     }
34
35     public static String JavaDoc getImageStorePath(long documentId, long branchId, long languageId, long versionId) {
36         return "/data/resources/" + documentId + "_" + branchId + "_" + languageId + "_" + versionId;
37     }
38
39     public static String JavaDoc getResourceStorePath(long documentId, long branchId, long languageId, long versionId, long partTypeId) {
40         return "/data/resources/" + documentId + "_" + branchId + "_" + languageId + "_" + versionId + "_" + partTypeId;
41     }
42
43     public static String JavaDoc geResourceStorePath() {
44         return "/data/resources/";
45     }
46
47     public static String JavaDoc getDocumentInPublicationStorePath(String JavaDoc documentStorePath, String JavaDoc publicationOutputName) {
48         return "/publications/" + publicationOutputName + "/documents/" + getFileName(documentStorePath);
49     }
50
51     public static String JavaDoc getPublicationOutputPath(String JavaDoc publicationOutputName) {
52         return "/publications/" + publicationOutputName + "/";
53     }
54
55     public static String JavaDoc getDependenciesPath() {
56         return "/data/dependencies.xml";
57     }
58
59     public static String JavaDoc getPublicationSpecsPath() {
60         return "/publications/pubspecs.xml";
61     }
62
63     public static String JavaDoc getProcessedBookDefinitionPath() {
64         return "/data/book_definition_processed.xml";
65     }
66
67     public static String JavaDoc getPublicationLogPath() {
68         return "/publications/log.txt";
69     }
70
71     public static String JavaDoc getLinkLogPath() {
72         return "/publications/link_errors.txt";
73     }
74
75     private static String JavaDoc getFileName(String JavaDoc path) {
76         int slashPos = path.lastIndexOf("/");
77         if (slashPos == -1)
78             return path;
79         return path.substring(slashPos + 1);
80     }
81
82 }
83
Popular Tags