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.linkextraction.impl;
17:
18: import org.xml.sax.helpers.DefaultHandler;
19: import org.xml.sax.Attributes;
20: import org.xml.sax.SAXException;
21: import org.xml.sax.ContentHandler;
22: import org.outerj.daisy.linkextraction.LinkCollector;
23: import org.outerj.daisy.linkextraction.LinkType;
24: import org.outerj.daisy.plugin.PluginRegistry;
25:
26: public class NavigationLinkExtractor extends AbstractLinkExtractor {
27:
28: public NavigationLinkExtractor(String name, String description,
29: PluginRegistry pluginRegistry) {
30: super (name, description, pluginRegistry);
31: }
32:
33: public NavigationLinkExtractor() {
34: super ();
35: }
36:
37: protected ContentHandler getContentHandler(
38: LinkCollector linkCollector, String defaultBranch,
39: String defaultLanguage) {
40: return new NavigationLinkExtractionHandler(linkCollector,
41: defaultBranch, defaultLanguage);
42: }
43:
44: public class NavigationLinkExtractionHandler extends DefaultHandler {
45: private final LinkCollector linkCollector;
46: private final String defaultBranch;
47: private final String defaultLanguage;
48: private static final String NAVIGATION_NS = "http://outerx.org/daisy/1.0#navigationspec";
49:
50: public NavigationLinkExtractionHandler(
51: LinkCollector linkCollector, String defaultBranch,
52: String defaultLanguage) {
53: this .linkCollector = linkCollector;
54: this .defaultBranch = defaultBranch;
55: this .defaultLanguage = defaultLanguage;
56: }
57:
58: public void startElement(String uri, String localName,
59: String qName, Attributes attributes)
60: throws SAXException {
61: if ((localName.equals("doc") || localName.equals("import"))
62: && uri.equals(NAVIGATION_NS)) {
63: String idString = attributes.getValue(localName
64: .equals("doc") ? "id" : "docId");
65: if (idString != null) {
66: String docId = idString.trim();
67: String branch = attributes.getValue("branch");
68: if (branch == null)
69: branch = defaultBranch;
70: String language = attributes.getValue("language");
71: if (language == null)
72: language = defaultLanguage;
73: linkCollector.addLink(LinkType.OTHER, docId,
74: branch, language, -1);
75: }
76: }
77: }
78: }
79: }
|