From: Niki Roo Date: Tue, 5 May 2020 16:33:25 +0000 (+0200) Subject: Merge commit '9b75402fd752653f27158f1c1775a062672c7b27' X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=commitdiff_plain;h=a1ff5c233eabcad91120cee2de614db98edec5da;hp=17625a9fa2683b4664675c7909008b2c61f39296 Merge commit '9b75402fd752653f27158f1c1775a062672c7b27' --- diff --git a/Instance.java b/Instance.java index 5c00a07..c3c086f 100644 --- a/Instance.java +++ b/Instance.java @@ -284,9 +284,9 @@ public class Instance { } /** - * Get the (unique) {@link LocalLibrary} for the program. + * Get the (unique) {@link BasicLibrary} for the program. * - * @return the {@link LocalLibrary} + * @return the {@link BasicLibrary} */ public BasicLibrary getLibrary() { if (lib == null) { @@ -296,6 +296,18 @@ public class Instance { return lib; } + /** + * Change the default {@link BasicLibrary} for this program. + *

+ * Be careful. + * + * @param lib + * the new {@link BasicLibrary} + */ + public void setLibrary(BasicLibrary lib) { + this.lib = lib; + } + /** * Return the directory where to look for default cover pages. * diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9cecc1d --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Main.java b/Main.java index 961816a..8d72803 100644 --- a/Main.java +++ b/Main.java @@ -22,8 +22,7 @@ import be.nikiroo.fanfix.library.RemoteLibraryServer; import be.nikiroo.fanfix.output.BasicOutput; import be.nikiroo.fanfix.output.BasicOutput.OutputType; import be.nikiroo.fanfix.reader.BasicReader; -import be.nikiroo.fanfix.reader.Reader; -import be.nikiroo.fanfix.reader.Reader.ReaderType; +import be.nikiroo.fanfix.reader.CliReader; import be.nikiroo.fanfix.searchable.BasicSearchable; import be.nikiroo.fanfix.supported.BasicSupport; import be.nikiroo.fanfix.supported.SupportType; @@ -38,7 +37,7 @@ import be.nikiroo.utils.serial.server.ServerObject; */ public class Main { private enum MainAction { - IMPORT, EXPORT, CONVERT, READ, READ_URL, LIST, HELP, SET_READER, START, VERSION, SERVER, STOP_SERVER, REMOTE, SET_SOURCE, SET_TITLE, SET_AUTHOR, SEARCH, SEARCH_TAG + IMPORT, EXPORT, CONVERT, READ, READ_URL, LIST, HELP, START, VERSION, SERVER, STOP_SERVER, REMOTE, SET_SOURCE, SET_TITLE, SET_AUTHOR, SEARCH, SEARCH_TAG } /** @@ -76,8 +75,6 @@ public class Main { *

  • --set-source [id] [new source]: change the source of the given story
  • *
  • --set-title [id] [new title]: change the title of the given story
  • *
  • --set-author [id] [new author]: change the author of the given story
  • - *
  • --set-reader [reader type]: set the reader type to CLI, TUI or LOCAL - * for this command
  • *
  • --version: get the version of the program
  • *
  • --server: start the server mode (see config file for parameters)
  • *
  • --stop-server: stop the running server on this port if any
  • @@ -314,10 +311,6 @@ public class Main { case HELP: exitCode = 255; break; - case SET_READER: - exitCode = setReaderType(args[i]); - action = MainAction.START; - break; case START: exitCode = 255; // not supposed to be selected by user break; @@ -339,10 +332,11 @@ public class Main { port = Integer.parseInt(args[i]); BasicLibrary lib = new RemoteLibrary(key, host, port); - lib = new CacheLibrary(Instance.getInstance().getRemoteDir(host), lib, + lib = new CacheLibrary( + Instance.getInstance().getRemoteDir(host), lib, Instance.getInstance().getUiConfig()); - BasicReader.setDefaultLibrary(lib); + Instance.getInstance().setLibrary(lib); action = MainAction.START; } else { @@ -413,11 +407,6 @@ public class Main { updates.ok(); // we consider it read break; case LIST: - if (BasicReader.getReader() == null) { - Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured")); - exitCode = 10; - break; - } exitCode = list(sourceString); break; case SET_SOURCE: @@ -445,20 +434,46 @@ public class Main { } break; case READ: - if (BasicReader.getReader() == null) { - Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured")); - exitCode = 10; + if (luid == null || luid.isEmpty()) { + syntax(false); + exitCode = 255; break; } - exitCode = read(luid, chapString, true); + + try { + BasicLibrary lib = Instance.getInstance().getLibrary(); + exitCode = read(lib.getStory(luid, null), chapString); + } catch (IOException e) { + Instance.getInstance().getTraceHandler() + .error(new IOException("Failed to read book", e)); + exitCode = 2; + } + break; case READ_URL: - if (BasicReader.getReader() == null) { - Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured")); - exitCode = 10; + if (urlString == null || urlString.isEmpty()) { + syntax(false); + exitCode = 255; break; } - exitCode = read(urlString, chapString, false); + + try { + BasicSupport support = BasicSupport + .getSupport(BasicReader.getUrl(urlString)); + if (support == null) { + Instance.getInstance().getTraceHandler() + .error("URL not supported: " + urlString); + exitCode = 2; + break; + } + + exitCode = read(support.process(null), chapString); + } catch (IOException e) { + Instance.getInstance().getTraceHandler() + .error(new IOException("Failed to read book", e)); + exitCode = 2; + } + break; case SEARCH: page = page == null ? 1 : page; @@ -475,19 +490,13 @@ public class Main { break; } - if (BasicReader.getReader() == null) { - Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured")); - exitCode = 10; - break; - } - try { if (searchOn == null) { - BasicReader.getReader().search(true); + new CliReader().listSearchables(); } else if (search != null) { - BasicReader.getReader().search(searchOn, search, page, - item, true); + new CliReader().searchBooksByKeyword(searchOn, search, page, + item); } else { exitCode = 255; } @@ -517,15 +526,9 @@ public class Main { break; } - if (BasicReader.getReader() == null) { - Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured")); - exitCode = 10; - break; - } - try { - BasicReader.getReader().searchTag(searchOn, page, item, - true, tags.toArray(new Integer[] {})); + new CliReader().searchBooksByTag(searchOn, page, item, + tags.toArray(new Integer[] {})); } catch (IOException e1) { Instance.getInstance().getTraceHandler().error(e1); } @@ -535,9 +538,6 @@ public class Main { syntax(true); exitCode = 0; break; - case SET_READER: - exitCode = 255; - break; case VERSION: System.out .println(String.format("Fanfix version %s" @@ -547,13 +547,8 @@ public class Main { updates.ok(); // we consider it read break; case START: - if (BasicReader.getReader() == null) { - Instance.getInstance().getTraceHandler().error(new Exception("No reader type has been configured")); - exitCode = 10; - break; - } try { - BasicReader.getReader().browse(null); + new CliReader().listBooks(null); } catch (IOException e) { Instance.getInstance().getTraceHandler().error(e); exitCode = 66; @@ -684,9 +679,8 @@ public class Main { * @return the exit return code (0 = success) */ private static int list(String source) { - BasicReader.setDefaultReaderType(ReaderType.CLI); try { - BasicReader.getReader().browse(source); + new CliReader().listBooks(source); } catch (IOException e) { Instance.getInstance().getTraceHandler().error(e); return 66; @@ -699,41 +693,41 @@ public class Main { * Start the current reader for this {@link Story}. * * @param story - * the LUID of the {@link Story} in the {@link LocalLibrary} - * or the {@link Story} {@link URL} + * the story to read * @param chapString * which {@link Chapter} to read (starting at 1), or NULL to get * the {@link Story} description - * @param library - * TRUE if the source is the {@link Story} LUID, FALSE if it is a - * {@link URL} * * @return the exit return code (0 = success) */ - private static int read(String story, String chapString, boolean library) { - try { - Reader reader = BasicReader.getReader(); - if (library) { - reader.setMeta(story); - } else { - reader.setMeta(BasicReader.getUrl(story), null); + private static int read(Story story, String chapString) { + Integer chap = null; + if (chapString != null) { + try { + chap = Integer.parseInt(chapString); + } catch (NumberFormatException e) { + Instance.getInstance().getTraceHandler().error(new IOException( + "Chapter number cannot be parsed: " + chapString, e)); + return 2; } + } - if (chapString != null) { - try { - reader.setChapter(Integer.parseInt(chapString)); - reader.read(true); - } catch (NumberFormatException e) { - Instance.getInstance().getTraceHandler() - .error(new IOException("Chapter number cannot be parsed: " + chapString, e)); - return 2; + if (story != null) { + try { + if (chap == null) { + new CliReader().listChapters(story); + } else { + new CliReader().printChapter(story, chap); } - } else { - reader.read(true); + } catch (IOException e) { + Instance.getInstance().getTraceHandler() + .error(new IOException("Failed to read book", e)); + return 2; } - } catch (IOException e) { - Instance.getInstance().getTraceHandler().error(e); - return 1; + } else { + Instance.getInstance().getTraceHandler() + .error("Cannot find book: " + chapString); + return 2; } return 0; @@ -862,24 +856,4 @@ public class Main { System.err.println(trans(StringId.ERR_SYNTAX)); } } - - /** - * Set the default reader type for this session only (it can be changed in - * the configuration file, too, but this value will override it). - * - * @param readerTypeString - * the type - */ - private static int setReaderType(String readerTypeString) { - try { - ReaderType readerType = ReaderType.valueOf(readerTypeString - .toUpperCase()); - BasicReader.setDefaultReaderType(readerType); - return 0; - } catch (IllegalArgumentException e) { - Instance.getInstance().getTraceHandler() - .error(new IOException("Unknown reader type: " + readerTypeString, e)); - return 1; - } - } } diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..ef538c2 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +3.1.2 diff --git a/bundles/Config.java b/bundles/Config.java index fd27a83..3af83c1 100644 --- a/bundles/Config.java +++ b/bundles/Config.java @@ -16,10 +16,6 @@ public enum Config { @Meta(description = "The language to use for in the program (example: en-GB, fr-BE...) or nothing for default system language (can be overwritten with the variable $LANG)",// format = Format.LOCALE, list = { "en-GB", "fr-BE" }) LANG, // - @Meta(description = "The default reader type to use to read stories:\nCLI = simple output to console\nTUI = a Text User Interface with menus and windows, based upon Jexer\nGUI = a GUI with locally stored files, based upon Swing", // - hidden = true, format = Format.FIXED_LIST, list = { "CLI", "GUI", "TUI" }, def = "GUI") - READER_TYPE, // - @Meta(description = "File format options",// group = true) FILE_FORMAT, // diff --git a/reader/BasicReader.java b/reader/BasicReader.java index 7f79da3..9ec0879 100644 --- a/reader/BasicReader.java +++ b/reader/BasicReader.java @@ -11,171 +11,18 @@ import java.util.Map; import java.util.TreeMap; import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.bundles.Config; import be.nikiroo.fanfix.bundles.UiConfig; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.library.BasicLibrary; -import be.nikiroo.fanfix.library.LocalLibrary; -import be.nikiroo.fanfix.supported.BasicSupport; -import be.nikiroo.utils.Progress; import be.nikiroo.utils.StringUtils; -import be.nikiroo.utils.serial.SerialUtils; /** * The class that handles the different {@link Story} readers you can use. - *

    - * All the readers should be accessed via {@link BasicReader#getReader()}. * * @author niki */ -public abstract class BasicReader implements Reader { - private static BasicLibrary defaultLibrary = Instance.getInstance().getLibrary(); - private static ReaderType defaultType = ReaderType.GUI; - - private BasicLibrary lib; - private MetaData meta; - private Story story; - private int chapter; - - /** - * Take the default reader type configuration from the config file. - */ - static { - String typeString = Instance.getInstance().getConfig().getString(Config.READER_TYPE); - if (typeString != null && !typeString.isEmpty()) { - try { - ReaderType type = ReaderType.valueOf(typeString.toUpperCase()); - defaultType = type; - } catch (IllegalArgumentException e) { - // Do nothing - } - } - } - - @Override - public synchronized Story getStory(Progress pg) throws IOException { - if (story == null) { - story = getLibrary().getStory(meta.getLuid(), pg); - } - - return story; - } - - @Override - public BasicLibrary getLibrary() { - if (lib == null) { - lib = defaultLibrary; - } - - return lib; - } - - @Override - public void setLibrary(BasicLibrary lib) { - this.lib = lib; - } - - @Override - public synchronized MetaData getMeta() { - return meta; - } - - @Override - public synchronized void setMeta(MetaData meta) throws IOException { - setMeta(meta == null ? null : meta.getLuid()); // must check the library - } - - @Override - public synchronized void setMeta(String luid) throws IOException { - story = null; - meta = getLibrary().getInfo(luid); - - if (meta == null) { - throw new IOException("Cannot retrieve story from library: " + luid); - } - } - - @Override - public synchronized void setMeta(URL url, Progress pg) throws IOException { - BasicSupport support = BasicSupport.getSupport(url); - if (support == null) { - throw new IOException("URL not supported: " + url.toString()); - } - - story = support.process(pg); - if (story == null) { - throw new IOException( - "Cannot retrieve story from external source: " - + url.toString()); - } - - meta = story.getMeta(); - } - - @Override - public int getChapter() { - return chapter; - } - - @Override - public void setChapter(int chapter) { - this.chapter = chapter; - } - - /** - * Return a new {@link BasicReader} ready for use if one is configured. - *

    - * Can return NULL if none are configured. - * - * @return a {@link BasicReader}, or NULL if none configured - */ - public static Reader getReader() { - try { - if (defaultType != null) { - return (Reader) SerialUtils.createObject(defaultType - .getTypeName()); - } - } catch (Exception e) { - Instance.getInstance().getTraceHandler() - .error(new Exception("Cannot create a reader of type: " + defaultType + " (Not compiled in?)", e)); - } - - return null; - } - - /** - * The default {@link Reader.ReaderType} used when calling - * {@link BasicReader#getReader()}. - * - * @return the default type - */ - public static ReaderType getDefaultReaderType() { - return defaultType; - } - - /** - * The default {@link Reader.ReaderType} used when calling - * {@link BasicReader#getReader()}. - * - * @param defaultType - * the new default type - */ - public static void setDefaultReaderType(ReaderType defaultType) { - BasicReader.defaultType = defaultType; - } - - /** - * Change the default {@link LocalLibrary} to open with the - * {@link BasicReader}s. - * - * @param lib - * the new {@link LocalLibrary} - */ - public static void setDefaultLibrary(BasicLibrary lib) { - BasicReader.defaultLibrary = lib; - } - +public abstract class BasicReader { /** * Return an {@link URL} from this {@link String}, be it a file path or an * actual {@link URL}. @@ -263,7 +110,6 @@ public abstract class BasicReader implements Reader { * @throws IOException * in case of I/O error */ - @Override public void openExternal(BasicLibrary lib, String luid, boolean sync) throws IOException { MetaData meta = lib.getInfo(luid); diff --git a/reader/CliReader.java b/reader/CliReader.java new file mode 100644 index 0000000..96ca644 --- /dev/null +++ b/reader/CliReader.java @@ -0,0 +1,256 @@ +package be.nikiroo.fanfix.reader; + +import java.io.IOException; +import java.util.List; + +import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.bundles.StringId; +import be.nikiroo.fanfix.data.Chapter; +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.fanfix.data.Paragraph; +import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.searchable.BasicSearchable; +import be.nikiroo.fanfix.searchable.SearchableTag; +import be.nikiroo.fanfix.supported.SupportType; +import be.nikiroo.utils.Image; +import be.nikiroo.utils.StringUtils; + +/** + * Command line {@link Story} reader. + *

    + * Will output stories to the console. + * + * @author niki + */ +public class CliReader extends BasicReader { + public void listBooks(String source) throws IOException { + List stories = Instance.getInstance().getLibrary().getList() + .filter(source, null, null); + + for (MetaData story : stories) { + String author = ""; + if (story.getAuthor() != null && !story.getAuthor().isEmpty()) { + author = " (" + story.getAuthor() + ")"; + } + + System.out.println( + story.getLuid() + ": " + story.getTitle() + author); + } + } + + public void listChapters(Story story) throws IOException { + if (story == null || story.getMeta() == null) { + throw new IOException("No story to read"); + } + MetaData meta = story.getMeta(); + if (meta == null) { + throw new IOException("No story to read"); + } + + String title = ""; + String author = ""; + + if (meta.getTitle() != null) { + title = meta.getTitle(); + } + + if (meta.getAuthor() != null) { + author = "©" + meta.getAuthor(); + if (meta.getDate() != null && !meta.getDate().isEmpty()) { + author = author + " (" + meta.getDate() + ")"; + } + } + + System.out.println(title); + System.out.println(author); + System.out.println(""); + + for (Chapter chap : story) { + if (chap.getName() != null && !chap.getName().isEmpty()) { + System.out.println(Instance.getInstance().getTrans().getString( + StringId.CHAPTER_NAMED, chap.getNumber(), + chap.getName())); + } else { + System.out.println(Instance.getInstance().getTrans() + .getString(StringId.CHAPTER_UNNAMED, chap.getNumber())); + } + } + } + + public void printChapter(Story story, int chapter) throws IOException { + if (story == null || story.getMeta() == null) { + throw new IOException("No story to read"); + } + MetaData meta = story.getMeta(); + if (meta == null) { + throw new IOException("No story to read"); + } + + if (chapter <= 0 || chapter > story.getChapters().size()) { + System.err.println("Chapter " + chapter + ": no such chapter"); + } else { + Chapter chap = story.getChapters().get(chapter - 1); + System.out.println( + "Chapter " + chap.getNumber() + ": " + chap.getName()); + System.out.println(); + + for (Paragraph para : chap) { + Image img = para.getContentImage(); + if (img != null) { + String sz = StringUtils.formatNumber(img.getSize(), 1); + System.out.println("[Image: " + sz + "]"); + } else { + System.out.println( + para.getContent() == null ? "" : para.getContent()); + } + System.out.println(""); + } + } + } + + public void listSearchables() throws IOException { + for (SupportType type : SupportType.values()) { + if (BasicSearchable.getSearchable(type) != null) { + System.out.println(type); + } + } + } + + public void searchBooksByKeyword(SupportType searchOn, String keywords, + int page, int item) throws IOException { + BasicSearchable search = BasicSearchable.getSearchable(searchOn); + + if (page == 0) { + System.out.println(search.searchPages(keywords)); + } else { + List metas = search.search(keywords, page); + + if (item == 0) { + System.out.println( + "Page " + page + " of stories for: " + keywords); + displayStories(metas); + } else { + // ! 1-based index ! + if (item <= 0 || item > metas.size()) { + throw new IOException("Index out of bounds: " + item); + } + + MetaData meta = metas.get(item - 1); + displayStory(meta); + } + } + } + + public void searchBooksByTag(SupportType searchOn, int page, int item, + Integer... tags) throws IOException { + + BasicSearchable search = BasicSearchable.getSearchable(searchOn); + SearchableTag stag = search.getTag(tags); + + if (stag == null) { + // TODO i18n + System.out.println("Known tags: "); + int i = 1; + for (SearchableTag s : search.getTags()) { + System.out.println(String.format("%d: %s", i, s.getName())); + i++; + } + } else { + if (page <= 0) { + if (stag.isLeaf()) { + System.out.println(search.searchPages(stag)); + } else { + System.out.println(stag.getCount()); + } + } else { + List metas = null; + List subtags = null; + int count; + + if (stag.isLeaf()) { + metas = search.search(stag, page); + count = metas.size(); + } else { + subtags = stag.getChildren(); + count = subtags.size(); + } + + if (item > 0) { + if (item <= count) { + if (metas != null) { + MetaData meta = metas.get(item - 1); + displayStory(meta); + } else { + SearchableTag subtag = subtags.get(item - 1); + displayTag(subtag); + } + } else { + System.out.println( + "Invalid item: only " + count + " items found"); + } + } else { + if (metas != null) { + // TODO i18n + System.out.println(String.format("Content of %s: ", + stag.getFqName())); + displayStories(metas); + } else { + // TODO i18n + System.out.println(String.format("Subtags of %s: ", + stag.getFqName())); + displayTags(subtags); + } + } + } + } + } + + private void displayTag(SearchableTag subtag) { + // TODO: i18n + String stories = "stories"; + String num = StringUtils.formatNumber(subtag.getCount()); + System.out.println(String.format("%s (%s), %s %s", subtag.getName(), + subtag.getFqName(), num, stories)); + } + + private void displayStory(MetaData meta) { + System.out.println(meta.getTitle()); + System.out.println(); + System.out.println(meta.getUrl()); + System.out.println(); + System.out.println("Tags: " + meta.getTags()); + System.out.println(); + for (Paragraph para : meta.getResume()) { + System.out.println(para.getContent()); + System.out.println(""); + } + } + + private void displayTags(List subtags) { + int i = 1; + for (SearchableTag subtag : subtags) { + String total = ""; + if (subtag.getCount() > 0) { + total = StringUtils.formatNumber(subtag.getCount()); + } + + if (total.isEmpty()) { + System.out + .println(String.format("%d: %s", i, subtag.getName())); + } else { + System.out.println(String.format("%d: %s (%s)", i, + subtag.getName(), total)); + } + + i++; + } + } + + private void displayStories(List metas) { + int i = 1; + for (MetaData meta : metas) { + System.out.println(i + ": " + meta.getTitle()); + i++; + } + } +} diff --git a/reader/Reader.java b/reader/Reader.java deleted file mode 100644 index 3ecf247..0000000 --- a/reader/Reader.java +++ /dev/null @@ -1,267 +0,0 @@ -package be.nikiroo.fanfix.reader; - -import java.io.IOException; -import java.net.URL; - -import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.library.BasicLibrary; -import be.nikiroo.fanfix.supported.SupportType; -import be.nikiroo.utils.Progress; - -/** - * A {@link Reader} is a class that will handle {@link Story} reading and - * browsing. - * - * @author niki - */ -public interface Reader { - /** - * A type of {@link BasicReader}. - * - * @author niki - */ - public enum ReaderType { - /** Simple reader that outputs everything on the console */ - CLI, - /** Reader that starts local programs to handle the stories */ - GUI, - /** A text (UTF-8) reader with menu and text windows */ - TUI, - /** A GUI reader implemented with the Android framework */ - ANDROID, - - ; - - /** - * Return the full class name of a type that implements said - * {@link ReaderType}. - * - * @return the class name - */ - public String getTypeName() { - String pkg = "be.nikiroo.fanfix.reader."; - switch (this) { - case CLI: - return pkg + "cli.CliReader"; - case TUI: - return pkg + "tui.TuiReader"; - case GUI: - return pkg + "ui.GuiReader"; - case ANDROID: - return pkg + "android.AndroidReader"; - } - - return null; - } - } - - /** - * Return the current target {@link MetaData}. - * - * @return the meta - */ - public MetaData getMeta(); - - /** - * Return the current {@link Story} as described by the current - * {@link MetaData}. - * - * @param pg - * the optional progress - * - * @return the {@link Story} - * - * @throws IOException - * in case of I/O error - * - */ - public Story getStory(Progress pg) throws IOException; - - /** - * The {@link BasicLibrary} to load the stories from (by default, takes the - * default {@link BasicLibrary}). - * - * @return the {@link BasicLibrary} - */ - public BasicLibrary getLibrary(); - - /** - * Change the {@link BasicLibrary} that will be managed by this - * {@link BasicReader}. - * - * @param lib - * the new {@link BasicLibrary} - */ - public void setLibrary(BasicLibrary lib); - - /** - * Set a {@link Story} from the current {@link BasicLibrary} into the - * {@link Reader}. - * - * @param luid - * the {@link Story} ID - * - * @throws IOException - * in case of I/O error - */ - public void setMeta(String luid) throws IOException; - - /** - * Set a {@link Story} from the current {@link BasicLibrary} into the - * {@link Reader}. - * - * @param meta - * the meta - * - * @throws IOException - * in case of I/O error - */ - public void setMeta(MetaData meta) throws IOException; - - /** - * Set an external {@link Story} into this {@link Reader}. - * - * @param source - * the {@link Story} {@link URL} - * @param pg - * the optional progress reporter - * - * @throws IOException - * in case of I/O error - */ - public void setMeta(URL source, Progress pg) throws IOException; - - /** - * Start the {@link Story} Reading. - * - * @param sync - * execute the process synchronously (wait until it is terminated - * before returning) - * - * @throws IOException - * in case of I/O error or if the {@link Story} was not - * previously set - */ - public void read(boolean sync) throws IOException; - - /** - * The selected chapter to start reading at (starting at 1, 0 = description, - * -1 = none). - * - * @return the chapter, or -1 for "no chapter" - */ - public int getChapter(); - - /** - * The selected chapter to start reading at (starting at 1, 0 = description, - * -1 = none). - * - * @param chapter - * the chapter, or -1 for "no chapter" - */ - public void setChapter(int chapter); - - /** - * Start the reader in browse mode for the given source (or pass NULL for - * all sources). - *

    - * Note that this must be a synchronous action. - * - * @param source - * the type of {@link Story} to take into account, or NULL for - * all - * - * @throws IOException - * in case of I/O error - */ - public void browse(String source) throws IOException; - - /** - * Display all supports that allow search operations. - * - * @param sync - * execute the process synchronously (wait until it is terminated - * before returning) - * - * @throws IOException - * in case of I/O error - */ - public void search(boolean sync) throws IOException; - - /** - * Search for the given terms and find stories that correspond if possible. - * - * @param searchOn - * the website to search on - * @param keywords - * the words to search for (cannot be NULL) - * @param page - * the page of results to show (0 = request the maximum number of - * pages, pages start at 1) - * @param item - * the item to select (0 = do not select a specific item but show - * all the page, items start at 1) - * @param sync - * execute the process synchronously (wait until it is terminated - * before returning) - * - * @throws IOException - * in case of I/O error - */ - public void search(SupportType searchOn, String keywords, int page, - int item, boolean sync) throws IOException; - - /** - * Search based upon a hierarchy of tags, or search for (sub)tags. - *

    - * We use the tags DisplayName. - *

    - * If no tag is given, the main tags will be shown. - *

    - * If a non-leaf tag is given, the subtags will be shown. - *

    - * If a leaf tag is given (or a full hierarchy ending with a leaf tag), - * stories will be shown. - *

    - * You can select the story you want with the item number. - * - * @param searchOn - * the website to search on - * @param page - * the page of results to show (0 = request the maximum number of - * pages, pages start at 1) - * @param item - * the item to select (0 = do not select a specific item but show - * all the page, items start at 1) - * @param sync - * execute the process synchronously (wait until it is terminated - * before returning) - * @param tags - * the tags indices to search for (this is a tag - * hierarchy, NOT a multiple tags choice) - * - * @throws IOException - * in case of I/O error - */ - public void searchTag(SupportType searchOn, int page, int item, - boolean sync, Integer... tags) throws IOException; - - /** - * Open the {@link Story} with an external reader (the program should be - * passed the main file associated with this {@link Story}). - * - * @param lib - * the {@link BasicLibrary} to select the {@link Story} from - * @param luid - * the {@link Story} LUID - * @param sync - * execute the process synchronously (wait until it is terminated - * before returning) - * - * @throws IOException - * in case of I/O error - */ - public void openExternal(BasicLibrary lib, String luid, boolean sync) - throws IOException; -} diff --git a/test/BasicSupportDeprecatedTest.java b/test/BasicSupportDeprecatedTest.java deleted file mode 100644 index c8c4b40..0000000 --- a/test/BasicSupportDeprecatedTest.java +++ /dev/null @@ -1,451 +0,0 @@ -package be.nikiroo.fanfix.test; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; - -import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.bundles.StringId; -import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.fanfix.data.Paragraph; -import be.nikiroo.fanfix.data.Paragraph.ParagraphType; -import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.supported.BasicSupport; -import be.nikiroo.fanfix.supported.BasicSupport_Deprecated; -import be.nikiroo.fanfix.supported.SupportType; -import be.nikiroo.utils.IOUtils; -import be.nikiroo.utils.Progress; -import be.nikiroo.utils.test.TestCase; -import be.nikiroo.utils.test.TestLauncher; - -class BasicSupportDeprecatedTest extends TestLauncher { - // quote chars - private char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE); - private char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE); - private char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE); - private char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE); - - public BasicSupportDeprecatedTest(String[] args) { - super("BasicSupportDeprecated", args); - - addSeries(new TestLauncher("General", args) { - { - addTest(new TestCase("BasicSupport.makeParagraphs()") { - @Override - public void test() throws Exception { - BasicSupportEmpty support = new BasicSupportEmpty() { - @Override - protected boolean isHtml() { - return true; - } - - @Override - public void fixBlanksBreaks(List paras) { - } - - @Override - public List requotify(Paragraph para) { - List paras = new ArrayList( - 1); - paras.add(para); - return paras; - } - }; - - List paras = null; - - paras = support.makeParagraphs(null, "", null); - assertEquals( - "An empty content should not generate paragraphs", - 0, paras.size()); - - paras = support.makeParagraphs(null, - "Line 1

    Line 2

    Line 3

    ", null); - assertEquals(5, paras.size()); - assertEquals("Line 1", paras.get(0).getContent()); - assertEquals(ParagraphType.BLANK, paras.get(1) - .getType()); - assertEquals("Line 2", paras.get(2).getContent()); - assertEquals(ParagraphType.BLANK, paras.get(3) - .getType()); - assertEquals("Line 3", paras.get(4).getContent()); - - paras = support.makeParagraphs(null, - "

    Line1

    Line2

    Line3

    ", null); - assertEquals(6, paras.size()); - } - }); - - addTest(new TestCase("BasicSupport.removeDoubleBlanks()") { - @Override - public void test() throws Exception { - BasicSupportEmpty support = new BasicSupportEmpty() { - @Override - protected boolean isHtml() { - return true; - } - }; - - List paras = null; - - paras = support - .makeParagraphs( - null, - "

    Line1

    Line2

    Line3

    ", - null); - assertEquals(5, paras.size()); - - paras = support - .makeParagraphs( - null, - "

    Line1

    Line2

    Line3

    * * *", - null); - assertEquals(5, paras.size()); - - paras = support.makeParagraphs(null, "1

    * * *

    2", - null); - assertEquals(3, paras.size()); - assertEquals(ParagraphType.BREAK, paras.get(1) - .getType()); - - paras = support.makeParagraphs(null, - "1


    * * *

    2", null); - assertEquals(3, paras.size()); - assertEquals(ParagraphType.BREAK, paras.get(1) - .getType()); - - paras = support.makeParagraphs(null, - "1

    * * *


    2", null); - assertEquals(3, paras.size()); - assertEquals(ParagraphType.BREAK, paras.get(1) - .getType()); - - paras = support.makeParagraphs(null, - "1



    * * *


    2", null); - assertEquals(3, paras.size()); - assertEquals(ParagraphType.BREAK, paras.get(1) - .getType()); - } - }); - - addTest(new TestCase("BasicSupport.processPara() quotes") { - @Override - public void test() throws Exception { - BasicSupportEmpty support = new BasicSupportEmpty() { - @Override - protected boolean isHtml() { - return true; - } - }; - - Paragraph para; - - // sanity check - para = support.processPara(""); - assertEquals(ParagraphType.BLANK, para.getType()); - // - - para = support.processPara("\"Yes, my Lord!\""); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openDoubleQuote + "Yes, my Lord!" - + closeDoubleQuote, para.getContent()); - - para = support.processPara("«Yes, my Lord!»"); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openDoubleQuote + "Yes, my Lord!" - + closeDoubleQuote, para.getContent()); - - para = support.processPara("'Yes, my Lord!'"); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openQuote + "Yes, my Lord!" + closeQuote, - para.getContent()); - - para = support.processPara("‹Yes, my Lord!›"); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openQuote + "Yes, my Lord!" + closeQuote, - para.getContent()); - } - }); - - addTest(new TestCase( - "BasicSupport.processPara() double-simple quotes") { - @Override - public void setUp() throws Exception { - super.setUp(); - - } - - @Override - public void tearDown() throws Exception { - - super.tearDown(); - } - - @Override - public void test() throws Exception { - BasicSupportEmpty support = new BasicSupportEmpty() { - @Override - protected boolean isHtml() { - return true; - } - }; - - Paragraph para; - - para = support.processPara("''Yes, my Lord!''"); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openDoubleQuote + "Yes, my Lord!" - + closeDoubleQuote, para.getContent()); - - para = support.processPara("‹‹Yes, my Lord!››"); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openDoubleQuote + "Yes, my Lord!" - + closeDoubleQuote, para.getContent()); - } - }); - - addTest(new TestCase("BasicSupport.processPara() apostrophe") { - @Override - public void test() throws Exception { - BasicSupportEmpty support = new BasicSupportEmpty() { - @Override - protected boolean isHtml() { - return true; - } - }; - - Paragraph para; - - String text = "Nous étions en été, mais cela aurait être l'hiver quand nous n'étions encore qu'à Aubeuge"; - para = support.processPara(text); - assertEquals(ParagraphType.NORMAL, para.getType()); - assertEquals(text, para.getContent()); - } - }); - - addTest(new TestCase("BasicSupport.processPara() words count") { - @Override - public void test() throws Exception { - BasicSupportEmpty support = new BasicSupportEmpty() { - @Override - protected boolean isHtml() { - return true; - } - }; - - Paragraph para; - - para = support.processPara("«Yes, my Lord!»"); - assertEquals(3, para.getWords()); - - para = support.processPara("One, twee, trois."); - assertEquals(3, para.getWords()); - } - }); - - addTest(new TestCase("BasicSupport.requotify() words count") { - @Override - public void test() throws Exception { - BasicSupportEmpty support = new BasicSupportEmpty(); - - char openDoubleQuote = Instance.getInstance().getTrans() - .getCharacter(StringId.OPEN_DOUBLE_QUOTE); - char closeDoubleQuote = Instance.getInstance().getTrans() - .getCharacter(StringId.CLOSE_DOUBLE_QUOTE); - - String content = null; - Paragraph para = null; - List paras = null; - long words = 0; - - content = "One, twee, trois."; - para = new Paragraph(ParagraphType.NORMAL, content, - content.split(" ").length); - paras = support.requotify(para); - words = 0; - for (Paragraph p : paras) { - words += p.getWords(); - } - assertEquals("Bad words count in a single paragraph", - para.getWords(), words); - - content = "Such WoW! So Web2.0! With Colours!"; - para = new Paragraph(ParagraphType.NORMAL, content, - content.split(" ").length); - paras = support.requotify(para); - words = 0; - for (Paragraph p : paras) { - words += p.getWords(); - } - assertEquals("Bad words count in a single paragraph", - para.getWords(), words); - - content = openDoubleQuote + "Such a good idea!" - + closeDoubleQuote - + ", she said. This ought to be a new para."; - para = new Paragraph(ParagraphType.QUOTE, content, - content.split(" ").length); - paras = support.requotify(para); - words = 0; - for (Paragraph p : paras) { - words += p.getWords(); - } - assertEquals( - "Bad words count in a requotified paragraph", - para.getWords(), words); - } - }); - } - }); - - addSeries(new TestLauncher("Text", args) { - { - addTest(new TestCase("Chapter detection simple") { - private File tmp; - - @Override - public void setUp() throws Exception { - tmp = File.createTempFile("fanfix-text-file_", ".test"); - IOUtils.writeSmallFile(tmp.getParentFile(), - tmp.getName(), "TITLE" - + "\n"// - + "By nona" - + "\n" // - + "\n" // - + "Chapter 0: Resumé" + "\n" + "\n" - + "'sume." + "\n" + "\n" - + "Chapter 1: chap1" + "\n" + "\n" - + "Fanfan." + "\n" + "\n" - + "Chapter 2: Chap2" + "\n" + "\n" // - + "Tulipe." + "\n"); - } - - @Override - public void tearDown() throws Exception { - tmp.delete(); - } - - @Override - public void test() throws Exception { - BasicSupport support = BasicSupport.getSupport( - SupportType.TEXT, tmp.toURI().toURL()); - - Story story = support.process(null); - - assertEquals(2, story.getChapters().size()); - assertEquals(1, story.getChapters().get(1) - .getParagraphs().size()); - assertEquals("Tulipe.", story.getChapters().get(1) - .getParagraphs().get(0).getContent()); - } - }); - - addTest(new TestCase("Chapter detection with String 'Chapter'") { - private File tmp; - - @Override - public void setUp() throws Exception { - tmp = File.createTempFile("fanfix-text-file_", ".test"); - IOUtils.writeSmallFile(tmp.getParentFile(), - tmp.getName(), "TITLE" - + "\n"// - + "By nona" - + "\n" // - + "\n" // - + "Chapter 0: Resumé" + "\n" + "\n" - + "'sume." + "\n" + "\n" - + "Chapter 1: chap1" + "\n" + "\n" - + "Chapter fout-la-merde" + "\n" - + "\n"// - + "Fanfan." + "\n" + "\n" - + "Chapter 2: Chap2" + "\n" + "\n" // - + "Tulipe." + "\n"); - } - - @Override - public void tearDown() throws Exception { - tmp.delete(); - } - - @Override - public void test() throws Exception { - BasicSupport support = BasicSupport.getSupport( - SupportType.TEXT, tmp.toURI().toURL()); - - Story story = support.process(null); - - assertEquals(2, story.getChapters().size()); - assertEquals(1, story.getChapters().get(1) - .getParagraphs().size()); - assertEquals("Tulipe.", story.getChapters().get(1) - .getParagraphs().get(0).getContent()); - } - }); - } - }); - } - - private class BasicSupportEmpty extends BasicSupport_Deprecated { - @Override - protected boolean supports(URL url) { - return false; - } - - @Override - protected boolean isHtml() { - return false; - } - - @Override - protected MetaData getMeta(URL source, InputStream in) - throws IOException { - return null; - } - - @Override - protected String getDesc(URL source, InputStream in) throws IOException { - return null; - } - - @Override - protected List> getChapters(URL source, - InputStream in, Progress pg) throws IOException { - return null; - } - - @Override - protected String getChapterContent(URL source, InputStream in, - int number, Progress pg) throws IOException { - return null; - } - - @Override - // and make it public! - public List makeParagraphs(URL source, String content, - Progress pg) throws IOException { - return super.makeParagraphs(source, content, pg); - } - - @Override - // and make it public! - public void fixBlanksBreaks(List paras) { - super.fixBlanksBreaks(paras); - } - - @Override - // and make it public! - public Paragraph processPara(String line) { - return super.processPara(line); - } - - @Override - // and make it public! - public List requotify(Paragraph para) { - return super.requotify(para); - } - } -} diff --git a/test/BasicSupportUtilitiesTest.java b/test/BasicSupportUtilitiesTest.java deleted file mode 100644 index 9cec220..0000000 --- a/test/BasicSupportUtilitiesTest.java +++ /dev/null @@ -1,397 +0,0 @@ -package be.nikiroo.fanfix.test; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.bundles.StringId; -import be.nikiroo.fanfix.data.Paragraph; -import be.nikiroo.fanfix.data.Paragraph.ParagraphType; -import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.supported.BasicSupport; -import be.nikiroo.fanfix.supported.BasicSupportHelper; -import be.nikiroo.fanfix.supported.BasicSupportImages; -import be.nikiroo.fanfix.supported.BasicSupportPara; -import be.nikiroo.fanfix.supported.SupportType; -import be.nikiroo.utils.IOUtils; -import be.nikiroo.utils.Progress; -import be.nikiroo.utils.test.TestCase; -import be.nikiroo.utils.test.TestLauncher; - -class BasicSupportUtilitiesTest extends TestLauncher { - // quote chars - private char openQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_SINGLE_QUOTE); - private char closeQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_SINGLE_QUOTE); - private char openDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.OPEN_DOUBLE_QUOTE); - private char closeDoubleQuote = Instance.getInstance().getTrans().getCharacter(StringId.CLOSE_DOUBLE_QUOTE); - - public BasicSupportUtilitiesTest(String[] args) { - super("BasicSupportUtilities", args); - - addSeries(new TestLauncher("General", args) { - { - addTest(new TestCase("BasicSupport.makeParagraphs()") { - @Override - public void test() throws Exception { - BasicSupportParaPublic bsPara = new BasicSupportParaPublic() { - @Override - public void fixBlanksBreaks(List paras) { - } - - @Override - public List requotify(Paragraph para, boolean html) { - List paras = new ArrayList( - 1); - paras.add(para); - return paras; - } - }; - - List paras = null; - - paras = bsPara.makeParagraphs(null, null, "", true, null); - assertEquals( - "An empty content should not generate paragraphs", - 0, paras.size()); - - paras = bsPara.makeParagraphs(null, null, - "Line 1

    Line 2

    Line 3

    ", true, null); - assertEquals(5, paras.size()); - assertEquals("Line 1", paras.get(0).getContent()); - assertEquals(ParagraphType.BLANK, paras.get(1) - .getType()); - assertEquals("Line 2", paras.get(2).getContent()); - assertEquals(ParagraphType.BLANK, paras.get(3) - .getType()); - assertEquals("Line 3", paras.get(4).getContent()); - - paras = bsPara.makeParagraphs(null, null, - "

    Line1

    Line2

    Line3

    ", true, null); - assertEquals(6, paras.size()); - } - }); - - addTest(new TestCase("BasicSupport.removeDoubleBlanks()") { - @Override - public void test() throws Exception { - BasicSupportParaPublic support = new BasicSupportParaPublic(); - - List paras = null; - - paras = support - .makeParagraphs( - null, - null, - "

    Line1

    Line2

    Line3

    ", - true, - null); - assertEquals(5, paras.size()); - - paras = support - .makeParagraphs( - null, - null, - "

    Line1

    Line2

    Line3

    * * *", - true, - null); - assertEquals(5, paras.size()); - - paras = support.makeParagraphs(null, null, "1

    * * *

    2", - true, null); - assertEquals(3, paras.size()); - assertEquals(ParagraphType.BREAK, paras.get(1) - .getType()); - - paras = support.makeParagraphs(null, null, - "1


    * * *

    2", true, null); - assertEquals(3, paras.size()); - assertEquals(ParagraphType.BREAK, paras.get(1) - .getType()); - - paras = support.makeParagraphs(null, null, - "1

    * * *


    2", true, null); - assertEquals(3, paras.size()); - assertEquals(ParagraphType.BREAK, paras.get(1) - .getType()); - - paras = support.makeParagraphs(null, null, - "1



    * * *


    2", true, null); - assertEquals(3, paras.size()); - assertEquals(ParagraphType.BREAK, paras.get(1) - .getType()); - } - }); - - addTest(new TestCase("BasicSupport.processPara() quotes") { - @Override - public void test() throws Exception { - BasicSupportParaPublic support = new BasicSupportParaPublic(); - - Paragraph para; - - // sanity check - para = support.processPara("", true); - assertEquals(ParagraphType.BLANK, para.getType()); - // - - para = support.processPara("\"Yes, my Lord!\"", true); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openDoubleQuote + "Yes, my Lord!" - + closeDoubleQuote, para.getContent()); - - para = support.processPara("«Yes, my Lord!»", true); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openDoubleQuote + "Yes, my Lord!" - + closeDoubleQuote, para.getContent()); - - para = support.processPara("'Yes, my Lord!'", true); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openQuote + "Yes, my Lord!" + closeQuote, - para.getContent()); - - para = support.processPara("‹Yes, my Lord!›", true); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openQuote + "Yes, my Lord!" + closeQuote, - para.getContent()); - } - }); - - addTest(new TestCase( - "BasicSupport.processPara() double-simple quotes") { - @Override - public void setUp() throws Exception { - super.setUp(); - - } - - @Override - public void tearDown() throws Exception { - - super.tearDown(); - } - - @Override - public void test() throws Exception { - BasicSupportParaPublic support = new BasicSupportParaPublic(); - - Paragraph para; - - para = support.processPara("''Yes, my Lord!''", true); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openDoubleQuote + "Yes, my Lord!" - + closeDoubleQuote, para.getContent()); - - para = support.processPara("‹‹Yes, my Lord!››", true); - assertEquals(ParagraphType.QUOTE, para.getType()); - assertEquals(openDoubleQuote + "Yes, my Lord!" - + closeDoubleQuote, para.getContent()); - } - }); - - addTest(new TestCase("BasicSupport.processPara() apostrophe") { - @Override - public void test() throws Exception { - BasicSupportParaPublic support = new BasicSupportParaPublic(); - - Paragraph para; - - String text = "Nous étions en été, mais cela aurait être l'hiver quand nous n'étions encore qu'à Aubeuge"; - para = support.processPara(text, true); - assertEquals(ParagraphType.NORMAL, para.getType()); - assertEquals(text, para.getContent()); - } - }); - - addTest(new TestCase("BasicSupport.processPara() words count") { - @Override - public void test() throws Exception { - BasicSupportParaPublic support = new BasicSupportParaPublic(); - - Paragraph para; - - para = support.processPara("«Yes, my Lord!»", true); - assertEquals(3, para.getWords()); - - para = support.processPara("One, twee, trois.", true); - assertEquals(3, para.getWords()); - } - }); - - addTest(new TestCase("BasicSupport.requotify() words count") { - @Override - public void test() throws Exception { - BasicSupportParaPublic support = new BasicSupportParaPublic(); - - char openDoubleQuote = Instance.getInstance().getTrans() - .getCharacter(StringId.OPEN_DOUBLE_QUOTE); - char closeDoubleQuote = Instance.getInstance().getTrans() - .getCharacter(StringId.CLOSE_DOUBLE_QUOTE); - - String content = null; - Paragraph para = null; - List paras = null; - long words = 0; - - content = "One, twee, trois."; - para = new Paragraph(ParagraphType.NORMAL, content, - content.split(" ").length); - paras = support.requotify(para, false); - words = 0; - for (Paragraph p : paras) { - words += p.getWords(); - } - assertEquals("Bad words count in a single paragraph", - para.getWords(), words); - - content = "Such WoW! So Web2.0! With Colours!"; - para = new Paragraph(ParagraphType.NORMAL, content, - content.split(" ").length); - paras = support.requotify(para, false); - words = 0; - for (Paragraph p : paras) { - words += p.getWords(); - } - assertEquals("Bad words count in a single paragraph", - para.getWords(), words); - - content = openDoubleQuote + "Such a good idea!" - + closeDoubleQuote - + ", she said. This ought to be a new para."; - para = new Paragraph(ParagraphType.QUOTE, content, - content.split(" ").length); - paras = support.requotify(para, false); - words = 0; - for (Paragraph p : paras) { - words += p.getWords(); - } - assertEquals( - "Bad words count in a requotified paragraph", - para.getWords(), words); - } - }); - } - }); - - addSeries(new TestLauncher("Text", args) { - { - addTest(new TestCase("Chapter detection simple") { - private File tmp; - - @Override - public void setUp() throws Exception { - tmp = File.createTempFile("fanfix-text-file_", ".test"); - IOUtils.writeSmallFile(tmp.getParentFile(), - tmp.getName(), "TITLE" - + "\n"// - + "By nona" - + "\n" // - + "\n" // - + "Chapter 0: Resumé" + "\n" + "\n" - + "'sume." + "\n" + "\n" - + "Chapter 1: chap1" + "\n" + "\n" - + "Fanfan." + "\n" + "\n" - + "Chapter 2: Chap2" + "\n" + "\n" // - + "Tulipe." + "\n"); - } - - @Override - public void tearDown() throws Exception { - tmp.delete(); - } - - @Override - public void test() throws Exception { - BasicSupport support = BasicSupport.getSupport( - SupportType.TEXT, tmp.toURI().toURL()); - - Story story = support.process(null); - - assertEquals(2, story.getChapters().size()); - assertEquals(1, story.getChapters().get(1) - .getParagraphs().size()); - assertEquals("Tulipe.", story.getChapters().get(1) - .getParagraphs().get(0).getContent()); - } - }); - - addTest(new TestCase("Chapter detection with String 'Chapter'") { - private File tmp; - - @Override - public void setUp() throws Exception { - tmp = File.createTempFile("fanfix-text-file_", ".test"); - IOUtils.writeSmallFile(tmp.getParentFile(), - tmp.getName(), "TITLE" - + "\n"// - + "By nona" - + "\n" // - + "\n" // - + "Chapter 0: Resumé" + "\n" + "\n" - + "'sume." + "\n" + "\n" - + "Chapter 1: chap1" + "\n" + "\n" - + "Chapter fout-la-merde" + "\n" - + "\n"// - + "Fanfan." + "\n" + "\n" - + "Chapter 2: Chap2" + "\n" + "\n" // - + "Tulipe." + "\n"); - } - - @Override - public void tearDown() throws Exception { - tmp.delete(); - } - - @Override - public void test() throws Exception { - BasicSupport support = BasicSupport.getSupport( - SupportType.TEXT, tmp.toURI().toURL()); - - Story story = support.process(null); - - assertEquals(2, story.getChapters().size()); - assertEquals(1, story.getChapters().get(1) - .getParagraphs().size()); - assertEquals("Tulipe.", story.getChapters().get(1) - .getParagraphs().get(0).getContent()); - } - }); - } - }); - } - - class BasicSupportParaPublic extends BasicSupportPara { - public BasicSupportParaPublic() { - super(new BasicSupportHelper(), new BasicSupportImages()); - } - - @Override - // and make it public! - public Paragraph makeParagraph(BasicSupport support, URL source, - String line, boolean html) { - return super.makeParagraph(support, source, line, html); - } - - @Override - // and make it public! - public List makeParagraphs(BasicSupport support, - URL source, String content, boolean html, Progress pg) - throws IOException { - return super.makeParagraphs(support, source, content, html, pg); - } - - @Override - // and make it public! - public Paragraph processPara(String line, boolean html) { - return super.processPara(line, html); - } - - @Override - // and make it public! - public List requotify(Paragraph para, boolean html) { - return super.requotify(para, html); - } - } -} diff --git a/test/ConversionTest.java b/test/ConversionTest.java deleted file mode 100644 index d730b3b..0000000 --- a/test/ConversionTest.java +++ /dev/null @@ -1,284 +0,0 @@ -package be.nikiroo.fanfix.test; - -import java.io.File; -import java.io.FilenameFilter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.Main; -import be.nikiroo.fanfix.output.BasicOutput; -import be.nikiroo.utils.IOUtils; -import be.nikiroo.utils.TraceHandler; -import be.nikiroo.utils.test.TestCase; -import be.nikiroo.utils.test.TestLauncher; - -class ConversionTest extends TestLauncher { - private String testUri; - private String expectedDir; - private String resultDir; - private List realTypes; - private Map> skipCompare; - private Map> skipCompareCross; - - public ConversionTest(String testName, final String testUri, - final String expectedDir, final String resultDir, String[] args) { - super("Conversion - " + testName, args); - - this.testUri = testUri; - this.expectedDir = expectedDir; - this.resultDir = resultDir; - - // Special mode SYSOUT is not a file type (System.out) - realTypes = new ArrayList(); - for (BasicOutput.OutputType type : BasicOutput.OutputType.values()) { - if (!BasicOutput.OutputType.SYSOUT.equals(type)) { - realTypes.add(type); - } - } - - if (!testUri.startsWith("http://") && !testUri.startsWith("https://")) { - addTest(new TestCase("Read the test file") { - @Override - public void test() throws Exception { - assertEquals("The test file \"" + testUri - + "\" cannot be found", true, - new File(testUri).exists()); - } - }); - } - - addTest(new TestCase("Assure directories exist") { - @Override - public void test() throws Exception { - new File(expectedDir).mkdirs(); - new File(resultDir).mkdirs(); - assertEquals("The Expected directory \"" + expectedDir - + "\" cannot be created", true, - new File(expectedDir).exists()); - assertEquals("The Result directory \"" + resultDir - + "\" cannot be created", true, - new File(resultDir).exists()); - } - }); - - for (BasicOutput.OutputType type : realTypes) { - addTest(getTestFor(type)); - } - } - - @Override - protected void start() throws Exception { - skipCompare = new HashMap>(); - skipCompareCross = new HashMap>(); - - skipCompare.put("epb.ncx", Arrays.asList( - " ", - " ")); - skipCompare.put(".info", Arrays.asList("CREATION_DATE=", - "URL=\"file:/", "UUID=EPUBCREATOR=\"", "")); - skipCompare.put("URL", Arrays.asList("file:/")); - - for (String key : skipCompare.keySet()) { - skipCompareCross.put(key, skipCompare.get(key)); - } - - skipCompareCross.put(".info", Arrays.asList("")); - skipCompareCross.put("epb.opf", Arrays.asList(" ")); - skipCompareCross.put("index.html", - Arrays.asList("

    ")); - skipCompareCross.put("URL", Arrays.asList("")); - } - - @Override - protected void stop() throws Exception { - } - - private TestCase getTestFor(final BasicOutput.OutputType type) { - return new TestCase(type + " output mode") { - @Override - public void test() throws Exception { - File target = generate(this, testUri, new File(resultDir), type); - target = new File(target.getAbsolutePath() - + type.getDefaultExtension(false)); - - // Check conversion: - compareFiles(this, new File(expectedDir), new File(resultDir), - type, "Generate " + type); - - // LATEX not supported as input - if (BasicOutput.OutputType.LATEX.equals(type)) { - return; - } - - // Cross-checks: - for (BasicOutput.OutputType crossType : realTypes) { - File crossDir = Test.tempFiles - .createTempDir("cross-result"); - - generate(this, target.getAbsolutePath(), crossDir, - crossType); - compareFiles(this, new File(resultDir), crossDir, - crossType, "Cross compare " + crossType - + " generated from " + type); - } - } - }; - } - - private File generate(TestCase testCase, String testUri, File resultDir, - BasicOutput.OutputType type) throws Exception { - final List errors = new ArrayList(); - - TraceHandler previousTraceHandler = Instance.getInstance().getTraceHandler(); - Instance.getInstance().setTraceHandler(new TraceHandler(true, true, 0) { - @Override - public void error(String message) { - errors.add(message); - } - - @Override - public void error(Exception e) { - error(" "); - for (Throwable t = e; t != null; t = t.getCause()) { - error(((t == e) ? "(" : "..caused by: (") - + t.getClass().getSimpleName() + ") " - + t.getMessage()); - for (StackTraceElement s : t.getStackTrace()) { - error("\t" + s.toString()); - } - } - } - }); - - try { - File target = new File(resultDir, type.toString()); - int code = Main.convert(testUri, type.toString(), - target.getAbsolutePath(), false, null); - - String error = ""; - for (String err : errors) { - if (!error.isEmpty()) - error += "\n"; - error += err; - } - testCase.assertEquals("The conversion returned an error message: " - + error, 0, errors.size()); - if (code != 0) { - testCase.fail("The conversion failed with return code: " + code); - } - - return target; - } finally { - Instance.getInstance().setTraceHandler(previousTraceHandler); - } - } - - private void compareFiles(TestCase testCase, File expectedDir, - File resultDir, final BasicOutput.OutputType limitTiFiles, - final String errMess) throws Exception { - - Map> skipCompare = errMess.startsWith("Cross") ? this.skipCompareCross - : this.skipCompare; - - FilenameFilter filter = null; - if (limitTiFiles != null) { - filter = new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.toLowerCase().startsWith( - limitTiFiles.toString().toLowerCase()); - } - }; - } - - List resultFiles; - List expectedFiles; - { - String[] resultArr = resultDir.list(filter); - Arrays.sort(resultArr); - resultFiles = Arrays.asList(resultArr); - String[] expectedArr = expectedDir.list(filter); - Arrays.sort(expectedArr); - expectedFiles = Arrays.asList(expectedArr); - } - - testCase.assertEquals(errMess, expectedFiles, resultFiles); - - for (int i = 0; i < resultFiles.size(); i++) { - File expected = new File(expectedDir, expectedFiles.get(i)); - File result = new File(resultDir, resultFiles.get(i)); - - testCase.assertEquals(errMess + ": type mismatch: expected a " - + (expected.isDirectory() ? "directory" : "file") - + ", received a " - + (result.isDirectory() ? "directory" : "file"), - expected.isDirectory(), result.isDirectory()); - - if (expected.isDirectory()) { - compareFiles(testCase, expected, result, null, errMess); - continue; - } - - if (expected.getName().endsWith(".cbz") - || expected.getName().endsWith(".epub")) { - File tmpExpected = Test.tempFiles.createTempDir(expected - .getName() + "[zip-content]"); - File tmpResult = Test.tempFiles.createTempDir(result.getName() - + "[zip-content]"); - IOUtils.unzip(expected, tmpExpected); - IOUtils.unzip(result, tmpResult); - compareFiles(testCase, tmpExpected, tmpResult, null, errMess); - } else { - List expectedLines = Arrays.asList(IOUtils - .readSmallFile(expected).split("\n")); - List resultLines = Arrays.asList(IOUtils.readSmallFile( - result).split("\n")); - - String name = expected.getAbsolutePath(); - if (name.startsWith(expectedDir.getAbsolutePath())) { - name = expectedDir.getName() - + name.substring(expectedDir.getAbsolutePath() - .length()); - } - - testCase.assertEquals(errMess + ": " + name - + ": the number of lines is not the same", - expectedLines.size(), resultLines.size()); - - for (int j = 0; j < expectedLines.size(); j++) { - String expectedLine = expectedLines.get(j); - String resultLine = resultLines.get(j); - - boolean skip = false; - for (Entry> skipThose : skipCompare - .entrySet()) { - for (String skipStart : skipThose.getValue()) { - if (name.endsWith(skipThose.getKey()) - && expectedLine.startsWith(skipStart) - && resultLine.startsWith(skipStart)) { - skip = true; - } - } - } - - if (skip) { - continue; - } - - testCase.assertEquals(errMess + ": line " + (j + 1) - + " is not the same in file " + name, expectedLine, - resultLine); - } - } - } - } -} diff --git a/test/LibraryTest.java b/test/LibraryTest.java deleted file mode 100644 index da44438..0000000 --- a/test/LibraryTest.java +++ /dev/null @@ -1,258 +0,0 @@ -package be.nikiroo.fanfix.test; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import be.nikiroo.fanfix.data.Chapter; -import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.fanfix.data.Paragraph; -import be.nikiroo.fanfix.data.Story; -import be.nikiroo.fanfix.library.BasicLibrary; -import be.nikiroo.fanfix.library.LocalLibrary; -import be.nikiroo.fanfix.output.BasicOutput.OutputType; -import be.nikiroo.utils.IOUtils; -import be.nikiroo.utils.test.TestCase; -import be.nikiroo.utils.test.TestLauncher; - -class LibraryTest extends TestLauncher { - private BasicLibrary lib; - private File tmp; - - public LibraryTest(String[] args) { - super("Library", args); - - final String luid1 = "001"; // A - final String luid2 = "002"; // B - final String luid3 = "003"; // B then A, then B - final String name1 = "My story 1"; - final String name2 = "My story 2"; - final String name3 = "My story 3"; - final String name3ex = "My story 3 [edited]"; - final String source1 = "Source A"; - final String source2 = "Source B"; - final String author1 = "Unknown author"; - final String author2 = "Another other otter author"; - - final String errMess = "The resulting stories in the list are not what we expected"; - - addSeries(new TestLauncher("Local", args) { - { - addTest(new TestCase("getList") { - @Override - public void test() throws Exception { - List metas = lib.getList().getMetas(); - assertEquals(errMess, Arrays.asList(), - titlesAsList(metas)); - } - }); - - addTest(new TestCase("save") { - @Override - public void test() throws Exception { - lib.save(story(luid1, name1, source1, author1), luid1, - null); - - List metas = lib.getList().getMetas(); - assertEquals(errMess, Arrays.asList(name1), - titlesAsList(metas)); - } - }); - - addTest(new TestCase("save more") { - @Override - public void test() throws Exception { - List metas = null; - - lib.save(story(luid2, name2, source2, author1), luid2, - null); - - metas = lib.getList().getMetas(); - assertEquals(errMess, Arrays.asList(name1, name2), - titlesAsList(metas)); - - lib.save(story(luid3, name3, source2, author1), luid3, - null); - - metas = lib.getList().getMetas(); - assertEquals(errMess, - Arrays.asList(name1, name2, name3), - titlesAsList(metas)); - } - }); - - addTest(new TestCase("save override luid (change author)") { - @Override - public void test() throws Exception { - // same luid as a previous one - lib.save(story(luid3, name3ex, source2, author2), - luid3, null); - - List metas = lib.getList().getMetas(); - assertEquals(errMess, - Arrays.asList(name1, name2, name3ex), - titlesAsList(metas)); - } - }); - - addTest(new TestCase("getList with results") { - @Override - public void test() throws Exception { - List metas = lib.getList().getMetas(); - assertEquals(3, metas.size()); - } - }); - - addTest(new TestCase("getList by source") { - @Override - public void test() throws Exception { - List metas = null; - - metas = lib.getList().filter(source1, null, null); - assertEquals(1, metas.size()); - - metas = lib.getList().filter(source2, null, null); - assertEquals(2, metas.size()); - - metas = lib.getList().filter((String)null, null, null); - assertEquals(3, metas.size()); - } - }); - - addTest(new TestCase("getList by author") { - @Override - public void test() throws Exception { - List metas = null; - - metas = lib.getList().filter(null, author1, null); - assertEquals(2, metas.size()); - - metas = lib.getList().filter(null, author2, null); - assertEquals(1, metas.size()); - - metas = lib.getList().filter((String)null, null, null); - assertEquals(3, metas.size()); - } - }); - - addTest(new TestCase("changeType") { - @Override - public void test() throws Exception { - List metas = null; - - lib.changeSource(luid3, source1, null); - - metas = lib.getList().filter(source1, null, null); - assertEquals(2, metas.size()); - - metas = lib.getList().filter(source2, null, null); - assertEquals(1, metas.size()); - - metas = lib.getList().filter((String)null, null, null); - assertEquals(3, metas.size()); - } - }); - - addTest(new TestCase("save override luid (change source)") { - @Override - public void test() throws Exception { - List metas = null; - - // same luid as a previous one - lib.save(story(luid3, "My story 3", source2, author2), - luid3, null); - - metas = lib.getList().filter(source1, null, null); - assertEquals(1, metas.size()); - - metas = lib.getList().filter(source2, null, null); - assertEquals(2, metas.size()); - - metas = lib.getList().filter((String)null, null, null); - assertEquals(3, metas.size()); - } - }); - } - }); - } - - @Override - protected void start() throws Exception { - tmp = File.createTempFile(".test-fanfix", ".library"); - tmp.delete(); - tmp.mkdir(); - - lib = new LocalLibrary(tmp, OutputType.INFO_TEXT, OutputType.CBZ); - } - - @Override - protected void stop() throws Exception { - IOUtils.deltree(tmp); - } - - /** - * Return the (sorted) list of titles present in this list of - * {@link MetaData}s. - * - * @param metas - * the meta - * - * @return the sorted list - */ - private List titlesAsList(List metas) { - List list = new ArrayList(); - for (MetaData meta : metas) { - list.add(meta.getTitle()); - } - - Collections.sort(list); - return list; - } - - private Story story(String luid, String title, String source, String author) { - Story story = new Story(); - - MetaData meta = new MetaData(); - meta.setLuid(luid); - meta.setTitle(title); - meta.setSource(source); - meta.setAuthor(author); - story.setMeta(meta); - - Chapter resume = chapter(0, "Resume"); - meta.setResume(resume); - - List chapters = new ArrayList(); - chapters.add(chapter(1, "Chap 1")); - chapters.add(chapter(2, "Chap 2")); - story.setChapters(chapters); - - long words = 0; - for (Chapter chap : story.getChapters()) { - words += chap.getWords(); - } - meta.setWords(words); - - return story; - } - - private Chapter chapter(int number, String name) { - Chapter chapter = new Chapter(number, name); - - List paragraphs = new ArrayList(); - paragraphs.add(new Paragraph(Paragraph.ParagraphType.NORMAL, - "some words in this paragraph please thank you", 8)); - - chapter.setParagraphs(paragraphs); - - long words = 0; - for (Paragraph para : chapter.getParagraphs()) { - words += para.getWords(); - } - chapter.setWords(words); - - return chapter; - } -} diff --git a/test/Test.java b/test/Test.java deleted file mode 100644 index 5ec24a4..0000000 --- a/test/Test.java +++ /dev/null @@ -1,177 +0,0 @@ -package be.nikiroo.fanfix.test; - -import java.io.File; -import java.io.IOException; - -import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.bundles.Config; -import be.nikiroo.fanfix.bundles.ConfigBundle; -import be.nikiroo.utils.IOUtils; -import be.nikiroo.utils.TempFiles; -import be.nikiroo.utils.resources.Bundles; -import be.nikiroo.utils.test.TestLauncher; - -/** - * Tests for Fanfix. - * - * @author niki - */ -public class Test extends TestLauncher { - // - // 4 files can control the test: - // - test/VERBOSE: enable verbose mode - // - test/OFFLINE: to forbid any downloading - // - test/URLS: to allow testing URLs - // - test/FORCE_REFRESH: to force a clear of the cache - // - // Note that test/CACHE can be kept, as it will contain all internet related - // files you need (if you allow URLs, run the test once which will populate - // the CACHE then go OFFLINE, it will still work). - // - // The test files will be: - // - test/*.url: URL to download in text format, content = URL - // - test/*.story: text mode story, content = story - // - - /** - * The temporary files handler. - */ - static TempFiles tempFiles; - - /** - * Create the Fanfix {@link TestLauncher}. - * - * @param args - * the arguments to configure the number of columns and the ok/ko - * {@link String}s - * @param urlsAllowed - * allow testing URLs (.url files) - * - * @throws IOException - */ - public Test(String[] args, boolean urlsAllowed) throws IOException { - super("Fanfix", args); - Instance.getInstance().setTraceHandler(null); - addSeries(new BasicSupportUtilitiesTest(args)); - addSeries(new BasicSupportDeprecatedTest(args)); - addSeries(new LibraryTest(args)); - - File sources = new File("test/"); - if (sources.isDirectory()) { - for (File file : sources.listFiles()) { - if (file.isDirectory()) { - continue; - } - - String expectedDir = new File(file.getParentFile(), "expected_" - + file.getName()).getAbsolutePath(); - String resultDir = new File(file.getParentFile(), "result_" - + file.getName()).getAbsolutePath(); - - String uri; - if (urlsAllowed && file.getName().endsWith(".url")) { - uri = IOUtils.readSmallFile(file).trim(); - } else if (file.getName().endsWith(".story")) { - uri = file.getAbsolutePath(); - } else { - continue; - } - - addSeries(new ConversionTest(file.getName(), uri, expectedDir, - resultDir, args)); - } - } - } - - /** - * Main entry point of the program. - * - * @param args - * the arguments passed to the {@link TestLauncher}s. - * @throws IOException - * in case of I/O error - */ - static public void main(String[] args) throws IOException { - Instance.init(); - - // Verbose mode: - boolean verbose = new File("test/VERBOSE").exists(); - - // Can force refresh - boolean forceRefresh = new File("test/FORCE_REFRESH").exists(); - - // Allow URLs: - boolean urlsAllowed = new File("test/URLS").exists(); - - - // Only download files if allowed: - boolean offline = new File("test/OFFLINE").exists(); - Instance.getInstance().getCache().setOffline(offline); - - - - int result = 0; - tempFiles = new TempFiles("fanfix-test"); - try { - File tmpConfig = tempFiles.createTempDir("fanfix-config"); - File localCache = new File("test/CACHE"); - prepareCache(localCache, forceRefresh); - - ConfigBundle config = new ConfigBundle(); - Bundles.setDirectory(tmpConfig.getAbsolutePath()); - config.setString(Config.CACHE_DIR, localCache.getAbsolutePath()); - config.setInteger(Config.CACHE_MAX_TIME_STABLE, -1); - config.setInteger(Config.CACHE_MAX_TIME_CHANGING, -1); - config.updateFile(tmpConfig.getPath()); - System.setProperty("CONFIG_DIR", tmpConfig.getAbsolutePath()); - - Instance.init(true); - Instance.getInstance().getCache().setOffline(offline); - - TestLauncher tests = new Test(args, urlsAllowed); - tests.setDetails(verbose); - - result = tests.launch(); - - IOUtils.deltree(tmpConfig); - prepareCache(localCache, forceRefresh); - } finally { - // Test temp files - tempFiles.close(); - - // This is usually done in Fanfix.Main: - Instance.getInstance().getTempFiles().close(); - } - - System.exit(result); - } - - /** - * Prepare the cache (or clean it up). - *

    - * The cache directory will always exist if this method succeed - * - * @param localCache - * the cache directory - * @param forceRefresh - * TRUE to force acache refresh (delete all files) - * - * @throw IOException if the cache cannot be created - */ - private static void prepareCache(File localCache, boolean forceRefresh) - throws IOException { - // if needed - localCache.mkdirs(); - - if (!localCache.isDirectory()) { - throw new IOException("Cannot get a cache"); - } - - // delete local cached files (_*) or all files if forceRefresh - for (File f : localCache.listFiles()) { - if (forceRefresh || f.getName().startsWith("_")) { - IOUtils.deltree(f); - } - } - } -}