001/**
002 * Copyright (c) 2011, The University of Southampton and the individual contributors.
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification,
006 * are permitted provided that the following conditions are met:
007 *
008 *   *  Redistributions of source code must retain the above copyright notice,
009 *      this list of conditions and the following disclaimer.
010 *
011 *   *  Redistributions in binary form must reproduce the above copyright notice,
012 *      this list of conditions and the following disclaimer in the documentation
013 *      and/or other materials provided with the distribution.
014 *
015 *   *  Neither the name of the University of Southampton nor the names of its
016 *      contributors may be used to endorse or promote products derived from this
017 *      software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030package org.openimaj.tools.web;
031
032import java.util.ArrayList;
033import java.util.List;
034
035import org.kohsuke.args4j.Argument;
036import org.kohsuke.args4j.CmdLineException;
037import org.kohsuke.args4j.Option;
038
039/**
040 * Options for the Reader command-line program.
041 * 
042 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
043 *
044 */
045public class ReaderOptions {
046        @Option(name = "--print-debug", aliases="-d", usage = "print debug messages to standard error")
047        private boolean debug = false;
048        
049        @Option(name = "-html", usage = "get article html")
050        private boolean html = false;
051        
052        @Option(name = "-text", usage = "get article text")
053        private boolean text = false;
054        
055        @Option(name = "-title", usage = "get article title")
056        private boolean title = false;
057        
058        @Option(name = "-links", usage = "get article links")
059        private boolean links = false;
060        
061        @Option(name = "-images", usage = "get article images")
062        private boolean images = false;
063
064        @Option(name = "-subhead", usage = "get article sub-headings")
065        private boolean subhead = false;
066        
067        @Option(name = "-date", usage = "get article date")
068        private boolean date = false;
069        
070        @Argument(required = true, usage = "document paths or urls to process", metaVar="files_or_urls")
071        private List<String> documents = new ArrayList<String>();
072        
073        /**
074         * @return the debug
075         */
076        public boolean isDebug() {
077                return debug;
078        }
079        
080        /**
081         * @return the html
082         */
083        public boolean isHtml() {
084                return html;
085        }
086
087        /**
088         * @return the text
089         */
090        public boolean isText() {
091                return text;
092        }
093
094        /**
095         * @return the title
096         */
097        public boolean isTitle() {
098                return title;
099        }
100
101        /**
102         * @return the links
103         */
104        public boolean isLinks() {
105                return links;
106        }
107
108        /**
109         * @return the images
110         */
111        public boolean isImages() {
112                return images;
113        }
114
115        /**
116         * @return the subhead
117         */
118        public boolean isSubhead() {
119                return subhead;
120        }
121        
122        /**
123         * @return the documents
124         */
125        public List<String> getDocuments() {
126                return documents;
127        }
128
129        /**
130         * @return the subhead
131         */
132        public boolean isDate() {
133                return date;
134        }
135        
136        /**
137         * @return true if there are multiple docs being processed
138         */
139        public boolean isMultiDocument() {
140                return documents.size() > 1;
141        }
142        
143        private int countModes() {
144                int count = 0;
145                
146                if (html) count++;
147                if (text) count++;
148                if (title) count++;
149                if (links) count++;
150                if (images) count++;
151                if (subhead) count++;
152                if (date) count++;
153                
154                return count;
155        }
156        
157        /**
158         * @return true if more than one mode is set.
159         */
160        public boolean isMultiMode() {
161                return countModes() > 1;
162        }
163        
164        protected void validate() throws CmdLineException {
165                if (countModes() == 0)
166                        throw new CmdLineException(null, "At least one of the [-html, -text, -title, -links or -images] options is required.");
167        }
168}