01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.dataretrieval;
17:
18: import org.outerx.daisy.x10Bookdeps.BookDependenciesDocument;
19: import org.apache.xmlbeans.XmlOptions;
20: import org.outerj.daisy.repository.VersionKey;
21:
22: import java.util.HashSet;
23: import java.util.Iterator;
24: import java.io.OutputStream;
25: import java.io.IOException;
26:
27: public class BookDependencies {
28: private HashSet keys = new HashSet();
29:
30: public void addDependency(VersionKey versionKey) {
31: keys.add(versionKey);
32: }
33:
34: public void store(OutputStream os) throws IOException {
35: BookDependenciesDocument.BookDependencies.Dependency[] dependenciesXml = new BookDependenciesDocument.BookDependencies.Dependency[keys
36: .size()];
37:
38: Iterator keysIt = keys.iterator();
39: for (int i = 0; keysIt.hasNext(); i++) {
40: VersionKey key = (VersionKey) keysIt.next();
41: BookDependenciesDocument.BookDependencies.Dependency dependencyXml = BookDependenciesDocument.BookDependencies.Dependency.Factory
42: .newInstance();
43: dependencyXml.setDocumentId(key.getDocumentId());
44: dependencyXml.setBranchId(key.getBranchId());
45: dependencyXml.setLanguageId(key.getLanguageId());
46: dependencyXml.setVersionId(key.getVersionId());
47: dependenciesXml[i] = dependencyXml;
48: }
49:
50: BookDependenciesDocument bookDependenciesDocument = BookDependenciesDocument.Factory
51: .newInstance();
52: bookDependenciesDocument.addNewBookDependencies()
53: .setDependencyArray(dependenciesXml);
54:
55: XmlOptions xmlOptions = new XmlOptions();
56: xmlOptions.setSavePrettyPrint();
57: bookDependenciesDocument.save(os, xmlOptions);
58: }
59:
60: }
|