libcds-savot-java/0000755000175000017500000000000012724035712013670 5ustar sladensladenlibcds-savot-java/LICENSE0000664000175000017500000010446012724035712014704 0ustar sladensladenGNU 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 .libcds-savot-java/README.md0000664000175000017500000000045012724035712015150 0ustar sladensladenSavot ===== This repository contains the CDS Savot library, the *Simple Access to VOTable* parser. Current release: - Savot 4.0.0 (beta release) Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) License ======= GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 See LICENSE libcds-savot-java/pom.xml0000664000175000017500000001062312724035712015211 0ustar sladensladen 4.0.0 cds.savot savot jar 4.0.0 Savot https://github.com/bourgesl/marlin-renderer Simple Access to VOTable - Parser (GPL3) Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) yyyy/MM/dd HH:mm:ss src/main/resources true org.apache.maven.plugins maven-resources-plugin 2.6 UTF-8 org.apache.maven.plugins maven-compiler-plugin 3.1 1.6 1.6 true UTF-8 org.apache.maven.plugins maven-jar-plugin 2.4 true ${maven.build.timestamp} default-jar package jar LICENSE README.md cds/** cds/astrores/** cds/savot/pull/** cds/savot/sax/** kxml package jar kxml LICENSE README.md cds/astrores/** cds/savot/pull/** cds/savot/sax/** provided net.sf.kxml kxml2 2.3.0 libcds-savot-java/src/0000775000175000017500000000000012724035712014461 5ustar sladensladenlibcds-savot-java/src/main/0000775000175000017500000000000012724035712015405 5ustar sladensladenlibcds-savot-java/src/main/resources/0000775000175000017500000000000012724035712017417 5ustar sladensladenlibcds-savot-java/src/main/resources/cds/0000775000175000017500000000000012724035712020170 5ustar sladensladenlibcds-savot-java/src/main/resources/cds/savot/0000775000175000017500000000000012724035712021324 5ustar sladensladenlibcds-savot-java/src/main/resources/cds/savot/Version.properties0000664000175000017500000000006112724035712025064 0ustar sladensladenversion=${project.artifactId}-${project.version} libcds-savot-java/src/main/java/0000775000175000017500000000000012724035712016326 5ustar sladensladenlibcds-savot-java/src/main/java/cds/0000775000175000017500000000000012724035712017077 5ustar sladensladenlibcds-savot-java/src/main/java/cds/astrores/0000775000175000017500000000000012724035712020741 5ustar sladensladenlibcds-savot-java/src/main/java/cds/astrores/Markups.java0000664000175000017500000000642312724035712023233 0ustar sladensladenpackage cds.astrores; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // // SAVOT 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, version 3 of the License. // // SAVOT 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. // // The GNU General Public License is available in COPYING file // along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* ASTRORES markups and attributes *

* @author Andre Schaaff */ public interface Markups { // markups final static String VOTABLE = "VOTABLE"; final String TABLE = "TABLE"; final static String FIELD = "FIELD"; final static String FIELDREF = "FIELDref"; /* new 1.1 */ final static String TABLEDATA = "TABLEDATA"; final static String DESCRIPTION = "DESCRIPTION"; final static String DATA = "DATA"; final static String RESOURCE = "RESOURCE"; final static String PARAM = "PARAM"; final static String PARAMREF = "PARAMref"; /* new 1.1 */ final static String DEFINITIONS = "DEFINITIONS"; final static String LINK = "LINK"; final static String GROUP = "GROUP"; /* new 1.1 */ final static String INFO = "INFO"; final static String TR = "TR"; final static String TD = "TD"; final static String COOSYS = "COOSYS"; final static String SYSTEM = "SYSTEM"; final static String OPTION = "OPTION"; final static String FITS = "FITS"; final static String STREAM = "STREAM"; final static String BINARY = "BINARY"; final static String VALUES = "VALUES"; // attributes final static String ARRAYSIZE = "arraysize"; final static String DATATYPE = "datatype"; final static String EPOCH = "epoch"; final static String EQUINOX = "equinox"; final static String INCLUSIVE = "inclusive"; final static String MAX = "max"; final static String MIN = "min"; final static String NAME = "name"; final static String PRECISION = "precision"; final static String REF = "ref"; final static String TYPE = "type"; final static String UTYPE = "utype"; /* new 1.1 */ final static String UCD = "ucd"; final static String UNIT = "unit"; final static String VALUE = "value"; final static String WIDTH = "width"; final static String ID = "ID"; final static String CONTENTROLE = "content-role"; final static String CONTENTTYPE = "content-type"; final static String TITLE = "title"; final static String HREF = "href"; final static String GREF = "gref"; final static String ACTION = "action"; final static String VERSION = "version"; final static String ENCODING = "encoding"; final static String EXTNUM = "extnum"; final static String NULL = "null"; final static String INVALID = "invalid"; final static String ACTUATE = "actuate"; final static String EXPIRES = "expires"; final static String RIGHTS = "rights"; } libcds-savot-java/src/main/java/cds/astrores/sax/0000775000175000017500000000000012724035712021534 5ustar sladensladenlibcds-savot-java/src/main/java/cds/astrores/sax/AstroresSAXConsumer.java0000664000175000017500000001050012724035712026265 0ustar sladensladenpackage cds.astrores.sax; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.util.ArrayList; /** * @author Andre Schaaff */ public interface AstroresSAXConsumer { // start elements public abstract void startAstrores(@SuppressWarnings("rawtypes") ArrayList attributes); /* * public abstract void startDescription(); * * public abstract void startResource(ArrayList attributes); * * public abstract void startTable(ArrayList attributes); * * public abstract void startField(ArrayList attributes); * * public abstract void startFieldref(ArrayList attributes); * * public abstract void startValues(ArrayList attributes); * * public abstract void startStream(ArrayList attributes); * * public abstract void startTR(); * * public abstract void startTD(ArrayList attributes); * * public abstract void startData(); * * public abstract void startBinary(); * * public abstract void startFits(ArrayList attributes); * * public abstract void startTableData(); * * public abstract void startParam(ArrayList attributes); * * public abstract void startParamRef(ArrayList attributes); * * public abstract void startLink(ArrayList attributes); * * public abstract void startInfo(ArrayList attributes); * * public abstract void startMin(ArrayList attributes); * * public abstract void startMax(ArrayList attributes); * * public abstract void startOption(ArrayList attributes); * * public abstract void startGroup(ArrayList attributes); * * public abstract void startCoosys(ArrayList attributes); * * public abstract void startDefinitions(); */ // end elements public abstract void endAstrores(); /* * * public abstract void endDescription(); * * public abstract void endResource(); * * public abstract void endTable(); * * public abstract void endField(); * * public abstract void endFieldref(); * * public abstract void endValues(); * * public abstract void endStream(); * * public abstract void endTR(); * * public abstract void endTD(); * * public abstract void endData(); * * public abstract void endBinary(); * * public abstract void endFits(); * * public abstract void endTableData(); * * public abstract void endParam(); * * public abstract void endParamRef(); * * public abstract void endLink(); * * public abstract void endInfo(); * * public abstract void endMin(); * * public abstract void endMax(); * * public abstract void endOption(); * * public abstract void endGroup(); * * public abstract void endCoosys(); * * public abstract void endDefinitions(); } */ // TEXT /* * public abstract void textTD(String text); * * public abstract void textMin(String text); * * public abstract void textMax(String text); * * public abstract void textCoosys(String text); * * public abstract void textLink(String text); * * public abstract void textOption(String text); * * public abstract void textGroup(String text); * * public abstract void textInfo(String text); * * public abstract void textDescription(String text); } */ // document public abstract void startDocument(); public abstract void endDocument(); } libcds-savot-java/src/main/java/cds/astrores/sax/AstroresSAXEngine.java0000664000175000017500000012144112724035712025706 0ustar sladensladenpackage cds.astrores.sax; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; // parser import org.kxml2.io.KXmlParser; import org.xmlpull.v1.XmlPullParser; import cds.savot.model.SavotCoosys; // model import cds.savot.model.SavotData; import cds.savot.model.SavotDefinitions; import cds.savot.model.SavotInfo; import cds.savot.model.SavotLink; import cds.savot.model.SavotOption; import cds.savot.model.SavotValues; import cds.table.TableModel; /** * Savot SAX Engine, it has been tested with kXML Pull parser implementation * * @author Andre Schaaff */ @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"}) public class AstroresSAXEngine { // markups private static String ASTRO = "ASTRO"; private static String TABLE = "TABLE"; private static String FIELD = "FIELD"; private static String TABLEDATA = "TABLEDATA"; private static String DESCRIPTION = "DESCRIPTION"; private static String DATA = "DATA"; private static String RESOURCE = "RESOURCE"; private static String DEFINITIONS = "DEFINITIONS"; private static String LINK = "LINK"; private static String INFO = "INFO"; private static String ROW = "ROW"; private static String CELL = "CELL"; private static String COOSYS = "COOSYS"; private static String SYSTEM = "SYSTEM"; private static String OPTION = "OPTION"; private static String VALUES = "VALUES"; private static String CSV = "CSV"; // attributes private static String ARRAYSIZE = "arraysize"; private static String DATATYPE = "datatype"; private static String EPOCH = "epoch"; private static String EQUINOX = "equinox"; // private static String INCLUSIVE = "inclusive"; // private static String MAX = "max"; // private static String MIN = "min"; private static String PRECISION = "precision"; private static String REF = "ref"; private static String TYPE = "type"; private static String UTYPE = "utype"; /* new 1.1 */ private static String UCD = "ucd"; private static String UNIT = "unit"; private static String VALUE = "value"; private static String WIDTH = "width"; private static String ID = "ID"; private static String CONTENTROLE = "content-role"; private static String CONTENTTYPE = "content-type"; private static String HREF = "href"; private static String GREF = "gref"; private static String ACTION = "action"; // private static String VERSION = "version"; private static String INVALID = "invalid"; // element or attribute private static String NAME = "NAME"; private static String TITLE = "TITLE"; private static String NULL = "NULL"; // data model global objects private ArrayList allTables = new ArrayList(); // contains all tables private boolean trace = false; TableModel tb = new TableModel(); // needed for sequential parsing protected XmlPullParser parser = null; // Astrores SAX consumer protected AstroresSAXConsumer consumer; // Statistics @SuppressWarnings("unused") private int resourceCounter; @SuppressWarnings("unused") private int tableCounter; @SuppressWarnings("unused") private int dataCounter; @SuppressWarnings("unused") private int rowCounter; /** * Constructor * * @param parser * @param file * a file to parse */ public AstroresSAXEngine(AstroresSAXConsumer consumer, XmlPullParser parser, String file, boolean debug) { try { this.parser = parser; this.consumer = consumer; // set the input of the parser FileInputStream inStream = new FileInputStream(new File(file)); BufferedInputStream dataBuffInStream = new BufferedInputStream(inStream); parser.setInput(dataBuffInStream, "UTF-8"); parse(parser); } catch (IOException e) { System.err.println("AstroresSAXEngine : " + e); } catch (Exception f) { System.err.println("AstroresSAXEngine : " + f); } } /** * Constructor * * @param parser * @param url * url to parse * @param enc * encoding (example : UTF-8) */ public AstroresSAXEngine(AstroresSAXConsumer consumer, XmlPullParser parser, URL url, String enc, boolean debug) { try { this.parser = parser; this.consumer = consumer; // set the input of the parser (with the given encoding) parser.setInput(new DataInputStream(url.openStream()), enc); parse(parser); } catch (IOException e) { System.err.println("AstroresSAXEngine : " + e); } catch (Exception f) { System.err.println("AstroresSAXEngine : " + f); } } /** * Constructor * * @param parser * @param instream * stream to parse * @param enc * encoding (example : UTF-8) */ public AstroresSAXEngine(AstroresSAXConsumer consumer, XmlPullParser parser, InputStream instream, String enc, boolean debug) { try { this.parser = parser; this.consumer = consumer; // DataInputStream dataInStream = new DataInputStream(instream); BufferedInputStream dataBuffInStream = new BufferedInputStream(instream); // set the input of the parser (with the given encoding) parser.setInput(dataBuffInStream, enc); parse(parser); } catch (IOException e) { System.err.println("AstroresSAXEngine : " + e); } catch (Exception f) { System.err.println("AstroresSAXEngine : " + f); } } /** * * @param buffer * String */ @SuppressWarnings("unchecked") private void CSVCut(String buffer) { int begin = 0; int linecount = 0; int headlines = 3; char colsep = 9; // TAB char recsep = 10; // TAB if (trace) { System.err.println("Entree CSVCut"); } for (int i = 0; i < buffer.length(); i++) { if (buffer.charAt(i) == recsep) { linecount++; @SuppressWarnings("rawtypes") ArrayList row = new ArrayList(); if (linecount < headlines) { System.err.println("L" + linecount + " ---> " + buffer.substring(begin, i)); } int begin2 = begin; for (int j = begin; j <= i; j++) { if (buffer.charAt(j) == colsep || buffer.charAt(j) == recsep) { if (linecount < headlines) { System.err.println("colsep-->"); System.err.println("---> " + buffer.substring(begin2, j)); } else { // line storage // add value to the current row row.add(buffer.substring(begin2, j)); } begin2 = j + 1; } } begin = i + 1; tb.addRow(row); } /* * if (buffer.charAt(i) == 10) { System.err.println("---> " + * buffer.substring(debut, i)); StringTokenizer sb = new * StringTokenizer(buffer.substring(debut, i)); while * (sb.hasMoreTokens()) System.err.println(sb.nextToken()); * * debut = i + 1; } */ } System.err.println("row count : " + tb.getRowCount()); /* * StringTokenizer sb = new StringTokenizer(buffer); * System.err.println("Token count : " + sb.countTokens()); while * (sb.hasMoreTokens()) System.err.println(sb.nextToken()); */ } /** * Parsing engine * * @param parser * an XML pull parser (example : kXML) * @throws IOException * */ @SuppressWarnings({"unchecked", "rawtypes"}) public void parse(XmlPullParser parser) throws IOException { String name = ""; ArrayList father = new ArrayList(); String currentMarkup = "XML"; ArrayList currentRow = new ArrayList(); StringBuffer description = new StringBuffer(); // global description @SuppressWarnings("unused") String id = null; // current resource id @SuppressWarnings("unused") String type = null; // current resource type ArrayList fieldPropertyNames = new ArrayList(); ArrayList fieldPropertyValues = new ArrayList(); @SuppressWarnings("unused") SavotData currentData = new SavotData(); SavotValues currentValues = new SavotValues(); // SavotTableData currentTableData = new SavotTableData(); String currentDescription = ""; SavotLink currentLink = new SavotLink(); SavotInfo currentInfo = new SavotInfo(); SavotOption currentOption = new SavotOption(); SavotCoosys currentCoosys = new SavotCoosys(); SavotDefinitions currentDefinitions = new SavotDefinitions(); try { // envent type int eventType = parser.getEventType(); int previousDepth = 0; // while the end of the document is not reach while (eventType != XmlPullParser.END_DOCUMENT) { // treatment depending on event type switch (eventType) { // if a start tag is reach case KXmlParser.START_TAG: try { // the name of the current tag name = parser.getName(); if (trace) { System.err.println("Name ---> " + parser.getName()); } if (name != null) { // ASTRO if (name.equalsIgnoreCase(ASTRO)) { if (trace) { System.err.println("VOTABLE begin"); } currentMarkup = ASTRO; } else // DESCRIPTION if (name.equalsIgnoreCase(DESCRIPTION)) { currentMarkup = DESCRIPTION; if (trace) { System.err.println("DESCRIPTION begin"); } } // RESOURCE else if (name.equalsIgnoreCase(RESOURCE)) { if (trace) { System.err.println("RESOURCE begin"); } currentMarkup = RESOURCE; // for statistics only resourceCounter++; // all resource properties init id = ""; type = ""; if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, TYPE) != null) { type = parser.getAttributeValue(null, TYPE); } if (parser.getAttributeValue(null, ID) != null) { id = parser.getAttributeValue(null, ID); } } } // TABLE else if (name.equalsIgnoreCase(TABLE)) { tb = new TableModel(); currentMarkup = TABLE; // for statistics only tableCounter++; if (parser.getAttributeCount() != 0 && parser.getAttributeValue(null, ID) != null) { tb.setId(parser.getAttributeValue(null, ID)); } } // FIELD else if (name.equalsIgnoreCase(FIELD)) { fieldPropertyNames = new ArrayList(); fieldPropertyValues = new ArrayList(); currentMarkup = FIELD; if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, UNIT) != null) { fieldPropertyNames.add(UNIT); fieldPropertyValues.add(parser.getAttributeValue(null, UNIT)); } if (parser.getAttributeValue(null, DATATYPE) != null) { fieldPropertyNames.add(DATATYPE); fieldPropertyValues.add(parser.getAttributeValue(null, DATATYPE)); } if (parser.getAttributeValue(null, PRECISION) != null) { fieldPropertyNames.add(PRECISION); fieldPropertyValues.add(parser.getAttributeValue(null, PRECISION)); } if (parser.getAttributeValue(null, WIDTH) != null) { fieldPropertyNames.add(WIDTH); fieldPropertyValues.add(parser.getAttributeValue(null, WIDTH)); } if (parser.getAttributeValue(null, REF) != null) { fieldPropertyNames.add(REF); fieldPropertyValues.add(parser.getAttributeValue(null, REF)); } if (parser.getAttributeValue(null, NAME) != null) { fieldPropertyNames.add(NAME); fieldPropertyValues.add(parser.getAttributeValue(null, NAME)); } if (parser.getAttributeValue(null, UCD) != null) { fieldPropertyNames.add(UCD); fieldPropertyValues.add(parser.getAttributeValue(null, UCD)); } if (parser.getAttributeValue(null, ARRAYSIZE) != null) { fieldPropertyNames.add(ARRAYSIZE); fieldPropertyValues.add(parser.getAttributeValue(null, ARRAYSIZE)); } if (parser.getAttributeValue(null, TYPE) != null) { fieldPropertyNames.add(TYPE); fieldPropertyValues.add(parser.getAttributeValue(null, TYPE)); } if (parser.getAttributeValue(null, UTYPE) != null) { fieldPropertyNames.add(UTYPE); fieldPropertyValues.add(parser.getAttributeValue(null, UTYPE)); } if (parser.getAttributeValue(null, ID) != null) { fieldPropertyNames.add(ID); fieldPropertyValues.add(parser.getAttributeValue(null, ID)); } } } // VALUES else if (name.equalsIgnoreCase(VALUES)) { currentValues = new SavotValues(); currentMarkup = VALUES; if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, TYPE) != null) { currentValues.setType(parser.getAttributeValue(null, TYPE)); } if (parser.getAttributeValue(null, NULL) != null) { currentValues.setNull(parser.getAttributeValue(null, NULL)); } if (parser.getAttributeValue(null, INVALID) != null) /* * 1.0 * mais * non * 1.1 */ { currentValues.setInvalid(parser.getAttributeValue(null, INVALID)); } if (parser.getAttributeValue(null, REF) != null) /* * 1.0 * mais * non * 1.1 */ { currentValues.setRef(parser.getAttributeValue(null, REF)); } if (parser.getAttributeValue(null, ID) != null) { currentValues.setId(parser.getAttributeValue(null, ID)); } } } // ROW else if (name.equalsIgnoreCase(ROW)) { if (trace) { System.err.println("ROW begin"); } currentMarkup = ROW; // create a new row currentRow = new ArrayList(); } // CELL else if (name.equalsIgnoreCase(CELL)) { if (trace) { System.err.println("CELL begin"); } currentMarkup = CELL; // for statistics only dataCounter++; } // DATA else if (name.equalsIgnoreCase(DATA)) { currentData = new SavotData(); currentMarkup = DATA; } // TABLEDATA else if (name.equalsIgnoreCase(TABLEDATA)) { // currentTableData = new SavotTableData(); currentMarkup = TABLEDATA; } // LINK else if (name.equalsIgnoreCase(LINK)) { currentLink = new SavotLink(); currentMarkup = LINK; if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, CONTENTROLE) != null) { currentLink.setContentRole(parser.getAttributeValue(null, CONTENTROLE)); } if (parser.getAttributeValue(null, CONTENTTYPE) != null) { currentLink.setContentType(parser.getAttributeValue(null, CONTENTTYPE)); } if (parser.getAttributeValue(null, TITLE) != null) { currentLink.setTitle(parser.getAttributeValue(null, TITLE)); } if (parser.getAttributeValue(null, VALUE) != null) { currentLink.setValue(parser.getAttributeValue(null, VALUE)); } if (parser.getAttributeValue(null, HREF) != null) { currentLink.setHref(parser.getAttributeValue(null, HREF)); } if (parser.getAttributeValue(null, GREF) != null) { currentLink.setGref(parser.getAttributeValue(null, GREF)); } if (parser.getAttributeValue(null, ACTION) != null) { currentLink.setAction(parser.getAttributeValue(null, ACTION)); } if (parser.getAttributeValue(null, ID) != null) { currentLink.setId(parser.getAttributeValue(null, ID)); } } if (trace) { System.err.println("LINK"); } } // INFO else if (name.equalsIgnoreCase(INFO)) { currentInfo = new SavotInfo(); currentMarkup = INFO; if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, NAME) != null) { currentInfo.setName(parser.getAttributeValue(null, NAME)); } if (parser.getAttributeValue(null, VALUE) != null) { currentInfo.setValue(parser.getAttributeValue(null, VALUE)); } if (parser.getAttributeValue(null, ID) != null) { currentInfo.setId(parser.getAttributeValue(null, ID)); } } if (trace) { System.err.println("INFO"); } } // OPTION else if (name.equalsIgnoreCase(OPTION)) { currentMarkup = OPTION; if (trace) { System.err.println("OPTION"); } currentOption = new SavotOption(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, NAME) != null) { currentOption.setName(parser.getAttributeValue(null, NAME)); } if (parser.getAttributeValue(null, VALUE) != null) { currentOption.setValue(parser.getAttributeValue(null, VALUE)); } } } else if (name.equalsIgnoreCase(COOSYS)) { currentMarkup = COOSYS; if (trace) { System.err.println("COOSYS"); } currentCoosys = new SavotCoosys(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, EQUINOX) != null) { currentCoosys.setEquinox(parser.getAttributeValue(null, EQUINOX)); } if (parser.getAttributeValue(null, EPOCH) != null) { currentCoosys.setEpoch(parser.getAttributeValue(null, EPOCH)); } if (parser.getAttributeValue(null, SYSTEM) != null) { currentCoosys.setSystem(parser.getAttributeValue(null, SYSTEM)); } if (parser.getAttributeValue(null, ID) != null) { currentCoosys.setId(parser.getAttributeValue(null, ID)); } } } // DEFINITIONS else if (name.equalsIgnoreCase(DEFINITIONS)) { currentMarkup = DEFINITIONS; currentDefinitions = new SavotDefinitions(); if (trace) { System.err.println("DEFINITIONS"); } } } currentMarkup = name; } catch (Exception e) { System.err.println("START_TAG : " + e); } break; // if an end tag is reach case KXmlParser.END_TAG: name = parser.getName(); try { if (trace) { System.err.println("End ---> " + name); } // DESCRIPTION - several fathers are possible if (name.equalsIgnoreCase(DESCRIPTION)) { if (((String) father.get(father.size() - 2)).equalsIgnoreCase(ASTRO)) { description.append(currentDescription); currentMarkup = ""; } else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(RESOURCE)) { description.append(currentDescription); currentMarkup = ""; } else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(TABLE)) { tb.setDescription(currentDescription); currentMarkup = ""; } else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(FIELD)) { fieldPropertyNames.add(DESCRIPTION); fieldPropertyValues.add(currentDescription); currentMarkup = ""; } } // TABLE else if (name.equalsIgnoreCase(TABLE)) { allTables.add(tb); currentMarkup = ""; if (trace) { System.err.println(tb.getName()); } } // FIELD - several fathers are possible else if (name.equalsIgnoreCase(FIELD)) { if (((String) father.get(father.size() - 2)).equalsIgnoreCase(TABLE)) { tb.setTableProperties(fieldPropertyNames, fieldPropertyValues); if (trace) { System.err.println("FIELD from TABLE father = " + father); } } } // TR else if (name.equalsIgnoreCase(ROW)) { if (trace) { System.err.println("TR end"); } currentMarkup = ""; // add the row to the table tb.addRow((String[]) currentRow.toArray()); // for statistics only rowCounter++; if (trace) { System.err.println("ADD row"); } } // DATA else if (name.equalsIgnoreCase(DATA)) { currentMarkup = ""; // currentTable.setData(currentData); } // CELL else if (name.equalsIgnoreCase(CELL)) { currentMarkup = ""; if (trace) { System.err.println("CELL end"); } } // RESOURCE else if (name.equalsIgnoreCase(RESOURCE)) { if (trace) { System.err.println("RESOURCE end"); } currentMarkup = ""; } // OPTION else if (name.equalsIgnoreCase(OPTION)) { if (trace) { System.err.println("OPTION end"); } currentMarkup = ""; } // TABLEDATA else if (name.equalsIgnoreCase(TABLEDATA)) { currentMarkup = ""; // currentData.setTableData(currentTableData); if (trace) { System.err.println(tb.getName()); } } // COOSYS else if (name.equalsIgnoreCase(COOSYS)) { currentMarkup = ""; // COOSYS - several fathers are possible if (((String) father.get(father.size() - 2)).equalsIgnoreCase(DEFINITIONS)) { currentDefinitions.getCoosys().addItem(currentCoosys); if (trace) { System.err.println("COOSYS from DEFINITIONS father = " + father); } } else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(RESOURCE)) { // currentResource.getCoosys().addItem(currentCoosys); if (trace) { System.err.println("COOSYS from RESOURCE father = " + father); } } } // LINK else if (name.equalsIgnoreCase(LINK)) { currentMarkup = ""; // LINK - several fathers are possible if (((String) father.get(father.size() - 2)).equalsIgnoreCase(RESOURCE)) { // currentResource.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from RESOURCE father = " + father); } } else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(TABLE)) { // currentTable.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from TABLE father = " + father); } } else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(FIELD)) { // currentField.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from FIELD father = " + father); } } } // VALUES else if (name.equalsIgnoreCase(VALUES)) { currentMarkup = ""; // VALUES - several fathers are possible if (((String) father.get(father.size() - 2)).equalsIgnoreCase(FIELD)) { // currentField.setValues(currentValues); if (trace) { System.err.println("VALUES from FIELD father = " + father + " ID : " + currentValues.getId()); } } } // INFO else if (name.equalsIgnoreCase(INFO)) { currentMarkup = ""; if (trace) { System.err.println("INFO father = " + father); } // INFO - several fathers are possible if (((String) father.get(father.size() - 2)).equalsIgnoreCase(ASTRO)) { if (trace) { System.err.println("INFO from VOTABLE father = " + father); } } else if (((String) father.get(father.size() - 2)).equalsIgnoreCase(RESOURCE)) { if (trace) { System.err.println("INFO from RESOURCE father = " + father); } } } // DEFINITIONS else if (name.equalsIgnoreCase(DEFINITIONS)) { currentMarkup = ""; if (trace) { System.err.println("DEFINITIONS"); } // allResources.setDefinitions(currentDefinitions); } } catch (Exception e) { System.err.println("FATHER : " + father + " END_TAG (" + name + ") : " + e); } break; case KXmlParser.END_DOCUMENT: try { if (trace) { System.err.println("Document end reached!"); } } catch (Exception e) { System.err.println("END_DOCUMENT : " + e); } break; case KXmlParser.TEXT: try { if (currentMarkup.equalsIgnoreCase(CSV)) { // System.err.println((parser.getText()).trim()); CSVCut((parser.getText()).trim()); if (trace) { System.err.println((parser.getText()).trim()); } // currentRow.addElement(parser.getText()); } else // add a data to the current row if (currentMarkup.equalsIgnoreCase(CELL)) { if (trace) { System.err.println("CELL : " + (parser.getText()).trim()); } currentRow.add(parser.getText()); } else if (currentMarkup.equalsIgnoreCase(DESCRIPTION)) { if (trace) { System.err.println("DESCRIPTION : " + (parser.getText()).trim()); } currentDescription = (parser.getText()).trim(); } else if (currentMarkup.equalsIgnoreCase(COOSYS)) { if (trace) { System.err.println("COOSYS : " + (parser.getText()).trim()); } currentCoosys.setContent((parser.getText()).trim()); } else if (currentMarkup.equalsIgnoreCase(LINK)) { if (trace) { System.err.println("LINK : " + (parser.getText()).trim()); } currentLink.setContent((parser.getText()).trim()); } else if (currentMarkup.equalsIgnoreCase(OPTION)) { if (trace) { System.err.println("OPTION : " + (parser.getText()).trim()); } } else if (currentMarkup.equalsIgnoreCase(INFO)) { currentInfo.setContent((parser.getText()).trim()); if (trace) { System.err.println("INFO : " + (parser.getText()).trim()); } } } catch (Exception e) { System.err.println("TEXT : " + e); } break; case KXmlParser.START_DOCUMENT: break; default: if (trace) { System.err.println(" ignoring some other (legacy) event at line : " + parser.getLineNumber()); } } // save previous values previousDepth = parser.getDepth(); // new values eventType = parser.next(); if (parser.getDepth() > previousDepth) { father.add((parser.getName())); } else if (parser.getDepth() == previousDepth) { if (((String) father.get(father.size() - 1)).equals((parser.getName()))) { father.remove(father.size() - 1); father.add((parser.getName())); } } else { father.remove(father.size() - 1); } if (trace) { System.err.println("father = " + father); } } } catch (Exception f) { if (trace) { System.err.println("parse : " + f); } } } } libcds-savot-java/src/main/java/cds/astrores/sax/AstroresSAXParser.java0000664000175000017500000001212112724035712025727 0ustar sladensladenpackage cds.astrores.sax; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // // SAVOT 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, version 3 of the License. // // SAVOT 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. // // The GNU General Public License is available in COPYING file // along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.io.IOException; import java.io.InputStream; import java.net.URL; // pull parser import org.kxml2.io.KXmlParser; import org.xmlpull.v1.XmlPullParser; /** *

* Savot Pull Parser, t has been tested with kXML Pull parser implementation *

*

* but it is possible to use other pull parsers *

*

* Designed to use with Pull parsers complient with Standard Pull Implementation * v1 *

* * @author Andre Schaaff */ @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"}) public class AstroresSAXParser { // the pull parser engine private AstroresSAXEngine engine = null; /** * Constructor * * @param consumer * AstroresSAXConsumer * @param file * a file to parse */ public AstroresSAXParser(AstroresSAXConsumer consumer, String file) { this(consumer, file, false); } /** * Constructor * * @param consumer * AstroresSAXConsumer * @param file * a file to parse * @param debug * boolean */ public AstroresSAXParser(AstroresSAXConsumer consumer, String file, boolean debug) { try { // new parser XmlPullParser parser = new KXmlParser(); engine = new AstroresSAXEngine(consumer, parser, file, debug); engine.parse(parser); } catch (IOException e) { System.err.println("AstroresSAXParser : " + e); } catch (Exception f) { System.err.println("AstroresSAXParser : " + f); } } /** * Constructor * * @param consumer * AstroresSAXConsumer * @param url * url to parse * @param enc * encoding (example : UTF-8) */ public AstroresSAXParser(AstroresSAXConsumer consumer, URL url, String enc) { this(consumer, url, enc, false); } /** * Constructor * * @param consumer * AstroresSAXConsumer * @param url * url to parse * @param enc * encoding (example : UTF-8) * @param debug * boolean */ public AstroresSAXParser(AstroresSAXConsumer consumer, URL url, String enc, boolean debug) { try { // new parser KXmlParser parser = new KXmlParser(); engine = new AstroresSAXEngine(consumer, parser, url, enc, debug); engine.parse(parser); } catch (IOException e) { System.err.println("AstroresSAXParser : " + e); } catch (Exception f) { System.err.println("AstroresSAXParser : " + f); } } /** * Constructor * * @param consumer * AstroresSAXConsumer * @param instream * stream to parse * @param enc * encoding (example : UTF-8) */ public AstroresSAXParser(AstroresSAXConsumer consumer, InputStream instream, String enc) { this(consumer, instream, enc, false); } /** * Constructor * * @param consumer * AstroresSAXConsumer * @param instream * stream to parse * @param enc * encoding (example : UTF-8) * @param debug * boolean */ public AstroresSAXParser(AstroresSAXConsumer consumer, InputStream instream, String enc, boolean debug) { try { // new parser KXmlParser parser = new KXmlParser(); engine = new AstroresSAXEngine(consumer, parser, instream, enc, debug); engine.parse(parser); } catch (IOException e) { System.err.println("AstroresSAXParser : " + e); } catch (Exception f) { System.err.println("AstroresSAXParser : " + f); } } /** * Main * * @param argv * @throws IOException */ public static void main(String[] argv) throws IOException { if (argv.length == 0) { System.err.println("Usage: java AstroresSAXParser "); } else { // new AstroresSAXParser(argv[0]); } } } libcds-savot-java/src/main/java/cds/savot/0000775000175000017500000000000012724035712020233 5ustar sladensladenlibcds-savot-java/src/main/java/cds/savot/pull/0000775000175000017500000000000012724035712021207 5ustar sladensladenlibcds-savot-java/src/main/java/cds/savot/pull/SavotPullParser.java0000664000175000017500000002402112724035712025157 0ustar sladensladenpackage cds.savot.pull; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.io.IOException; import java.io.InputStream; import java.net.URL; // VOTable internal data model import cds.savot.common.SavotStatistics; import cds.savot.model.SavotCoosys; import cds.savot.model.SavotField; import cds.savot.model.SavotInfo; import cds.savot.model.SavotLink; import cds.savot.model.SavotParam; import cds.savot.model.SavotResource; import cds.savot.model.SavotTR; import cds.savot.model.SavotTable; import cds.savot.model.SavotVOTable; import cds.savot.model.SavotValues; import java.io.Reader; import java.util.Map; // pull parser import org.kxml2.io.KXmlParser; /** *

* It has been tested with kXML Pull parser implementation *

*

* but it is possible to use other pull parsers *

*

* Designed to use with Pull parsers complient with Standard Pull Implementation * v1 *

* * @author Andre Schaaff */ @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"}) public final class SavotPullParser { /** the pull parser engine */ private final SavotPullEngine engine; /** statistics dedicated to this parser */ private final SavotStatistics stats = new SavotStatistics(); /** * Constructor * * @param file * a file to parse * @param mode * FULL or RESOURCEREAD/ROWREAD (for small memory size * applications) */ public SavotPullParser(final String file, final int mode) { this(file, mode, false); } /** * Constructor * * @param file * a file to parse * @param mode * FULL or RESOURCEREAD/ROWREAD (for small memory size * applications) * @param debug */ public SavotPullParser(final String file, final int mode, final boolean debug) { // new parser this.engine = new SavotPullEngine(new KXmlParser(), file, mode, debug, stats); } /** * Constructor * * @param url * url to parse * @param mode * FULL or RESOURCEREAD/ROWREAD (for small memory size * applications) * @param enc * encoding (example : UTF-8) */ public SavotPullParser(final URL url, final int mode, final String enc) { this(url, mode, enc, false); } /** * Constructor * * @param url * url to parse * @param mode * FULL or RESOURCEREAD/ROWREAD (for small memory size * applications) * @param enc * encoding (example : UTF-8) * @param debug */ public SavotPullParser(final URL url, final int mode, final String enc, final boolean debug) { // new parser this.engine = new SavotPullEngine(new KXmlParser(), url, mode, enc, debug, stats); } /** * Constructor * * @param instream * stream to parse * @param mode * FULL or RESOURCEREAD/ROWREAD (for small memory size * applications) * @param enc * encoding (example : UTF-8) */ public SavotPullParser(final InputStream instream, final int mode, final String enc) { this(instream, mode, enc, false); } /** * Constructor * * @param instream * stream to parse * @param mode * FULL or RESOURCEREAD/ROWREAD (for small memory size * applications) * @param enc * encoding (example : UTF-8) * @param debug */ public SavotPullParser(final InputStream instream, final int mode, final String enc, final boolean debug) { // new parser this.engine = new SavotPullEngine(new KXmlParser(), instream, mode, enc, debug, stats); } /** * Constructor * * @param reader * reader to parse * @param mode * FULL or RESOURCEREAD/ROWREAD (for small memory size * applications) */ public SavotPullParser(final Reader reader, final int mode) { this(reader, mode, false); } /** * Constructor * * @param reader * reader to parse * @param mode * FULL or RESOURCEREAD/ROWREAD (for small memory size * applications) * @param debug */ public SavotPullParser(final Reader reader, final int mode, final boolean debug) { // new parser this.engine = new SavotPullEngine(new KXmlParser(), reader, mode, debug, stats); } /** * Close the input stream if still opened */ public void close() { engine.close(); } /** * Returns the stats * * @return statistics */ public SavotStatistics getStatistics() { return stats; } /** * Get the next Resource (sequential mode only) * * @return a SavotResource */ public SavotResource getNextResource() { return engine.getNextResource(); } /** * Get the next Resource (sequential mode only) * * @return a SavotResource */ public SavotTR getNextTR() { return engine.getNextTR(); } /** * Get a reference to V0TABLE object * * @return SavotVOTable */ public SavotVOTable getVOTable() { return engine.getAllResources(); } /** * Get the number of RESOURCE elements in the document (for statistics) * * @return an int value */ public int getResourceCount() { return engine.getResourceCount(); } /** * Get the number of TABLE elements in the document (for statistics) * * @return an int value */ public int getTableCount() { return engine.getTableCount(); } /** * Get the number of TR elements in the document (for statistics) * * @return an int value */ public int getTRCount() { return engine.getTRCount(); } /** * Get the number of DATA elements in the document (for statistics) * * @return an int value */ public int getDataCount() { return engine.getDataCount(); } /** * Get a reference on the Hashtable containing the link between ID and ref * * @return a refernce to the Hashtable */ public Map getIdRefLinks() { return engine.getIdRefLinks(); } /** * Search a RESOURCE corresponding to an ID ref * * @param ref * @return a reference to a SavotResource object */ public SavotResource getResourceFromRef(final String ref) { return engine.getResourceFromRef(ref); } /** * Search a FIELD corresponding to an ID ref * * @param ref * @return SavotField */ public SavotField getFieldFromRef(final String ref) { return engine.getFieldFromRef(ref); } /** * Search a PARAM corresponding to an ID ref * * @param ref * @return SavotParam */ public SavotParam getParamFromRef(final String ref) { return engine.getParamFromRef(ref); } /** * Search a TABLE corresponding to an ID ref * * @param ref * @return SavotTable */ public SavotTable getTableFromRef(final String ref) { return engine.getTableFromRef(ref); } /** * Search a RESOURCE corresponding to an ID ref * * @param ref * @return SavotInfo */ public SavotInfo getInfoFromRef(final String ref) { return engine.getInfoFromRef(ref); } /** * Search a VALUES corresponding to an ID ref * * @param ref * @return SavotValues */ public SavotValues getValuesFromRef(final String ref) { return engine.getValuesFromRef(ref); } /** * Search a LINK corresponding to an ID ref * * @param ref * @return SavotLink */ public SavotLink getLinkFromRef(final String ref) { return engine.getLinkFromRef(ref); } /** * Search a COOSYS corresponding to an ID ref * * @param ref * @return SavotCoosys */ public SavotCoosys getCoosysFromRef(final String ref) { return engine.getCoosysFromRef(ref); } /** * Get all resources * * @return SavotVOTable */ public SavotVOTable getAllResources() { return engine.getAllResources(); } /** * Get Parser Version * * @return String */ public String getVersion() { return SavotPullEngine.SAVOTPARSER; } /** * Enable debug mode * * @param debug * boolean */ public void enableDebug(final boolean debug) { engine.enableDebug(debug); } /** * For test only * */ public void sequentialTester() { SavotResource currentResource = null; do { currentResource = engine.getNextResource(); } while (currentResource != null); } /** * Main * * @param argv * @throws IOException */ public static void main(String[] argv) throws IOException { if (argv.length == 0) { System.out.println("Usage: java SavotPullParser "); } else { new SavotPullParser(argv[0], SavotPullEngine.FULL); } } } libcds-savot-java/src/main/java/cds/savot/pull/SavotPullEngine.java0000664000175000017500000026360412724035712025144 0ustar sladensladenpackage cds.savot.pull; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; // XML pull parser import org.xmlpull.v1.XmlPullParser; // VOTable internal data model import cds.savot.common.Markups; import cds.savot.common.SavotStatistics; import cds.savot.common.VOTableTag; import cds.savot.model.SavotBinary; import cds.savot.model.SavotCoosys; import cds.savot.model.SavotData; import cds.savot.model.SavotDefinitions; import cds.savot.model.SavotField; import cds.savot.model.SavotFieldRef; import cds.savot.model.SavotFits; import cds.savot.model.SavotGroup; import cds.savot.model.SavotInfo; import cds.savot.model.SavotLink; import cds.savot.model.SavotMax; import cds.savot.model.SavotMin; import cds.savot.model.SavotOption; import cds.savot.model.SavotParam; import cds.savot.model.SavotParamRef; import cds.savot.model.SavotResource; import cds.savot.model.SavotStream; import cds.savot.model.SavotTD; import cds.savot.model.SavotTR; import cds.savot.model.SavotTable; import cds.savot.model.SavotTableData; import cds.savot.model.SavotVOTable; import cds.savot.model.SavotValues; import cds.savot.model.TDSet; import java.io.Reader; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.zip.GZIPInputStream; /** *

* It has been tested with kXML Pull parser implementation *

*

* but it is possible to use other pull parsers *

*

* Designed to use with Pull parsers complient with Standard Pull Implementation * v1 *

* * LBO: Note: equalsIgnoreCase() vs() equals as XML is case sensitive and VOTable specification says that clearly * * @author Andre Schaaff */ @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"}) public final class SavotPullEngine implements Markups { /** Logger associated to SavotPullEngine classes */ private final static java.util.logging.Logger logger = java.util.logging.Logger.getLogger(SavotPullEngine.class.getName()); /** flag to enable / disable usage of String.trim() on every value (enabled by default) */ private static final boolean doTrimValues = false; /** flag to enable / disable line numbers (TR) */ private static final boolean doLineInfo = false; /** flag to enable / disable statistics */ private static final boolean doStats = false; /* parsing modes */ /** FULL parsing mode: deprecated and replaced by FULLREAD */ public static final int FULL = 0; /** FULLREAD parsing mode all in memory */ public static final int FULLREAD = 0; /** SEQUENTIAL parsing mode: deprecated and replaced by RESOURCEREAD */ public static final int SEQUENTIAL = 1; /** RESOURCEREAD parsing mode: row per row reading */ public static final int RESOURCEREAD = 1; /** ROWREAD parsing mode: row per row reading */ public static final int ROWREAD = 2; /** default stack capacity = 4 slots */ public final static int DEFAULT_STACK_CAPACITY = 4; /** empty TD instance */ private final static SavotTD EMPTY_TD = new SavotTD(); /* members */ /** statistics dedicated to this parser */ private final SavotStatistics statistics; /** xml pull parser needed for sequential parsing */ private XmlPullParser xmlParser = null; /** input stream used to close it anyway */ private InputStream inputStream = null; /** reader used to close it anyway */ private Reader reader = null; /** debug mode */ private boolean debugMode = false; // data model objects private SavotVOTable _currentVOTable = new SavotVOTable(); private SavotResource _currentResource = new SavotResource(); // RESOURCEREAD mode only private SavotTR _currentTR = new SavotTR(); // ROWREAD mode only // used for statistics private int resourceCounter = 0; private int tableCounter = 0; private int rowCounter = 0; private int dataCounter = 0; // used for recursive management private final ArrayList fatherTags = new ArrayList(DEFAULT_STACK_CAPACITY); // used for recursive resources, LIFO mode private final ArrayList resourcestack = new ArrayList(DEFAULT_STACK_CAPACITY); // used for recursive options, LIFO mode private final ArrayList optionstack = new ArrayList(DEFAULT_STACK_CAPACITY); // used for recursives groups, LIFO mode private final ArrayList groupstack = new ArrayList(DEFAULT_STACK_CAPACITY); // for multi level resource private int includedResource = 0; // for multi level option private int includedOption = 0; // for multi level group private int includedGroup = 0; private SavotTable currentTable = null; private SavotField currentField = null; private SavotFieldRef currentFieldRef = null; private SavotGroup currentGroup = null; // new since VOTable 1.1 private SavotParam currentParam = null; private SavotParamRef currentParamRef = null; private SavotData currentData = null; private SavotValues currentValues = null; private SavotTableData currentTableData = null; private String currentDescription = null; private SavotLink currentLink = null; private SavotInfo currentInfo = null; private SavotMin currentMin = null; private SavotMax currentMax = null; private SavotOption currentOption = null; private SavotCoosys currentCoosys = null; private SavotDefinitions currentDefinitions = null; private SavotBinary currentBinary = null; private SavotFits currentFits = null; private SavotStream currentStream = null; /** * Map containing object references which have an ID * So it is possible to retrieve such object reference * Used to resolve ID ref * * TODO: move such mapping into SavotVOTable (root element) */ private final Map idRefLinks = new HashMap(256); /** * Constructor * * @param parser * @param file * a file to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @param debug * @param stats */ public SavotPullEngine(final XmlPullParser parser, final String file, final int mode, final boolean debug, final SavotStatistics stats) { this.xmlParser = parser; this.statistics = stats; enableDebug(debug); try { final boolean compressed = file.endsWith("gz"); // set the input of the parser this.inputStream = getInputStream(new FileInputStream(file), compressed); parser.setInput(this.inputStream, "UTF-8"); /* specify encoding ? */ // fix parsing mode: final int parsingType = parseMode(mode); // parse the stream in the given mode if (parsingType == SavotPullEngine.FULLREAD) { parse(parsingType); } } catch (IOException ioe) { logger.log(Level.SEVERE, "Exception SavotPullEngine : ", ioe); } catch (Exception e) { logger.log(Level.SEVERE, "Exception SavotPullEngine : ", e); } } /** * Constructor * * @param parser * @param url url to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @param enc encoding (example : UTF-8) * @param debug * @param stats */ public SavotPullEngine(final XmlPullParser parser, final URL url, final int mode, final String enc, final boolean debug, final SavotStatistics stats) { this.xmlParser = parser; this.statistics = stats; enableDebug(debug); // TODO: detect compression final boolean compressed = url.getPath().endsWith("gz"); try { // set the input of the parser (with the given encoding) this.inputStream = getInputStream(url.openStream(), compressed); parser.setInput(this.inputStream, enc); // fix parsing mode: final int parsingType = parseMode(mode); // parse the stream in the given mode if (parsingType == SavotPullEngine.FULLREAD) { parse(parsingType); } } catch (IOException ioe) { logger.log(Level.SEVERE, "Exception SavotPullEngine : ", ioe); } catch (Exception e) { logger.log(Level.SEVERE, "Exception SavotPullEngine : ", e); } } /** * Constructor * * @param parser * @param instream stream to parse * @param mode * FULL (all in memory), RESOURCEREAD (per RESOURCE) or ROWREAD * (per TR for small memory size applications) * @param enc encoding (example : UTF-8) * @param debug * @param stats */ public SavotPullEngine(final XmlPullParser parser, final InputStream instream, final int mode, final String enc, final boolean debug, final SavotStatistics stats) { this.xmlParser = parser; this.statistics = stats; enableDebug(debug); try { // set the input of the parser (with the given encoding) this.inputStream = getInputStream(instream, false); parser.setInput(this.inputStream, enc); // fix parsing mode: final int parsingType = parseMode(mode); // parse the stream in the given mode if (parsingType == SavotPullEngine.FULLREAD) { parse(parsingType); } } catch (IOException ioe) { logger.log(Level.SEVERE, "Exception SavotPullEngine : ", ioe); } catch (Exception e) { logger.log(Level.SEVERE, "Exception SavotPullEngine : ", e); } } /** * Constructor * * @param parser * @param reader reader to parse * @param mode * FULL (all in memory), RESOURCEREAD (per RESOURCE) or ROWREAD * (per TR for small memory size applications) * @param debug * @param stats */ public SavotPullEngine(final XmlPullParser parser, final Reader reader, final int mode, final boolean debug, final SavotStatistics stats) { this.xmlParser = parser; this.statistics = stats; enableDebug(debug); try { // set the input of the parser this.reader = reader; parser.setInput(reader); // fix parsing mode: final int parsingType = parseMode(mode); // parse the stream in the given mode if (parsingType == SavotPullEngine.FULLREAD) { parse(parsingType); } } catch (IOException ioe) { logger.log(Level.SEVERE, "Exception SavotPullEngine : ", ioe); } catch (Exception e) { logger.log(Level.SEVERE, "Exception SavotPullEngine : ", e); } } /** * Return the parsing type (FULLREAD, RESOURCEREAD or ROWREAD) * @param mode mode (FULL, SEQUENTIAL, FULLREAD, RESOURCEREAD or ROWREAD) * @return parsing type */ private int parseMode(final int mode) { switch (mode) { case ROWREAD: return ROWREAD; case SEQUENTIAL: return RESOURCEREAD; case FULL: default: return FULLREAD; } } /** * Get a buffered input stream or a gzip input stream * @param instream stream to wrap * @param compressed true to indicate to use a gzip input stream * @return input stream * @throws IOException useless */ private InputStream getInputStream(final InputStream instream, final boolean compressed) throws IOException { // best buffer size = 8K because kXmlParser uses also a 8K read buffer final int bufferSize = 8 * 1024; // 8K read buffer final InputStream in; if (compressed) { in = new GZIPInputStream(instream, bufferSize); // 512 bytes by default } else { // no buffer as kXmlParser has a 8K read buffer too in = instream; } return in; } /** * Close the input stream if still opened and free the internal parser */ public void close() { if (this.xmlParser != null) { this.xmlParser = null; } if (this.inputStream != null) { try { this.inputStream.close(); } catch (IOException ioe) { logger.log(Level.INFO, "Exception SavotPullEngine.close: ", ioe); } this.inputStream = null; } if (this.reader != null) { try { this.reader.close(); } catch (IOException ioe) { logger.log(Level.INFO, "Exception SavotPullEngine.close: ", ioe); } this.reader = null; } } /** * Reset of the engine before another parsing * LBO: useless methods ? */ public void reset() { // data model global classes _currentVOTable = new SavotVOTable(); _currentResource = new SavotResource(); rowCounter = 0; resourceCounter = 0; tableCounter = 0; dataCounter = 0; idRefLinks.clear(); // used for recursive resources, LIFO mode resourcestack.clear(); // used for recursive options, LIFO mode optionstack.clear(); // used for recursive groups, LIFO mode groupstack.clear(); } /** * Get the last element from the resourcestack * @return SavotResource */ private SavotResource getResourceStack() { return resourcestack.remove(resourcestack.size() - 1); } /** * Put a resource on the resourcestack * @param resource */ private void putResourceStack(final SavotResource resource) { resourcestack.add(resource); } /** * Get the last element from the optionstack * @return SavotOption */ private SavotOption getOptionStack() { return optionstack.remove(optionstack.size() - 1); } /** * Put an option on the optionstack * @param option */ private void putOptionStack(final SavotOption option) { optionstack.add(option); } /** * Get the last element from the groupstack * @return SavotGroup */ private SavotGroup getGroupStack() { return groupstack.remove(groupstack.size() - 1); } /** * Put a group on the groupstack * @param group */ private void putGroupStack(final SavotGroup group) { groupstack.add(group); } /** * Return last father tag * @return tag or null */ private VOTableTag lastFather() { int size = fatherTags.size(); if (size == 0) { return VOTableTag.UNDEFINED; } return fatherTags.get(size - 1); } /** * Parsing engine * * @param parsingType * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @throws IOException */ public void parse(final int parsingType) throws IOException, Exception { final XmlPullParser parser = this.xmlParser; if (parser == null) { return; } if (parsingType != ROWREAD && parsingType != RESOURCEREAD) { // for multi level resource includedResource = 0; // for multi level option includedOption = 0; // for multi level group includedGroup = 0; currentTable = new SavotTable(); currentField = new SavotField(); currentFieldRef = new SavotFieldRef(); currentGroup = new SavotGroup(); // new since VOTable 1.1 currentParam = new SavotParam(); currentParamRef = new SavotParamRef(); currentData = new SavotData(); currentValues = new SavotValues(); currentTableData = new SavotTableData(); currentDescription = ""; currentLink = new SavotLink(); currentInfo = new SavotInfo(); currentMin = new SavotMin(); currentMax = new SavotMax(); currentOption = new SavotOption(); currentCoosys = new SavotCoosys(); currentDefinitions = new SavotDefinitions(); currentBinary = new SavotBinary(); currentFits = new SavotFits(); currentStream = new SavotStream(); } String operation = "UNDEFINED"; VOTableTag tag = null; int rowCount = rowCounter; int dataCount = dataCounter; try { // local copy for performance: final boolean trace = debugMode; final SavotStatistics stats = statistics; final SavotTD emptyTD = EMPTY_TD; final ArrayList father = fatherTags; // used for RESOURCEREAD parsing boolean resourceComplete = false; // used for ROWREAD parsing boolean TRComplete = false; // local variables for performance: SavotTR currentTR = _currentTR; TDSet tdSet = null; SavotTD currentTD = null; // name from parser.getName and current markup String name; VOTableTag currentMarkup = VOTableTag.UNDEFINED; String attrName, attrValue; String textValue; int i, counter; if (currentTR != null) { currentTR.clear(); // recycle TR instance (also TDSet) tdSet = currentTR.getTDs(); } // event type int eventType = parser.getEventType(); // System.out.println("ENTREE DANS PARSER"); // while the end of the document is not reach while (eventType != XmlPullParser.END_DOCUMENT) { // treatment depending on event type switch (eventType) { // if a start tag is reach case XmlPullParser.START_TAG: operation = "START_TAG"; // the name of the current tag name = parser.getName(); if (name != null) { if (trace) { System.err.println("Name ---> " + name); } // avoid parsing name twice: if (tag == null) { tag = VOTableTag.parseTag(name); } if (trace) { System.err.println(tag + " begin"); } // use most probable tags FIRST (performance) i.e TD / TR first : switch (tag) { case TD: // avoid creating new SavotTD if the value is empty !! currentTD = null; if (doStats) { // for statistics only dataCount++; } break; case TR: stats.iTDLocalReset(); // recycle TR instance: if (currentTR == null) { // create a new row currentTR = new SavotTR(); tdSet = currentTR.getTDs(); } if (doLineInfo) { currentTR.setLineInXMLFile(parser.getLineNumber()); } break; case DESCRIPTION: break; case VOTABLE: // partie à revoir pour permettre la prise // en compte de plusieurs namespaces counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(VERSION)) { _currentVOTable.setVersion(attrValue); } else if (attrName.equalsIgnoreCase(XMLNSXSI)) { _currentVOTable.setXmlnsxsi(attrValue); } else if (attrName.equalsIgnoreCase(XSINOSCHEMA)) { _currentVOTable.setXsinoschema(attrValue); } else if (attrName.equalsIgnoreCase(XSISCHEMA)) { _currentVOTable.setXsischema(attrValue); } else if (attrName.equalsIgnoreCase(XMLNS)) { _currentVOTable.setXmlns(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { _currentVOTable.setId(attrValue); idRefLinks.put(attrValue, _currentVOTable); } } } } break; case RESOURCE: stats.iResourcesInc(); if (includedResource > 0) { // inner case (multi level resources) putResourceStack(_currentResource); if (trace) { System.err.println("RESOURCE - included"); } } else if (trace) { System.err.println("RESOURCE - not included"); } includedResource++; // for statistics only resourceCounter++; if (parsingType == FULL || _currentResource == null || parsingType == ROWREAD) { _currentResource = new SavotResource(); } else { _currentResource.init(); } _currentResource.setType(""); // correct the "results" default value counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(NAME)) { _currentResource.setName(attrValue); } else if (attrName.equalsIgnoreCase(TYPE)) { _currentResource.setType(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { _currentResource.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { _currentResource.setId(attrValue); if (parsingType == FULL) { idRefLinks.put(attrValue, _currentResource); } } } } } break; case TABLE: stats.iTablesInc(); currentTable = new SavotTable(); // for statistics only tableCounter++; counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(NAME)) { currentTable.setName(attrValue); if (trace) { System.err.println("TABLE name " + currentTable.getName()); } } else if (attrName.equalsIgnoreCase(UCD)) { // new since VOTable 1.1 currentTable.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { // new since VOTable 1.1 currentTable.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(REF)) { currentTable.setRef(attrValue); } else if (attrName.equalsIgnoreCase(NROWS)) { // new since VOTable 1.1 currentTable.setNrows(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentTable.setId(attrValue); if (parsingType == FULL) { idRefLinks.put(attrValue, currentTable); if (trace) { System.err.println(attrValue); } } } } } } break; case FIELD: currentField = new SavotField(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(UNIT)) { currentField.setUnit(attrValue); } else if (attrName.equalsIgnoreCase(DATATYPE)) { currentField.setDataType(attrValue); } else if (attrName.equalsIgnoreCase(PRECISION)) { currentField.setPrecision(attrValue); } else if (attrName.equalsIgnoreCase(WIDTH)) { currentField.setWidth(attrValue); } else if (attrName.equalsIgnoreCase(REF)) { currentField.setRef(attrValue); } else if (attrName.equalsIgnoreCase(NAME)) { currentField.setName(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentField.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(ARRAYSIZE)) { currentField.setArraySize(attrValue); } else if (attrName.equalsIgnoreCase(TYPE)) { // deprecated since VOTable 1.1 currentField.setType(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentField.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentField.setId(attrValue); idRefLinks.put(attrValue, currentField); } } } } if (trace) { System.err.println("on vient de remplir un FIELD ---> " + currentField.getName()); } break; case FIELDREF: currentFieldRef = new SavotFieldRef(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(REF)) { currentFieldRef.setRef(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentFieldRef.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentFieldRef.setUtype(attrValue); } } } } break; case VALUES: currentValues = new SavotValues(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(TYPE)) { currentValues.setType(attrValue); } else if (attrName.equalsIgnoreCase(NULL)) { currentValues.setNull(attrValue); } else if (attrName.equalsIgnoreCase(INVALID)) { currentValues.setInvalid(attrValue); } else if (attrName.equalsIgnoreCase(REF)) { currentValues.setRef(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentValues.setId(attrValue); idRefLinks.put(attrValue, currentValues); } } } } break; case STREAM: currentStream = new SavotStream(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(TYPE)) { currentStream.setType(attrValue); } else if (attrName.equalsIgnoreCase(HREF)) { currentStream.setHref(attrValue); } else if (attrName.equalsIgnoreCase(ACTUATE)) { currentStream.setActuate(attrValue); } else if (attrName.equalsIgnoreCase(ENCODING)) { currentStream.setEncoding(attrValue); } else if (attrName.equalsIgnoreCase(EXPIRES)) { currentStream.setExpires(attrValue); } else if (attrName.equalsIgnoreCase(RIGHTS)) { currentStream.setRights(attrValue); } } } } break; case DATA: currentData = new SavotData(); break; case BINARY: currentBinary = new SavotBinary(); break; case FITS: currentFits = new SavotFits(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(REF)) { currentFits.setExtnum(attrValue); } } } } break; case TABLEDATA: currentTableData = new SavotTableData(); if (parsingType == ROWREAD) { // if row sequential reading then storage of the metadata if (stats.getITablesLocal() > 1) { // not the first TABLE of the RESOURCE _currentVOTable.getResources().removeItemAt(_currentVOTable.getResources().getItemCount() - 1); } // TODO: use current table directly with a getter ? _currentResource.getTables().addItem(currentTable); _currentVOTable.getResources().addItem(_currentResource); } break; case PARAM: currentParam = new SavotParam(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(UNIT)) { currentParam.setUnit(attrValue); } else if (attrName.equalsIgnoreCase(DATATYPE)) { currentParam.setDataType(attrValue); } else if (attrName.equalsIgnoreCase(PRECISION)) { currentParam.setPrecision(attrValue); } else if (attrName.equalsIgnoreCase(WIDTH)) { currentParam.setWidth(attrValue); } else if (attrName.equalsIgnoreCase(REF)) { currentParam.setRef(attrValue); } else if (attrName.equalsIgnoreCase(NAME)) { currentParam.setName(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentParam.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentParam.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(VALUE)) { currentParam.setValue(attrValue); } else if (attrName.equalsIgnoreCase(XTYPE)) { currentParam.setXtype(attrValue); } else if (attrName.equalsIgnoreCase(ARRAYSIZE)) { currentParam.setArraySize(attrValue); } else if (attrName.equalsIgnoreCase(XTYPE)) { currentParam.setXtype(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentParam.setId(attrValue); idRefLinks.put(attrValue, currentParam); } } } } break; case PARAMREF: currentParamRef = new SavotParamRef(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(REF)) { currentParamRef.setRef(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentParamRef.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentParamRef.setUtype(attrValue); } } } } break; case LINK: currentLink = new SavotLink(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(CONTENTROLE)) { currentLink.setContentRole(attrValue); } else if (attrName.equalsIgnoreCase(CONTENTTYPE)) { currentLink.setContentType(attrValue); } else if (attrName.equalsIgnoreCase(TITLE)) { currentLink.setTitle(attrValue); } else if (attrName.equalsIgnoreCase(VALUE)) { currentLink.setValue(attrValue); } else if (attrName.equalsIgnoreCase(HREF)) { currentLink.setHref(attrValue); } else if (attrName.equalsIgnoreCase(GREF)) { // deprecated since VOTable 1.1 currentLink.setGref(attrValue); } else if (attrName.equalsIgnoreCase(ACTION)) { currentLink.setAction(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentLink.setId(attrValue); idRefLinks.put(attrValue, currentLink); } } } } break; case INFO: currentInfo = new SavotInfo(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(NAME)) { currentInfo.setName(attrValue); } else if (attrName.equalsIgnoreCase(VALUE)) { currentInfo.setValue(attrValue); } else if (attrName.equalsIgnoreCase(XTYPE)) { currentInfo.setXtype(attrValue); } else if (attrName.equalsIgnoreCase(UNIT)) { currentInfo.setUnit(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentInfo.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentInfo.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(REF)) { currentInfo.setRef(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentInfo.setId(attrValue); idRefLinks.put(attrValue, currentInfo); } } } } break; case MIN: currentMin = new SavotMin(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(VALUE)) { currentMin.setValue(attrValue); } else if (attrName.equalsIgnoreCase(INCLUSIVE)) { currentMin.setInclusive(attrValue); } } } } break; case MAX: currentMax = new SavotMax(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(VALUE)) { currentMax.setValue(attrValue); } else if (attrName.equalsIgnoreCase(INCLUSIVE)) { currentMax.setInclusive(attrValue); } } } } break; case OPTION: if (includedOption > 0) { // inner case (multi level options) putOptionStack(currentOption); if (trace) { System.err.println("OPTION - included"); } } else if (trace) { System.err.println("OPTION - not included"); } includedOption++; currentOption = new SavotOption(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(NAME)) { currentOption.setName(attrValue); } else if (attrName.equalsIgnoreCase(VALUE)) { currentOption.setValue(attrValue); } } } } break; case GROUP: // new since VOTable 1.1 stats.iGroupsGlobalInc(); if (includedGroup > 0) { // inner case (multi level groups) putGroupStack(currentGroup); if (trace) { System.err.println("GROUP - included"); } } else if (trace) { System.err.println("GROUP - not included"); } includedGroup++; currentGroup = new SavotGroup(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(REF)) { currentGroup.setRef(attrValue); } else if (attrName.equalsIgnoreCase(NAME)) { currentGroup.setName(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentGroup.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentGroup.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentGroup.setId(attrValue); idRefLinks.put(attrValue, currentGroup); } } } } break; case COOSYS: // deprecated since VOTable 1.2 currentCoosys = new SavotCoosys(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeName(i); if (attrName.equalsIgnoreCase(EQUINOX)) { currentCoosys.setEquinox(attrValue); } else if (attrName.equalsIgnoreCase(EPOCH)) { currentCoosys.setEpoch(attrValue); } else if (attrName.equalsIgnoreCase(SYSTEM)) { currentCoosys.setSystem(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentCoosys.setId(attrValue); idRefLinks.put(attrValue, currentCoosys); } } } } break; case DEFINITIONS: currentDefinitions = new SavotDefinitions(); break; default: System.err.println("VOTable markup error " + operation + " : " + tag + " at line " + parser.getLineNumber()); } // Anyway define currentMarkup: currentMarkup = tag; } break; // if an end tag is reach case XmlPullParser.END_TAG: operation = "END_TAG"; // the name of the current tag name = parser.getName(); if (name != null) { if (trace) { System.err.println("End ---> " + name); } tag = VOTableTag.parseTag(name); if (trace) { System.err.println(tag + " end"); } // use most probable tags FIRST (performance) i.e TD / TR first : switch (tag) { case TD: stats.iTDInc(); // reduce SavotTD instances: tdSet.addItem((currentTD == null) ? emptyTD : currentTD); break; case TR: stats.iTRInc(); stats.iTDLocalReset(); // trim TDset (reduce memory footprint): tdSet.trim(); if (parsingType != ROWREAD) { // add the row to the table currentTableData.getTRs().addItem(currentTR); currentTR = null; // used so do not recycle it } else { // TR will be used without storage in the model TRComplete = true; // update reference: _currentTR = currentTR; } if (doStats) { // for statistics only rowCount++; } if (trace) { System.err.println("ADD row"); } break; case DESCRIPTION: // DESCRIPTION - several fathers are possible switch (lastFather()) { case VOTABLE: _currentVOTable.setDescription(currentDescription); break; case RESOURCE: _currentResource.setDescription(currentDescription); break; case PARAM: currentParam.setDescription(currentDescription); break; case TABLE: currentTable.setDescription(currentDescription); break; case FIELD: currentField.setDescription(currentDescription); break; case GROUP: currentGroup.setDescription(currentDescription); break; default: } currentDescription = null; break; case TABLE: // avoid duplicates: if (parsingType != ROWREAD) { _currentResource.getTables().addItem(currentTable); if (trace) { System.err.println("TABLE " + currentTable.getName() + " added"); } } break; case FIELD: if (trace) { System.err.println("FIELD from father = " + lastFather()); } if (lastFather() == VOTableTag.TABLE) { currentTable.getFields().addItem(currentField); if (trace) { System.err.println("FIELD from TABLE father = " + father); } } break; case FIELDREF: if (lastFather() == VOTableTag.GROUP) { currentGroup.getFieldsRef().addItem(currentFieldRef); if (trace) { System.err.println("FIELDRef from GROUP father = " + father); } } break; case DATA: currentTable.setData(currentData); break; case RESOURCE: if (includedResource > 1) { final SavotResource tmp = _currentResource; _currentResource = getResourceStack(); _currentResource.getResources().addItem(tmp); } else { if (parsingType == FULL) { _currentVOTable.getResources().addItem(_currentResource); } if (trace) { System.err.println(">>>>>>>> RESOURCE COMPLETED"); } resourceComplete = true; } includedResource--; break; case OPTION: if (includedOption > 1) { final SavotOption tmp = currentOption; currentOption = getOptionStack(); currentOption.getOptions().addItem(tmp); includedOption--; } else { if (lastFather() == VOTableTag.VALUES) { currentValues.getOptions().addItem(currentOption); if (trace) { System.err.println("OPTION from VALUES father = " + father); } includedOption--; } } break; case GROUP: if (includedGroup > 1) { final SavotGroup tmp = currentGroup; currentGroup = getGroupStack(); currentGroup.getGroups().addItem(tmp); includedGroup--; } else { if (lastFather() == VOTableTag.TABLE) { currentTable.getGroups().addItem(currentGroup); if (trace) { System.err.println("GROUP from TABLE father = " + father); } includedGroup--; } } break; case TABLEDATA: stats.iTRLocalReset(); // trim TRset (reduce memory footprint): currentTableData.getTRs().trim(); currentData.setTableData(currentTableData); if (trace) { System.err.println("TABLEDATA " + currentTable.getName() + " added"); } break; case COOSYS: // COOSYS - several fathers are possible switch (lastFather()) { case DEFINITIONS: // deprecated since VOTable 1.1 currentDefinitions.getCoosys().addItem(currentCoosys); if (trace) { System.err.println("COOSYS from DEFINITIONS father = " + father); } break; case RESOURCE: _currentResource.getCoosys().addItem(currentCoosys); if (trace) { System.err.println("COOSYS from RESOURCE father = " + father); } break; case VOTABLE: _currentVOTable.getCoosys().addItem(currentCoosys); if (trace) { System.err.println("COOSYS from VOTABLE father = " + father); } break; default: } break; case PARAM: // PARAM - several fathers are possible switch (lastFather()) { case DEFINITIONS: // deprecated since VOTable 1.1 currentDefinitions.getParams().addItem(currentParam); if (trace) { System.err.println("PARAM from DEFINITIONS father = " + father); } break; case RESOURCE: _currentResource.getParams().addItem(currentParam); if (trace) { System.err.println("PARAM from RESOURCE father = " + father); } break; case TABLE: currentTable.getParams().addItem(currentParam); if (trace) { System.err.println("PARAM from TABLE father = " + father); } break; case GROUP: currentGroup.getParams().addItem(currentParam); if (trace) { System.err.println("PARAM from GROUP father = " + father); } break; case VOTABLE: _currentVOTable.getParams().addItem(currentParam); if (trace) { System.err.println("PARAM from VOTABLE father = " + father); } break; default: } break; case PARAMREF: if (lastFather() == VOTableTag.GROUP) { currentGroup.getParamsRef().addItem(currentParamRef); if (trace) { System.err.println("PARAMRef from GROUP father = " + father); } } break; case LINK: // LINK - several fathers are possible switch (lastFather()) { case RESOURCE: _currentResource.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from RESOURCE father = " + father); } break; case TABLE: currentTable.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from TABLE father = " + father); } break; case FIELD: currentField.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from FIELD father = " + father); } break; case PARAM: currentParam.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from PARAM father = " + father); } break; default: } break; case VALUES: // VALUES - several fathers are possible switch (lastFather()) { case PARAM: currentParam.setValues(currentValues); if (trace) { System.err.println("VALUES from PARAM father = " + father + " ID : " + currentValues.getId()); } break; case FIELD: currentField.setValues(currentValues); if (trace) { System.err.println("VALUES from FIELD father = " + father + " ID : " + currentValues.getId()); } break; default: } break; case MIN: currentValues.setMin(currentMin); break; case MAX: currentValues.setMax(currentMax); break; case STREAM: // STREAM - several fathers are possible switch (lastFather()) { case BINARY: currentBinary.setStream(currentStream); if (trace) { System.err.println("STREAM from BINARY father = " + father); } break; case FITS: currentFits.setStream(currentStream); if (trace) { System.err.println("STREAM from FITS father = " + father); } break; default: } break; case BINARY: currentData.setBinary(currentBinary); break; case FITS: currentData.setFits(currentFits); break; case INFO: if (trace) { System.err.println("INFO father = " + father); } // INFO - several fathers are possible switch (lastFather()) { case VOTABLE: // since VOTable 1.2 - if RESOURCE then INFO at the end if (_currentVOTable.getResources() != null && _currentVOTable.getResources().getItemCount() != 0) { _currentVOTable.getInfosAtEnd().addItem(currentInfo); } else { _currentVOTable.getInfos().addItem(currentInfo); } if (trace) { System.err.println("INFO from VOTABLE father = " + father); } break; case RESOURCE: // since VOTable 1.2 - if RESOURCE or LINK or TABLE then INFO at the end if ((_currentResource.getResources() != null && _currentResource.getResources().getItemCount() != 0) || (_currentResource.getTables() != null && _currentResource.getTables().getItemCount() != 0) || (_currentResource.getLinks() != null && _currentResource.getLinks().getItemCount() != 0)) { _currentResource.getInfosAtEnd().addItem(currentInfo); } else { _currentResource.getInfos().addItem(currentInfo); } if (trace) { System.err.println("INFO from RESOURCE father = " + father); } break; case TABLE: // since VOTable 1.2 currentTable.getInfosAtEnd().addItem(currentInfo); if (trace) { System.err.println("INFO from TABLE father = " + father); } break; default: } break; case DEFINITIONS: // deprecated since VOTable 1.1 _currentVOTable.setDefinitions(currentDefinitions); break; case VOTABLE: break; default: System.err.println("VOTable markup error " + operation + " : " + tag + " at line " + parser.getLineNumber()); } // Anyway reset currentMarkup: currentMarkup = VOTableTag.UNDEFINED; } break; case XmlPullParser.TEXT: operation = "TEXT"; // avoid parser creating empty String if (!parser.isWhitespace()) { // Get new String from parser: textValue = parser.getText(); if (doTrimValues) { textValue = textValue.trim(); } // only store not empty content: if (textValue.length() != 0) { if (trace) { System.err.println(currentMarkup + " : " + textValue); } // use most probable tags FIRST (performance) i.e TD / TR first : switch (currentMarkup) { case TD: // create a new data currentTD = new SavotTD(textValue); break; case DESCRIPTION: currentDescription = textValue; break; case INFO: currentInfo.setContent(textValue); break; case LINK: currentLink.setContent(textValue); break; case COOSYS: currentCoosys.setContent(textValue); break; case MIN: currentMin.setContent(textValue); break; case MAX: currentMax.setContent(textValue); break; case STREAM: currentStream.setContent(textValue); break; default: } } } break; case XmlPullParser.START_DOCUMENT: operation = "START_DOCUMENT"; if (trace) { System.err.println("Document start."); } break; default: operation = "UNDEFINED"; if (trace) { System.err.println("Ignoring some other (legacy) event at line : " + parser.getLineNumber()); } } // reset name and tag: tag = null; // new values from parser: eventType = parser.next(); // treatment depending on event type switch (eventType) { case XmlPullParser.START_TAG: operation = "START_TAG"; // the name of the current tag name = parser.getName(); if (trace) { System.err.println("> FATHER, add : " + name); } tag = VOTableTag.parseTag(name); father.add(tag); break; case XmlPullParser.END_TAG: operation = "END_TAG"; // the name of the current tag name = parser.getName(); if (name != null) { if (trace) { System.err.println("> FATHER, remove : " + name); } father.remove(father.size() - 1); } else if (trace) { // when a lf or cd is reached System.err.println("> FATHER, case null"); } break; // if an end document is reached: case XmlPullParser.END_DOCUMENT: operation = "END_DOCUMENT"; if (trace) { System.err.println("Document end reached!"); } // Anyway: if (parsingType == ROWREAD) { // terminate now (return TR null) to indicate that the complete document is done: _currentTR = null; } // Close the stream anyway: close(); break; default: // do nothing } if (TRComplete && (parsingType == ROWREAD)) { eventType = XmlPullParser.END_DOCUMENT; if (trace) { System.err.println(">>>>>>>>>>>>>>> ROWREAD case : TR end"); } } else if (resourceComplete && (parsingType == RESOURCEREAD)) { eventType = XmlPullParser.END_DOCUMENT; if (trace) { System.err.println(">>>>>>>>>>>>>>> RESOURCEREAD case : RESOURCE end"); } } } } catch (Exception e) { logger.log(Level.SEVERE, "Exception " + operation + " - TAG (" + tag + ") : parse : " + e + " at line " + parser.getLineNumber(), e); throw e; } if (doStats) { // update statistics: rowCounter = rowCount; dataCounter = dataCount; } } /** * Get the next Resource (warning : RESOURCEREAD mode only) * * @return a SavotResource (always NULL if other mode) */ public SavotResource getNextResource() { _currentResource = null; try { parse(RESOURCEREAD); } catch (IOException ioe) { logger.log(Level.SEVERE, "Exception getNextResource : ", ioe); _currentResource = null; } catch (Exception e) { logger.log(Level.SEVERE, "Exception getNextResource : ", e); _currentResource = null; } return _currentResource; } /** * Get the next TR (warning : ROWREAD mode only) * * @return a SavotTR (always NULL if other mode) */ public SavotTR getNextTR() { // note: currentTR is not null as it can be recycled try { parse(ROWREAD); } catch (IOException ioe) { logger.log(Level.SEVERE, "Exception getNextTR : ", ioe); _currentTR = null; } catch (Exception e) { logger.log(Level.SEVERE, "Exception getNextTR : ", e); _currentTR = null; } return _currentTR; } /** * Get a reference to V0TABLE object * * @return SavotVOTable */ public SavotVOTable getVOTable() { return _currentVOTable; } /** * Get the number of RESOURCE elements in the document (for statistics) * * @return a long value */ public int getResourceCount() { return resourceCounter; } /** * Get the number of TABLE elements in the document (for statistics) * * @return a long value */ public int getTableCount() { return tableCounter; } /** * Get the number of TR elements in the document (for statistics) * * @return a long value */ public int getTRCount() { return rowCounter; } /** * Get the number of DATA elements in the document (for statistics) * * @return a long value */ public int getDataCount() { return dataCounter; } /** * Get a reference on the Hashtable containing the link between ID and ref * * @return a refernce to the Hashtable */ public Map getIdRefLinks() { return idRefLinks; } /** * Search a RESOURCE corresponding to an ID ref * * @param ref * @return a reference to a SavotResource object */ public SavotResource getResourceFromRef(final String ref) { return (SavotResource) idRefLinks.get(ref); } /** * Search a FIELD corresponding to an ID ref * * @param ref * @return SavotField */ public SavotField getFieldFromRef(final String ref) { return (SavotField) idRefLinks.get(ref); } /** * Search a FIELDref corresponding to an ID ref * * @param ref * @return SavotFieldRef */ public SavotFieldRef getFieldRefFromRef(final String ref) { return (SavotFieldRef) idRefLinks.get(ref); } /** * Search a PARAM corresponding to an ID ref * * @param ref * @return SavotParam */ public SavotParam getParamFromRef(final String ref) { return (SavotParam) idRefLinks.get(ref); } /** * Search a PARAMref corresponding to an ID ref * * @param ref * @return SavotParamRef */ public SavotParamRef getParamRefFromRef(final String ref) { return (SavotParamRef) idRefLinks.get(ref); } /** * Search a TABLE corresponding to an ID ref * * @param ref * @return SavotTable */ public SavotTable getTableFromRef(final String ref) { return (SavotTable) idRefLinks.get(ref); } /** * Search a GROUP corresponding to an ID ref * * @param ref * @return SavotGROUP */ public SavotGroup getGroupFromRef(final String ref) { return (SavotGroup) idRefLinks.get(ref); } /** * Search a RESOURCE corresponding to an ID ref * * @param ref * @return SavotInfo */ public SavotInfo getInfoFromRef(final String ref) { return (SavotInfo) idRefLinks.get(ref); } /** * Search a VALUES corresponding to an ID ref * * @param ref * @return SavotValues */ public SavotValues getValuesFromRef(final String ref) { return (SavotValues) idRefLinks.get(ref); } /** * Search a LINK corresponding to an ID ref * * @param ref * @return SavotLink */ public SavotLink getLinkFromRef(final String ref) { return (SavotLink) idRefLinks.get(ref); } /** * Search a COOSYS corresponding to an ID ref * * @param ref * @return SavotCoosys */ public SavotCoosys getCoosysFromRef(final String ref) { return (SavotCoosys) idRefLinks.get(ref); } /** * Get current VOTable (all resources) * * @return SavotVOTable */ public SavotVOTable getAllResources() { return _currentVOTable; } /** * Enable debug mode * * @param debug * boolean */ public void enableDebug(boolean debug) { debugMode = debug; } } libcds-savot-java/src/main/java/cds/savot/binary/0000775000175000017500000000000012724035712021517 5ustar sladensladenlibcds-savot-java/src/main/java/cds/savot/binary/Base64.java0000664000175000017500000002753212724035712023417 0ustar sladensladenpackage cds.savot.binary; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (LAOG) import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.Arrays; /** *

Lets encoding and decoding String with the Base64.

* *

Note: * To encode/decode stream of data, you can also use Base64InputStream and Base64OutputStream. *

* *

Examples:

*
 * public final static void main(final String[] args) throws Exception {
 * 	String message = "Hi ! If you can read this, the Base64 encoding/decoding has completely worked ! Well done ;-) !";
 * 
 * 	System.out.println("ORIGINAL MESSAGE:\n\""+message+"\"");
 * 
 * 	String encoded, decoded;
 * 
 * 	System.out.println("\nEncoding....");
 * 	encoded = Base64.encodeStr(message);
 * 	System.out.println("ENCODED MESSAGE:\n\""+encoded+"\"");
 * 
 * 	System.out.println("\nDecoding....");
 * 	decoded = Base64.decodeStr(encoded);
 * 	System.out.println("DECODED MESSAGE:\n\""+decoded+"\"");
 * }
 * 
* * @author Gregory Mantelet (CDS) * @since 09/2011 */ public final class Base64 { /* package protected fields */ static final int LINE_LENGTH = 76; static final String NEW_LINE = System.getProperty("line.separator"); static final char[] base64code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray(); static final char PADDING_CHAR = '='; static final int[] base64decode = new int[256]; static { Arrays.fill(base64decode, -1); for (int i = 0, iS = base64code.length; i < iS; i++) { base64decode[base64code[i]] = i; } base64decode[PADDING_CHAR] = 0; } private Base64() { } /* ************ BASE 64 ENCODING ************ */ /** * Encodes the given string in Base64. * * @param string The string to encode. * * @return Its Base64 encoding. * * @see #encodeStr(String, String) */ public static String encodeStr(final String string) { return encodeStr(string, null); } /** * Encodes the given string in Base64. * * @param string The string to encode (string supposed to be encoded with the given {@link Charset charset}). * @param charset The name of a supported {@link Charset charset} (i.e. 'UTF-8'). * * @return Its Base64 encoding. * * @see #encode(byte[]) */ public static String encodeStr(final String string, final String charset) { byte[] byteArray; try { byteArray = (charset == null) ? string.getBytes() : string.getBytes(charset); // use appropriate encoding string! } catch (UnsupportedEncodingException ignored) { byteArray = string.getBytes(); // use local default rather than croak } return encode(byteArray); } /** * Encodes the given bytes array in Base64 characters. * * @param byteArray Data to encode. * * @return The encoded data. */ public static String encode(final byte[] byteArray) { /* TODO: define intial capacity or recycle StringBuilder instances */ final StringBuilder encoded = new StringBuilder(); // 1st STEP: Pad the given bytes array with 0 so that ALL bytes can be read in groups of 3 bytes: final int nbRealBytes = byteArray.length; int paddingCount = (3 - (nbRealBytes % 3)) % 3; byte[] paddedByteArray = zeroPad(nbRealBytes + paddingCount, byteArray); for (int i = 0; i < paddedByteArray.length; i += 3) { // 2nd STEP: group 3 bytes (=> 3*8 = 24 bits): int group = ((paddedByteArray[i] & 0xff) << 16); group |= ((paddedByteArray[i + 1] & 0xff) << 8); group |= (paddedByteArray[i + 2] & 0xff); // 3rd STEP: split this group in 4 sub-groups (of 6 bits) which correspond each to one character in the Base64 alphabet: encoded.append(base64code[(group >> 18) & 0x3f]); encoded.append(base64code[(group >> 12) & 0x3f]); encoded.append((i + 1 >= nbRealBytes) ? Base64.PADDING_CHAR : Base64.base64code[(group >> 6) & 0x3f]); encoded.append((i + 2 >= nbRealBytes) ? Base64.PADDING_CHAR : Base64.base64code[group & 0x3f]); } // 4th step: split the encoded data in lines of LINE_LENGTH (76) characters: return splitLines(encoded).toString(); } /** *

Pads the given bytes array with length-bytes.length 0.

* *

In other words: * Creates a bytes array of the given length and whose the first items are those given in parameter. * All other items are initialized to 0x00.

* * @param length Length of the resulting bytes array. * @param bytes First bytes of the resulting bytes array. * * @return The 0-padded array. */ static byte[] zeroPad(final int length, final byte[] bytes) { byte[] padded = new byte[length]; // initialized to zero by JVM System.arraycopy(bytes, 0, padded, 0, bytes.length); return padded; } /** * Splits the given encoded data in lines of {@link #LINE_LENGTH} characters. * * @param encoded Data to split in lines. * * @return The line-split data. */ static StringBuilder splitLines(final StringBuilder encoded) { for (int i = 0; i < encoded.length(); i += LINE_LENGTH + NEW_LINE.length()) { if ((i + LINE_LENGTH) <= encoded.length()) { encoded.insert(i + LINE_LENGTH, NEW_LINE); } } return encoded; } /* ************ BASE 64 DECODING ************ */ /** * Decodes the given string which is supposed to be encoded in Base64. * * @param encoded Message to decode. * * @return The decoded message. * * @throws Base64Exception If the encoded message is corrupted (that's to say: not conform to the Base64 encoding). * * @see #decodeStr(String, String) */ public static String decodeStr(final String encoded) throws Base64Exception { return decodeStr(encoded, null); } /** * Decodes the given string which is supposed to be encoded in Base64. * * @param encoded Message to decode. * @param charset The name of a supported {@link Charset charset}. * * @return The decoded message (string encoded using the given {@link Charset charset}). * * @throws Base64Exception If the encoded message is corrupted (that's to say: not conform to the Base64 encoding). * * @see #decode(String) */ public static String decodeStr(final String encoded, final String charset) throws Base64Exception { byte[] bytes = decode(encoded); if (bytes == null) { return null; } if (charset != null) { try { return new String(bytes, charset); } catch (UnsupportedEncodingException e) { /* ignored */ } } return new String(bytes); } /** * Decodes the given string which is supposed to be encoded in Base64. * * @param encoded Data to decode. * * @return The decoded data. * * @throws Base64Exception If the encoded data are corrupted (that's to say: not conform to the Base64 encoding). * * @see #decode(char[]) */ public static byte[] decode(final String encoded) throws Base64Exception { return decode(encoded.toCharArray()); } /** * Decodes the given string which is supposed to be encoded in Base64. * * @param encoded Data to decode. * * @return The decoded data. * * @throws Base64Exception If the encoded data are corrupted (that's to say: not conform to the Base64 encoding). */ public static byte[] decode(final char[] encoded) throws Base64Exception { int cLength = 0; // number of valid bytes int pad = 0; // number of padding bytes boolean eom = false; // End Of Message: true if padding character(s) has(ve) been encountered // 1st STEP: Count the number of valid characters and of padding characters: for (int i = 0; !eom && i < encoded.length; i++) { if (base64decode[encoded[i]] > -1) { if (pad > 0 && encoded[i] != PADDING_CHAR) { throw new Base64Exception("Encoded message corrupted: \"" + encoded[i] + "\" has been encountered after a padding character (\"" + PADDING_CHAR + "\") !"); } else { cLength++; if (encoded[i] == PADDING_CHAR) { pad++; } } } else { if (!Character.isWhitespace(encoded[i])) // only white-spaces are ignored { System.err.println("Warning: encoded message may be corrupted: unknown base64 character: \"" + encoded[i] + "\" !"); } } // EOM if a group of 4 characters ends with padding characters: if (pad > 0 && cLength % 4 == 0) { eom = true; } // Check the number padding characters: if (pad > 2) { throw new Base64Exception("Encoded message corrupted: a message encoding in base64 can end with at most 2 padding characters (\"" + PADDING_CHAR + "\") !"); } } // Throw an error if it's not possible to read ALL characters by group of 4: if (cLength % 4 != 0) { throw new Base64Exception("Encoded message corrupted (only " + cLength + " valid characters) !"); } // 2nd STEP: Build the bytes array which will be filled with decoded data: int bLength = ((cLength / 4) * 3) - pad; // N group of 4 characters => N*3 bytes - P (where P is the number of padding bytes) byte[] decoded = new byte[bLength]; // Decode all valid characters in the built bytes array: int nbChar = 0, nbBytes = 0; int nbGroupedChars = 0, group = 0; for (int i = 0; i < encoded.length && nbChar < cLength; i++) { if (base64decode[encoded[i]] > -1) { // 3rd STEP: group the 6 last bits of 4 characters: group |= ((base64decode[encoded[i]] & 0x3f) << (6 * (3 - nbGroupedChars))); nbGroupedChars++; // 4th STEP: when 4 characters have been grouped, extract the 3 resulting bytes (=> 4*6 bits = 24 bits = 3*8 bits): if (nbGroupedChars == 4) { decoded[nbBytes++] = (byte) ((group >> 16) & 0xff); if (nbBytes < bLength) { // extract the 2nd byte only if it's not a padding: decoded[nbBytes++] = (byte) ((group >> 8) & 0xff); if (nbBytes < bLength) // extract the 3rd byte only if it's not a padding: { decoded[nbBytes++] = (byte) (group & 0xff); } } group = 0; nbGroupedChars = 0; } nbChar++; } } return decoded; } } libcds-savot-java/src/main/java/cds/savot/binary/DataBinaryReader.java0000664000175000017500000004647012724035712025536 0ustar sladensladenpackage cds.savot.binary; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // // SAVOT 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, version 3 of the License. // // SAVOT 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. // // The GNU General Public License is available in COPYING file // along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (LAOG) import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.zip.GZIPInputStream; //import org.apache.commons.codec.binary.Base64InputStream; import cds.savot.model.FieldSet; import cds.savot.model.SavotField; import cds.savot.model.SavotStream; import cds.savot.model.SavotTD; import cds.savot.model.SavotTR; import cds.savot.model.TDSet; import cds.savot.model.interpreter.BinaryFieldInterpreter; import cds.savot.model.interpreter.BinaryInterpreterException; /** *

Lets read binary data (that is to say: a votable.resource.table.data.binary node).

* *

* A DataBinaryReader must be initialized with a {@link SavotStream} object which contains all information to access and read the data, * and with a {@link FieldSet} which lists all fields (or cells) that are expected in the data. * A {@link SavotStream} has several attributes that are more or less managed by a DataBinaryReader: *

*
    *
  • href: path to the resource which contains the binary data. This attribute is fully MANAGED !
  • *
  • encoding: it specifies how binary data have been encoded. This attribute is MANAGED WITH the value "base64", "gzip" and "dynamic" !
  • *
  • expires: data expiration date. After this date, data are supposed to be not valid any more. This attribute is fully MANAGED and can be ignored on demand !
  • *
  • rights: it expresses authentication information (i.e. password). This attribute is NOT MANAGED !
  • *
  • actuate: it indicates when data have to be fetched (onRequest (by default) or onLoad). This attribute is NOT MANAGED !
  • *
* *

HREF attribute

*

* The following protocols are accepted in the "href" attribute: http, https, httpg (not tested at all), ftp and file. * If the "href" attribute contains a relative path to a local file, the parent directory must be specified to the reader. *

* *

Encoding attribute

*

* The following STREAM encoding are managed: base64, gzip, dynamic. * If no encoding is specified, the data will be merely considered as just binary data. *

*

* The "dynamic" encoding implies that the data is in a remote resource (specified by the "href" attribute), * and the encoding will be delivered with the header of the data. This occurs with the http protocol, * where the MIME header (http header field "Content-Encoding") indicates the type of encoding that has been used. * In this case only base64 and gzip are accepted. *

* *

Expires attribute

*

* If the date given by this attribute has been reached, no data will be read and an {@link IOException} will be thrown. * However, this attribute can be ignored at the creation of a DataBinaryReader if needed. *

* * @author Gregory Mantelet (CDS) * @since 09/2011 */ public final class DataBinaryReader implements SavotDataReader { /** Regular expression of a valid URL (http, https, httpg, ftp, file) for the "href" attribute. */ private static final String URL_REGEXP = "^(http(s|g)?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"; /** Valid date format (Universal Time ; ISO-8601) for the "expires" attribute. */ private static final DateFormat EXPIRES_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); /** Stream toward the (decoded) binary data. */ private InputStream data; /** List of decoders: one per available cell. */ private BinaryFieldInterpreter[] decoders; /** The last read row (the length of the array is equal to the number of decoders). */ private Object[] row; /** Indicates whether the next() function has yet been called. */ private boolean nextCalled = false; /** Indicates whether the end of the file has been reached. */ private boolean eof = false; /* CONSTRUCTORS */ /** *

Builds a DataBinaryReader with a {@link SavotStream}.

* *

NOTE: The expiration date is NOT ignored and there is no parent directory.

* * @param stream The {@link SavotStream} which contains data to read. * @param fields List of fields metadata (one per cell). * * @throws IOException If an error occurs while building the input stream. * * @see #DataBinaryReader(SavotStream, FieldSet, boolean, String) */ public DataBinaryReader(final SavotStream stream, final FieldSet fields) throws IOException { this(stream, fields, false, null); } /** *

Builds a DataBinaryReader with a {@link SavotStream}.

* *

NOTE: There is no parent directory.

* * @param stream The {@link SavotStream} which contains data to read. * @param fields List of fields metadata (one per cell). * @param ignoreExpiryDate true to ignore the "expires" attribute, false otherwise. * * @throws IOException If an error occurs while building the input stream. * * @see #DataBinaryReader(SavotStream, FieldSet, boolean, String) */ public DataBinaryReader(final SavotStream stream, final FieldSet fields, final boolean ignoreExpiryDate) throws IOException { this(stream, fields, ignoreExpiryDate, null); } /** *

Builds a DataBinaryReader with a {@link SavotStream}.

* * @param stream The {@link SavotStream} which contains data to read. * @param fields List of fields metadata (one per cell). * @param ignoreExpiryDate true to ignore the "expires" attribute, false otherwise. * @param parentDirectory Directory which contains the data file if the path given in the "href" attribute is relative. * * @throws IOException If an error occurs while building the input stream. * * @see #DataBinaryReader(FieldSet) * @see #getData(SavotStream, boolean, String) */ public DataBinaryReader(final SavotStream stream, final FieldSet fields, final boolean ignoreExpiryDate, final String parentDirectory) throws IOException { this(fields); data = getData(stream, ignoreExpiryDate, parentDirectory); } /** *

Builds a DataBinaryReader with an {@link InputStream} on the ENCODED data.

* * @param encodedData Encoded data. * @param encoding Encoding of the data (base64, gzip or null). * @param fields List of fields metadata (one per cell). * * @throws IOException If an error occurs while building the input stream. * * @see #DataBinaryReader(FieldSet) * @see #getDecodedStream(InputStream, String) */ public DataBinaryReader(final InputStream encodedData, final String encoding, final FieldSet fields) throws IOException { this(fields); data = getDecodedStream(encodedData, encoding); } /** *

Builds a DataBinaryReader with an {@link InputStream} on the DECODED data.

* * @param decodedData Decoded data. * @param fields List of fields metadata (one per cell). * * @throws BinaryInterpreterException If it is impossible to build a field decoder. * * @see #DataBinaryReader(FieldSet) */ public DataBinaryReader(final InputStream decodedData, final FieldSet fields) throws BinaryInterpreterException { this(fields); data = decodedData; } /** *

* Builds one binary decoder per field and initializes the variable * which aims to contains the read row after a {@link #next()} call. *

* *

* WARNING: The {@link #data} attribute is not initialized ! * This constructor is just designed to initialize the decoders list. * Thus it must be called by another constructor which will be able * to initialize the data input stream. *

* * @param fields List of fields metadata (one per cell). * * @throws BinaryInterpreterException It it is impossible to build a field decoder. * * @see BinaryFieldInterpreter#createInterpreter(SavotField) */ protected DataBinaryReader(final FieldSet fields) throws BinaryInterpreterException { final int nFields = fields.getItemCount(); decoders = new BinaryFieldInterpreter[nFields]; for (int i = 0; i < nFields; i++) { decoders[i] = BinaryFieldInterpreter.createInterpreter(fields.getItemAt(i)); } row = new Object[nFields]; } /* STREAM BUILDING METHODS */ /** * Builds an input stream on decoded binary data with the given {@link SavotStream}. * * @param stream The {@link SavotStream} which contains all information to get the (encoded or not) binary data. * @param ignoreExpiryDate true to ignore the expiration date, false otherwise. * @param parentDirectory Directory which contains the data file if the path given in the "href" attribute is relative. * * @return An input stream which reads the encoded binary data and returns the corresponding decoded binary data. * * @throws IOException If the expiration date has been reached, if the given encoding is unknown * or if there is an error while building the input stream. * * @see #getInputFromURL(URL, String) * @see #getDynamicEncoding(URL, String) * @see #getDecodedStream(InputStream, String) */ private InputStream getData(final SavotStream stream, final boolean ignoreExpiryDate, final String parentDirectory) throws IOException { // 1. CHECK THE DATA VALIDITY THANKS TO THE EXPIRES ATTRIBUTE: if (!ignoreExpiryDate && stream.getExpires() != null) { String expires = stream.getExpires().trim(); if (!expires.isEmpty()) { try { Date expiryDate = EXPIRES_DATE_FORMAT.parse(expires); if (expiryDate.before(new Date())) { throw new IOException("Data are not valid any more (expiry date: \"" + expires + "\") !"); } } catch (ParseException pe) { System.out.println("Warning: unknown date format (" + expires + "): the stream expiry date will be ignored !"); } } } InputStream data = null; String encoding = (stream.getEncoding() == null) ? null : stream.getEncoding().trim(); // 2. GET THE ENCODED DATA: String href = stream.getHref(); // href data: if (href != null && !href.trim().isEmpty()) { href = href.trim(); // URL: if (href.matches(URL_REGEXP)) { URL url = new URL(href); data = getInputFromURL(url, stream.getRights()); // extract the data encoding, if needed: if (encoding != null && encoding.equalsIgnoreCase("dynamic")) { try { encoding = getDynamicEncoding(url, stream.getRights()); } catch (IOException ioe) { throw new IOException("Can't fetch the data encoding from the URL \"" + href + "\", because: " + ioe.getMessage(), ioe); } } } // FILE: else { File dataFile; if (parentDirectory == null) { dataFile = new File(href); } else { dataFile = new File(parentDirectory, href); } data = new FileInputStream(dataFile); } } // Inline data: else { data = new ByteArrayInputStream(stream.getContent().getBytes()); } // 3. GET THE DECODED DATA: data = getDecodedStream(data, encoding); return data; } /** *

Gets an input stream on the given URL considering the given rights.

* *

* WARNING: By default, rights is not considered. * That is to say, by default what is returned is: dataUrl.openStream(). *

* * @param dataUrl The URL toward the data. * @param rights Authentication information (i.e. password) needed to open a stream on the given URL. * * @return An input stream on the given URL. * * @throws IOException If there is an error while creating the input stream. */ private InputStream getInputFromURL(final URL dataUrl, final String rights) throws IOException { return dataUrl.openStream(); } /** *

Extracts the encoding of the data from the protocol header.

* *

For instance: if the protocol is HTTP, the header Content-Encoding gives the data encoding.

* *

WARNING: By default, rights is not considered.

* * @param dataUrl The URL toward the data. * @param rights Authentication information (i.e. password) needed to open a stream on the given URL. * * @return The name of the data encoding. (may be null). * * @throws IOException If there is an error while opening a connection on the given URL. */ private String getDynamicEncoding(final URL dataUrl, final String rights) throws IOException { URLConnection connection = dataUrl.openConnection(); connection.connect(); return connection.getContentEncoding(); } /** *

Gets a stream which decodes data coming from the given input stream.

* *

NOTE: Accepted encoding algorithms are: base64 or gzip.

* * @param encodedStream Input stream on encoded data. * @param encoding Name of the encoding algorithm (base64 or gzip). * * @return An input stream which decodes the encoded data read from the given input stream. * * @throws IOException If there is an error while building the input stream. * * @see Base64InputStream * @see GZIPInputStream */ private InputStream getDecodedStream(final InputStream encodedStream, final String encoding) throws IOException { if (encoding == null || encoding.isEmpty()) { return encodedStream; } else if (encoding.equalsIgnoreCase("base64")) { return new Base64InputStream(encodedStream); } else if (encoding.equalsIgnoreCase("gzip")) { return new GZIPInputStream(encodedStream); } else { throw new BinaryInterpreterException("Unknown encoding \"" + encoding + "\" ! It must be either \"base64\" or \"gzip\" !"); } } /* INHERITED METHODS */ /** * @throws IOException */ @Override public boolean next() throws IOException { if (row == null) { throw new IOException("Reader closed !"); } else if (eof) { return false; } for (int i = 0; i < row.length; i++) { // Reads the value of the i-th cell: row[i] = decoders[i].decode(data); // EOF detection: if (row[i] == null) { // decode(...) must return an array. If null is returned => EOF ! // EOF accepted ONLY while getting the first cell of a row: if (i == 0) { eof = true; nextCalled = true; return false; } // otherwise an exception is thrown ! else { throw new IOException("Unexpected EOF: the row has not been read completely ; only " + i + " columns on " + row.length + " has been successfully read !"); } } } nextCalled = true; return true; } /** *

Ensures that:

*
    *
  • the input stream is open
  • *
  • the end of file has not yet been reached
  • *
  • next() has been called.
  • *
* * @throws IllegalStateException If at least one check fails. */ private void ensureRowAvailable() throws IllegalStateException { if (row == null) { throw new IllegalStateException("No more row available: the reader is closed !"); } else if (eof) { throw new IllegalStateException("No more row available: the end of file has been reached !"); } else if (!nextCalled) { throw new IllegalStateException("No row available: next() has not yet been called !"); } } /** * @return an Object * @throws IllegalStateException */ @Override public Object[] getRow() throws IllegalStateException { ensureRowAvailable(); return row; } /** * @return a SAVOT TR internal model object * @throws IllegalStateException */ @Override public SavotTR getTR() throws IllegalStateException { ensureRowAvailable(); SavotTR tr = new SavotTR(); TDSet tds = new TDSet(); for (int i = 0; i < row.length; i++) { tds.addItem(getTD(i)); } tr.setTDs(tds); return tr; } /** * @param indColumn * @return Object * @throws IndexOutOfBoundsException * @throws IllegalStateException */ @Override public Object getCell(final int indColumn) throws IndexOutOfBoundsException, IllegalStateException { ensureRowAvailable(); return (row == null) ? null : row[indColumn]; } /** * @param indColumn * @return String * @throws IndexOutOfBoundsException * @throws IllegalStateException */ @Override public String getCellAsString(final int indColumn) throws IndexOutOfBoundsException, IllegalStateException { ensureRowAvailable(); return (row == null) ? null : decoders[indColumn].convertToString(row[indColumn]); } /** * @param indColumn * @return SavotTD SAVOT TD internal model object * @throws IndexOutOfBoundsException * @throws IllegalStateException */ @Override public SavotTD getTD(final int indColumn) throws IndexOutOfBoundsException, IllegalStateException { ensureRowAvailable(); SavotTD td = new SavotTD(); td.setContent(getCellAsString(indColumn)); return td; } /** * @throws IOException */ @Override public void close() throws IOException { data.close(); data = null; row = null; decoders = null; } } libcds-savot-java/src/main/java/cds/savot/binary/SavotDataReader.java0000664000175000017500000001003012724035712025365 0ustar sladensladenpackage cds.savot.binary; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // // SAVOT 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, version 3 of the License. // // SAVOT 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. // // The GNU General Public License is available in COPYING file // along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (LAOG) import cds.savot.model.SavotTD; import cds.savot.model.SavotTR; import java.io.Closeable; import java.io.IOException; /** * Common interface of a reader of a VOTable DATA node * (whatever is its child node: FITS, BINARY or TABLEDATA). * * @author Gregory Mantelet * @since 09/2011 */ public interface SavotDataReader extends Closeable { /** *

Reads to the next row.

* *

* Once this function called, you can get the full row with {@link #getRow()} or {@link #getTR()}, * or get specific cells with {@link #getCell(int)}, {@link #getCellAsString(int)} * or {@link #getTD(int)}. *

* * @return true if the next row has been successfully fetched, false otherwise. * * @throws IOException If an error occurs while reading the next row. */ public boolean next() throws IOException; /** * Gets the last read row. * * @return The last read row. * @throws IllegalStateException If next has not yet been called, if the EOF has been reached, or if the reader is closed. */ public Object[] getRow() throws IllegalStateException; /** * Gets the last read row as a {@link SavotTR} object. * * @return The last read row. * @throws IllegalStateException If next has not yet been called, if the EOF has been reached, or if the reader is closed. */ public SavotTR getTR() throws IllegalStateException; /** * Gets the specified cell of the last read row. * * @param indColumn Index of the cell to get. * * @return The specified cell of the last read row. * * @throws ArrayIndexOutOfBoundsException If the given index is less than 0 or is greater than the number of available cell. * @throws IllegalStateException If next has not yet been called, if the EOF has been reached, or if the reader is closed. */ public Object getCell(final int indColumn) throws ArrayIndexOutOfBoundsException, IllegalStateException; /** * Gets the specified cell of the last read row as a String. * * @param indColumn Index of the cell to get. * * @return The string representation of specified cell. * * @throws ArrayIndexOutOfBoundsException If the given index is less than 0 or is greater than the number of available cell. * @throws IllegalStateException If next has not yet been called, if the EOF has been reached, or if the reader is closed. */ public String getCellAsString(final int indColumn) throws ArrayIndexOutOfBoundsException, IllegalStateException; /** * Gets the specified cell of the last read row as {@link SavotTD}. * * @param indColumn Index of the cell to get. * * @return The specified cell of the last read row. * * @throws ArrayIndexOutOfBoundsException If the given index is less than 0 or is greater than the number of available cell. * @throws IllegalStateException If next has not yet been called, if the EOF has been reached, or if the reader is closed. */ public SavotTD getTD(final int indColumn) throws ArrayIndexOutOfBoundsException, IllegalStateException; } libcds-savot-java/src/main/java/cds/savot/binary/SavotDataWriter.java0000664000175000017500000000323512724035712025450 0ustar sladensladenpackage cds.savot.binary; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // // SAVOT 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, version 3 of the License. // // SAVOT 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. // // The GNU General Public License is available in COPYING file // along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (LAOG) import cds.savot.model.SavotTR; import cds.savot.model.TRSet; import java.io.Closeable; import java.io.Flushable; import java.io.IOException; /** * Common interface of a writer of the data of a VOTable DATA node * (whatever is its child node: FITS, BINARY or TABLEDATA). * * @author Gregory Mantelet * @since 09/2011 */ public interface SavotDataWriter extends Closeable, Flushable { /** * Writes the given row. * * @param row Row to write. * * @throws IOException If there is an error while writing the given row. */ public void writeTR(SavotTR row) throws IOException; /** * Writes the given rows. * * @param rows Rows to write. * * @throws IOException If there is an error while writing the given rows. */ public void writeTRSet(TRSet rows) throws IOException; } libcds-savot-java/src/main/java/cds/savot/binary/DataBinaryWriter.java0000664000175000017500000001436512724035712025606 0ustar sladensladenpackage cds.savot.binary; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // // SAVOT 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, version 3 of the License. // // SAVOT 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. // // The GNU General Public License is available in COPYING file // along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (LAOG) import cds.savot.model.FieldSet; import cds.savot.model.SavotField; import cds.savot.model.SavotTD; import cds.savot.model.SavotTR; import cds.savot.model.TDSet; import cds.savot.model.TRSet; import cds.savot.model.interpreter.BinaryFieldInterpreter; import cds.savot.model.interpreter.BinaryInterpreterException; import java.io.IOException; import java.io.OutputStream; import java.util.zip.GZIPOutputStream; /** *

Lets write binary data (that is to say: a votable.resource.table.data.binary node).

* *

NOTE: * Accepted encoding algorithms are: base64, gzip or dynamic. * "dynamic" encoding is accepted but no particular encoding will be applied while writing data. They will be written just in binary. *

* * @author Gregory Mantelet * @since 09/2011 */ public final class DataBinaryWriter implements SavotDataWriter { /** Stream in which binary data will be written encoded. */ private OutputStream output; /** List of encoders: one per available cell. */ private BinaryFieldInterpreter[] encoders; /* CONSTRUCTORS */ /** * Builds a DataBinaryWriter with no encoding. * * @param rawStream Simple output stream. * @param fields List of fields metadata (one per cell). * @throws cds.savot.model.interpreter.BinaryInterpreterException * @throws IOException If an error occurs while building the output stream. * * @see #DataBinaryWriter(OutputStream, FieldSet, String) */ public DataBinaryWriter(final OutputStream rawStream, final FieldSet fields) throws BinaryInterpreterException, IOException { this(rawStream, fields, null); } /** * Builds a DataBinaryWriter with a particular encoding (base64 or gzip). * * @param rawStream Simple output stream. * @param fields List of fields metadata (one per cell). * @param encoding Name of an encoding algorithm (base64, gzip or null). * * @throws IOException If an error occurs while building the output stream. * * @see #getEncodedStream(OutputStream, String) * @see BinaryFieldInterpreter#createInterpreter(SavotField) */ public DataBinaryWriter(final OutputStream rawStream, final FieldSet fields, final String encoding) throws IOException { if (rawStream == null) { throw new NullPointerException("The given output stream is NULL !"); } this.output = getEncodedStream(rawStream, encoding); final int nFields = fields.getItemCount(); encoders = new BinaryFieldInterpreter[nFields]; for (int i = 0; i < nFields; i++) { encoders[i] = BinaryFieldInterpreter.createInterpreter(fields.getItemAt(i)); } } /* STREAM BUILDING METHOD */ /** *

Gets a stream which encodes data into the given output stream.

* *

NOTE: Accepted encoding algorithms are: base64 or gzip.

* * @param rawStream Simple output stream. * @param encoding Name of the encoding algorithm (base64 or gzip). * * @return An output stream which encodes data read into the given output stream. * * @throws IOException If there is an error while building the output stream. * @throws cds.savot.model.interpreter.BinaryInterpreterException * @see Base64OutputStream * @see GZIPOutputStream */ OutputStream getEncodedStream(final OutputStream rawStream, final String encoding) throws IOException, BinaryInterpreterException { if (encoding == null || encoding.isEmpty()) { return rawStream; } else if (encoding.equalsIgnoreCase("base64")) { return new Base64OutputStream(rawStream); } else if (encoding.equalsIgnoreCase("gzip")) { return new GZIPOutputStream(rawStream); } else if (encoding.equalsIgnoreCase("dynamic")) { return rawStream; } else { throw new BinaryInterpreterException("Unknown encoding \"" + encoding + "\" ! It must be either \"base64\" or \"gzip\" !"); } } /** * @param row SavotTR * @throws java.io.IOException * @throws cds.savot.model.interpreter.BinaryInterpreterException */ @Override public void writeTR(final SavotTR row) throws IOException, BinaryInterpreterException { if (output == null) { throw new IOException("Writer closed !"); } final TDSet tds = row.getTDSet(); for (int i = 0, len = tds.getItemCount(); i < len; i++) { final SavotTD td = tds.getItemAt(i); encoders[i].encode(output, td.getContent()); } } /** * @param rows TRSet * @throws java.io.IOException * @throws cds.savot.model.interpreter.BinaryInterpreterException */ @Override public void writeTRSet(final TRSet rows) throws IOException, BinaryInterpreterException { if (output == null) { throw new IOException("Writer closed !"); } for (int i = 0, len = rows.getItemCount(); i < len; i++) { writeTR(rows.getItemAt(i)); } } /** * @throws IOException */ @Override public void flush() throws IOException { output.flush(); } /** * @throws IOException */ @Override public void close() throws IOException { output.close(); output = null; encoders = null; } } libcds-savot-java/src/main/java/cds/savot/binary/Base64Exception.java0000664000175000017500000000270212724035712025266 0ustar sladensladenpackage cds.savot.binary; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (LAOG) /** * Exception that can occur during the encoding/decoding of data in Base64. * If such an error occurs during the decoding, it would mean that the encoded message/data have been corrupted. * * @author Gregory Mantelet * @since 09/2011 */ public final class Base64Exception extends Exception { private static final long serialVersionUID = 1L; public Base64Exception() { super(); } public Base64Exception(String msg, Throwable cause) { super(msg, cause); } public Base64Exception(String msg) { super(msg); } public Base64Exception(Throwable cause) { super(cause); } } libcds-savot-java/src/main/java/cds/savot/binary/Base64OutputStream.java0000664000175000017500000001530512724035712026007 0ustar sladensladenpackage cds.savot.binary; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // // SAVOT 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, version 3 of the License. // // SAVOT 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. // // The GNU General Public License is available in COPYING file // along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (LAOG) import java.io.BufferedOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; /** *

A Base64OutputStream encodes given bytes in Base64 characters and writes them in the given OutputStream.

* *

The Base 64 encoding

*
    *
  • According to the RFC-2045, valid Base64 characters are: * A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9,+,/.
  • *
  • Encoded data ARE splitted in lines of 76 characters, using the local line separator (System.getProperty("line.separator")).
  • *
* *

Buffer

*

* This stream is buffered. That means that encoded bytes sent to the inner output stream will be written when a given number of bytes are collected. * By default the buffer size is: 8192. *

*

* Warning ! * Actually the buffer is not managed in Base64OutputStream but in its inner output stream. At the initialization the given output stream is used * to create a {@link BufferedOutputStream} with (N/3)*4 as buffer size (where N is the given buffer size). * Indeed, with the Base64 encoding, the number of encoded bytes is always greater than the number of the corresponding decoded bytes: * 3 bytes will be encoded by 4 characters encoded on 6 bits (which allows an alphabet of 2^6=64 characters, hence base64). * Consequently: a buffer of N bytes in a BufferedOutputStream corresponds to a buffer of (N/3)*4 bytes in its inner output stream. * So, when you set a buffer size of 8192 bytes at the creation of a Base64OutputStream, it is really implemented by a buffer of 10924 bytes. *

* * @author Gregory Mantelet * @since 09/2011 * * @see Base64 */ public final class Base64OutputStream extends FilterOutputStream { /** Default buffer size. */ private static int defaultBufferSize = 8192; /** Group of 3 bytes. */ private int group = 0; /** Number of grouped bytes (0≤bytecounter≤3) */ private int bytecounter = 0; /** Number of bytes on the current line. After {@link Base64#LINE_LENGTH} bytes a {@link Base64#NEW_LINE} is added. */ private int linecounter = 0; /** * * @param stream */ public Base64OutputStream(final OutputStream stream) { this(stream, defaultBufferSize); } /** * * @param stream * @param bufferSize */ public Base64OutputStream(final OutputStream stream, final int bufferSize) { super(new BufferedOutputStream(stream, encodedDataSize(bufferSize))); } /** * Computes the size of the encoded data (3 decoded bytes => 4 encoded characters/bytes). * * @param nbDataToEncode Size of the data to encode. * * @return Size of the encoded data. */ static int encodedDataSize(final int nbDataToEncode) { if (nbDataToEncode <= 0) { return 0; } int encodedSize = nbDataToEncode / 3; if (nbDataToEncode % 3 != 0) { encodedSize++; } encodedSize *= 4; return encodedSize; } @Override public void write(int b) throws IOException { group |= ((b & 0xFF) << (16 - (bytecounter * 8))); bytecounter++; if (bytecounter == 3) { commit(); } } @Override public void write(byte[] b) throws IOException { if (b == null) { throw new NullPointerException("The given byte buffer is NULL !"); } write(b, 0, b.length); } @Override public void write(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException("The given byte buffer is NULL !"); } if (off < 0) { throw new ArrayIndexOutOfBoundsException("The offset parameter is negative (" + off + ") !"); } else if (off >= b.length) { throw new ArrayIndexOutOfBoundsException("The offset parameter (" + off + ") is greater than the buffer size (" + b.length + ") !"); } if (len < 0) { throw new ArrayIndexOutOfBoundsException("The length parameter is negative (" + len + ") !"); } else if ((off + len) > b.length) { throw new ArrayIndexOutOfBoundsException("Impossible to read " + len + " bytes from a byte array whose the size is " + b.length + " from the " + off + "-th item !"); } for (int i = 0; i < len; i++) { write(b[off + i]); } } /** * It commits 4 bytes to the underlying stream. * * @throws IOException If an error occurs while writing bytes thanks to the inner output stream. */ private void commit() throws IOException { if (bytecounter > 0) { if (Base64.LINE_LENGTH > 0 && linecounter == Base64.LINE_LENGTH) { out.write(Base64.NEW_LINE.getBytes()); linecounter = 0; } linecounter += 4; out.write(Base64.base64code[(group >> 18) & 0x3f]); out.write(Base64.base64code[(group >> 12) & 0x3f]); out.write((bytecounter < 2) ? Base64.PADDING_CHAR : Base64.base64code[(group >> 6) & 0x3f]); out.write((bytecounter < 3) ? Base64.PADDING_CHAR : Base64.base64code[group & 0x3f]); bytecounter = 0; group = 0; } } /** * ONLY FLUSH THE INNER OUTPUT STREAM ! * * @throws java.io.IOException * @see java.io.FilterOutputStream#flush() */ @Override public void flush() throws IOException { out.flush(); } /** * Decodes and writes last given bytes * and finally flushes and closes the inner output stream. * * @throws java.io.IOException * @see java.io.FilterOutputStream#close() */ @Override public void close() throws IOException { commit(); out.flush(); out.close(); } } libcds-savot-java/src/main/java/cds/savot/binary/Base64InputStream.java0000664000175000017500000002651612724035712025614 0ustar sladensladenpackage cds.savot.binary; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // // SAVOT 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, version 3 of the License. // // SAVOT 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. // // The GNU General Public License is available in COPYING file // along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (LAOG) import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; /** *

A Base64InputStream decodes Base64-encoded bytes read from the given InputStream.

* *

The Base 64 decoding

*
    *
  • The length of Base64-encoded data MUST be a multiple of 4 and MAY end by 1 or 2 padding characters (=).
  • *
  • Encoded data MAY be splitted in lines of 76 characters.
  • *
  • Valid Base64 characters are: A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9,+,/.
  • *
  • Invalid Base64 characters are ignored but a warning message is displayed in the standard error output.
  • *
* *

Buffer

*

* This stream is buffered. That means that several bytes have already been read and decoded from the inner input stream. * By default the buffer size is: 8192. *

*

* Warning ! * To fill the buffer of a Base64InputStream with N bytes, (N/3)*4 bytes must be fetched from the inner input stream. * Indeed, with the Base64 encoding, the number of encoded bytes is always greater than the number of the corresponding decoded bytes: * 3 bytes will be encoded by 4 characters encoded on 6 bits (which allows an alphabet of 2^6=64 characters, hence base64). * Consequently: for a buffer of 8192 bytes, 10924 bytes are needed. *

*

* However the number of bytes stored in the buffer may be less than the size given at the initialization. * That is to say: the buffer can contain AT MOST 8192 decoded bytes. * Indeed some bytes coming from the inner input stream may correspond to invalid Base64 characters. * In this case, they are ignored and so they are not stored in the buffer. *

* *

Warning & Errors

*

A Base64InputStream writes a warning in the standard error output when:

*
    *
  • invalid Base64 characters are encountered before the end of the encoded data
  • *
* *

A Base64InputStream throws an exception when:

*
    *
  • the inner stream ends whereas a group of 4 valid characters/bytes is not complete
  • *
  • valid Base64 characters are encountered after padding characters
  • *
  • more than 2 padding characters are encountered
  • *
* *

Mark & Reset

*

The mark(int) and reset() methods are not supported in a Base64InputStream.

* * @author Gregory Mantelet * @since 09/2011 * * @see Base64 */ public final class Base64InputStream extends FilterInputStream { /** Default buffer size. */ private static int defaultBufferSize = 8192; /** Buffer of decoded data. */ private byte[] buffer; /** The size of the block of encoded data to fetch so that filling the buffer. */ private int fetchSize; /** The position (in the buffer) of the next byte to read. */ private int pos; /** The number of buffered decoded bytes. */ private int count; /** Indicates whether the end of the message has been reached. */ private boolean eom = false; private int pad = 0, group = 0, nbGroupedChars = 0; public Base64InputStream(final InputStream encodedStream) { this(encodedStream, defaultBufferSize); } /** * * @param encodedStream * @param bufferSize */ public Base64InputStream(final InputStream encodedStream, final int bufferSize) { super(encodedStream); if (bufferSize <= 0) { throw new IllegalArgumentException("bufferSize <= 0"); } buffer = new byte[bufferSize]; count = 0; pos = 0; // compute the size of the buffer of encoded data to fetch: (3 decoded bytes => 4 encoded characters/bytes) fetchSize = bufferSize / 3; if (bufferSize % 3 != 0) { fetchSize++; } fetchSize *= 4; } /** * Check to make sure that this stream has not been closed. * * @throws IOException If the stream is closed. */ private void ensureOpen() throws IOException { if (in == null) { throw new IOException("Stream closed"); } } /** *

Fill as completely as possible the buffer.

* *

* Concretely fetchSize bytes are fetched from the input stream. * Then bytes are grouped by 4 so that to be decoded in 3 bytes which are finally written in the buffer. *

* *

Note: * An encoding message is supposed to end with one full group of 4 bytes. * The 2 last bytes of this group may be a padding character (see {@link Base64#PADDING_CHAR}). * If these conditions are not respected, an {@link IOException} is thrown. *

* * @throws IOException If the stream is closed or if the encoded message is corrupted. */ private void fill() throws IOException { count = pos = 0; // Get a block of encoded data: byte[] data = new byte[fetchSize]; int n1 = in.read(data); // Return immediately if EOF: if (n1 == -1) { if (nbGroupedChars > 0) { throw new IOException("Encoded message corrupted: unexpected EOF !"); } else { return; } } // Decode all the fetched data: for (int i = 0; !eom && i < n1; i++) { // If the character is in the Base64 alphabet, add it to the group, else go to the next character: if (Base64.base64decode[data[i]] > -1) { if (pad > 0 && data[i] != Base64.PADDING_CHAR) { throw new IOException("Encoded message corrupted: \"" + ((char) data[i]) + "\" has been encountered after a padding character (\"" + Base64.PADDING_CHAR + "\") !"); } else { group |= ((Base64.base64decode[data[i]] & 0x3f) << (6 * (3 - nbGroupedChars))); nbGroupedChars++; if (data[i] == Base64.PADDING_CHAR) { pad++; } } } else { if (!Character.isWhitespace(data[i])) // only white-spaces are ignored ! { System.err.println("Warning: encoded message may be corrupted: unknown base64 character encountered: \"" + ((char) data[i]) + "\" !"); } } // If 4 characters have been grouped, extract the 3 encoded bytes: if (nbGroupedChars == 4) { if (pad > 0) { eom = true; // padding characters => End Of Message ! } if (pad > 2) { throw new IOException("Encoded message corrupted: a message encoding in base64 can end with at most 2 padding characters (\"" + Base64.PADDING_CHAR + "\") !"); } buffer[count++] = (byte) (group >> 16); if (pad <= 1) { buffer[count++] = (byte) (group >> 8); if (pad <= 0) { buffer[count++] = (byte) group; } } group = 0; nbGroupedChars = 0; } } } @Override public int available() throws IOException { ensureOpen(); return (count - pos) + ((in.available() * 6) / 8); // just an estimation (white spaces, wrong characters and padding are not considered) } @Override public int read() throws IOException { if (pos >= count) { ensureOpen(); fill(); if (pos >= count) { return -1; } } return buffer[pos++] & 0xff; } @Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); } @Override public int read(byte[] b, int off, int len) throws IOException { ensureOpen(); if (b == null) { throw new NullPointerException("The given byte buffer is NULL !"); } if (off < 0) { throw new ArrayIndexOutOfBoundsException("The offset parameter is negative (" + off + ") !"); } else if (off >= b.length) { throw new ArrayIndexOutOfBoundsException("The offset parameter (" + off + ") is greater than the buffer size (" + b.length + ") !"); } if (len == 0) { return 0; } else if (len < 0) { throw new ArrayIndexOutOfBoundsException("The length parameter is negative (" + len + ") !"); } else if ((off + len) > b.length) { throw new ArrayIndexOutOfBoundsException("Impossible to store " + len + " bytes in a byte array whose the size is " + b.length + " from the " + off + "-th item !"); } int nbReadBytes = 0; int avail, remLen, cnt; while (nbReadBytes < len) { if (pos >= count) { fill(); } avail = (count - pos); if (avail <= 0) { return (nbReadBytes == 0) ? -1 : nbReadBytes; } remLen = (len - nbReadBytes); cnt = (remLen < avail) ? remLen : avail; System.arraycopy(buffer, pos, b, (off + nbReadBytes), cnt); nbReadBytes += cnt; pos += cnt; } return nbReadBytes; } @Override public long skip(long n) throws IOException { if (n < 0) { throw new IllegalArgumentException("Number of bytes to skip < 0"); } if (n == 0) { return 0; } long nbSkipped = 0; long nbIteration = n / buffer.length; byte[] skipped = new byte[buffer.length]; int nbRead; for (long i = 0; i < nbIteration; i++) { nbRead = read(skipped); if (nbRead == -1) { return nbSkipped; } nbSkipped += nbRead; } skipped = new byte[(int) (n % buffer.length)]; nbRead = read(skipped); if (nbRead > 0) { nbSkipped += nbRead; } return nbSkipped; } @Override public void close() throws IOException { if (in == null) { return; } in.close(); in = null; buffer = null; pos = count = 0; } /* MARK & RESET NOT SUPPORTED */ @Override public boolean markSupported() { return false; } @Override public synchronized void mark(int readlimit) { } @Override public synchronized void reset() throws IOException { throw new IOException("Mark not supported in a Base64InputStream !"); } } libcds-savot-java/src/main/java/cds/savot/common/0000775000175000017500000000000012724035712021523 5ustar sladensladenlibcds-savot-java/src/main/java/cds/savot/common/Markups.java0000664000175000017500000000774512724035712024025 0ustar sladensladenpackage cds.savot.common; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* VOTable markups and attributes *

* * @author Andre Schaaff */ public interface Markups { // markups final static String SAVOTPARSER = "4.0"; final static String XML = "XML"; final static String VOTABLE = "VOTABLE"; final static String TABLE = "TABLE"; final static String FIELD = "FIELD"; final static String FIELDREF = "FIELDref"; /* new since VOTAble 1.1 */ final static String TABLEDATA = "TABLEDATA"; final static String DESCRIPTION = "DESCRIPTION"; final static String DATA = "DATA"; final static String RESOURCE = "RESOURCE"; final static String PARAM = "PARAM"; final static String PARAMREF = "PARAMref"; /* new since VOTAble 1.1 */ final static String DEFINITIONS = "DEFINITIONS"; final static String LINK = "LINK"; final static String GROUP = "GROUP"; /* new since VOTAble 1.1 */ final static String INFO = "INFO"; final static String TR = "TR"; final static String TD = "TD"; final static String COOSYS = "COOSYS"; final static String SYSTEM = "SYSTEM"; final static String OPTION = "OPTION"; final static String FITS = "FITS"; final static String STREAM = "STREAM"; final static String BINARY = "BINARY"; final static String VALUES = "VALUES"; // attributes final static String ARRAYSIZE = "arraysize"; final static String DATATYPE = "datatype"; final static String EPOCH = "epoch"; final static String EQUINOX = "equinox"; final static String INCLUSIVE = "inclusive"; final static String MAX = "max"; final static String MIN = "min"; final static String NAME = "name"; final static String PRECISION = "precision"; final static String REF = "ref"; final static String TYPE = "type"; final static String XTYPE = "xtype"; // since VOTable 1.2 final static String UTYPE = "utype"; // since VOTable 1.1 final static String UCD = "ucd"; final static String UNIT = "unit"; final static String VALUE = "value"; final static String WIDTH = "width"; final static String ID = "id"; final static String CONTENTROLE = "content-role"; final static String CONTENTTYPE = "content-type"; final static String TITLE = "title"; final static String HREF = "href"; final static String GREF = "gref"; // deprecated since VOTable 1.1 final static String ACTION = "action"; final static String VERSION = "version"; final static String ENCODING = "encoding"; final static String EXTNUM = "extnum"; final static String NULL = "null"; final static String INVALID = "invalid"; final static String ACTUATE = "actuate"; final static String EXPIRES = "expires"; final static String RIGHTS = "rights"; final static String NROWS = "nrows"; // since VOTable 1.1 final static String XMLNS = "xmlns"; final static String XSI = "xsi"; final static String XMLNSXSI = XMLNS + ":" + XSI; final static String XSI_NOSCHEMA = "noNamespaceSchemaLocation"; final static String XSI_SCHEMA = "schemaLocation"; final static String XSINOSCHEMA = XSI + ":" + XSI_NOSCHEMA; final static String XSISCHEMA = XSI + ":" + XSI_SCHEMA; final static String SYSTEM_ATTRIBUTE = "system"; } libcds-savot-java/src/main/java/cds/savot/common/SavotStatistics.java0000664000175000017500000000576612724035712025553 0ustar sladensladenpackage cds.savot.common; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Statistics *

* @author Andre Schaaff * */ public final class SavotStatistics { private int iTablesGlobal = 0; // index of TABLE element private int iTablesLocal = 0; // index of TABLE element in current RESOURCE private int iTRGlobal = 0; // index of TR element private int iTRLocal = 0; // index of TR element in current TABLE private int iTDGlobal = 0; // index of TD element private int iTDLocal = 0; // index of TD element in current TABLE private int iResources = 0; // index of RESOURCES element private int iGroupsGlobal = 0; // index of GROUP element public void iTablesInc() { iTablesGlobal++; iTablesLocal++; } public void iTablesGlobalReset() { iTablesGlobal = 0; } public int getITablesGlobal() { return iTablesGlobal; } public void iTablesLocalReset() { iTablesLocal = 0; } public int getITablesLocal() { return iTablesLocal; } public void iTRInc() { iTRGlobal++; iTRLocal++; } public void iTRGlobalReset() { iTRGlobal = 0; } public int getITRGlobal() { return iTRGlobal; } public void iTRLocalReset() { iTRLocal = 0; } public int getITRLocal() { return iTRLocal; } public void iTDInc() { iTDGlobal++; iTDLocal++; } public void iTDGlobalReset() { iTDGlobal = 0; } public int getITDGlobal() { return iTDGlobal; } public void iTDLocalReset() { iTDLocal = 0; } public int getITDLocal() { return iTDLocal; } public void iResourcesInc() { iResources++; } public void iResourcesReset() { iResources = 0; } public void iResources(final int value) { iResources = value; } public int getIResources() { return iResources; } public void iGroupsGlobalInc() { iGroupsGlobal++; } public void iGroupsGlobalReset() { iGroupsGlobal = 0; } public void iGroupsGlobal(final int value) { iGroupsGlobal = value; } public int getIGroupsGlobal() { return iGroupsGlobal; } } libcds-savot-java/src/main/java/cds/savot/common/VOTableTag.java0000664000175000017500000001342512724035712024323 0ustar sladensladenpackage cds.savot.common; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** * This enum contains all tags present in VOTable specification * @author Laurent Bourges */ public enum VOTableTag { UNDEFINED, BINARY, COOSYS, DATA, DEFINITIONS, DESCRIPTION, FIELD, FIELDREF, FITS, GROUP, INFO, LINK, MIN, MAX, OPTION, PARAM, PARAMREF, RESOURCE, STREAM, SYSTEM, TABLE, TABLEDATA, TD, TR, VALUES, VOTABLE; /** * Return the VoTableTag corresponding to the given string (ignore case) * * LBO: Note: equalsIgnoreCase() vs() equals as XML is case sensitive and VOTable specification says that clearly * * @param name tag name to look up * @return VoTableTag or VoTableTag.UNDEFINED if no match */ public static VOTableTag parseTag(final String name) { switch (name.charAt(0)) { case 'T': case 't': // note: String comparison using == because our kXml parser or Java Stax Parser provides interned strings using SymbolTable: if (Markups.TD == name) { return TD; } if (Markups.TR == name) { return TR; } // standard comparison fallback: if (Markups.TD.equalsIgnoreCase(name)) { return TD; } if (Markups.TR.equalsIgnoreCase(name)) { return TR; } if (Markups.TABLE.equalsIgnoreCase(name)) { return TABLE; } if (Markups.TABLEDATA.equalsIgnoreCase(name)) { return TABLEDATA; } break; case 'F': case 'f': if (Markups.FIELD.equalsIgnoreCase(name)) { return FIELD; } if (Markups.FIELDREF.equalsIgnoreCase(name)) { return FIELDREF; } if (Markups.FITS.equalsIgnoreCase(name)) { return FITS; } break; case 'G': case 'g': if (Markups.GROUP.equalsIgnoreCase(name)) { return GROUP; } break; case 'P': case 'p': if (Markups.PARAM.equalsIgnoreCase(name)) { return PARAM; } if (Markups.PARAMREF.equalsIgnoreCase(name)) { return PARAMREF; } break; case 'I': case 'i': if (Markups.INFO.equalsIgnoreCase(name)) { return INFO; } break; case 'D': case 'd': if (Markups.DESCRIPTION.equalsIgnoreCase(name)) { return DESCRIPTION; } if (Markups.DATA.equalsIgnoreCase(name)) { return DATA; } if (Markups.DEFINITIONS.equalsIgnoreCase(name)) { return DEFINITIONS; } break; case 'B': case 'b': if (Markups.BINARY.equalsIgnoreCase(name)) { return BINARY; } break; case 'C': case 'c': if (Markups.COOSYS.equalsIgnoreCase(name)) { return COOSYS; } break; case 'L': case 'l': if (Markups.LINK.equalsIgnoreCase(name)) { return LINK; } break; case 'M': case 'm': if (Markups.MIN.equalsIgnoreCase(name)) { return MIN; } if (Markups.MAX.equalsIgnoreCase(name)) { return MAX; } break; case 'O': case 'o': if (Markups.OPTION.equalsIgnoreCase(name)) { return OPTION; } break; case 'S': case 's': if (Markups.STREAM.equalsIgnoreCase(name)) { return STREAM; } if (Markups.SYSTEM.equalsIgnoreCase(name)) { return SYSTEM; } break; case 'R': case 'r': if (Markups.RESOURCE.equalsIgnoreCase(name)) { return RESOURCE; } break; case 'V': case 'v': if (Markups.VALUES.equalsIgnoreCase(name)) { return VALUES; } if (Markups.VOTABLE.equalsIgnoreCase(name)) { return VOTABLE; } break; default: } return UNDEFINED; } } libcds-savot-java/src/main/java/cds/savot/sax/0000775000175000017500000000000012724035712021026 5ustar sladensladenlibcds-savot-java/src/main/java/cds/savot/sax/SavotSAXParser.java0000664000175000017500000001225212724035712024520 0ustar sladensladenpackage cds.savot.sax; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.io.IOException; import java.io.InputStream; import java.net.URL; // pull parser import org.kxml2.io.KXmlParser; import org.xmlpull.v1.XmlPullParser; /** *

* It has been tested with kXML parser implementation *

* * @author Andre Schaaff */ @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"}) public final class SavotSAXParser { // the parser engine private SavotSAXEngine engine = null; /** * Constructor * * @param consumer * @param file * a file to parse */ public SavotSAXParser(SavotSAXConsumer consumer, String file) { this(consumer, file, false); } /** * Constructor * * @param consumer * SavotSAXConsumer * @param file * a file to parse * @param debug * boolean */ public SavotSAXParser(SavotSAXConsumer consumer, String file, boolean debug) { try { // new parser XmlPullParser parser = new KXmlParser(); engine = new SavotSAXEngine(consumer, parser, file, debug); // parse the stream // engine.parse(parser); // } catch (IOException e){ // System.err.println("SavotSAXParser : " + e); } catch (Exception f) { System.err.println("SavotSAXParser : " + f); } } /** * Constructor * * @param consumer * SavotSAXConsumer * @param url * url to parse * @param enc * encoding (example : UTF-8) */ public SavotSAXParser(SavotSAXConsumer consumer, URL url, String enc) { this(consumer, url, enc, false); } /** * Constructor * * @param consumer * SavotSAXConsumer * @param url * url to parse * @param enc * encoding (example : UTF-8) * @param debug * boolean */ public SavotSAXParser(SavotSAXConsumer consumer, URL url, String enc, boolean debug) { try { // new parser KXmlParser parser = new KXmlParser(); engine = new SavotSAXEngine(consumer, parser, url, enc, debug); // parse the stream // engine.parse(parser); // } catch (IOException e){ // System.err.println("SavotSAXParser : " + e); } catch (Exception f) { System.err.println("SavotSAXParser : " + f); } } /** * Constructor * * @param consumer * SavotSAXConsumer * @param instream * stream to parse * @param enc * encoding (example : UTF-8) */ public SavotSAXParser(SavotSAXConsumer consumer, InputStream instream, String enc) { this(consumer, instream, enc, false); } /** * Constructor * * @param consumer * SavotSAXConsumer * @param instream * stream to parse * @param enc * encoding (example : UTF-8) * @param debug * boolean */ public SavotSAXParser(SavotSAXConsumer consumer, InputStream instream, String enc, boolean debug) { try { // new parser KXmlParser parser = new KXmlParser(); engine = new SavotSAXEngine(consumer, parser, instream, enc, debug); // parse the stream // engine.parse(parser); // } catch (IOException e){ // System.err.println("SavotSAXParser : " + e); } catch (Exception f) { System.err.println("SavotSAXParser : " + f); } } /** * Get Parser Version * * @return String */ public String getVersion() { return SavotSAXEngine.SAVOTPARSER; } /** * Enable debug mode * * @param debug * boolean */ public void enableDebug(boolean debug) { engine.enableDebug(debug); } /** * Main * * @param argv * @throws IOException */ public static void main(String[] argv) throws IOException { if (argv.length == 0) { System.out.println("Usage: java SavotSAXParser "); } else { // new SavotSAXParser(consumer, argv[0]); } } } libcds-savot-java/src/main/java/cds/savot/sax/SavotSAXConsumer.java0000664000175000017500000001201112724035712025050 0ustar sladensladenpackage cds.savot.sax; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.util.ArrayList; import cds.savot.model.SavotCoosys; import cds.savot.model.SavotField; import cds.savot.model.SavotFieldRef; import cds.savot.model.SavotFits; import cds.savot.model.SavotGroup; import cds.savot.model.SavotInfo; import cds.savot.model.SavotLink; import cds.savot.model.SavotMax; import cds.savot.model.SavotMin; import cds.savot.model.SavotOption; import cds.savot.model.SavotParam; import cds.savot.model.SavotParamRef; import cds.savot.model.SavotResource; import cds.savot.model.SavotStream; import cds.savot.model.SavotTD; import cds.savot.model.SavotTable; import cds.savot.model.SavotVOTable; import cds.savot.model.SavotValues; /** *

* This interface must be implemented to use the Savot SAX parser *

* * @author Andre Schaaff */ @SuppressWarnings("deprecation") public interface SavotSAXConsumer { // start elements public abstract void startVotable(ArrayList attributes); public abstract void startDescription(); public abstract void startResource(ArrayList attributes); public abstract void startTable(ArrayList attributes); public abstract void startField(ArrayList attributes); public abstract void startFieldref(ArrayList attributes); public abstract void startValues(ArrayList attributes); public abstract void startStream(ArrayList attributes); public abstract void startTR(); public abstract void startTD(ArrayList attributes); public abstract void startData(); public abstract void startBinary(); public abstract void startFits(ArrayList attributes); public abstract void startTableData(); public abstract void startParam(ArrayList attributes); public abstract void startParamRef(ArrayList attributes); public abstract void startLink(ArrayList attributes); public abstract void startInfo(ArrayList attributes); public abstract void startMin(ArrayList attributes); public abstract void startMax(ArrayList attributes); public abstract void startOption(ArrayList attributes); public abstract void startGroup(ArrayList attributes); /** * @deprecated since VOTable 1.2 * @param attributes */ public abstract void startCoosys(ArrayList attributes); /** * @deprecated since VOTable 1.1 */ public abstract void startDefinitions(); // end elements public abstract void endVotable(); public abstract void endDescription(); public abstract void endResource(); public abstract void endTable(); public abstract void endField(); public abstract void endFieldref(); public abstract void endValues(); public abstract void endStream(); public abstract void endTR(); public abstract void endTD(); public abstract void endData(); public abstract void endBinary(); public abstract void endFits(); public abstract void endTableData(); public abstract void endParam(); public abstract void endParamRef(); public abstract void endLink(); public abstract void endInfo(); public abstract void endMin(); public abstract void endMax(); public abstract void endOption(); public abstract void endGroup(); /** * @deprecated since VOTable 1.2 */ public abstract void endCoosys(); /** * @deprecated since VOTable 1.1 */ public abstract void endDefinitions(); // TEXT public abstract void textTD(String text); public abstract void textMin(String text); public abstract void textMax(String text); /** * @deprecated since VOTable 1.2 * @param text */ public abstract void textCoosys(String text); public abstract void textLink(String text); public abstract void textOption(String text); public abstract void textGroup(String text); public abstract void textInfo(String text); public abstract void textDescription(String text); public abstract void textStream(String text); // document public abstract void startDocument(); public abstract void endDocument(); } libcds-savot-java/src/main/java/cds/savot/sax/SavotSAXEngine.java0000664000175000017500000017407612724035712024506 0ustar sladensladenpackage cds.savot.sax; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import org.kxml2.io.KXmlParser; import org.xmlpull.v1.XmlPullParser; /** *

* It has been tested with kXML Pull parser implementation *

* * @author Andre Schaaff */ @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"}) public final class SavotSAXEngine implements cds.savot.common.Markups { // use for debug private boolean trace = false; // needed for sequential parsing private XmlPullParser parser = null; // SAVOT SAX consumer SavotSAXConsumer consumer; // father of a markup ArrayList father = new ArrayList(); /** * */ public SavotSAXEngine() { try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } } /** * Constructor * * @param consumer * SavotSAXConsumer * @param parser * XmlPullParser * @param file * a file to parse * @param debug * boolean */ public SavotSAXEngine(SavotSAXConsumer consumer, XmlPullParser parser, String file, boolean debug) { try { this.setParser(parser); this.consumer = consumer; enableDebug(debug); // set the input of the parser FileInputStream inStream = new FileInputStream(new File(file)); BufferedInputStream dataBuffInStream = new BufferedInputStream(inStream); parser.setInput(dataBuffInStream, "UTF-8"); // parse the stream parse(parser); } catch (IOException e) { System.err.println("Exception SavotSAXEngine : " + e); } catch (Exception f) { System.err.println("Exception SavotSAXEngine : " + f); } } /** * Constructor * * @param consumer * SavotSAXConsumer * @param parser * XmlPullParser * @param url * url to parse * @param enc * encoding (example : UTF-8) * @param debug * boolean */ public SavotSAXEngine(SavotSAXConsumer consumer, XmlPullParser parser, URL url, String enc, boolean debug) { try { this.setParser(parser); this.consumer = consumer; enableDebug(debug); // set the input of the parser (with the given encoding) parser.setInput(new DataInputStream(url.openStream()), enc); // parse the stream parse(parser); } catch (IOException e) { System.err.println("Exception SavotSAXEngine : " + e); } catch (Exception f) { System.err.println("Exception SavotSAXEngine : " + f); } } /** * Constructor * * @param consumer * SavotSAXConsumer * @param parser * XmlPullParser * @param instream * stream to parse * @param enc * encoding (example : UTF-8) * @param debug * boolean */ public SavotSAXEngine(SavotSAXConsumer consumer, XmlPullParser parser, InputStream instream, String enc, boolean debug) { // public SavotSAXEngine(XmlPullParser parser, InputStream instream, int // mode, String enc) { try { this.setParser(parser); this.consumer = consumer; enableDebug(debug); // DataInputStream dataInStream = new DataInputStream(instream); BufferedInputStream dataBuffInStream = new BufferedInputStream(instream); // set the input of the parser (with the given encoding) // parser.setInput(new DataInputStream(instream), enc); parser.setInput(dataBuffInStream, enc); // parser the stream parse(parser); } catch (IOException e) { System.err.println("Exception SavotSAXEngine : " + e); } catch (Exception f) { System.err.println("Exception SavotSAXEngine : " + f); } } /** * Parsing engine * * @param parser * an XML pull parser (example : kXML) * * @throws IOException */ @SuppressWarnings({"unchecked", "deprecation"}) public void parse(XmlPullParser parser) throws IOException { String currentMarkup = "XML"; try { // envent type int eventType = parser.getEventType(); father.add((parser.getName())); // while the end of the document is not reach while (eventType != XmlPullParser.END_DOCUMENT) { // treatment depending on event type switch (eventType) { // if a start tag is reach case KXmlParser.START_TAG: try { // the name of the current tag currentMarkup = parser.getName(); father.add((parser.getName())); // trace mode if (trace) { System.err.println("Name ---> " + parser.getName()); } if (currentMarkup != null) { // VOTABLE if (currentMarkup.equalsIgnoreCase(VOTABLE)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, VERSION) != null) { attributes.add(VERSION); attributes.add(parser.getAttributeValue(null, VERSION)); } if (parser.getAttributeValue(null, ID) != null) { attributes.add(ID); attributes.add(parser.getAttributeValue(null, ID)); } consumer.startVotable(attributes); } // trace mode if (trace) { System.err.println("VOTABLE begin"); } } else // DESCRIPTION if (currentMarkup.equalsIgnoreCase(DESCRIPTION)) { consumer.startDescription(); // trace mode if (trace) { System.err.println("DESCRIPTION begin"); } } // RESOURCE else if (currentMarkup.equalsIgnoreCase(RESOURCE)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, NAME) != null) { attributes.add(NAME); attributes.add(parser.getAttributeValue(null, NAME)); } if (parser.getAttributeValue(null, TYPE) != null) { attributes.add(TYPE); attributes.add(parser.getAttributeValue(null, TYPE)); } // new since VOTable 1.1 if (parser.getAttributeValue(null, UTYPE) != null) { attributes.add(UTYPE); attributes.add(parser.getAttributeValue(null, UTYPE)); } if (parser.getAttributeValue(null, ID) != null) { attributes.add(ID); attributes.add(parser.getAttributeValue(null, ID)); } } consumer.startResource(attributes); // trace mode if (trace) { System.err.println("RESOURCE"); } } // TABLE else if (currentMarkup.equalsIgnoreCase(TABLE)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, NAME) != null) { attributes.add(NAME); attributes.add(parser.getAttributeValue(null, NAME)); } // new since VOTable 1.1 if (parser.getAttributeValue(null, UCD) != null) { attributes.add(UCD); attributes.add(parser.getAttributeValue(null, UCD)); } // new since VOTable 1.1 if (parser.getAttributeValue(null, UTYPE) != null) { attributes.add(UTYPE); attributes.add(parser.getAttributeValue(null, UTYPE)); } if (parser.getAttributeValue(null, REF) != null) { attributes.add(REF); attributes.add(parser.getAttributeValue(null, REF)); } if (parser.getAttributeValue(null, ID) != null) { attributes.add(ID); attributes.add(parser.getAttributeValue(null, ID)); } // new since VOTable 1.1 if (parser.getAttributeValue(null, NROWS) != null) { attributes.add(NROWS); attributes.add(parser.getAttributeValue(null, NROWS)); } } consumer.startTable(attributes); // trace mode if (trace) { System.err.println("TABLE begin"); } } // FIELD else if (currentMarkup.equalsIgnoreCase(FIELD)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, UNIT) != null) { attributes.add(UNIT); attributes.add(parser.getAttributeValue(null, UNIT)); } if (parser.getAttributeValue(null, DATATYPE) != null) { attributes.add(DATATYPE); attributes.add(parser.getAttributeValue(null, DATATYPE)); } if (parser.getAttributeValue(null, PRECISION) != null) { attributes.add(PRECISION); attributes.add(parser.getAttributeValue(null, PRECISION)); } if (parser.getAttributeValue(null, WIDTH) != null) { attributes.add(WIDTH); attributes.add(parser.getAttributeValue(null, WIDTH)); } // since VOTable 1.2 if (parser.getAttributeValue(null, XTYPE) != null) { attributes.add(XTYPE); attributes.add(parser.getAttributeValue(null, XTYPE)); } if (parser.getAttributeValue(null, REF) != null) { attributes.add(REF); attributes.add(parser.getAttributeValue(null, REF)); } if (parser.getAttributeValue(null, NAME) != null) { attributes.add(NAME); attributes.add(parser.getAttributeValue(null, NAME)); } if (parser.getAttributeValue(null, UCD) != null) { attributes.add(UCD); attributes.add(parser.getAttributeValue(null, UCD)); } if (parser.getAttributeValue(null, ARRAYSIZE) != null) { attributes.add(ARRAYSIZE); attributes.add(parser.getAttributeValue(null, ARRAYSIZE)); } if (parser.getAttributeValue(null, TYPE) != null) { // deprecated // since // VOTable // 1.1 attributes.add(TYPE); attributes.add(parser.getAttributeValue(null, TYPE)); } if (parser.getAttributeValue(null, UTYPE) != null) { attributes.add(UTYPE); attributes.add(parser.getAttributeValue(null, UTYPE)); } if (parser.getAttributeValue(null, ID) != null) { attributes.add(ID); attributes.add(parser.getAttributeValue(null, ID)); } } consumer.startField(attributes); // trace mode if (trace) { System.err.println("FIELD begin"); } } // FIELDREF else if (currentMarkup.equalsIgnoreCase(FIELDREF)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, REF) != null) { attributes.add(REF); } attributes.add(parser.getAttributeValue(null, REF)); } consumer.startFieldref(attributes); // trace mode if (trace) { System.err.println("FIELDREF begin"); } } // VALUES else if (currentMarkup.equalsIgnoreCase(VALUES)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, TYPE) != null) { attributes.add(TYPE); attributes.add(parser.getAttributeValue(null, TYPE)); } if (parser.getAttributeValue(null, NULL) != null) { attributes.add(NULL); attributes.add(parser.getAttributeValue(null, NULL)); } if (parser.getAttributeValue(null, INVALID) != null) { // deprecated // since // VOTable // 1.1 attributes.add(INVALID); attributes.add(parser.getAttributeValue(null, INVALID)); } if (parser.getAttributeValue(null, REF) != null) { attributes.add(REF); attributes.add(parser.getAttributeValue(null, REF)); } if (parser.getAttributeValue(null, ID) != null) { attributes.add(ID); attributes.add(parser.getAttributeValue(null, ID)); } } consumer.startValues(attributes); // trace mode if (trace) { System.err.println("VALUES begin"); } } // STREAM else if (currentMarkup.equalsIgnoreCase(STREAM)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, TYPE) != null) { attributes.add(TYPE); attributes.add(parser.getAttributeValue(null, TYPE)); } if (parser.getAttributeValue(null, HREF) != null) { attributes.add(HREF); attributes.add(parser.getAttributeValue(null, HREF)); } if (parser.getAttributeValue(null, ACTUATE) != null) { attributes.add(ACTUATE); attributes.add(parser.getAttributeValue(null, ACTUATE)); } if (parser .getAttributeValue(null, ENCODING) != null) { attributes.add(ENCODING); attributes.add(parser.getAttributeValue(null, ENCODING)); } if (parser.getAttributeValue(null, EXPIRES) != null) { attributes.add(EXPIRES); attributes.add(parser.getAttributeValue(null, EXPIRES)); } if (parser.getAttributeValue(null, RIGHTS) != null) { attributes.add(RIGHTS); attributes.add(parser.getAttributeValue(null, RIGHTS)); } } consumer.startStream(attributes); // trace mode if (trace) { System.err.println("STREAM begin"); } } // TR else if (currentMarkup.equalsIgnoreCase(TR)) { consumer.startTR(); // trace mode if (trace) { System.err.println("TR begin"); } } // TD else if (currentMarkup.equalsIgnoreCase(TD)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser .getAttributeValue(null, ENCODING) != null) { attributes.add(ENCODING); attributes.add(parser .getAttributeValue(null, ENCODING)); } } consumer.startTD(attributes); // trace mode if (trace) { System.err.println("TD begin"); } } // DATA else if (currentMarkup.equalsIgnoreCase(DATA)) { consumer.startData(); // trace mode if (trace) { System.err.println("DATA begin"); } } // BINARY else if (currentMarkup.equalsIgnoreCase(BINARY)) { consumer.startBinary(); // trace mode if (trace) { System.err.println("BINARY begin"); } } // FITS else if (currentMarkup.equalsIgnoreCase(FITS)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, EXTNUM) != null) { attributes.add(EXTNUM); attributes.add(parser.getAttributeValue(null, EXTNUM)); } } consumer.startFits(attributes); // trace mode if (trace) { System.err.println("FITS begin"); } } // TABLEDATA else if (currentMarkup.equalsIgnoreCase(TABLEDATA)) { consumer.startTableData(); // trace mode if (trace) { System.err.println("TABLEDATA begin"); } } // PARAM else if (currentMarkup.equalsIgnoreCase(PARAM)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, UNIT) != null) { attributes.add(UNIT); attributes.add(parser.getAttributeValue(null, UNIT)); } if (parser .getAttributeValue(null, DATATYPE) != null) { attributes.add(DATATYPE); attributes.add(parser.getAttributeValue(null, DATATYPE)); } if (parser.getAttributeValue(null, PRECISION) != null) { attributes.add(PRECISION); attributes.add(parser.getAttributeValue(null, PRECISION)); } if (parser.getAttributeValue(null, WIDTH) != null) { attributes.add(WIDTH); attributes.add(parser.getAttributeValue(null, WIDTH)); } // since VOTable 1.2 if (parser.getAttributeValue(null, XTYPE) != null) { attributes.add(XTYPE); attributes.add(parser.getAttributeValue(null, XTYPE)); } if (parser.getAttributeValue(null, REF) != null) { attributes.add(REF); attributes.add(parser.getAttributeValue(null, REF)); } if (parser.getAttributeValue(null, NAME) != null) { attributes.add(NAME); attributes.add(parser.getAttributeValue(null, NAME)); } if (parser.getAttributeValue(null, UCD) != null) { attributes.add(UCD); attributes.add(parser.getAttributeValue(null, UCD)); } if (parser.getAttributeValue(null, UTYPE) != null) { // new // since // VOTable // 1.1 attributes.add(UTYPE); attributes.add(parser.getAttributeValue(null, UTYPE)); } if (parser.getAttributeValue(null, VALUE) != null) { attributes.add(VALUE); attributes.add(parser.getAttributeValue(null, VALUE)); } if (parser.getAttributeValue(null, ARRAYSIZE) != null) { attributes.add(ARRAYSIZE); attributes.add(parser.getAttributeValue(null, ARRAYSIZE)); } if (parser.getAttributeValue(null, ID) != null) { attributes.add(ID); attributes.add(parser.getAttributeValue(null, ID)); } } consumer.startParam(attributes); // trace mode if (trace) { System.err.println("PARAM begin"); } } // PARAMREF else if (currentMarkup.equalsIgnoreCase(PARAMREF)) { // new // since // VOTable // 1.1 ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, REF) != null) { attributes.add(REF); attributes.add(parser.getAttributeValue(null, REF)); } } consumer.startParamRef(attributes); // trace mode if (trace) { System.err.println("PARAMref begin"); } } // LINK else if (currentMarkup.equalsIgnoreCase(LINK)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, CONTENTROLE) != null) { attributes.add(CONTENTROLE); attributes.add(parser.getAttributeValue(null, CONTENTROLE)); } if (parser.getAttributeValue(null, CONTENTTYPE) != null) { attributes.add(CONTENTTYPE); attributes.add(parser.getAttributeValue(null, CONTENTTYPE)); } if (parser.getAttributeValue(null, TITLE) != null) { attributes.add(TITLE); attributes.add(parser.getAttributeValue(null, TITLE)); } if (parser.getAttributeValue(null, VALUE) != null) { attributes.add(VALUE); attributes.add(parser.getAttributeValue(null, VALUE)); } if (parser.getAttributeValue(null, HREF) != null) { attributes.add(HREF); attributes.add(parser.getAttributeValue(null, HREF)); } if (parser.getAttributeValue(null, GREF) != null) { // deprecated // since // VOTable // 1.1 attributes.add(GREF); attributes.add(parser.getAttributeValue(null, GREF)); } if (parser.getAttributeValue(null, ACTION) != null) { attributes.add(ACTION); attributes.add(parser.getAttributeValue(null, ACTION)); } if (parser.getAttributeValue(null, ID) != null) { attributes.add(ID); attributes.add(parser.getAttributeValue(null, ID)); } } consumer.startLink(attributes); if (trace) { System.err.println("LINK begin"); } } // INFO else if (currentMarkup.equalsIgnoreCase(INFO)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, NAME) != null) { attributes.add(NAME); attributes.add(parser.getAttributeValue(null, NAME)); } if (parser.getAttributeValue(null, VALUE) != null) { attributes.add(VALUE); attributes.add(parser.getAttributeValue(null, VALUE)); } if (parser.getAttributeValue(null, ID) != null) { attributes.add(ID); attributes.add(parser.getAttributeValue(null, ID)); } // since VOTable 1.2 if (parser.getAttributeValue(null, XTYPE) != null) { attributes.add(XTYPE); attributes.add(parser.getAttributeValue(null, XTYPE)); } // since VOTable 1.2 if (parser.getAttributeValue(null, REF) != null) { attributes.add(REF); attributes.add(parser.getAttributeValue(null, REF)); } // since VOTable 1.2 if (parser.getAttributeValue(null, UNIT) != null) { attributes.add(UNIT); attributes.add(parser.getAttributeValue(null, UNIT)); } // since VOTable 1.2 if (parser.getAttributeValue(null, UCD) != null) { attributes.add(UCD); attributes.add(parser.getAttributeValue(null, UCD)); } // since VOTable 1.2 if (parser.getAttributeValue(null, UTYPE) != null) { attributes.add(UTYPE); attributes.add(parser.getAttributeValue(null, UTYPE)); } } consumer.startInfo(attributes); if (trace) { System.err.println("INFO begin"); } } // MIN else if (currentMarkup.equalsIgnoreCase(MIN)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, VALUE) != null) { attributes.add(VALUE); attributes.add(parser.getAttributeValue(null, VALUE)); } if (parser.getAttributeValue(null, INCLUSIVE) != null) { attributes.add(INCLUSIVE); attributes.add(parser.getAttributeValue(null, INCLUSIVE)); } } consumer.startMin(attributes); // mode trace if (trace) { System.err.println("MIN begin"); } } // MAX else if (currentMarkup.equalsIgnoreCase(MAX)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, VALUE) != null) { attributes.add(VALUE); attributes.add(parser.getAttributeValue(null, VALUE)); } if (parser.getAttributeValue(null, INCLUSIVE) != null) { attributes.add(INCLUSIVE); attributes.add(parser.getAttributeValue(null, INCLUSIVE)); } } consumer.startMax(attributes); // mode trace if (trace) { System.err.println("MAX begin "); } } // OPTION else if (currentMarkup.equalsIgnoreCase(OPTION)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, NAME) != null) { attributes.add(NAME); attributes.add(parser.getAttributeValue(null, NAME)); } if (parser.getAttributeValue(null, VALUE) != null) { attributes.add(VALUE); attributes.add(parser.getAttributeValue(null, VALUE)); } } consumer.startOption(attributes); // mode trace if (trace) { System.err.println("OPTION begin - not included"); } } // GROUP new 1.1 else if (currentMarkup.equalsIgnoreCase(GROUP)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, REF) != null) { attributes.add(REF); attributes.add(parser.getAttributeValue(null, REF)); } if (parser.getAttributeValue(null, NAME) != null) { attributes.add(NAME); attributes.add(parser.getAttributeValue(null, NAME)); } if (parser.getAttributeValue(null, UCD) != null) { attributes.add(UCD); attributes.add(parser.getAttributeValue(null, UCD)); } if (parser.getAttributeValue(null, UTYPE) != null) { attributes.add(UTYPE); attributes.add(parser.getAttributeValue(null, UTYPE)); } if (parser.getAttributeValue(null, ID) != null) { attributes.add(ID); attributes.add(parser.getAttributeValue(null, ID)); } } consumer.startGroup(attributes); // mode trace if (trace) { System.err.println("GROUP begin - not included"); } } // COOSYS - deprecated since VOTable 1.2 else if (currentMarkup.equalsIgnoreCase(COOSYS)) { ArrayList attributes = new ArrayList(); if (parser.getAttributeCount() != 0) { if (parser.getAttributeValue(null, EQUINOX) != null) { attributes.add(EQUINOX); attributes.add(parser.getAttributeValue(null, EQUINOX)); } if (parser.getAttributeValue(null, EPOCH) != null) { attributes.add(EPOCH); attributes.add(parser.getAttributeValue(null, EPOCH)); } if (parser.getAttributeValue(null, SYSTEM) != null) { attributes.add(SYSTEM); attributes.add(parser.getAttributeValue(null, SYSTEM)); } if (parser.getAttributeValue(null, ID) != null) { attributes.add(ID); attributes.add(parser.getAttributeValue(null, ID)); } } consumer.startCoosys(attributes); // mode trace if (trace) { System.err.println("COOSYS begin"); } } // DEFINITIONS - deprecated since VOTable 1.1 else if (currentMarkup.equalsIgnoreCase(DEFINITIONS)) { consumer.startDefinitions(); // mode trace if (trace) { System.err.println("DEFINITIONS begin"); } } else { System.err.println("VOTable markup error : " + currentMarkup + " at line " + parser.getLineNumber()); } } // currentMarkup = name; } catch (Exception e) { System.err.println("Exception START_TAG : " + e + " at line " + parser.getLineNumber()); } break; // if an end tag is reach case KXmlParser.END_TAG: try { if (trace) { System.err.println("End ---> " + currentMarkup); } // DESCRIPTION if (currentMarkup.equalsIgnoreCase(DESCRIPTION)) { consumer.endDescription(); // trace mode if (trace) { System.err.println("DESCRIPTION"); } } // TABLE else if (currentMarkup.equalsIgnoreCase(TABLE)) { consumer.endTable(); // trace mode if (trace) { System.err.println("TABLE"); } } // FIELD else if (currentMarkup.equalsIgnoreCase(FIELD)) { consumer.endField(); // trace mode if (trace) { System.err.println("FIELD"); } } // FIELDref else if (currentMarkup.equalsIgnoreCase(FIELDREF)) { consumer.endFieldref(); // trace mode if (trace) { System.err.println("FIELDRef"); } } // TR else if (currentMarkup.equalsIgnoreCase(TR)) { consumer.endTR(); // trace mode if (trace) { System.err.println("TR"); } } // DATA else if (currentMarkup.equalsIgnoreCase(DATA)) { consumer.endData(); // trace mode if (trace) { System.err.println("DATA"); } } // TD else if (currentMarkup.equalsIgnoreCase(TD)) { consumer.endTD(); // trace mode if (trace) { System.err.println("TD"); } } // RESOURCE else if (currentMarkup.equalsIgnoreCase(RESOURCE)) { consumer.endResource(); // trace mode if (trace) { System.err.println("RESOURCE"); } } // OPTION else if (currentMarkup.equalsIgnoreCase(OPTION)) { consumer.endOption(); // trace mode if (trace) { System.err.println("OPTION"); } } // GROUP else if (currentMarkup.equalsIgnoreCase(GROUP)) { consumer.endGroup(); // trace mode if (trace) { System.err.println("GROUP"); } } // TABLEDATA else if (currentMarkup.equalsIgnoreCase(TABLEDATA)) { consumer.endTableData(); // trace mode if (trace) { System.err.println("TABLEDATA"); } } // COOSYS - deprecated since VOTable 1.2 else if (currentMarkup.equalsIgnoreCase(COOSYS)) { consumer.endCoosys(); // trace mode if (trace) { System.err.println("COOSYS"); } } // PARAM else if (currentMarkup.equalsIgnoreCase(PARAM)) { consumer.endParam(); // trace mode if (trace) { System.err.println("PARAM"); } } // PARAMREF else if (currentMarkup.equalsIgnoreCase(PARAMREF)) { consumer.endParamRef(); // trace mode if (trace) { System.err.println("PARAMRef"); } } // LINK else if (currentMarkup.equalsIgnoreCase(LINK)) { consumer.endLink(); // trace mode if (trace) { System.err.println("LINK"); } } // VALUES else if (currentMarkup.equalsIgnoreCase(VALUES)) { consumer.endValues(); // trace mode if (trace) { System.err.println("VALUES"); } } // MIN else if (currentMarkup.equalsIgnoreCase(MIN)) { consumer.endMin(); // trace mode if (trace) { System.err.println("MIN"); } } // MAX else if (currentMarkup.equalsIgnoreCase(MAX)) { consumer.endMax(); // trace mode if (trace) { System.err.println("MAX"); } } // STREAM else if (currentMarkup.equalsIgnoreCase(STREAM)) { consumer.endStream(); // trace mode if (trace) { System.err.println("STREAM"); } } // BINARY else if (currentMarkup.equalsIgnoreCase(BINARY)) { consumer.endBinary(); // trace mode if (trace) { System.err.println("BINARY"); } } // FITS else if (currentMarkup.equalsIgnoreCase(FITS)) { consumer.endFits(); // trace mode if (trace) { System.err.println("FITS"); } } // INFO else if (currentMarkup.equalsIgnoreCase(INFO)) { consumer.endInfo(); // trace mode if (trace) { System.err.println("INFO"); } } // DEFINITIONS - deprecated since VOTable 1.1 else if (currentMarkup.equalsIgnoreCase(DEFINITIONS)) { consumer.endDefinitions(); // trace mode if (trace) { System.err.println("DEFINITIONS"); } } // VOTABLE else if (currentMarkup.equalsIgnoreCase(VOTABLE)) { consumer.endVotable(); // trace mode if (trace) { System.err.println("VOTABLE"); } } else { System.err.println("VOTable markup error : " + currentMarkup + " at line " + parser.getLineNumber()); } father.remove(father.size() - 1); currentMarkup = (String) father.get(father.size() - 1); } catch (Exception e) { System.err.println("Exception END_TAG : " + e + " at line " + parser.getLineNumber()); } break; case KXmlParser.END_DOCUMENT: try { consumer.endDocument(); // trace mode if (trace) { System.err.println("Document end reached!"); } } catch (Exception e) { System.err.println("Exception END_DOCUMENT : " + e + " at line " + parser.getLineNumber()); } break; case KXmlParser.TEXT: try { // TD if (currentMarkup.equalsIgnoreCase(TD)) { consumer.textTD((parser.getText()).trim()); // trace mode if (trace) { System.err.println("TD : " + (parser.getText()).trim()); } } // STREAM else if (currentMarkup.equalsIgnoreCase(STREAM)) { consumer.textStream((parser.getText()).trim()); // trace mode if (trace) { System.err.println("STREAM : " + (parser.getText()).trim()); } } // DESCRIPTION else if (currentMarkup.equalsIgnoreCase(DESCRIPTION)) { consumer.textDescription((parser.getText()).trim()); // trace mode if (trace) { System.err.println("DESCRIPTION : " + (parser.getText()).trim()); } } // MIN else if (currentMarkup.equalsIgnoreCase(MIN)) { consumer.textMin((parser.getText()).trim()); // trace mode if (trace) { System.err.println("MIN : " + (parser.getText()).trim()); } } // MAX else if (currentMarkup.equalsIgnoreCase(MAX)) { consumer.textMax((parser.getText()).trim()); // trace mode if (trace) { System.err.println("MAX : " + (parser.getText()).trim()); } } // COOSYS - deprecated since VOTable 1.2 else if (currentMarkup.equalsIgnoreCase(COOSYS)) { consumer.textCoosys((parser.getText()).trim()); // trace mode if (trace) { System.err.println("COOSYS : " + (parser.getText()).trim()); } } // LINK else if (currentMarkup.equalsIgnoreCase(LINK)) { consumer.textLink((parser.getText()).trim()); // trace mode if (trace) { System.err.println("LINK : " + (parser.getText()).trim()); } } // OPTION else if (currentMarkup.equalsIgnoreCase(OPTION)) { consumer.textOption((parser.getText()).trim()); // trace mode if (trace) { System.err.println("OPTION : " + (parser.getText()).trim()); } } // GROUP else if (currentMarkup.equalsIgnoreCase(GROUP)) { consumer.textGroup((parser.getText()).trim()); // trace mode if (trace) { System.err.println("GROUP : " + (parser.getText()).trim()); } } // INFO else if (currentMarkup.equalsIgnoreCase(INFO)) { consumer.textInfo((parser.getText()).trim()); // trace mode if (trace) { System.err.println("INFO : " + (parser.getText()).trim()); } } } catch (Exception e) { System.err.println("Exception TEXT : " + e + " at line " + parser.getLineNumber()); } break; case KXmlParser.START_DOCUMENT: try { consumer.startDocument(); // trace mode if (trace) { System.err.println("Document start reached!"); } } catch (Exception e) { System.err.println("Exception START_DOCUMENT : " + e + " at line " + parser.getLineNumber()); } break; default: if (trace) { System.err.println(" ignoring some other (legacy) event at line : " + parser.getLineNumber()); } } // new values eventType = parser.next(); } } catch (Exception f) { System.err.println("Exception parse : " + f + " at line " + parser.getLineNumber()); } try { consumer.endDocument(); // trace mode if (trace) { System.err.println("Document end reached!"); } } catch (Exception e) { System.err.println("Exception END_DOCUMENT : " + e + " at line " + parser.getLineNumber()); } } /** * Enable debug mode * * @param debug * boolean */ public void enableDebug(boolean debug) { trace = debug; } private void jbInit() throws Exception { } public XmlPullParser getParser() { return parser; } public void setParser(XmlPullParser parser) { this.parser = parser; } } libcds-savot-java/src/main/java/cds/savot/model/0000775000175000017500000000000012724035712021333 5ustar sladensladenlibcds-savot-java/src/main/java/cds/savot/model/FieldSet.java0000664000175000017500000000202612724035712023675 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of Field elements *

* * @author Andre Schaaff * @see SavotSet */ public final class FieldSet extends SavotSet { /** * Constructor */ public FieldSet() { } } libcds-savot-java/src/main/java/cds/savot/model/ResourceSet.java0000664000175000017500000000206312724035712024442 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of Resource elements *

* * @author Andre Schaaff * @see SavotSet */ public final class ResourceSet extends SavotSet { /** * Constructor */ public ResourceSet() { super(); } } libcds-savot-java/src/main/java/cds/savot/model/GroupSet.java0000664000175000017500000000202612724035712023746 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of Group elements *

* * @author Andre Schaaff * @see SavotSet */ public final class GroupSet extends SavotSet { /** * Constructor */ public GroupSet() { } } libcds-savot-java/src/main/java/cds/savot/model/CoosysSet.java0000664000175000017500000000211012724035712024123 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Description: Set of Coosys elements *

* * @author Andre Schaaff * @see SavotSet */ @SuppressWarnings("deprecation") public final class CoosysSet extends SavotSet { /** * Constructor */ public CoosysSet() { } } libcds-savot-java/src/main/java/cds/savot/model/SavotParamRef.java0000664000175000017500000000426512724035712024717 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Reference to Param element *

* * @author Andre Schaaff */ public final class SavotParamRef extends MarkupComment implements RefSupport { // ref attribute private String ref = null; // ucd attribute - since VOTable 1.2 private String ucd = null; // utype attribute - since VOTable 1.2 private String utype = null; /** * Constructor */ public SavotParamRef() { } /** * Set ref attribute * * @param ref */ @Override public void setRef(final String ref) { this.ref = ref; } /** * Get ref attribute * * @return String */ @Override public String getRef() { return str(ref); } /** * Set ucd attribute * * @param ucd * @since VOTable 1.2 */ public void setUcd(final String ucd) { this.ucd = ucd; } /** * Get ucd attribute * * @return String * @since VOTable 1.2 */ public String getUcd() { return str(ucd); } /** * Set utype attribute * * @param utype * @since VOTable 1.2 */ public void setUtype(final String utype) { this.utype = utype; } /** * Get utype attribute * * @return String * @since VOTable 1.2 */ public String getUtype() { return str(utype); } } libcds-savot-java/src/main/java/cds/savot/model/MarkupComment.java0000664000175000017500000000345012724035712024762 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Comments for XML output *

* * @author Andre Schaaff */ public class MarkupComment extends SavotBase { // comments used for VOTable XML document creation private String aboveComment = null; private String belowComment = null; /** * Constructor */ public MarkupComment() { } /** * Set below comment * * @param belowComment */ public final void setBelow(final String belowComment) { this.belowComment = belowComment; } /** * Get below comment * * @return a String */ public final String getBelow() { return str(belowComment); } /** * Set above comment * * @param aboveComment */ public final void setAbove(final String aboveComment) { this.aboveComment = aboveComment; } /** * Get above comment * * @return a String */ public final String getAbove() { return str(aboveComment); } } libcds-savot-java/src/main/java/cds/savot/model/SavotTable.java0000664000175000017500000001501112724035712024240 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Table element *

* * @author Andre Schaaff */ public final class SavotTable extends MarkupComment implements IDSupport, NameSupport, RefSupport { // id attribute private String id = null; // name attribute private String name = null; // ucd attribute private String ucd = null; // utype attribute private String utype = null; // ref attribute private String ref = null; // nrows attribute private String nrows = null; // DESCRIPTION element private String description = null; // FIELD element private FieldSet fields = null; // PARAM element private ParamSet params = null; // GROUP element - since VOTable 1.1 private GroupSet groups = null; // LINK element private LinkSet links = null; // DATA element private SavotData data = null; // INFO element at the end - since VOTable 1.2 private InfoSet infosAtEnd = null; /** * Constructor */ public SavotTable() { } /** * Set ID attribute * * @param id */ @Override public void setId(final String id) { this.id = id; } /** * Get ID attribute * * @return a String */ @Override public String getId() { return str(id); } /** * Set name attribute * * @param name */ @Override public void setName(final String name) { this.name = name; } /** * Get name attribute * * @return a String */ @Override public String getName() { return str(name); } /** * Set ucd attribute * * @param ucd */ public void setUcd(final String ucd) { this.ucd = ucd; } /** * Get ucd attribute * * @return a String */ public String getUcd() { return str(ucd); } /** * Set utype attribute * * @param utype */ public void setUtype(final String utype) { this.utype = utype; } /** * Get utype attribute * * @return a String */ public String getUtype() { return str(utype); } /** * Set ref attribute * * @param ref */ @Override public void setRef(final String ref) { this.ref = ref; } /** * Get ref attribute * * @return a String */ @Override public String getRef() { return str(ref); } /** * Set nrows attribute * * @param nrows */ public void setNrows(final String nrows) { this.nrows = nrows; } /** * Set nrows attribute * * @param nrows */ public void setNrowsValue(final int nrows) { this.nrows = toStr(nrows); } /** * Get nrows attribute * * @return a String */ public String getNrows() { return str(nrows); } /** * Get nrows attribute * * @return an int */ public int getNrowsValue() { return integer(nrows); } /** * Set DESCRIPTION content * * @param description */ public void setDescription(final String description) { this.description = description; } /** * Get DESCRIPTION content * * @return a String */ public String getDescription() { return str(description); } /** * Get FIELD element set reference * * @return FieldSet */ public FieldSet getFields() { if (fields == null) { fields = new FieldSet(); } return fields; } /** * Set FIELD element set reference * * @param fields */ public void setFields(final FieldSet fields) { this.fields = fields; } /** * Get PARAM element set reference * * @return ParamSet */ public ParamSet getParams() { if (params == null) { params = new ParamSet(); } return params; } /** * Set PARAM element set reference * * @param params */ public void setParams(final ParamSet params) { this.params = params; } /** * Get GROUP element set reference * * @since VOTable 1.1 * @return GroupSet */ public GroupSet getGroups() { if (groups == null) { groups = new GroupSet(); } return groups; } /** * Set GROUP element set reference * * @since VOTable 1.1 * @param groups */ public void setGroups(final GroupSet groups) { this.groups = groups; } /** * Get LINK element set reference * * @return LinkSet */ public LinkSet getLinks() { if (links == null) { links = new LinkSet(); } return links; } /** * Set LINK element set reference * * @param links */ public void setLinks(final LinkSet links) { this.links = links; } /** * Set DATA element * * @param data */ public void setData(final SavotData data) { this.data = data; } /** * Get DATA element * * @return SavotData */ public SavotData getData() { return data; } /** * Set the InfosAtEnd elements * * @param infosAtEnd * @since VOTable 1.2 */ public void setInfosAtEnd(final InfoSet infosAtEnd) { this.infosAtEnd = infosAtEnd; } /** * Get the InfosAtEnd elements * * @return an InfoSet object * @since VOTable 1.2 */ public InfoSet getInfosAtEnd() { if (infosAtEnd == null) { infosAtEnd = new InfoSet(); } return infosAtEnd; } } libcds-savot-java/src/main/java/cds/savot/model/SavotField.java0000664000175000017500000001621112724035712024237 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Field element *

* * @author Andre Schaaff */ public final class SavotField extends MarkupComment implements IDSupport, NameSupport, RefSupport { // ID attribute private String id = null; // unit attribute private String unit = null; // datatype attribute private String datatype = null; // precision attribute private String precision = null; // width attribute private String width = null; // xtype attribute @since 1.2 private String xtype = null; // ref attribute private String ref = null; // name attribute private String name = null; // ucd attribute private String ucd = null; // utype attribute private String utype = null; // arraysize attribute private String arraysize = null; // type attribute - extension since 1.1 private String type = null; // DESCRIPTION element private String description = null; // VALUES element private SavotValues values = null; // LINK elements private LinkSet links = null; /** * Constructor */ public SavotField() { } /** * Set ID attribute * * @param id */ @Override public void setId(final String id) { this.id = id; } /** * Get id attribute * * @return String */ @Override public String getId() { return str(id); } /** * Get unit attribute * * @return String */ public String getUnit() { return str(unit); } /** * Set unit attribute * * @param unit */ public void setUnit(final String unit) { this.unit = unit; } /** * Get datatype attribute * * @return String */ public String getDataType() { return str(datatype); } /** * Set datatype attribute * * @param datatype * (boolean, bit, unsignedByte, short, int, long, char, * unicodeChar, float, double, floatComplex, doubleComplex) */ public void setDataType(final String datatype) { this.datatype = datatype; } /** * Set name attribute * * @param name */ @Override public void setName(final String name) { this.name = name; } /** * Get name attribute * * @return String */ @Override public String getName() { return str(name); } /** * Set ucd attribute * * @param ucd * ([A-Za-z0-9_.,-]*) */ public void setUcd(final String ucd) { this.ucd = ucd; } /** * Get ucd attribute * * @return String */ public String getUcd() { return str(ucd); } /** * Set ref attribute * * @param ref */ @Override public void setRef(final String ref) { this.ref = ref; } /** * Get ref attribute * * @return String */ @Override public String getRef() { return str(ref); } /** * Set precision attribute * * @param precision * ([EF]?[1-0][0-9]*) */ public void setPrecision(final String precision) { this.precision = precision; } /** * Get precision attribute * * @return String */ public String getPrecision() { return str(precision); } /** * Set width attribute * * @param width */ public void setWidth(final String width) { this.width = width; } /** * Get width attribute * * @return String */ public String getWidth() { return str(width); } /** * Set width attribute * * @param width */ public void setWidthValue(final int width) { this.width = toStr(width); } /** * Get width attribute * * @return String */ public int getWidthValue() { return integer(width); } /** * Set xtype attribute * * @since VOTable 1.2 * @param xtype */ public void setXtype(final String xtype) { this.xtype = xtype; } /** * Get xtype attribute * * @since VOTable 1.2 * @return String */ public String getXtype() { return str(xtype); } /** * Set arraysize attribute * * @param arraysize */ public void setArraySize(final String arraysize) { this.arraysize = arraysize; } /** * Get arraysize attribute * * @return String */ public String getArraySize() { return str(arraysize); } /** * Set type attribute * * @param type * (hidden, no_query, trigger, location) warning : deprecated in * VOTable 1.1 */ public void setType(final String type) { this.type = type; } /** * Get type attribute * * @return String warning : deprecated in VOTable 1.1 */ public String getType() { return str(type); } /** * Set utype attribute * * @param utype */ public void setUtype(final String utype) { this.utype = utype; } /** * Get utype attribute * * @return String */ public String getUtype() { return str(utype); } /** * Set DESCRIPTION content * * @param description */ public void setDescription(final String description) { this.description = description; } /** * Get DESCRIPTION content * * @return String */ public String getDescription() { return str(description); } /** * Set the VALUES element * * @param values */ public void setValues(final SavotValues values) { this.values = values; } /** * Get the VALUES element * * @return SavotValues */ public SavotValues getValues() { return values; } /** * Get LINK elements set reference * * @return LinkSet */ public LinkSet getLinks() { if (links == null) { links = new LinkSet(); } return links; } /** * Set LINK elements set reference * * @param links */ public void setLinks(final LinkSet links) { this.links = links; } } libcds-savot-java/src/main/java/cds/savot/model/SavotResource.java0000664000175000017500000002277712724035712025021 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Resource element *

* * @author Andre Schaaff */ public final class SavotResource extends MarkupComment implements IDSupport, NameSupport { // name attribute private String name = null; // id attribute private String id = null; // type attribute (results, meta) private String type = "results"; // default // utype attribute private String utype = null; // DESCRIPTION element private String description = null; // COOSYS element set - deprecated since 1.2 private CoosysSet coosys = null; // GROUP element set - since VOTable 1.2 private GroupSet groups = null; // PARAM element set private ParamSet params = null; // INFO element set private InfoSet infos = null; // LINK element set private LinkSet links = null; // TABLE element set private TableSet tables = null; // RESOURCE element set (recursive usage) private ResourceSet resources = null; // INFO (at End) element set - since VOTable 1.2 private InfoSet infosAtEnd = null; /** * Constructor */ public SavotResource() { } /** * init a SavotResource object */ public void init() { name = null; id = null; type = null; utype = null; description = null; coosys = null; groups = null; params = null; infos = null; links = null; tables = null; resources = null; infosAtEnd = null; } /** * Set the description * * @param description * String */ public void setDescription(final String description) { this.description = description; } /** * Get the description * * @return a String */ public String getDescription() { return str(description); } /** * Set the Coosys elements * * @deprecated since VOTable 1.2 * @param coosys */ public void setCoosys(final CoosysSet coosys) { this.coosys = coosys; } /** * Get the Coosys elements * * @deprecated since VOTable 1.2 * @return a CoosysSet object */ public CoosysSet getCoosys() { if (coosys == null) { coosys = new CoosysSet(); } return coosys; } /** * Set GROUP element set reference * * @since VOTable 1.2 * @param groups */ public void setGroups(final GroupSet groups) { this.groups = groups; } /** * Get GROUP element set reference * * @since VOTable 1.2 * @return GroupSet */ public GroupSet getGroups() { if (groups == null) { groups = new GroupSet(); } return groups; } /** * Set the Infos elements * * @param infos */ public void setInfos(final InfoSet infos) { this.infos = infos; } /** * Get the Infos elements * * @return a InfoSet object */ public InfoSet getInfos() { if (infos == null) { infos = new InfoSet(); } return infos; } /** * Set the Param elements * * @param params */ public void setParams(final ParamSet params) { this.params = params; } /** * Get the Param elements * * @return a ParamSet object */ public ParamSet getParams() { if (params == null) { params = new ParamSet(); } return params; } /** * Set the Link elements * * @param links */ public void setLinks(final LinkSet links) { this.links = links; } /** * Get the Link elements * * @return a LinkSet object */ public LinkSet getLinks() { if (links == null) { links = new LinkSet(); } return links; } /** * Set the Table elements * * @param tables */ public void setTables(final TableSet tables) { this.tables = tables; } /** * Get the Table elements * * @return a TableSet object */ public TableSet getTables() { if (tables == null) { tables = new TableSet(); } return tables; } /** * Set the Resource elements * * @param resources */ public void setResources(final ResourceSet resources) { this.resources = resources; } /** * Get the Resource elements * * @return a ResourceSet object */ public ResourceSet getResources() { if (resources == null) { resources = new ResourceSet(); } return resources; } /** * Set the InfosAtEnd elements * * @param infosAtEnd * @since VOTable 1.2 */ public void setInfosAtEnd(final InfoSet infosAtEnd) { this.infosAtEnd = infosAtEnd; } /** * Get the InfosAtEnd elements * * @return a InfoSet object * @since VOTable 1.2 */ public InfoSet getInfosAtEnd() { if (infosAtEnd == null) { infosAtEnd = new InfoSet(); } return infosAtEnd; } /** * Set the name attribute * * @param name * String */ @Override public void setName(final String name) { this.name = name; } /** * Get the name attribute * * @return a String */ @Override public String getName() { return str(name); } /** * Set the id attribute * * @param id * String */ @Override public void setId(final String id) { this.id = id; } /** * Get the id attribute * * @return String */ @Override public String getId() { return str(id); } /** * Set the type attribute * * @param type * String (results, meta) */ public void setType(final String type) { this.type = type; } /** * Get the type attribute * * @return a String */ public String getType() { return str(type); } /** * Set the utype attribute * * @param utype * String */ public void setUtype(final String utype) { this.utype = utype; } /** * Get the utype attribute * * @return a String */ public String getUtype() { return str(utype); } /** * Get the number of TR object for table index tableIndex (shortcut) * * @param tableIndex * @return int */ public int getTRCount(final int tableIndex) { return getTables().getItemAt(tableIndex).getData().getTableData().getTRs().getItemCount(); } /** * Get a TRSet object for table index tableIndex (shortcut) * * @param tableIndex * @return TRSet */ public TRSet getTRSet(final int tableIndex) { return getTables().getItemAt(tableIndex).getData().getTableData().getTRs(); } /** * Get a TR object for table index tableIndex and the corresponding row * index rowIndex of this table (shortcut) * * @param tableIndex * @param rowIndex * @return SavotTR */ public SavotTR getTR(final int tableIndex, final int rowIndex) { return getTables().getItemAt(tableIndex).getData().getTableData().getTRs().getItemAt(rowIndex); } /** * Return the number of tables contained in the resource this value doesn't * contain the tables of included resources (shortcut) * * @return int */ public int getTableCount() { return getTables().getItemCount(); } /** * Get a FieldSet object for table index tableIndex (shortcut) * * @param tableIndex * @return FieldSet */ public FieldSet getFieldSet(final int tableIndex) { return getTables().getItemAt(tableIndex).getFields(); } /** * Get a LinkSet object for table index tableIndex (shortcut) * * @param tableIndex * @return LinkSet */ public LinkSet getLinkSet(final int tableIndex) { return getTables().getItemAt(tableIndex).getLinks(); } /** * Get a Description object (String) for table index tableIndex (shortcut) * * @param tableIndex * @return String */ public String getDescription(final int tableIndex) { return getTables().getItemAt(tableIndex).getDescription(); } /** * Get a SavotData object for table index tableIndex (shortcut) * * @param tableIndex * @return SavotData */ public SavotData getData(final int tableIndex) { return getTables().getItemAt(tableIndex).getData(); } } libcds-savot-java/src/main/java/cds/savot/model/TRSet.java0000664000175000017500000000250212724035712023176 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of TR elements *

* * @author Andre Schaaff * @see SavotSet */ public final class TRSet extends SavotSet { /** * Constructor */ public TRSet() { } /** * Get a TDSet object at the TRIndex position of the TRSet * * @param TRIndex * @return TDSet */ public TDSet getTDSet(final int TRIndex) { if (this.getItemCount() != 0) { return getItemAt(TRIndex).getTDSet(); } return new TDSet(); } } libcds-savot-java/src/main/java/cds/savot/model/SavotStream.java0000664000175000017500000000715612724035712024457 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Stream element *

* * @author Andre Schaaff */ public final class SavotStream extends MarkupComment { // content private String content = null; // type attribute (locator, other) private String type = "locator"; // default // href attribute private String href = null; // actuate attribute private String actuate = null; // width encoding private String encoding = null; // expires attribute private String expires = null; // rights attribute private String rights = null; /** * Constructor */ public SavotStream() { } /** * Set type attribute * * @param type * (locator, other) */ public void setType(final String type) { this.type = type; } /** * Get type attribute * * @return String */ public String getType() { return str(type); } /** * Set href attribute * * @param href * (URI) */ public void setHref(final String href) { this.href = href; } /** * Get href attribute * * @return String */ public String getHref() { return str(href); } /** * Set actuate attribute * * @param actuate * (onLoad, onRequest, other, none) */ public void setActuate(final String actuate) { this.actuate = actuate; } /** * Get actuate attribute * * @return String */ public String getActuate() { return str(actuate); } /** * Set encoding attribute * * @param encoding * (gzip, base64, dynamic, none) */ public void setEncoding(final String encoding) { this.encoding = encoding; } /** * Get encoding attribute * * @return String */ public String getEncoding() { return str(encoding); } /** * Set expires attribute * * @param expires */ public void setExpires(final String expires) { this.expires = expires; } /** * Get width attribute * * @return String */ public String getExpires() { return str(expires); } /** * Set rights attribute * * @param rights */ public void setRights(final String rights) { this.rights = rights; } /** * Get rights attribute * * @return String */ public String getRights() { return str(rights); } /** * Set content * * @param content */ public void setContent(final String content) { this.content = content; } /** * Get content * * @return String */ public String getContent() { return str(content); } } libcds-savot-java/src/main/java/cds/savot/model/SavotGroup.java0000664000175000017500000001212412724035712024307 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Group element *

* * @author Andre Schaaff */ public final class SavotGroup extends MarkupComment implements IDSupport, NameSupport, RefSupport { // ID attribute private String id = null; // name attribute private String name = null; // ref attribute private String ref = null; // ucd attribute private String ucd = null; // utype attribute private String utype = null; // description element private String description = null; // FIELDRef elements private FieldRefSet fieldsref = null; // PARAM elements private ParamSet params = null; // PARAMRef elements private ParamRefSet paramsref = null; // GROUP elements private GroupSet groups = null; /** * Constructor */ public SavotGroup() { } /** * Set ID attribute * * @param id */ @Override public void setId(final String id) { this.id = id; } /** * Get id attribute * * @return String */ @Override public String getId() { return str(id); } /** * Set name attribute * * @param name */ @Override public void setName(final String name) { this.name = name; } /** * Get name attribute * * @return String */ @Override public String getName() { return str(name); } /** * Set ref attribute * * @param ref */ @Override public void setRef(final String ref) { this.ref = ref; } /** * Get ref attribute * * @return String */ @Override public String getRef() { return str(ref); } /** * Set ucd attribute * * @param ucd * ([A-Za-z0-9_.,-]*) */ public void setUcd(final String ucd) { this.ucd = ucd; } /** * Get ucd attribute * * @return String */ public String getUcd() { return str(ucd); } /** * Set utype attribute * * @param utype */ public void setUtype(final String utype) { this.utype = utype; } /** * Get utype attribute * * @return String */ public String getUtype() { return str(utype); } /** * Set DESCRIPTION element content * * @param description */ public void setDescription(final String description) { this.description = description; } /** * Get DESCRIPTION element content * * @return String */ public String getDescription() { return str(description); } /** * Get PARAM elements set reference * * @return ParamSet */ public ParamSet getParams() { if (params == null) { params = new ParamSet(); } return params; } /** * Set PARAM elements set reference * * @param params */ public void setParams(final ParamSet params) { this.params = params; } /** * Set PARAMref elements set reference * * @param paramsref */ public void setParamsRef(final ParamRefSet paramsref) { this.paramsref = paramsref; } /** * Get PARAMref elements set reference * * @return ParamRefSet */ public ParamRefSet getParamsRef() { if (paramsref == null) { paramsref = new ParamRefSet(); } return paramsref; } /** * Get FIELDref elements set reference * * @return FieldRefSet */ public FieldRefSet getFieldsRef() { if (fieldsref == null) { fieldsref = new FieldRefSet(); } return fieldsref; } /** * Set FIELDref elements set reference * * @param fieldsref */ public void setFieldsRef(final FieldRefSet fieldsref) { this.fieldsref = fieldsref; } /** * Get GROUP elements set reference * * @return GroupSet */ public GroupSet getGroups() { if (groups == null) { groups = new GroupSet(); } return groups; } /** * Set GROUP elements set reference * * @param groups */ public void setGroups(final GroupSet groups) { this.groups = groups; } } libcds-savot-java/src/main/java/cds/savot/model/OptionSet.java0000664000175000017500000000205312724035712024122 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of Option elements *

* * @author Andre Schaaff * @see SavotSet */ public final class OptionSet extends SavotSet { /** * Constructor */ public OptionSet() { super(); } } libcds-savot-java/src/main/java/cds/savot/model/SavotFits.java0000664000175000017500000000334412724035712024124 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Fits element *

* * @author Andre Schaaff */ public final class SavotFits extends MarkupComment { // extnum attribute private String extnum = null; // STREAM element private SavotStream stream = null; /** * Constructor */ public SavotFits() { } /** * Set the extnum * * @param extnum * String */ public void setExtnum(final String extnum) { this.extnum = extnum; } /** * Get the extnum * * @return a String */ public String getExtnum() { return str(extnum); } /** * Set the STREAM element * * @param stream */ public void setStream(final SavotStream stream) { this.stream = stream; } /** * Get the STREAM element * * @return SavotStream */ public SavotStream getStream() { return stream; } } libcds-savot-java/src/main/java/cds/savot/model/SavotTD.java0000664000175000017500000000325612724035712023530 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* A data (of a row) *

* * @author Andre Schaaff * @see SavotSet */ public final class SavotTD extends SavotBase { // TD content private String content = null; /** * Constructor */ public SavotTD() { } /** * Constructor with content * @param content */ public SavotTD(final String content) { this.content = content; } /** * Set element content * * @param content */ public void setContent(final String content) { this.content = content; } /** * Get element content * * @return a String */ public String getContent() { return str(content); } /** * Get the raw content value (maybe null) * * @return a String or null */ public String getRawContent() { return content; } } libcds-savot-java/src/main/java/cds/savot/model/Boundary.java0000664000175000017500000000422512724035712023764 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* For min and max *

* * @author Andre Schaaff */ public class Boundary extends MarkupComment { // value attribute private String value = null; // inclusive attribute private String inclusive = "yes"; // MIN, MAX, ... element content private String content = null; /** * Constructor */ public Boundary() { } /** * Set value attribute * * @param value */ public final void setValue(final String value) { this.value = value; } /** * Get value attribute * * @return a String */ public final String getValue() { return str(value); } /** * Set inclusive attribute * * @param inclusive * (yes, no) */ public final void setInclusive(final String inclusive) { this.inclusive = inclusive; } /** * Get inclusive attribute * * @return a String */ public final String getInclusive() { return str(inclusive); } /** * Set element content * * @param content */ public final void setContent(final String content) { this.content = content; } /** * Get element content * * @return a String */ public final String getContent() { return str(content); } } libcds-savot-java/src/main/java/cds/savot/model/SavotSet.java0000664000175000017500000000666612724035712023764 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.util.ArrayList; import java.util.List; /** *

* Generic class for other set classes *

* * @param element type * @author Andre Schaaff * @see SavotSet */ public class SavotSet { /** storage of the set elements */ private ArrayList set = null; /** * Constructor */ public SavotSet() { } /** * Add an item to the set * * @param item */ public final void addItem(final E item) { if (set == null) { set = new ArrayList(); } set.add(item); } /** * Get an item at a given position (index) * * @param index * @return Object */ public final E getItemAt(final int index) { if (set == null) { return null; } if (index >= 0 && index < set.size()) { return set.get(index); } return null; } /** * Remove an item at a given position (index) * * @param index */ public final void removeItemAt(final int index) { if (set != null && index >= 0 && index < set.size()) { set.remove(index); } } /** * Remove all items */ public final void removeAllItems() { if (set != null && !set.isEmpty()) { set.clear(); } } /** * Set the whole set to a given set * * @param set */ public final void setItems(final ArrayList set) { this.set = set; } /** * Get the whole set * * @return a ArrayList */ public final List getItems() { return set; } /** * Get the number of items * * @return int */ public final int getItemCount() { if (set != null) { return set.size(); } return 0; } /** * Increases the capacity of this SavotSet instance, if * necessary, to ensure that it can hold at least the number of elements * specified by the minimum capacity argument. * * @param minCapacity the desired minimum capacity */ public final void ensureCapacity(final int minCapacity) { if (set == null) { set = new ArrayList(minCapacity); } else { set.ensureCapacity(minCapacity); } } /** * Trims the capacity of this SavotSet instance to be the * list's current size. An application can use this operation to minimize * the storage of an SavotSet instance. */ public final void trim() { if (set != null) { set.trimToSize(); } } } libcds-savot-java/src/main/java/cds/savot/model/IDSupport.java0000664000175000017500000000221212724035712024064 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** * This interface defines id attribute handling (get / set) * @author Laurent Bourges (JMMC) */ public interface IDSupport { /** * Set ID attribute * * @param id */ public void setId(final String id); /** * Get ID attribute * * @return String */ public String getId(); } libcds-savot-java/src/main/java/cds/savot/model/NameSupport.java0000664000175000017500000000223212724035712024452 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** * This interface defines name attribute handling (get / set) * @author Laurent Bourges (JMMC) */ public interface NameSupport { /** * Set name attribute * * @param name */ public void setName(final String name); /** * Get name attribute * * @return String */ public String getName(); } libcds-savot-java/src/main/java/cds/savot/model/SavotCoosys.java0000664000175000017500000000624112724035712024475 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Coosys element *

* * @author Andre Schaaff * @deprecated since 1.2 */ public final class SavotCoosys extends MarkupComment implements IDSupport { // ID attribute private String id = null; // equinox attribute private String equinox = null; // epoch attribute private String epoch = null; // system attribute eq_FK4, eq_FK5, ICRS, ecl_FK4, ecl_FK5, galactic, // supergalactic, xy, barycentric, geo_app private String system = "eq_FK5"; // default // element content private String content = null; /** * Constructor */ public SavotCoosys() { } /** * Set the id attribute * * @param id */ @Override public void setId(final String id) { this.id = id; } /** * Get the id attribute value * * @return String */ @Override public String getId() { return str(id); } /** * Set the equinox attribute * * @param equinox * ([JB]?[0-9]+([.][0-9]*)?) */ public void setEquinox(final String equinox) { this.equinox = equinox; } /** * Get the equinox attribute value * * @return String */ public String getEquinox() { return str(equinox); } /** * Set the epoch attribute * * @param epoch * ([JB]?[0-9]+([.][0-9]*)?) */ public void setEpoch(final String epoch) { this.epoch = epoch; } /** * Get the epoch attribute value * * @return String */ public String getEpoch() { return str(epoch); } /** * Set the system attribute * * @param system * (eq_FK4, eq_FK5, ICRS, ecl_FK4, ecl_FK5, galactic, * supergalactic, xy, barycentric, geo_app) */ public void setSystem(final String system) { this.system = system; } /** * Get the system attribute value * * @return String */ public String getSystem() { return str(system); } /** * Set element content * * @param content */ public void setContent(final String content) { this.content = content; } /** * Get element content * * @return a String */ public String getContent() { return str(content); } } libcds-savot-java/src/main/java/cds/savot/model/SavotParam.java0000664000175000017500000001602212724035712024254 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Param element *

* * @author Andre Schaaff */ public final class SavotParam extends MarkupComment implements IDSupport, NameSupport, RefSupport { // ID attribute private String id = null; // unit attribute private String unit = null; // datatype attribute private String datatype = null; // precision attribute private String precision = null; // width attribute private String width = null; // xtype attribute @since 1.2 private String xtype = null; // ref attribute private String ref = null; // name attribute private String name = null; // ucd attribute private String ucd = null; // utype attribute private String utype = null; // arraysize attribute private String arraysize = null; // value attribute private String value = null; // DESCRIPTION element private String description = null; // VALUES element private SavotValues values = null; // LINK element private LinkSet links = null; /** * Constructor */ public SavotParam() { } /** * Set ID attribute * * @param id */ @Override public void setId(final String id) { this.id = id; } /** * Get id attribute * * @return String */ @Override public String getId() { return str(id); } /** * Set unit attribute * * @param unit */ public void setUnit(final String unit) { this.unit = unit; } /** * Get unit attribute * * @return String */ public String getUnit() { return str(unit); } /** * Set datatype attribute * * @param datatype * (boolean, bit, unsignedByte, short, int, long, char, * unicodeChar, float, double, floatComplex, doubleComplex) */ public void setDataType(final String datatype) { this.datatype = datatype; } /** * Get datatype attribute * * @return String */ public String getDataType() { return str(datatype); } /** * Set precision attribute * * @param precision * ([EF]?[1-0][0-9]*) */ public void setPrecision(final String precision) { this.precision = precision; } /** * Get precision attribute * * @return String */ public String getPrecision() { return str(precision); } /** * Set width attribute * * @param width */ public void setWidth(final String width) { this.width = width; } /** * Set width attribute * * @param width */ public void setWidthValue(final int width) { this.width = toStr(width); } /** * Get width attribute * * @return String */ public String getWidth() { return str(width); } /** * Get width attribute * * @return String */ public int getWidthValue() { return integer(width); } /** * Set xtype attribute * * @since VOTable 1.2 * @param xtype */ public void setXtype(final String xtype) { this.xtype = xtype; } /** * Get xtype attribute * * @since VOTable 1.2 * @return String */ public String getXtype() { return str(xtype); } /** * Set ref attribute * * @param ref */ @Override public void setRef(final String ref) { this.ref = ref; } /** * Get ref attribute * * @return String */ @Override public String getRef() { return str(ref); } /** * Set name attribute * * @param name */ @Override public void setName(final String name) { this.name = name; } /** * Get name attribute * * @return String */ @Override public String getName() { return str(name); } /** * Set ucd attribute * * @param ucd * ([A-Za-z0-9_.,-]*) */ public void setUcd(final String ucd) { this.ucd = ucd; } /** * Get ucd attribute * * @return String */ public String getUcd() { return str(ucd); } /** * Set utype attribute * * @param utype */ public void setUtype(final String utype) { this.utype = utype; } /** * Get utype attribute * * @return String */ public String getUtype() { return str(utype); } /** * Set value attribute * * @param value */ public void setValue(final String value) { this.value = value; } /** * Get value attribute * * @return String */ public String getValue() { return str(value); } /** * Set arraysize attribute * * @param arraysize * (([0-9]+x)*[0-9]*[*]?(s\W)?) */ public void setArraySize(final String arraysize) { this.arraysize = arraysize; } /** * Get arraysize attribute * * @return String */ public String getArraySize() { return str(arraysize); } /** * Set DESCRIPTION content * * @param description */ public void setDescription(final String description) { this.description = description; } /** * Get DESCRIPTION content * * @return String */ public String getDescription() { return str(description); } /** * Set VALUES element * * @param values */ public void setValues(final SavotValues values) { this.values = values; } /** * Get VALUES element * * @return a SavotValues object */ public SavotValues getValues() { return values; } /** * Get Link set reference * * @return a set of LINK elements */ public LinkSet getLinks() { if (links == null) { links = new LinkSet(); } return links; } /** * Set Link set reference * * @param links */ public void setLinks(LinkSet links) { this.links = links; } } libcds-savot-java/src/main/java/cds/savot/model/SavotData.java0000664000175000017500000000415412724035712024070 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Data element *

* * @author Andre Schaaff */ public final class SavotData extends MarkupComment { // TABLEDATA element private SavotTableData tableData = null; // BINARY element private SavotBinary binary = null; // FITS element private SavotFits fits = null; /** * Constructor */ public SavotData() { } /** * Set the TABLEDATA element * * @param tableData */ public void setTableData(final SavotTableData tableData) { this.tableData = tableData; } /** * Get the TABLEDATA element * * @return SavotTableData */ public SavotTableData getTableData() { return tableData; } /** * Set the BINARY element * * @param binary */ public void setBinary(final SavotBinary binary) { this.binary = binary; } /** * Get the BINARY element * * @return SavotBinary */ public SavotBinary getBinary() { return binary; } /** * Set the FITS element * * @param fits */ public void setFits(final SavotFits fits) { this.fits = fits; } /** * Get the FITS element * * @return SavotFits */ public SavotFits getFits() { return fits; } } libcds-savot-java/src/main/java/cds/savot/model/SavotBase.java0000664000175000017500000000366312724035712024075 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Base class of the Savot model *

* * @author Andre Schaaff */ public class SavotBase implements SimpleTypes { /** * Protected constructor */ protected SavotBase() { } // TODO: type conversion /** * Helper function to return String value or "" if the given string is null * @param str any String value * @return String value or "" if the given string is null */ final String str(final String str) { return (str != null) ? str : ""; } /** * Helper function to return int value or 0 if the given string is null * @param str any String value * @return int value or 0 if the given string is null */ final int integer(final String str) { return (str != null) ? Integer.parseInt(str) : 0; } /** * Helper function to convert the integer value to String or null if the given integer is negative * @param val an integer value * @return String value or null if the given integer is negative */ final String toStr(final int val) { return (val >= 0) ? Integer.toString(val) : null; } } libcds-savot-java/src/main/java/cds/savot/model/InfoSet.java0000664000175000017500000000206112724035712023544 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of Info elements - deprecated since VOTable 1.1 *

* * @author Andre Schaaff * @see SavotSet */ public final class InfoSet extends SavotSet { /** * Constructor */ public InfoSet() { } } libcds-savot-java/src/main/java/cds/savot/model/SavotMin.java0000664000175000017500000000176312724035712023745 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* For MIN element *

* * @author Andre Schaaff */ public final class SavotMin extends Boundary { /** * Constructor */ public SavotMin() { } } libcds-savot-java/src/main/java/cds/savot/model/SavotBinary.java0000664000175000017500000000256512724035712024447 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Binary element *

* * @author Andre Schaaff */ public final class SavotBinary extends MarkupComment { // STREAM element private SavotStream stream = null; /** * Constructor */ public SavotBinary() { } /** * Set the STREAM element * * @param stream */ public void setStream(final SavotStream stream) { this.stream = stream; } /** * Get the STREAM element * * @return SavotStream */ public SavotStream getStream() { return stream; } } libcds-savot-java/src/main/java/cds/savot/model/SavotVOTable.java0000664000175000017500000002000012724035712024477 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* VOTable element *

* * @author Andre Schaaff */ public final class SavotVOTable extends MarkupComment implements IDSupport { // xmlns attribute private String xmlns = null; // xmlns:xsi attribute private String xmlnsxsi = null; // xsi:NoNamespaceSchemaLocation attribute private String xsinoschema = null; // xsi:schemaLocation attribute private String xsischema = null; // id attribute private String id = null; // version attribute (default : 1.2) private String version = "1.2"; // DESCRIPTION element private String description = null; // COOSYS element set - deprecated since 1.2 private CoosysSet coosys = null; // PARAM element set private ParamSet params = null; // GROUP element set private GroupSet groups = null; // INFO element set private InfoSet infos = null; // DEFINITIONS element @SuppressWarnings("deprecation") private SavotDefinitions definitions = null; // RESOURCE element private ResourceSet resources = null; // INFO element set at the end - since VOTable1.2 private InfoSet infosAtEnd = null; /** * Constructor */ public SavotVOTable() { } /** * Set the global attributes () (used for the writer) * * @param xmlns * String */ public void setXmlns(final String xmlns) { this.xmlns = xmlns; } /** * Get the global attributes ( (used for the writer) * * @return String */ public String getXmlns() { return str(xmlns); } /** * Set the global attributes () (used for the writer) * * @param xmlnsxsi * String */ public void setXmlnsxsi(final String xmlnsxsi) { this.xmlnsxsi = xmlnsxsi; } /** * Get the global attributes ( (used for the writer) * * @return String */ public String getXmlnsxsi() { return str(xmlnsxsi); } /** * Set the global attributes () (used for the writer) * * @param xsinoschema * String */ public void setXsinoschema(final String xsinoschema) { this.xsinoschema = xsinoschema; } /** * Get the global attributes ( (used for the writer) * * @return String */ public String getXsinoschema() { return str(xsinoschema); } /** * Set the global attributes () (used for the writer) * * @param xsischema * String */ public void setXsischema(final String xsischema) { this.xsischema = xsischema; } /** * Get the global attributes ( (used for the writer) * * @return String */ public String getXsischema() { return str(xsischema); } /** * Set the id attribute * * @param id * String */ @Override public void setId(final String id) { this.id = id; } /** * Get the id attribute * * @return String */ @Override public String getId() { return str(id); } /** * Set the version attribute * * @param version * String */ public void setVersion(final String version) { this.version = version; } /** * Get the version attribute * * @return String */ public String getVersion() { return str(version); } /** * Set DESCRIPTION element * * @param description */ public void setDescription(final String description) { this.description = description; } /** * Get DESCRIPTION element * * @return a String */ public String getDescription() { return str(description); } /** * Set DEFINITIONS element * * @deprecated since VOTable 1.1 * @param definitions */ public void setDefinitions(final SavotDefinitions definitions) { this.definitions = definitions; } /** * Get DEFINITIONS element * * @deprecated since VOTable 1.1 * @return SavotDefinitions */ public SavotDefinitions getDefinitions() { return definitions; } /** * Set the Coosys elements * * @deprecated since VOTable 1.2 * @param coosys */ public void setCoosys(final CoosysSet coosys) { this.coosys = coosys; } /** * Get the Coosys elements * * @deprecated since VOTable 1.2 * @return a CoosysSet object */ public CoosysSet getCoosys() { if (coosys == null) { coosys = new CoosysSet(); } return coosys; } /** * Set the Infos elements * * @param infos */ public void setInfos(final InfoSet infos) { this.infos = infos; } /** * Get the Infos elements * * @return a InfoSet object */ public InfoSet getInfos() { if (infos == null) { infos = new InfoSet(); } return infos; } /** * Set the Param elements * * @param params */ public void setParams(final ParamSet params) { this.params = params; } /** * Get the Param elements * * @return a ParamSet object */ public ParamSet getParams() { if (params == null) { params = new ParamSet(); } return params; } /** * Set GROUP element set reference * * @since VOTable 1.2 * @param groups */ public void setGroups(final GroupSet groups) { this.groups = groups; } /** * Get GROUP element set reference * * @since VOTable 1.2 * @return GroupSet */ public GroupSet getGroups() { if (groups == null) { groups = new GroupSet(); } return groups; } /** * Get RESOURCE set reference (FULL mode only) * * @return ResourceSet (always NULL in SEQUENTIAL mode) */ public ResourceSet getResources() { if (resources == null) { resources = new ResourceSet(); } return resources; } /** * Set RESOURCE set reference * * @param resources */ public void setResources(final ResourceSet resources) { this.resources = resources; } /** * Set the InfosAtEnd elements * * @param infosAtEnd * @since VOTable 1.2 */ public void setInfosAtEnd(final InfoSet infosAtEnd) { this.infosAtEnd = infosAtEnd; } /** * Get the InfosAtEnd elements * * @return a InfoSet object * @since VOTable 1.2 */ public InfoSet getInfosAtEnd() { if (infosAtEnd == null) { infosAtEnd = new InfoSet(); } return infosAtEnd; } } libcds-savot-java/src/main/java/cds/savot/model/SavotInfo.java0000664000175000017500000001401512724035712024107 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Info element *

* * @author Andre Schaaff */ public final class SavotInfo extends MarkupComment implements IDSupport, NameSupport, RefSupport { // id attribute private String id = null; // name attribute private String name = null; // value attribute private String value = null; // INFO element content private String content = null; // xtype attribute @since 1.2 private String xtype = null; // ref attribute @since 1.2 private String ref = null; // unit attribute @since 1.2 private String unit = null; // ucd attribute @since 1.2 private String ucd = null; // utype attribute @since 1.2 private String utype = null; // DESCRIPTION element - since VOTable 1.2 (not in the standard) private String description = null; // VALUES element - since VOTable 1.2 (not in the standard) private SavotValues values = null; // LINK elements - since VOTable 1.2 (not in the standard) private LinkSet links = null; /** * Constructor */ public SavotInfo() { } /** * Set ID attribute * * @param id */ @Override public void setId(final String id) { this.id = id; } /** * Get ID attribute * * @return String */ @Override public String getId() { return str(id); } /** * Set name attribute * * @param name */ @Override public void setName(final String name) { this.name = name; } /** * Get name attribute * * @return String */ @Override public String getName() { return str(name); } /** * Set value attribute * * @param value */ public void setValue(final String value) { this.value = value; } /** * Get value attribute * * @return String */ public String getValue() { return str(value); } /** * Set xtype attribute * * @since VOTable 1.2 * @param xtype */ public void setXtype(final String xtype) { this.xtype = xtype; } /** * Get xtype attribute * * @since VOTable 1.2 * @return String */ public String getXtype() { return str(xtype); } /** * Set ref attribute * * @since VOTable 1.2 * @param ref */ @Override public void setRef(final String ref) { this.ref = ref; } /** * Get ref attribute * * @since VOTable 1.2 * @return String */ @Override public String getRef() { return str(ref); } /** * Set unit attribute * * @since VOTable 1.2 * @param unit */ public void setUnit(final String unit) { this.unit = unit; } /** * Get unit attribute * * @since VOTable 1.2 * @return String */ public String getUnit() { return str(unit); } /** * Set ucd attribute * * @since VOTable 1.2 * @param ucd */ public void setUcd(final String ucd) { this.ucd = ucd; } /** * Get ucd attribute * * @since VOTable 1.2 * @return String */ public String getUcd() { return str(ucd); } /** * Set utype attribute * * @since VOTable 1.2 * @param utype */ public void setUtype(final String utype) { this.utype = utype; } /** * Get utype attribute * * @since VOTable 1.2 * @return String */ public String getUtype() { return str(utype); } /** * Set element content * * @param content */ public void setContent(final String content) { this.content = content; } /** * Get element content * * @return a String */ public String getContent() { return str(content); } /** * Set DESCRIPTION content * * @since VOTable 1.2 (not in the standard) * @param description */ public void setDescription(final String description) { this.description = description; } /** * Get DESCRIPTION content * * @since VOTable 1.2 (not in the standard) * @return String */ public String getDescription() { return str(description); } /** * Set the VALUES element * * @since VOTable 1.2 (not in the standard) * @param values */ public void setValues(final SavotValues values) { this.values = values; } /** * Get the VALUES element * * @since VOTable 1.2 (not in the standard) * @return SavotValues */ public SavotValues getValues() { return values; } /** * Get LINK elements set reference * * @since VOTable 1.2 (not in the standard) * @return LinkSet */ public LinkSet getLinks() { if (links == null) { links = new LinkSet(); } return links; } /** * Set LINK elements set reference * * @since VOTable 1.2 (not in the standard) * @param links */ public void setLinks(final LinkSet links) { this.links = links; } } libcds-savot-java/src/main/java/cds/savot/model/ParamRefSet.java0000664000175000017500000000206712724035712024354 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of ref to Param elements *

* * @author Andre Schaaff * @see SavotSet */ public final class ParamRefSet extends SavotSet { /** * Constructor */ public ParamRefSet() { super(); } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/0000775000175000017500000000000012724035712023676 5ustar sladensladenlibcds-savot-java/src/main/java/cds/savot/model/interpreter/FloatComplexInterpreter.java0000664000175000017500000000661312724035712031370 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.util.ArrayList; /** *

Binary interpreter for the type "floatComplex" of VOTable.

*
    *
  • Null value = NaN NaN
  • *
  • Size = 2*4 bytes
  • *
  • Java type = Float[2]
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class FloatComplexInterpreter extends BinaryFieldInterpreter { private final FloatInterpreter floatDecoder; public FloatComplexInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "float complex", 8); floatDecoder = new FloatInterpreter(); } @Override public Float[] decodePrimary(final byte[] bytes, final int offset) throws BinaryInterpreterException { Float[] complex = new Float[2]; complex[0] = floatDecoder.decodePrimary(bytes, offset); complex[1] = floatDecoder.decodePrimary(bytes, offset + (NB_BYTES / 2)); if (complex[0] == null || complex[0] == Float.NaN || complex[1] == null || complex[1] == Float.NaN) { complex = new Float[]{Float.NaN, Float.NaN}; } return complex; } @Override protected Class getArrayClass() { return Float[][].class; } @Override protected ArrayList convertIntoArray(Object value) throws BinaryInterpreterException { ArrayList floats = floatDecoder.convertIntoArray(value); if (floats.size() % 2 > 0) { throw new BinaryInterpreterException("Bad number of float values (" + floats.size() + "): not a factor of 2 ! Note: a Float Complex is composed of 2 float values."); } ArrayList list = new ArrayList(); for (int i = 0; i + 1 < floats.size(); i += 2) { list.add(new Float[]{floats.get(i), floats.get(i + 1)}); } return list; } @Override protected Float[] convertPrimary(Object value) throws BinaryInterpreterException { throw new UnsupportedOperationException(); } @Override public byte[] encodePrimary(Float[] value) throws BinaryInterpreterException { if (value.length % 2 > 0) { throw new BinaryInterpreterException("Bad number of float values: a Float Complex is composed of 2 float values !"); } byte[] encoded = new byte[2 * floatDecoder.NB_BYTES]; for (int i = 0; i < 2; i++) { byte[] bytes = floatDecoder.encodePrimary(value[i]); for (int b = 0; b < floatDecoder.NB_BYTES; b++) { encoded[i * 8 + b] = bytes[b]; } } return encoded; } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/ShortInterpreter.java0000664000175000017500000000511112724035712030062 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

Binary interpreter for the type "short" of VOTable.

*
    *
  • Null value = 0xffff
  • *
  • Size = 2 bytes
  • *
  • Java type = Short
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class ShortInterpreter extends BinaryFieldInterpreter { public ShortInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "short value", 2); } @Override public Short decodePrimary(final byte[] b, final int offset) throws BinaryInterpreterException { return (short) ((b[offset] << 8) | (b[offset + 1] & 0xff)); } @Override protected Class getArrayClass() { return Short[].class; } @Override protected Short convertPrimary(Object value) throws BinaryInterpreterException { if (value == null) { return null; } if (value instanceof Short) { return (Short) value; } else if (value instanceof String) { try { return Short.parseShort((String) value); } catch (NumberFormatException nfe) { throw new BinaryInterpreterException("Impossible to convert \"" + value + "\" into a Short: " + nfe.getMessage() + " !"); } } else { throw new BinaryInterpreterException("Impossible to convert a " + value.getClass().getName() + " into a Short !"); } } @Override public byte[] encodePrimary(Short value) throws BinaryInterpreterException { if (value == null) { return new byte[]{(byte) 0xff, (byte) 0xff}; } byte[] encoded = new byte[2]; encoded[0] = (byte) (value >> 8); encoded[1] = (byte) (value & 0xff); return encoded; } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/UnsignedByteInterpreter.java0000664000175000017500000000514112724035712031366 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

Binary interpreter for the type "unsignedByte" of VOTable.

*
    *
  • Null value = 0xff
  • *
  • Size = 1 bytes
  • *
  • Java type = Short
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class UnsignedByteInterpreter extends BinaryFieldInterpreter { public UnsignedByteInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "unsigned byte", 1); } @Override public Short decodePrimary(final byte[] b, final int offset) throws BinaryInterpreterException { return (short) (b[offset] & 0x00ff); } @Override protected Class getArrayClass() { return Short[].class; } @Override protected Short convertPrimary(Object value) throws BinaryInterpreterException { if (value == null) { return null; } if (value instanceof Short) { return (Short) value; } else if (value instanceof Byte) { return (short) ((Byte) value).byteValue(); } else if (value instanceof String) { try { return Short.parseShort((String) value); } catch (NumberFormatException nfe) { throw new BinaryInterpreterException("Impossible to convert \"" + value + "\" into an Unsigned Byte: " + nfe.getMessage() + " !"); } } else { throw new BinaryInterpreterException("Impossible to convert a " + value.getClass().getName() + " into an Unsigned Byte !"); } } @Override public byte[] encodePrimary(Short value) throws BinaryInterpreterException { if (value == null) { return new byte[]{(byte) 0xff}; } else { return new byte[]{(byte) (value & 0xff)}; } } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/BooleanInterpreter.java0000664000175000017500000000610012724035712030341 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

Binary interpreter for the type "logical" of VOTable.

*
    *
  • Null value = 0x00
  • *
  • Size = 1 byte
  • *
  • Java type = Boolean
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class BooleanInterpreter extends BinaryFieldInterpreter { public BooleanInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "logical value", 1); } @Override public Boolean decodePrimary(final byte[] b, final int offset) throws BinaryInterpreterException { char temp = (char) (b[offset] & 0xff); switch (temp) { case '1': case 'T': case 't': return Boolean.TRUE; case '0': case 'F': case 'f': return Boolean.FALSE; case '\0': case ' ': case '?': return null; default: throw new BinaryInterpreterException("Unknown logical representation: \"" + temp + "\" !"); } } @Override protected Class getArrayClass() { return Boolean[].class; } @Override protected Boolean convertPrimary(Object value) throws BinaryInterpreterException { if (value == null) { return null; } if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof String) { String str = (String) value; if (str.equalsIgnoreCase("true") || str.equalsIgnoreCase("t") || str.equalsIgnoreCase("1")) { return Boolean.TRUE; } else if (str.equalsIgnoreCase("false") || str.equalsIgnoreCase("f") || str.equalsIgnoreCase("0")) { return Boolean.FALSE; } else { return null; } } else { throw new BinaryInterpreterException("Impossible to convert a " + value.getClass().getName() + " into a Boolean !"); } } @Override public byte[] encodePrimary(Boolean value) throws BinaryInterpreterException { if (value == null) { return getPadding(); } else { return new byte[]{(value ? (byte) '1' : (byte) '0')}; } } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/CharInterpreter.java0000664000175000017500000000547012724035712027650 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

Binary interpreter for the type "character" of VOTable.

*
    *
  • Null value = \0
  • *
  • Size = 1 byte
  • *
  • Java type = Character
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class CharInterpreter extends BinaryFieldInterpreter { public CharInterpreter(final int[] arraysizes) throws BinaryInterpreterException { this(arraysizes, "character", 1); } public CharInterpreter(final int[] arraysizes, final String typeLabel, final int nbBytes) throws BinaryInterpreterException { super(arraysizes, "character", 1); arraySeparator = ""; } @Override public Character decodePrimary(final byte[] b, final int offset) throws BinaryInterpreterException { return (char) (b[offset] & 0xff); } @Override protected Class getArrayClass() { return Character[].class; } @Override protected Character convertPrimary(Object value) throws BinaryInterpreterException { if (value == null) { return '\0'; } if (value instanceof Character) { return (Character) value; } else if (value instanceof String) { String str = (String) value; if (str.length() > 1) { throw new BinaryInterpreterException("Impossible to convert into a single " + TYPE_LABEL + " a String which contains " + str.length() + " characters !"); } else if (str.isEmpty()) { return '\0'; } else { return str.charAt(0); } } else { throw new BinaryInterpreterException("Impossible to convert a " + value.getClass().getName() + " into a " + TYPE_LABEL + " !"); } } @Override public byte[] encodePrimary(Character value) throws BinaryInterpreterException { if (value == null) { return getPadding(); } else { return new byte[]{(byte) value.charValue()}; } } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/BitInterpreter.java0000664000175000017500000001201312724035712027500 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; /** * * @author Gregory Mantelet * */ public class BitInterpreter extends CharInterpreter { public BitInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "bit array", 1); } @Override public Character[] decode(final InputStream input) throws IOException, BinaryInterpreterException { int arraysize = getArraySize(input); int nbBytes = arraysize / 8; if (arraysize % 8 > 0) { nbBytes++; } byte[] bytes = readBytes(input, nbBytes); Character[] decoded = createEmptyArray(arraysize); int indBit = 0; for (int i = 0; i < nbBytes && indBit < arraysize; i++) { byte b = bytes[i]; for (int j = 0; j < 8 && indBit < arraysize; j++, indBit++) { char c = (char) (((0x80 & (b << j)) >>> 7) | '0'); decoded[indBit] = c; } } return decoded; } @Override public Character decodePrimary(final byte[] bytes, final int offset) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } @Override protected Class getArrayClass() { return Character[].class; } @Override protected Character convertPrimary(Object value) throws BinaryInterpreterException { if (value != null && value instanceof Boolean) { return ((Boolean) value) ? '1' : '0'; } else { char c = super.convertPrimary(value); if (c != '0' && c != '1') { throw new BinaryInterpreterException("Incorrect bit value: \"" + c + "\" !"); } return c; } } @Override public void encode(OutputStream output, Object value) throws IOException, BinaryInterpreterException { boolean variableArray = (nbItems < 0); boolean encodeInArray = (variableArray || (nbItems > 1)); // get the corresponding array, but of only 1 dimension: ArrayList values = new ArrayList(); if (value.getClass().isArray()) { if (!encodeInArray) { throw new BinaryInterpreterException("Impossible to encode an array into a single " + TYPE_LABEL + " !"); } else { values.addAll(convertIntoArray((Object[]) value)); } } else { values.add(convertPrimary(value)); } // write the number of bytes if needed: if (variableArray) { arraySizeInterpreter.encode(output, values.size()); } else if (values.size() > nbItems) { throw new BinaryInterpreterException("The given array is bigger than the arraysize set by the savot field: " + values.size() + " > " + nbItems + " !"); } // count needed bytes (padding included): int nbBytes; if (nbItems > 0) { nbBytes = (nbItems / 8); if (nbItems % 8 > 0) { nbBytes++; } } else { nbBytes = (values.size() / 8); if (values.size() % 8 > 0) { nbBytes++; } } // write all the given items (and the padding bytes): byte[] bytes = new byte[nbBytes]; for (int b = 0; b < nbBytes; b++) { bytes[b] = 0; for (int i = 0, v = b * 8; i < 8 && v < values.size(); i++, v++) { char c = values.get(v).charValue(); switch (c) { case '1': bytes[b] |= (byte) (1 << (7 - i)); break; case '0': break; default: throw new BinaryInterpreterException("Incorrect bit value: " + c); } } } output.write(bytes); } @Override public byte[] encodePrimary(Character value) throws BinaryInterpreterException { throw new UnsupportedOperationException(); } @Override public byte[] getPadding(final int length) { throw new UnsupportedOperationException(); } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/IntegerInterpreter.java0000664000175000017500000000570012724035712030364 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

Binary interpreter for the type "int" of VOTable.

*
    *
  • Null value = 0xffffffff
  • *
  • Size = 4 bytes
  • *
  • Java type = Integer
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class IntegerInterpreter extends BinaryFieldInterpreter { public IntegerInterpreter() throws BinaryInterpreterException { this(new int[]{1}); } public IntegerInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "integer value", 4); } @Override public Integer decodePrimary(final byte[] b, final int offset) throws BinaryInterpreterException { return (int) ((((b[offset] & 0xff) << 24) | ((b[offset + 1] & 0xff) << 16) | ((b[offset + 2] & 0xff) << 8) | ((b[offset + 3] & 0xff)))); } @Override protected Class getArrayClass() { return Integer[].class; } @Override protected Integer convertPrimary(Object value) throws BinaryInterpreterException { if (value == null) { return null; } if (value instanceof Integer) { return (Integer) value; } else if (value instanceof String) { try { return Integer.parseInt((String) value); } catch (NumberFormatException nfe) { throw new BinaryInterpreterException("Impossible to convert \"" + value + "\" into an Integer: " + nfe.getMessage() + " !"); } } else { throw new BinaryInterpreterException("Impossible to convert a " + value.getClass().getName() + " into an Integer !"); } } @Override public byte[] encodePrimary(Integer value) throws BinaryInterpreterException { if (value == null) { return new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; } byte[] encoded = new byte[4]; encoded[0] = (byte) (value >>> 24); encoded[1] = (byte) (value >>> 16); encoded[2] = (byte) (value >>> 8); encoded[3] = (byte) (value & 0xff); return encoded; } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/BinaryFieldInterpreter.java0000664000175000017500000005754112724035712031171 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import cds.savot.model.SavotField; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Array; import java.util.ArrayList; /** * A BinaryFieldInterpreter is able to encode and to decode a given type of data in binary. * * @author Gregory Mantelet * @since 09/2011 * * @param Type this interpreter can encode into and decode from binary data. */ public abstract class BinaryFieldInterpreter { /** Name/Label of the type managed by this BinaryFieldInterpreter. */ protected final String TYPE_LABEL; /** Number of bytes occupied by the type managed in this BinaryFieldInterpreter. */ protected final int NB_BYTES; /** Interpreter used only to encode or to decode the array size. */ protected final IntegerInterpreter arraySizeInterpreter; /** Indicates the dimension(s) of the data to encode/decode. */ protected final int[] fixArraySizes; /** Total number of items to encode/decode, all dimensions confounded. */ protected final int nbItems; /** String representation of a null value. */ protected String strNullValue = ""; /** Separator of items in the string representation of an array. */ protected String arraySeparator = " "; /** * Builds a BinaryFieldInterpreter. * * @param arraysizes Dimensions of the primary data type to encode/decode. * @param typeLabel Name/Label of the type to manage. * @param nbBytes Number of bytes of a primary data type. * * @throws BinaryInterpreterException If the dimensions are not valid or if there is a problem while creating the array size interpreter. */ public BinaryFieldInterpreter(final int[] arraysizes, final String typeLabel, final int nbBytes) throws BinaryInterpreterException { TYPE_LABEL = (typeLabel == null || typeLabel.trim().isEmpty()) ? "byte" : typeLabel.trim(); NB_BYTES = (nbBytes <= 0) ? 1 : nbBytes; // Count the total number of items and check the given array-sizes: int nbItems = 0; fixArraySizes = new int[arraysizes.length]; for (int i = 0; i < arraysizes.length; i++) { if (arraysizes[i] <= 0) { if (i == arraysizes.length - 1) { fixArraySizes[i] = -1; nbItems = -1; } else { throw new BinaryInterpreterException("Incorrect arraysize: only the last dimension of an array can be variable in length !"); } } else { fixArraySizes[i] = arraysizes[i]; nbItems += arraysizes[i]; } } this.nbItems = (nbItems <= 0) ? -1 : nbItems; // An array-size interpreter is needed only if the array-size is variable: if (this.nbItems != -1) { arraySizeInterpreter = null; } else { arraySizeInterpreter = new IntegerInterpreter(); } } /** *

Decodes the binary data coming from the given input stream.

* *

* Basically, this method gets the array-size (particularly if variable), * creates an empty array of the good dimension(s) and fills it by decoding * one by one data of type T. *

* * @param input Data to decode. * * @return null if EOF, else the decoded data of type T. * * @throws IOException If the EOF has been reached in an unexpected manner * or if an error occurs while reading bytes from the given input stream. * * @see #getArraySize(InputStream) * @see #readBytes(InputStream, int) * @see #createEmptyArray(int) * @see #decodePrimary(byte[],int) */ public T[] decode(final InputStream input) throws IOException { int arraysize = getArraySize(input); if (arraysize == -1) { return null; } byte[] bytes = readBytes(input, arraysize); if (bytes == null) { if (arraySizeInterpreter == null) { return null; } else { throw new BinaryInterpreterException("Unexpected EOF: " + arraysize + " items of type " + TYPE_LABEL + " should be read !"); } } T[] decoded = createEmptyArray(arraysize); for (int i = 0; i < arraysize; i++) { decoded[i] = decodePrimary(bytes, i * NB_BYTES); } return decoded; } /** *

Gets the number of data of type T to get currently.

* *

* Either the array-size is defined at the creation, or it is variable. In one hand the given array-size is just returned. * In another hand the array-size is an integer value which prefixes the data to read. * In that case, we must read one integer from the given input stream. * This integer corresponds to the length of the data of type T to get. *

* * @param input The data to decode. * @return -1 if EOF, else the length of data of type T to return. * * @throws IOException If an error occurs while decoding the array-size from the given input stream. */ protected int getArraySize(final InputStream input) throws IOException { if (arraySizeInterpreter != null) { Integer[] ints = arraySizeInterpreter.decode(input); if (ints == null) { return -1; } else { return ints[0]; } } else { return nbItems; } } /** *

* Reads length data of type T from the given input stream considering * the number of bytes one data of this type is supposed to occupied (see {@link #NB_BYTES}). *

* * @param input Input stream from which bytes must be read. * @param length * @return null if EOF, else the read bytes (the length of this array is a multiple of {@link #NB_BYTES}). * * @throws IOException If the end of file has been reached before getting length full items of type T * or if there is an error while reading bytes from the given input stream. */ protected byte[] readBytes(final InputStream input, final int length) throws IOException { if (length < 0) { throw new NegativeArraySizeException("Impossible to get negative number of " + TYPE_LABEL + " !"); } else if (length == 0) { return new byte[0]; } // Read "length" items that is to say: (length * NB_BYTES) bytes: byte[] bytes = new byte[NB_BYTES * length]; int nbRead = input.read(bytes); // If all bytes have been read: if (nbRead == bytes.length) { return bytes; } // If EOF has been reached before getting one byte: else if (nbRead == -1) { return null; } // If less than "length" full items have been read: else if (nbRead % NB_BYTES == 0) { throw new BinaryInterpreterException("Unexpected EOF: can not get " + length + " value of type " + TYPE_LABEL + " ! (" + (nbRead / NB_BYTES) + " items successfully read)"); } // If one item has not been read completely: else { throw new BinaryInterpreterException("Unexpected EOF: can not get a full " + TYPE_LABEL + " (= " + NB_BYTES + " bytes) ! (" + (nbRead / NB_BYTES) + " items successfully read)"); } } /** *

Serializes the given cell value.

* *

NOTE: * The given value can be a single value or a multidimensional array. * In this last case all items (whatever is their dimension) * are written in a String separated by {@link #arraySeparator} * (which depends of the type managed by the BinaryFieldInterpreter ; by default ' '). *

* * @param cellValue Value (single value or array) of a column/cell/field. (may be null) * * @return The String serialization of the given value. */ public String convertToString(Object cellValue) { if (cellValue == null) { return strNullValue; } else if (cellValue.getClass().isArray()) { Object[] array = (Object[]) cellValue; /* TODO : define initial capacity or recycle StringBuilder instances */ StringBuilder str = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (i > 0) { str.append(arraySeparator); } str.append(convertToString(array[i])); } return str.toString(); } else { return cellValue.toString(); } } /** * Creates an array (1 dimension) of type T with the given length. * * @param arraysize Length of the array to create. (MUST BE >= 0) * * @return An empty array of type T and of length arraysize. * * @throws ClassCastException If it is impossible to create an array of T. * @throws NegativeArraySizeException If the given array size is negative. * * @see #getArrayClass() */ protected T[] createEmptyArray(final int arraysize) throws ClassCastException, NegativeArraySizeException { return getArrayClass().cast(Array.newInstance(getArrayClass().getComponentType(), arraysize)); } /** *

Gets the precise array type.

* *

Generally: T[].class, where T must be a concrete class.

* * @return The class of an array of type T. */ protected abstract Class getArrayClass(); /** *

Decodes only one data of type T from the given bytes array.

* *

WARNING: bytes is supposed to contain enough bytes (>= {@link #NB_BYTES}) from the given offset.

* * @param bytes Array to use to extract enough bytes so that decoding one data of type T. * @param offset Position from which bytes must be read. * * @return The decoded value. * * @throws BinaryInterpreterException If an error occurs while decoding bytes. */ public abstract T decodePrimary(final byte[] bytes, final int offset) throws BinaryInterpreterException; /* *************** */ /* BINARY ENCODING */ /* *************** */ /** * Encodes the given value in binary and writes it in the given output stream. * * @param output Stream in which the encoded value must be written. * @param value The value to write once encoded in binary. * * @throws IOException If there is an error while writing in the given stream. * @throws BinaryInterpreterException If there is an error while encoding the given value. * * @see #convertIntoArray(Object) * @see #encodePrimary(Object) * @see #getPadding() */ public void encode(final OutputStream output, final Object value) throws IOException, BinaryInterpreterException { boolean variableArray = (nbItems < 0); boolean encodeInArray = (variableArray || (nbItems > 1)); // Get the corresponding array, but of only 1 dimension: if (value != null && value.getClass().isArray()) { if (!encodeInArray) { throw new BinaryInterpreterException("Impossible to encode an array into a single " + TYPE_LABEL + " !"); } } ArrayList values = new ArrayList(convertIntoArray(value)); // Write the number of items if needed: if (variableArray) { arraySizeInterpreter.encode(output, values.size()); } else if (values.size() > nbItems) { throw new BinaryInterpreterException("The given array is bigger than the arraysize set by the savot field: " + values.size() + " > " + nbItems + " !"); } // Write all given items: for (int i = 0; i < values.size(); i++) { output.write(encodePrimary(values.get(i))); } // Include padding items if needed: if (values.size() < nbItems) { output.write(getPadding(nbItems - values.size())); } } /** * Creates an array of the given length with padding values (0x00). * * param length * @return Array of the given length of padding values. */ public byte[] getPadding(final int length) { return new byte[length]; } /** * Creates an array of the length of the type T ({@link #NB_BYTES}) with padding values (0x00). * * @return Bytes of one padding value of type T. * * @see #getPadding(int) */ public final byte[] getPadding() { return getPadding(NB_BYTES); } /** *

Converts the given value (single value or multidimensional array) into one array of one dimension.

* *

NOTE: * A String value will be considered as an array whose items are separated by {@link #arraySeparator}. * Another type (except an array) must be understandable by {@link #convertPrimary(Object)}. *

* * @param value Value to convert (single value or multidimensional array). * * @return A list of all values included into the given object. * * @throws BinaryInterpreterException If {@link #convertPrimary(Object)} fails. * * @see #convertPrimary(Object) */ protected ArrayList convertIntoArray(final Object value) throws BinaryInterpreterException { ArrayList list = new ArrayList(); // NULL values must be understandable by convertPrimary(...): if (value == null) { list.add(convertPrimary(value)); return list; } // If the value is a string, it could be an array in which items are separated by the given array separator (by default a whitespace): if (value instanceof String) { String str = (String) value; // Split the string in function of the given array separator: /* TODO: define initial capacity or recycle StringBuilder instances */ String[] values; if (arraySeparator == null || arraySeparator.isEmpty()) { values = new String[str.length()]; for (int i = 0; i < values.length; i++) { values[i] = str.charAt(i) + ""; } } else { values = str.split(arraySeparator); } // Convert all items: for (String v : values) { if (v == null || v.equalsIgnoreCase(strNullValue)) { list.add(null); } else { list.add(convertPrimary(v)); } } } // If the given object is actually an array, all items are converted and added in the list: else if (value.getClass().isArray()) { Object[] array = (Object[]) value; for (int i = 0; i < array.length; i++) { list.addAll(convertIntoArray(array[i])); } } // Otherwise the given object is supposed to be a single value: else { list.add(convertPrimary(value)); } return list; } /** * Converts/Casts the given object into an object of type T. * * @param value The value to cast. (MAY BE NULL) * * @return The casted value. * * @throws BinaryInterpreterException If there is an error while converting the given value. */ protected abstract T convertPrimary(final Object value) throws BinaryInterpreterException; /** *

Encodes a single value of type T in binary.

* *

NOTE: If the given value is null, {@link #getPadding()} will be returned.

* * @param value The value to encode. (MAY BE NULL). * * @return The value encoded in binary. * * @throws BinaryInterpreterException If there is an error while encoding the given value. */ public abstract byte[] encodePrimary(final T value) throws BinaryInterpreterException; /* **************************************** */ /* SAVOT_FIELD --> BINARY_FIELD_INTERPRETER */ /* **************************************** */ /** *

Creates the BinaryFieldInterpreter corresponding to the given {@link SavotField}.

* *

Data type

*
    *
  • Accepted data-types are: boolean, bit, unsignedByte, char, unicode char, short, int, * long, float, double, floatComplex, doubleComplex.
  • *
  • Another data-type will be considered as: char[*].
  • *
* *

Array size

*
    *
  • The array-size can be multi-dimensional (each dimension separated by a 'x' character) * and variable (specified by a '*' character) on the last dimension.
  • *
  • Delimited dimension (i.e. 12*) will be considered as variable dimension (so 12* => *).
  • *
  • A negative, null or non-numeric value will be considered as variable (*).
  • *
* *

Values

*

* Only the null attribute is managed. It indicates the string representation of a null value. * It is used to identify a nulls and to write them while converting a cell value in string (see {@link #convertToString(Object)}). *

* * @param field A {@link SavotField}. * * @return Its corresponding BinaryFieldInterpreter. * * @throws BinaryInterpreterException If there is an error while creating the interpreter. */ public static final BinaryFieldInterpreter createInterpreter(SavotField field) throws BinaryInterpreterException { // 1. EXTRACTS THE DATA TYPE FROM THIS FIELD: String type = field.getDataType(); if (type == null) { type = ""; } // 2. EXTRACTS THE ARRAY SIZE IF ANY: int[] arraysizes; // no array size => 1 item of T if (field.getArraySize().trim().isEmpty()) { arraysizes = new int[]{1}; } // otherwise, interpret it completely: else { // If there are several dimensions, they are separated by a 'x' character. String[] sizesStr = field.getArraySize().trim().split("x"); arraysizes = new int[sizesStr.length]; for (int i = 0; i < sizesStr.length; i++) { // CASE 1: variable dimension. It is specified by a '*' character. if (sizesStr[i].endsWith("*")) { arraysizes[i] = -1; } // CASE 2: defined dimension. Must be a positive numeric value. else { try { arraysizes[i] = Integer.parseInt(sizesStr[i]); if (arraysizes[i] <= 0) { System.err.println("Warning: an array-size must be positive and non-null => \"" + arraysizes[i] + "\" in the array-size \"" + field.getArraySize() + "\" of \"" + field.getName() + "\" will be considered as variable !"); arraysizes[i] = -1; } } catch (NumberFormatException nfe) { /* 2 cases: * - the array-size is not numeric => syntax error. * - the dimension is delimited. For instance: "12*", which means "at least 12 items and maybe more". * In both cases, the array-size will be considered as variable (the same as '*'). */ arraysizes[i] = -1; System.err.println("Warning: undefined array-size \"" + sizesStr[i] + "\" (in \"" + field.getArraySize() + "\") for \"" + field.getName() + "\". Supposed to be \"*\"."); } } // ONLY THE LAST DIMENSION CAN BE VARIABLE ! if (arraysizes[i] == -1 && i != sizesStr.length - 1) { arraysizes = new int[]{-1}; System.err.println("Warning: incorrect arraysize syntax \"" + field.getArraySize() + "\" for \"" + field.getName() + "\". Only the last dimension can be variable in length ! This field will be considered as an array of \"" + field.getDataType() + "\" with only one dimension variable in length."); break; } } } // 3. BUILD THE INTERPRETER CORRESPONDING TO THE EXTRACTED DATA-TYPE AND CONSIDERING THE INTERPRETED ARRAY-SIZE: BinaryFieldInterpreter interpreter; if (type.equalsIgnoreCase("boolean")) { interpreter = new BooleanInterpreter(arraysizes); } else if (type.equalsIgnoreCase("bit")) { interpreter = new BitInterpreter(arraysizes); } else if (type.equalsIgnoreCase("unsignedByte")) { interpreter = new UnsignedByteInterpreter(arraysizes); } else if (type.equalsIgnoreCase("char")) { interpreter = new CharInterpreter(arraysizes); } else if (type.equalsIgnoreCase("unicodeChar")) { interpreter = new UnicodeCharInterpreter(arraysizes); } else if (type.equalsIgnoreCase("short")) { interpreter = new ShortInterpreter(arraysizes); } else if (type.equalsIgnoreCase("int")) { interpreter = new IntegerInterpreter(arraysizes); } else if (type.equalsIgnoreCase("long")) { interpreter = new LongInterpreter(arraysizes); } else if (type.equalsIgnoreCase("float")) { interpreter = new FloatInterpreter(arraysizes); } else if (type.equalsIgnoreCase("double")) { interpreter = new DoubleInterpreter(arraysizes); } else if (type.equalsIgnoreCase("floatComplex")) { interpreter = new FloatComplexInterpreter(arraysizes); } else if (type.equalsIgnoreCase("doubleComplex")) { interpreter = new DoubleComplexInterpreter(arraysizes); } else { System.err.println("Warning: missing type attribute for \"" + field.getName() + "\". Supposed to be char(" + arraySizeToString(arraysizes) + ") !"); interpreter = new CharInterpreter(arraysizes); } // 4. SET THE STRING REPRESENTATION OF A NULL VALUE IF NEEDED: if (field.getValues() != null && field.getValues().getNull() != null && !field.getValues().getNull().equalsIgnoreCase(interpreter.arraySeparator)) { interpreter.strNullValue = field.getValues().getNull(); } return interpreter; } /* ******************************** */ /* ARRAY SIZE INTERPRETATION METHOD */ /* ******************************** */ /** * Lets serialize the given array size in String. * * @param arraysize Array-size to serialize. * * @return Its serialization. */ public static final String arraySizeToString(final int[] arraysize) { /* TODO: define initial capacity or recycle StringBuilder instances */ StringBuilder str = new StringBuilder(); for (int i = 0; i < arraysize.length; i++) { if (i > 0) { str.append('x'); } if (arraysize[i] <= 0) { str.append('*'); } else { str.append(arraysize[i]); } } return str.toString(); } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/DoubleInterpreter.java0000664000175000017500000000527412724035712030207 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

Binary interpreter for the type "double" of VOTable.

*
    *
  • Null value = NaN
  • *
  • Size = 8 bytes
  • *
  • Java type = Double
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class DoubleInterpreter extends BinaryFieldInterpreter { private final LongInterpreter longDecoder = new LongInterpreter(); public DoubleInterpreter() throws BinaryInterpreterException { this(new int[]{1}); } public DoubleInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "double value", 8); } @Override public Double decodePrimary(final byte[] bytes, final int offset) throws BinaryInterpreterException { return Double.longBitsToDouble(longDecoder.decodePrimary(bytes, offset)); } @Override protected Class getArrayClass() { return Double[].class; } @Override protected Double convertPrimary(Object value) throws BinaryInterpreterException { if (value == null) { return Double.NaN; } if (value instanceof Double) { return (Double) value; } else if (value instanceof String) { try { return Double.parseDouble((String) value); } catch (NumberFormatException nfe) { throw new BinaryInterpreterException("Impossible to convert \"" + value + "\" into a Double: " + nfe.getMessage() + " !"); } } else { throw new BinaryInterpreterException("Impossible to convert a " + value.getClass().getName() + " into a Double !"); } } @Override public byte[] encodePrimary(Double value) throws BinaryInterpreterException { if (value == null) { value = Double.NaN; } return longDecoder.encodePrimary(Double.doubleToRawLongBits(value)); } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/FloatInterpreter.java0000664000175000017500000000527312724035712030041 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

Binary interpreter for the type "float" of VOTable.

*
    *
  • Null value = NaN
  • *
  • Size = 4 bytes
  • *
  • Java type = Float
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class FloatInterpreter extends BinaryFieldInterpreter { private final IntegerInterpreter intDecoder; public FloatInterpreter() throws BinaryInterpreterException { this(new int[]{1}); } public FloatInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "float complex", 4); intDecoder = new IntegerInterpreter(); } @Override public Float decodePrimary(final byte[] bytes, final int offset) throws BinaryInterpreterException { return Float.intBitsToFloat(intDecoder.decodePrimary(bytes, offset)); } @Override protected Class getArrayClass() { return Float[].class; } @Override protected Float convertPrimary(Object value) throws BinaryInterpreterException { if (value == null) { return Float.NaN; } if (value instanceof Float) { return (Float) value; } else if (value instanceof String) { try { return Float.parseFloat((String) value); } catch (NumberFormatException nfe) { throw new BinaryInterpreterException("Impossible to convert \"" + value + "\" into a Float: " + nfe.getMessage() + " !"); } } else { throw new BinaryInterpreterException("Impossible to convert a " + value.getClass().getName() + " into a Float !"); } } @Override public byte[] encodePrimary(Float value) throws BinaryInterpreterException { if (value == null) { value = Float.NaN; } return intDecoder.encodePrimary(Float.floatToRawIntBits(value)); } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/DoubleComplexInterpreter.java0000664000175000017500000000665512724035712031543 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.util.ArrayList; /** *

Binary interpreter for the type "doubleComplex" of VOTable.

*
    *
  • Null value = NaN NaN
  • *
  • Size = 2*8 bytes
  • *
  • Java type = Double[2]
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class DoubleComplexInterpreter extends BinaryFieldInterpreter { private final DoubleInterpreter doubleDecoder; public DoubleComplexInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "double complex", 16); doubleDecoder = new DoubleInterpreter(); } @Override public Double[] decodePrimary(final byte[] bytes, final int offset) throws BinaryInterpreterException { Double[] complex = new Double[2]; complex[0] = doubleDecoder.decodePrimary(bytes, offset); complex[1] = doubleDecoder.decodePrimary(bytes, offset + (NB_BYTES / 2)); if (complex[0] == null || complex[0] == Double.NaN || complex[1] == null || complex[1] == Double.NaN) { complex = new Double[]{null, null}; } return complex; } @Override protected Class getArrayClass() { return Double[][].class; } @Override protected ArrayList convertIntoArray(Object value) throws BinaryInterpreterException { ArrayList doubles = doubleDecoder.convertIntoArray(value); if (doubles.size() % 2 > 0) { throw new BinaryInterpreterException("Bad number of double values (" + doubles.size() + "): not a factor of 2 ! Note: a Double Complex is composed of 2 double values."); } ArrayList list = new ArrayList(); for (int i = 0; i + 1 < doubles.size(); i += 2) { list.add(new Double[]{doubles.get(i), doubles.get(i + 1)}); } return list; } @Override protected Double[] convertPrimary(Object value) throws BinaryInterpreterException { throw new UnsupportedOperationException(); } @Override public byte[] encodePrimary(Double[] value) throws BinaryInterpreterException { if (value.length % 2 > 0) { throw new BinaryInterpreterException("Bad number of double values: a Double Complex is composed of 2 double values !"); } byte[] encoded = new byte[2 * doubleDecoder.NB_BYTES]; for (int i = 0; i < 2; i++) { byte[] bytes = doubleDecoder.encodePrimary(value[i]); for (int b = 0; b < doubleDecoder.NB_BYTES; b++) { encoded[i * 8 + b] = bytes[b]; } } return encoded; } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/BinaryInterpreterException.java0000664000175000017500000000272612724035712032077 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.io.IOException; /** * Exception sent while encoding/decoding binary data. * * @author Gregory Mantelet * @since 09/2011 * * @see cds.savot.model.interpreter.BinaryFieldInterpreter */ public class BinaryInterpreterException extends IOException { private static final long serialVersionUID = 1L; public BinaryInterpreterException() { super(); } public BinaryInterpreterException(String msg) { super(msg); } public BinaryInterpreterException(Throwable cause) { super(cause); } public BinaryInterpreterException(String msg, Throwable cause) { super(msg, cause); } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/UnicodeCharInterpreter.java0000664000175000017500000000332712724035712031156 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

Binary interpreter for the type "unicodeChar" of VOTable.

*
    *
  • Null value = \0
  • *
  • Size = 2 bytes
  • *
  • Java type = Character
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class UnicodeCharInterpreter extends CharInterpreter { public UnicodeCharInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "unicode character", 2); } @Override public Character decodePrimary(final byte[] b, final int offset) throws BinaryInterpreterException { return (char) ((b[offset] << 8) | (b[offset + 1] & 0xff)); } @Override public byte[] encodePrimary(Character value) throws BinaryInterpreterException { if (value == null) { return getPadding(); } else { return new byte[]{(byte) (value >> 8), (byte) (value & 0xff)}; } } } libcds-savot-java/src/main/java/cds/savot/model/interpreter/LongInterpreter.java0000664000175000017500000000623012724035712027665 0ustar sladensladenpackage cds.savot.model.interpreter; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

Binary interpreter for the type "long" of VOTable.

*
    *
  • Null value = 0xffffffffffffffff
  • *
  • Size = 8 bytes
  • *
  • Java type = Long
  • *
* * @author Gregory Mantelet * @since 09/2011 */ public class LongInterpreter extends BinaryFieldInterpreter { public LongInterpreter() throws BinaryInterpreterException { this(new int[]{1}); } public LongInterpreter(final int[] arraysizes) throws BinaryInterpreterException { super(arraysizes, "long value", 8); } @Override public Long decodePrimary(final byte[] b, final int offset) throws BinaryInterpreterException { return ((((long) b[offset] & 0xff) << 56) | (((long) b[offset + 1] & 0xff) << 48) | (((long) b[offset + 2] & 0xff) << 40) | (((long) b[offset + 3] & 0xff) << 32) | (((long) b[offset + 4] & 0xff) << 24) | (((long) b[offset + 5] & 0xff) << 16) | (((long) b[offset + 6] & 0xff) << 8) | (((long) b[offset + 7] & 0xff))); } @Override protected Class getArrayClass() { return Long[].class; } @Override protected Long convertPrimary(Object value) throws BinaryInterpreterException { if (value == null) { return null; } if (value instanceof Long) { return (Long) value; } else if (value instanceof String) { try { return Long.parseLong((String) value); } catch (NumberFormatException nfe) { throw new BinaryInterpreterException("Impossible to convert \"" + value + "\" into a Long: " + nfe.getMessage() + " !"); } } else { throw new BinaryInterpreterException("Impossible to convert a " + value.getClass().getName() + " into a Long !"); } } @Override public byte[] encodePrimary(Long value) throws BinaryInterpreterException { if (value == null) { return new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff}; } byte[] encoded = new byte[8]; for (int i = 0; i < encoded.length; i++) { encoded[i] = (byte) (value >>> 8 * (encoded.length - 1 - i)); } return encoded; } } libcds-savot-java/src/main/java/cds/savot/model/LinkSet.java0000664000175000017500000000204312724035712023546 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of Link elements *

* * @author Andre Schaaff * @see SavotSet */ public final class LinkSet extends SavotSet { /** * Constructor */ public LinkSet() { super(); } } libcds-savot-java/src/main/java/cds/savot/model/FieldRefSet.java0000664000175000017500000000204612724035712024334 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of ref to Field elements *

* * @author Andre Schaaff * @see SavotSet */ public final class FieldRefSet extends SavotSet { /** * Constructor */ public FieldRefSet() { } } libcds-savot-java/src/main/java/cds/savot/model/SavotTableData.java0000664000175000017500000000257612724035712025046 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* TableData element *

* * @author Andre Schaaff */ public final class SavotTableData extends MarkupComment { private TRSet TRs = null; /** * Constructor */ public SavotTableData() { } /** * Get the TR set reference * * @return TRs */ public TRSet getTRs() { if (TRs == null) { TRs = new TRSet(); } return TRs; } /** * Set the TR set reference * * @param TRs */ public void setTRs(final TRSet TRs) { this.TRs = TRs; } } libcds-savot-java/src/main/java/cds/savot/model/SavotTR.java0000664000175000017500000000713712724035712023550 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Row element *

* * @author Andre Schaaff */ public final class SavotTR extends SavotBase { // TR element set private TDSet TDs = null; private int lineInXMLFile = 0; /** * Constructor */ public SavotTR() { } /** * Create a TR element from a Separated Value String * * @param svline * String, line with separated values * @param sv * char, separated value */ public void SVtoTR(final String svline, final char sv) { String line = svline; int index; String token; TDs = new TDSet(); // cut sv following the separator // tabulation do { if ((index = line.indexOf(sv)) >= 0) { token = line.substring(0, index); line = line.substring(index + 1); } else { // last element token = line; } SavotTD td = new SavotTD(); td.setContent(token); TDs.addItem(td); } while (index >= 0); } /** * Get the TD set (same as getTDSet) TDSet * * @return TDSet */ public TDSet getTDs() { if (TDs == null) { TDs = new TDSet(); } return TDs; } /** * Get the TD set (same as getTDs) TDSet * @param capacity minimal capacity to provide * @return TDSet */ public TDSet getTDSet(final int capacity) { if (TDs == null) { TDs = new TDSet(); TDs.ensureCapacity(capacity); } return TDs; } /** * Get the TD set (same as getTDs) TDSet * @see #getTDSet(int) * * @return TDSet */ public TDSet getTDSet() { if (TDs == null) { TDs = new TDSet(); } return TDs; } /** * Set the TD set (same as setTDSet) TDSet * * @param TDs */ public void setTDs(final TDSet TDs) { this.TDs = TDs; } /** * Set the TD set (same as setTDs) TDSet * * @param TDs */ public void setTDSet(final TDSet TDs) { this.TDs = TDs; } /** * Get the corresponding line in the XML file or flow * * @return lineInXMLFile */ public int getLineInXMLFile() { return lineInXMLFile; } /** * Set the corresponding line in the XML file or flow during the parsing * * @param lineInXMLFile */ public void setLineInXMLFile(final int lineInXMLFile) { this.lineInXMLFile = lineInXMLFile; } /** * Clear this TR instance to recycle it */ public void clear() { if (TDs != null) { TDs.removeAllItems(); // recycle TDSet (same capacity) } lineInXMLFile = 0; } } libcds-savot-java/src/main/java/cds/savot/model/SavotLink.java0000664000175000017500000001046612724035712024117 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Link element *

* * @author Andre Schaaff */ public final class SavotLink extends MarkupComment implements IDSupport { // content private String content = null; // ID attribute private String id = null; // content-role attribute private String contentRole = null; // content-type attribute private String contentType = null; // title attribute private String title = null; // value attribute private String value = null; // href attribute private String href = null; // gref attribute - removed since 1.1 private String gref = null; // action attribute - extension since 1.1 private String action = null; /** * Constructor */ public SavotLink() { } /** * Set content * * @param content */ public void setContent(final String content) { this.content = content; } /** * Get content * * @return String */ public String getContent() { return str(content); } /** * Set ID attribute * * @param id */ @Override public void setId(final String id) { this.id = id; } /** * Get ID attribute * * @return String */ @Override public String getId() { return str(id); } /** * Set contentRole attribute * * @param contentRole * (query, hints, doc, location) */ public void setContentRole(final String contentRole) { this.contentRole = contentRole; } /** * Get contentRole attribute * * @return String */ public String getContentRole() { return str(contentRole); } /** * Set contentType attribute * * @param contentType */ public void setContentType(final String contentType) { this.contentType = contentType; } /** * Get contentType attribute * * @return String */ public String getContentType() { return str(contentType); } /** * Set title attribute * * @param title */ public void setTitle(final String title) { this.title = title; } /** * Get title attribute * * @return String */ public String getTitle() { return str(title); } /** * Set value attribute * * @param value */ public void setValue(final String value) { this.value = value; } /** * Get value attribute * * @return String */ public String getValue() { return str(value); } /** * Set href attribute * * @param href */ public void setHref(final String href) { this.href = href; } /** * Get href attribute * * @return String */ public String getHref() { return str(href); } /** * Set gref attribute removed in VOTable 1.1 * * @param gref */ public void setGref(final String gref) { this.gref = gref; } /** * Get gref attribute removed in VOTable 1.1 * * @return String */ public String getGref() { return str(gref); } /** * Set action attribute * * @param action */ public void setAction(final String action) { this.action = action; } /** * Get action attribute * * @return String */ public String getAction() { return str(action); } } libcds-savot-java/src/main/java/cds/savot/model/SavotDefinitions.java0000664000175000017500000000406712724035712025475 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Definitions element - removed in VOTable 1.1 *

* * @author Andre Schaaff * @deprecated since VOTable 1.1 */ public final class SavotDefinitions extends MarkupComment { // COOSYS elements private CoosysSet coosys = null; // PARAM elements private ParamSet params = null; /** * Constructor */ public SavotDefinitions() { } /** * Get COOSYS set reference removed in VOTable 1.1 * * @return a CoosysSet reference */ public CoosysSet getCoosys() { if (coosys == null) { coosys = new CoosysSet(); } return coosys; } /** * Set COOSYS set reference removed in VOTable 1.1 * * @param coosys */ public void setCoosys(final CoosysSet coosys) { this.coosys = coosys; } /** * Get PARAM set reference removed in VOTable 1.1 * * @return a ParamSet reference */ public ParamSet getParams() { if (params == null) { params = new ParamSet(); } return params; } /** * Set PARAM set reference removed in VOTable 1.1 * * @param params */ public void setParams(final ParamSet params) { this.params = params; } } libcds-savot-java/src/main/java/cds/savot/model/SimpleTypes.java0000664000175000017500000000706112724035712024460 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* This interface will be used to reduce the memory usage *

* * @author Andre Schaaff */ public interface SimpleTypes { static final String[] DATATYPE = {"boolean", "bit", "unsignedByte", "short", "int", "long", "char", "unicodeChar", "float", "double", "floatComplex", "doubleComplex"}; static final String version = "1.1"; static final byte BOOLEAN = 0; static final byte BIT = 1; static final byte UNSIGNEDBYTE = 2; static final byte SHORT = 3; static final byte INT = 4; static final byte LONG = 5; static final byte CHAR = 6; static final byte UNICODECHAR = 7; static final byte FLOAT = 8; static final byte DOUBLE = 8; static final byte FLOATCOMPLEX = 8; static final byte DOUBLECOMPLEX = 8; static final String[] YESNO = {"yes", "no"}; static final byte YES = 0; static final byte NO = 1; static final String[] RESOURCETYPE = {"results", "meta"}; static final byte RESULTS = 0; static final byte META = 1; static final String[] FIELDTYPE = {"hidden", "no_query", "trigger", "location"}; static final byte HIDDEN = 0; static final byte NO_QUERY = 1; static final byte TRIGGER = 2; static final String[] VALUESTYPE = {"legal", "actual"}; static final byte LEGAL = 0; static final byte ACTUAL = 1; static final String[] LINKCONTENT_ROLE = {"query", "hints", "doc", "location"}; static final byte QUERY = 0; static final byte HINTS = 1; static final byte DOC = 2; static final byte LOCATION = 3; static final String[] STREAMACTUATE = {"onLoad", "onRequest", "other", "none"}; static final byte ONLOAD = 0; static final byte ONREQUEST = 1; static final byte OTHER = 2; static final byte NONE = 3; static final String[] ENCODINGTYPE = {"gzip", "base64", "dynamic", "none"}; static final byte GZIP = 0; static final byte BASE64 = 1; static final byte DYNAMIC = 2; /* defined in STREAMACTUATE final static byte NONE = 3; */ static final String[] COOSYSSYSTEM = {"eq_FK4", "eq_FK5", "ICRS", "ecl_FK4", "ecl_FK5", "galactic", "supergalactic", "xy", "barycentric", "geo_app"}; static final byte EQ_FK4 = 0; static final byte EQ_FK5 = 1; static final byte ICRS = 2; static final byte ECL_FK4 = 2; static final byte ECL_FK5 = 2; static final byte GALACTIC = 2; static final byte SUPERGALACTIC = 2; static final byte XY = 2; static final byte BARYCENTRIC = 2; static final byte GEO_APP = 2; } libcds-savot-java/src/main/java/cds/savot/model/SavotFieldRef.java0000664000175000017500000000426512724035712024702 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Reference to Field element *

* * @author Andre Schaaff */ public final class SavotFieldRef extends MarkupComment implements RefSupport { // ref attribute private String ref = null; // ucd attribute - since VOTable 1.2 private String ucd = null; // utype attribute - since VOTable 1.2 private String utype = null; /** * Constructor */ public SavotFieldRef() { } /** * Set ref attribute * * @param ref */ @Override public void setRef(final String ref) { this.ref = ref; } /** * Get ref attribute * * @return String */ @Override public String getRef() { return str(ref); } /** * Set ucd attribute * * @param ucd * @since VOTable 1.2 */ public void setUcd(final String ucd) { this.ucd = ucd; } /** * Get ucd attribute * * @return String * @since VOTable 1.2 */ public String getUcd() { return str(ucd); } /** * Set utype attribute * * @param utype * @since VOTable 1.2 */ public void setUtype(final String utype) { this.utype = utype; } /** * Get utype attribute * * @return String * @since VOTable 1.2 */ public String getUtype() { return str(utype); } } libcds-savot-java/src/main/java/cds/savot/model/SavotValues.java0000664000175000017500000001015312724035712024452 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Values element *

* * @author Andre Schaaff */ public final class SavotValues extends MarkupComment implements IDSupport, RefSupport { // ID attribute private String id = null; // type attribute private String type = "legal"; // null content private String nul = null; // ref content private String ref = null; // invalid content - deprecated since VOTable 1.1 private String invalid = null; // MIN element private SavotMin min = null; // MAX element private SavotMax max = null; // OPTION element private OptionSet options = null; /** * Constructor */ public SavotValues() { } /** * Set the id attribute * * @param id * String */ @Override public void setId(final String id) { this.id = id; } /** * Get the id attribute * * @return a String */ @Override public String getId() { return str(id); } /** * Set the type attribute * * @param type * String (legal, actual) */ public void setType(final String type) { this.type = type; } /** * Get the type attribute * * @return a String */ public String getType() { return str(type); } /** * Set the null attribute * * @param nul * String */ public void setNull(final String nul) { this.nul = nul; } /** * Get the null attribute * * @return a String */ public String getNull() { return str(nul); } /** * Set the ref attribute * * @param ref * ref */ @Override public void setRef(final String ref) { this.ref = ref; } /** * Get the ref attribute * * @return a String */ @Override public String getRef() { return str(ref); } /** * Set the invalid attribute deprecated since VOTable 1.1 * * @param invalid * String */ public void setInvalid(final String invalid) { this.invalid = invalid; } /** * Get the invalid attribute deprecated since VOTable 1.1 * * @return a String */ public String getInvalid() { return str(invalid); } /** * Set MIN element * * @param min */ public void setMin(final SavotMin min) { this.min = min; } /** * Get MIN element * * @return a SavotMin object */ public SavotMin getMin() { return min; } /** * Set MAX element * * @param max */ public void setMax(final SavotMax max) { this.max = max; } /** * Get MAX element * * @return a SavotMax object */ public SavotMax getMax() { return max; } /** * Get OPTION element set reference * * @return OptionSet object */ public OptionSet getOptions() { if (options == null) { options = new OptionSet(); } return options; } /** * Set OPTION element set reference * * @param options */ public void setOptions(final OptionSet options) { this.options = options; } } libcds-savot-java/src/main/java/cds/savot/model/RefSupport.java0000664000175000017500000000226212724035712024311 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** * This interface defines ref attribute handling (get / set) * @author Laurent Bourges (JMMC) */ public interface RefSupport { /** * Set the ref attribute * * @param ref * ref */ public void setRef(final String ref); /** * Get the ref attribute * * @return a String */ public String getRef(); } libcds-savot-java/src/main/java/cds/savot/model/TableSet.java0000664000175000017500000000202612724035712023701 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of Table elements *

* * @author Andre Schaaff * @see SavotSet */ public final class TableSet extends SavotSet { /** * Constructor */ public TableSet() { } } libcds-savot-java/src/main/java/cds/savot/model/DefinitionsSet.java0000664000175000017500000000211712724035712025126 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of Definitions elements *

* * @author Andre Schaaff * @see SavotSet */ @SuppressWarnings("deprecation") public final class DefinitionsSet extends SavotSet { /** * Constructor */ public DefinitionsSet() { } } libcds-savot-java/src/main/java/cds/savot/model/DescriptionSet.java0000664000175000017500000000204412724035712025135 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of Description elements *

* * @author Andre Schaaff * @see SavotSet */ public final class DescriptionSet extends SavotSet { /** * Constructor */ public DescriptionSet() { } } libcds-savot-java/src/main/java/cds/savot/model/SavotOption.java0000664000175000017500000000426212724035712024467 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Option element *

* * @author Andre Schaaff */ public final class SavotOption extends MarkupComment implements NameSupport { // name attribute private String name = null; // value attribute private String value = null; // OPTION elements private OptionSet options = null; /** * Constructor */ public SavotOption() { } /** * Set name attribute * * @param name */ @Override public void setName(final String name) { this.name = name; } /** * Get name attribute * * @return String */ @Override public String getName() { return str(name); } /** * Set value attribute * * @param value */ public void setValue(final String value) { this.value = value; } /** * Get value attribute * * @return String */ public String getValue() { return str(value); } /** * Get OPTION elements reference * * @return OptionSet */ public OptionSet getOptions() { if (options == null) { options = new OptionSet(); } return options; } /** * Set OPTION elements reference * * @param options */ public void setOptions(final OptionSet options) { this.options = options; } } libcds-savot-java/src/main/java/cds/savot/model/SavotMax.java0000664000175000017500000000176312724035712023747 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* For MAX element *

* * @author Andre Schaaff */ public final class SavotMax extends Boundary { /** * Constructor */ public SavotMax() { } } libcds-savot-java/src/main/java/cds/savot/model/TDSet.java0000664000175000017500000000326312724035712023165 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of TD elements *

* * @author Andre Schaaff * @see SavotSet */ public final class TDSet extends SavotSet { /** * Constructor */ public TDSet() { } /** * Get the content at the TDIndex position of the TDSet * * @param TDIndex * @return String */ public String getContent(final int TDIndex) { final SavotTD td = getItemAt(TDIndex); if (td == null) { return ""; } return td.getContent(); } /** * Get the raw content at the TDIndex position of the TDSet (maybe null) * * @param TDIndex * @return a String or null */ public String getRawContent(final int TDIndex) { final SavotTD td = getItemAt(TDIndex); if (td == null) { return null; } return td.getRawContent(); } } libcds-savot-java/src/main/java/cds/savot/model/ParamSet.java0000664000175000017500000000204712724035712023715 0ustar sladensladenpackage cds.savot.model; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) /** *

* Set of Param elements *

* * @author Andre Schaaff * @see SavotSet */ public final class ParamSet extends SavotSet { /** * Constructor */ public ParamSet() { super(); } } libcds-savot-java/src/main/java/cds/savot/stax/0000775000175000017500000000000012724035712021212 5ustar sladensladenlibcds-savot-java/src/main/java/cds/savot/stax/SavotStaxParser.java0000664000175000017500000030231512724035712025172 0ustar sladensladenpackage cds.savot.stax; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; // Stax parser import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.events.XMLEvent; // VOTable internal data model import cds.savot.common.Markups; import cds.savot.common.SavotStatistics; import cds.savot.common.VOTableTag; import cds.savot.model.SavotBinary; import cds.savot.model.SavotCoosys; import cds.savot.model.SavotData; import cds.savot.model.SavotDefinitions; import cds.savot.model.SavotField; import cds.savot.model.SavotFieldRef; import cds.savot.model.SavotFits; import cds.savot.model.SavotGroup; import cds.savot.model.SavotInfo; import cds.savot.model.SavotLink; import cds.savot.model.SavotMax; import cds.savot.model.SavotMin; import cds.savot.model.SavotOption; import cds.savot.model.SavotParam; import cds.savot.model.SavotParamRef; import cds.savot.model.SavotResource; import cds.savot.model.SavotStream; import cds.savot.model.SavotTD; import cds.savot.model.SavotTR; import cds.savot.model.SavotTable; import cds.savot.model.SavotTableData; import cds.savot.model.SavotVOTable; import cds.savot.model.SavotValues; import cds.savot.model.TDSet; import java.io.Reader; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.zip.GZIPInputStream; import javax.xml.stream.FactoryConfigurationError; import javax.xml.stream.XMLStreamException; /** *

* It has been tested with Java 1.6 Stax implementation * but it is possible to use other Stax implementations *

*

* Designed to use with JSR-173 compliant (Streaming API for XML) *

* *

remark L. Bourgès : equalsIgnoreCase() vs() equals as XML is case sensitive and VOTable specification says that clearly

* * @author Andre Schaaff */ @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"}) public final class SavotStaxParser implements Markups { /** Logger associated to SavotStaxParser classes */ private final static java.util.logging.Logger logger = java.util.logging.Logger.getLogger(SavotStaxParser.class.getName()); /** flag to enable / disable usage of String.trim() on every value (disabled by default) */ private static final boolean doTrimValues = false; /** flag to enable / disable line numbers (TR) */ private static final boolean doLineInfo = false; /** flag to enable / disable statistics */ private static final boolean doStats = false; /* Parsing modes */ /** FULL parsing mode: deprecated and replaced by FULLREAD */ public static final int FULL = 0; /** FULLREAD parsing mode: all in memory */ public static final int FULLREAD = 0; /** SEQUENTIAL parsing mode: deprecated and replaced by RESOURCEREAD */ public static final int SEQUENTIAL = 1; /** RESOURCEREAD parsing mode: resource per resource reading */ public static final int RESOURCEREAD = 1; /** ROWREAD parsing mode: row per row reading */ public static final int ROWREAD = 2; /** default stack capacity = 4 slots */ public final static int DEFAULT_STACK_CAPACITY = 4; /** empty TD instance */ private final static SavotTD EMPTY_TD = new SavotTD(); /** shared XMLInputFactory instance */ private static volatile XMLInputFactory XML_INPUT_FACTORY = null; /* members */ /** statistics dedicated to this parser */ private final SavotStatistics statistics; /** xml stream parser needed for sequential parsing */ private XMLStreamReader xmlParser = null; /** input stream used to close it anyway */ private InputStream inputStream = null; /** reader used to close it anyway */ private Reader reader = null; /** debug mode */ private boolean debugMode = false; // data model objects private SavotVOTable _currentVOTable = new SavotVOTable(); private SavotResource _currentResource = new SavotResource(); // RESOURCEREAD mode only private SavotTR _currentTR = new SavotTR(); // ROWREAD mode only // used for statistics private int resourceCounter = 0; private int tableCounter = 0; private int rowCounter = 0; private int dataCounter = 0; /** used for recursive management */ private final ArrayList fatherTags = new ArrayList(DEFAULT_STACK_CAPACITY); /** used for recursive resources, LIFO mode */ private final ArrayList resourcestack = new ArrayList(DEFAULT_STACK_CAPACITY); /** used for recursive options, LIFO mode */ private final ArrayList optionstack = new ArrayList(DEFAULT_STACK_CAPACITY); /** used for recursives groups, LIFO mode */ private final ArrayList groupstack = new ArrayList(DEFAULT_STACK_CAPACITY); // for multi level resource private int includedResource = 0; // for multi level option private int includedOption = 0; // for multi level group private int includedGroup = 0; private SavotTable currentTable = null; private SavotField currentField = null; private SavotFieldRef currentFieldRef = null; private SavotGroup currentGroup = null; // new since VOTable 1.1 private SavotParam currentParam = null; private SavotParamRef currentParamRef = null; private SavotData currentData = null; private SavotValues currentValues = null; private SavotTableData currentTableData = null; private String currentDescription = null; private SavotLink currentLink = null; private SavotInfo currentInfo = null; private SavotMin currentMin = null; private SavotMax currentMax = null; private SavotOption currentOption = null; private SavotCoosys currentCoosys = null; private SavotDefinitions currentDefinitions = null; private SavotBinary currentBinary = null; private SavotFits currentFits = null; private SavotStream currentStream = null; /** * Map containing object references which have an ID * So it is possible to retrieve such object reference * Used to resolve ID ref * TODO: move such mapping into SavotVOTable (root element) */ private final Map idRefLinks = new HashMap(256); /** * @return XMLInputFactory instance * @throws FactoryConfigurationError if the factory can not be loaded * @throws IllegalArgumentException if the property "javax.xml.stream.isCoalescing" is not supported */ private static synchronized XMLInputFactory getXMLInputFactory() throws FactoryConfigurationError, IllegalArgumentException { if (XML_INPUT_FACTORY == null) { final XMLInputFactory xmlif = XMLInputFactory.newInstance(); xmlif.setProperty("javax.xml.stream.isCoalescing", true); XML_INPUT_FACTORY = xmlif; } return XML_INPUT_FACTORY; } /** * Constructor * * @param file * a file to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final String file, final int mode) throws IOException, XMLStreamException { this(file, mode, false); } /** * Constructor * * @param file * a file to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @param debug * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final String file, final int mode, final boolean debug) throws IOException, XMLStreamException { this(file, mode, debug, new SavotStatistics()); } /** * Constructor * * @param file * a file to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @param debug * @param stats * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final String file, final int mode, final boolean debug, final SavotStatistics stats) throws IOException, XMLStreamException { this.statistics = stats; enableDebug(debug); final boolean compressed = file.endsWith("gz"); // set the input of the parser this.inputStream = getInputStream(new FileInputStream(file), compressed); this.xmlParser = getXMLInputFactory().createXMLStreamReader(this.inputStream, "UTF-8"); /* specify encoding ? */ // fix parsing mode: final int parsingType = parseMode(mode); // parse the stream in the given mode if (parsingType == SavotStaxParser.FULLREAD) { parse(parsingType); } } /** * Constructor * * @param url * url to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final URL url, final int mode) throws IOException, XMLStreamException { this(url, mode, false); } /** * Constructor * * @param url * url to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @param debug * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final URL url, final int mode, final boolean debug) throws IOException, XMLStreamException { this(url, mode, debug, new SavotStatistics()); } /** * Constructor * * @param url url to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @param debug * @param stats * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final URL url, final int mode, final boolean debug, final SavotStatistics stats) throws IOException, XMLStreamException { this.statistics = stats; enableDebug(debug); // TODO: detect compression final boolean compressed = url.getPath().endsWith("gz"); // set the input of the parser this.inputStream = getInputStream(url.openStream(), compressed); this.xmlParser = getXMLInputFactory().createXMLStreamReader(this.inputStream); /* specify encoding ? */ // fix parsing mode: final int parsingType = parseMode(mode); // parse the stream in the given mode if (parsingType == SavotStaxParser.FULLREAD) { parse(parsingType); } } /** * Constructor * * @param instream * stream to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final InputStream instream, final int mode) throws IOException, XMLStreamException { this(instream, mode, false); } /** * Constructor * * @param instream * stream to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @param debug * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final InputStream instream, final int mode, final boolean debug) throws IOException, XMLStreamException { this(instream, mode, debug, new SavotStatistics()); } /** * Constructor * * @param instream stream to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @param debug * @param stats * * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final InputStream instream, final int mode, final boolean debug, final SavotStatistics stats) throws IOException, XMLStreamException { this.statistics = stats; enableDebug(debug); // set the input of the parser this.inputStream = getInputStream(instream, false); this.xmlParser = getXMLInputFactory().createXMLStreamReader(this.inputStream); /* specify encoding ? */ // fix parsing mode: final int parsingType = parseMode(mode); // parse the stream in the given mode if (parsingType == SavotStaxParser.FULLREAD) { parse(parsingType); } } /** * Constructor * * @param reader reader to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final Reader reader, final int mode) throws IOException, XMLStreamException { this(reader, mode, false); } /** * Constructor * * @param reader reader to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @param debug * * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final Reader reader, final int mode, final boolean debug) throws IOException, XMLStreamException { this(reader, mode, debug, new SavotStatistics()); } /** * Constructor * * @param reader reader to parse * @param mode * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @param debug * @param stats * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public SavotStaxParser(final Reader reader, final int mode, final boolean debug, final SavotStatistics stats) throws IOException, XMLStreamException { this.statistics = stats; enableDebug(debug); // set the input of the parser this.reader = reader; this.xmlParser = getXMLInputFactory().createXMLStreamReader(this.reader); // fix parsing mode: final int parsingType = parseMode(mode); // parse the stream in the given mode if (parsingType == SavotStaxParser.FULLREAD) { parse(parsingType); } } /** * Return the parsing type (FULLREAD, RESOURCEREAD or ROWREAD) * @param mode mode (FULL, SEQUENTIAL, FULLREAD, RESOURCEREAD or ROWREAD) * @return parsing type */ private int parseMode(final int mode) { switch (mode) { case ROWREAD: return ROWREAD; case SEQUENTIAL: return RESOURCEREAD; case FULL: default: return FULLREAD; } } /** * Get a buffered input stream or a gzip input stream * @param instream stream to wrap * @param compressed true to indicate to use a gzip input stream * @return input stream * @throws IOException useless */ private InputStream getInputStream(final InputStream instream, final boolean compressed) throws IOException { // best buffer size = 8K because kXmlParser uses also a 8K read buffer final int bufferSize = 8 * 1024; // 8K read buffer final InputStream in; if (compressed) { in = new GZIPInputStream(instream, bufferSize); // 512 bytes by default } else { // no buffer as Stax parser has a 8K read buffer too in = instream; } return in; } /** * Close the input stream if still opened and free the internal parser */ public void close() { if (this.xmlParser != null) { try { this.xmlParser.close(); } catch (XMLStreamException xse) { logger.log(Level.INFO, "Exception SavotStaxParser.close: ", xse); } this.xmlParser = null; } if (this.inputStream != null) { try { this.inputStream.close(); } catch (IOException ioe) { logger.log(Level.INFO, "Exception SavotStaxParser.close: ", ioe); } this.inputStream = null; } if (this.reader != null) { try { this.reader.close(); } catch (IOException ioe) { logger.log(Level.INFO, "Exception SavotStaxParser.close: ", ioe); } this.reader = null; } } /** * Reset of the engine before another parsing * LBO: useless methods ? */ public void reset() { // data model global classes _currentVOTable = new SavotVOTable(); _currentResource = new SavotResource(); rowCounter = 0; resourceCounter = 0; tableCounter = 0; dataCounter = 0; idRefLinks.clear(); // used for recursive resources, LIFO mode resourcestack.clear(); // used for recursive options, LIFO mode optionstack.clear(); // used for recursive groups, LIFO mode groupstack.clear(); } /** * Get the last element from the resourcestack * @return SavotResource */ private SavotResource getResourceStack() { return resourcestack.remove(resourcestack.size() - 1); } /** * Put a resource on the resourcestack * @param resource */ private void putResourceStack(final SavotResource resource) { resourcestack.add(resource); } /** * Get the last element from the optionstack * @return SavotOption */ private SavotOption getOptionStack() { return optionstack.remove(optionstack.size() - 1); } /** * Put an option on the optionstack * @param option */ private void putOptionStack(final SavotOption option) { optionstack.add(option); } /** * Get the last element from the groupstack * @return SavotGroup */ private SavotGroup getGroupStack() { return groupstack.remove(groupstack.size() - 1); } /** * Put a group on the groupstack * @param group */ private void putGroupStack(final SavotGroup group) { groupstack.add(group); } /** * Return last father tag * @return tag or null */ private VOTableTag lastFather() { int size = fatherTags.size(); if (size == 0) { return VOTableTag.UNDEFINED; } return fatherTags.get(size - 1); } /** * Parsing engine * * @param parsingType * FULLREAD (all in memory), RESOURCEREAD (per RESOURCE) or * ROWREAD (per ROW, for small memory size applications) * @throws IOException * @throws javax.xml.stream.XMLStreamException */ public void parse(final int parsingType) throws IOException, XMLStreamException { final XMLStreamReader parser = this.xmlParser; if (parser == null) { return; } if (parsingType != ROWREAD && parsingType != RESOURCEREAD) { // for multi level resource includedResource = 0; // for multi level option includedOption = 0; // for multi level group includedGroup = 0; currentTable = new SavotTable(); currentField = new SavotField(); currentFieldRef = new SavotFieldRef(); currentGroup = new SavotGroup(); // new since VOTable 1.1 currentParam = new SavotParam(); currentParamRef = new SavotParamRef(); currentData = new SavotData(); currentValues = new SavotValues(); currentTableData = new SavotTableData(); currentDescription = ""; currentLink = new SavotLink(); currentInfo = new SavotInfo(); currentMin = new SavotMin(); currentMax = new SavotMax(); currentOption = new SavotOption(); currentCoosys = new SavotCoosys(); currentDefinitions = new SavotDefinitions(); currentBinary = new SavotBinary(); currentFits = new SavotFits(); currentStream = new SavotStream(); } String operation = "UNDEFINED"; VOTableTag tag = null; int rowCount = rowCounter; int dataCount = dataCounter; int lineNumber = 0; try { // local copy for performance: final boolean trace = debugMode; final SavotStatistics stats = statistics; final SavotTD emptyTD = EMPTY_TD; final ArrayList father = fatherTags; // used for RESOURCEREAD parsing boolean resourceComplete = false; // used for ROWREAD parsing boolean TRComplete = false; // local variables for performance: SavotTR currentTR = _currentTR; TDSet tdSet = null; SavotTD currentTD = null; // name from parser.getName and current markup String name, prefix; VOTableTag currentMarkup = VOTableTag.UNDEFINED; String attrName, attrValue; String textValue; int i, counter; if (currentTR != null) { currentTR.clear(); // recycle TR instance (also TDSet) tdSet = currentTR.getTDs(); } // event type int eventType = parser.getEventType(); // System.out.println("ENTREE DANS PARSER"); // while the end of the document is not reach while (eventType != XMLEvent.END_DOCUMENT) { /* custom line number as not provided by Stax parser */ lineNumber++; // treatment depending on event type switch (eventType) { // if a start tag is reach case XMLEvent.START_ELEMENT: operation = "START_ELEMENT"; // the name of the current tag name = parser.getLocalName(); if (name != null) { if (trace) { System.err.println("Name ---> " + name); } // avoid parsing name twice: if (tag == null) { tag = VOTableTag.parseTag(name); } if (trace) { System.err.println(tag + " begin"); } // use most probable tags FIRST (performance) i.e TD / TR first : switch (tag) { case TD: // avoid creating new SavotTD if the value is empty !! currentTD = null; if (doStats) { // for statistics only dataCount++; } break; case TR: stats.iTDLocalReset(); // recycle TR instance: if (currentTR == null) { // create a new row currentTR = new SavotTR(); tdSet = currentTR.getTDs(); } if (doLineInfo) { currentTR.setLineInXMLFile(lineNumber); } break; case DESCRIPTION: break; case VOTABLE: // Get namespaces from Stax: counter = parser.getNamespaceCount(); if (counter != 0) { String uri; for (i = 0; i < parser.getNamespaceCount(); i++) { prefix = parser.getNamespacePrefix(i); uri = parser.getNamespaceURI(i); if (prefix == null) { // xmlns attribute: if (trace) { System.err.println("xmlns='" + uri + "'"); } _currentVOTable.setXmlns(uri); } else { if (trace) { System.err.println("xmlns:" + prefix + "='" + uri + "'"); } // TODO: handle multiple namespaces: if (prefix.equalsIgnoreCase(XSI)) { _currentVOTable.setXmlnsxsi(uri); } } } } counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { if (trace) { System.err.println("VOTABLE attribute:" + parser.getAttributeName(i) + "='" + attrValue + "'"); } attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(VERSION)) { _currentVOTable.setVersion(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { _currentVOTable.setId(attrValue); idRefLinks.put(attrValue, _currentVOTable); } else { prefix = parser.getAttributePrefix(i); if (trace) { System.err.println("VOTABLE attribute:" + prefix + ":" + attrName); } /* TODO: use uri because prefix can be changed ? */ if (XSI.equalsIgnoreCase(prefix)) { if (attrName.equalsIgnoreCase(XSI_NOSCHEMA)) { _currentVOTable.setXsinoschema(attrValue); } else if (attrName.equalsIgnoreCase(XSI_SCHEMA)) { _currentVOTable.setXsischema(attrValue); } } } } } } break; case RESOURCE: stats.iResourcesInc(); if (includedResource > 0) { // inner case (multi level resources) putResourceStack(_currentResource); if (trace) { System.err.println("RESOURCE - included"); } } else if (trace) { System.err.println("RESOURCE - not included"); } includedResource++; // for statistics only resourceCounter++; if (parsingType == FULL || _currentResource == null || parsingType == ROWREAD) { _currentResource = new SavotResource(); } else { _currentResource.init(); } _currentResource.setType(""); // correct the "results" default value counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(NAME)) { _currentResource.setName(attrValue); } else if (attrName.equalsIgnoreCase(TYPE)) { _currentResource.setType(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { _currentResource.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { _currentResource.setId(attrValue); if (parsingType == FULL) { idRefLinks.put(attrValue, _currentResource); } } } } } break; case TABLE: stats.iTablesInc(); currentTable = new SavotTable(); // for statistics only tableCounter++; counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(NAME)) { currentTable.setName(attrValue); if (trace) { System.err.println("TABLE name " + currentTable.getName()); } } else if (attrName.equalsIgnoreCase(UCD)) { // new since VOTable 1.1 currentTable.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { // new since VOTable 1.1 currentTable.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(REF)) { currentTable.setRef(attrValue); } else if (attrName.equalsIgnoreCase(NROWS)) { // new since VOTable 1.1 currentTable.setNrows(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentTable.setId(attrValue); if (parsingType == FULL) { idRefLinks.put(attrValue, currentTable); if (trace) { System.err.println(attrValue); } } } } } } break; case FIELD: currentField = new SavotField(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(UNIT)) { currentField.setUnit(attrValue); } else if (attrName.equalsIgnoreCase(DATATYPE)) { currentField.setDataType(attrValue); } else if (attrName.equalsIgnoreCase(PRECISION)) { currentField.setPrecision(attrValue); } else if (attrName.equalsIgnoreCase(WIDTH)) { currentField.setWidth(attrValue); } else if (attrName.equalsIgnoreCase(REF)) { currentField.setRef(attrValue); } else if (attrName.equalsIgnoreCase(NAME)) { currentField.setName(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentField.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(ARRAYSIZE)) { currentField.setArraySize(attrValue); } else if (attrName.equalsIgnoreCase(TYPE)) { // deprecated since VOTable 1.1 currentField.setType(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentField.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentField.setId(attrValue); idRefLinks.put(attrValue, currentField); } } } } if (trace) { System.err.println("on vient de remplir un FIELD ---> " + currentField.getName()); } break; case FIELDREF: currentFieldRef = new SavotFieldRef(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(REF)) { currentFieldRef.setRef(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentFieldRef.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentFieldRef.setUtype(attrValue); } } } } break; case VALUES: currentValues = new SavotValues(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(TYPE)) { currentValues.setType(attrValue); } else if (attrName.equalsIgnoreCase(NULL)) { currentValues.setNull(attrValue); } else if (attrName.equalsIgnoreCase(INVALID)) { currentValues.setInvalid(attrValue); } else if (attrName.equalsIgnoreCase(REF)) { currentValues.setRef(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentValues.setId(attrValue); idRefLinks.put(attrValue, currentValues); } } } } break; case STREAM: currentStream = new SavotStream(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(TYPE)) { currentStream.setType(attrValue); } else if (attrName.equalsIgnoreCase(HREF)) { currentStream.setHref(attrValue); } else if (attrName.equalsIgnoreCase(ACTUATE)) { currentStream.setActuate(attrValue); } else if (attrName.equalsIgnoreCase(ENCODING)) { currentStream.setEncoding(attrValue); } else if (attrName.equalsIgnoreCase(EXPIRES)) { currentStream.setExpires(attrValue); } else if (attrName.equalsIgnoreCase(RIGHTS)) { currentStream.setRights(attrValue); } } } } break; case DATA: currentData = new SavotData(); break; case BINARY: currentBinary = new SavotBinary(); break; case FITS: currentFits = new SavotFits(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(REF)) { currentFits.setExtnum(attrValue); } } } } break; case TABLEDATA: currentTableData = new SavotTableData(); if (parsingType == ROWREAD) { // if row sequential reading then storage of the metadata if (stats.getITablesLocal() > 1) { // not the first TABLE of the RESOURCE _currentVOTable.getResources().removeItemAt(_currentVOTable.getResources().getItemCount() - 1); } // TODO: use current table directly with a getter ? _currentResource.getTables().addItem(currentTable); _currentVOTable.getResources().addItem(_currentResource); } break; case PARAM: currentParam = new SavotParam(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(UNIT)) { currentParam.setUnit(attrValue); } else if (attrName.equalsIgnoreCase(DATATYPE)) { currentParam.setDataType(attrValue); } else if (attrName.equalsIgnoreCase(PRECISION)) { currentParam.setPrecision(attrValue); } else if (attrName.equalsIgnoreCase(WIDTH)) { currentParam.setWidth(attrValue); } else if (attrName.equalsIgnoreCase(REF)) { currentParam.setRef(attrValue); } else if (attrName.equalsIgnoreCase(NAME)) { currentParam.setName(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentParam.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentParam.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(VALUE)) { currentParam.setValue(attrValue); } else if (attrName.equalsIgnoreCase(XTYPE)) { currentParam.setXtype(attrValue); } else if (attrName.equalsIgnoreCase(ARRAYSIZE)) { currentParam.setArraySize(attrValue); } else if (attrName.equalsIgnoreCase(XTYPE)) { currentParam.setXtype(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentParam.setId(attrValue); idRefLinks.put(attrValue, currentParam); } } } } break; case PARAMREF: currentParamRef = new SavotParamRef(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(REF)) { currentParamRef.setRef(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentParamRef.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentParamRef.setUtype(attrValue); } } } } break; case LINK: currentLink = new SavotLink(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(CONTENTROLE)) { currentLink.setContentRole(attrValue); } else if (attrName.equalsIgnoreCase(CONTENTTYPE)) { currentLink.setContentType(attrValue); } else if (attrName.equalsIgnoreCase(TITLE)) { currentLink.setTitle(attrValue); } else if (attrName.equalsIgnoreCase(VALUE)) { currentLink.setValue(attrValue); } else if (attrName.equalsIgnoreCase(HREF)) { currentLink.setHref(attrValue); } else if (attrName.equalsIgnoreCase(GREF)) { // deprecated since VOTable 1.1 currentLink.setGref(attrValue); } else if (attrName.equalsIgnoreCase(ACTION)) { currentLink.setAction(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentLink.setId(attrValue); idRefLinks.put(attrValue, currentLink); } } } } break; case INFO: currentInfo = new SavotInfo(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(NAME)) { currentInfo.setName(attrValue); } else if (attrName.equalsIgnoreCase(VALUE)) { currentInfo.setValue(attrValue); } else if (attrName.equalsIgnoreCase(XTYPE)) { currentInfo.setXtype(attrValue); } else if (attrName.equalsIgnoreCase(UNIT)) { currentInfo.setUnit(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentInfo.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentInfo.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(REF)) { currentInfo.setRef(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentInfo.setId(attrValue); idRefLinks.put(attrValue, currentInfo); } } } } break; case MIN: currentMin = new SavotMin(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(VALUE)) { currentMin.setValue(attrValue); } else if (attrName.equalsIgnoreCase(INCLUSIVE)) { currentMin.setInclusive(attrValue); } } } } break; case MAX: currentMax = new SavotMax(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(VALUE)) { currentMax.setValue(attrValue); } else if (attrName.equalsIgnoreCase(INCLUSIVE)) { currentMax.setInclusive(attrValue); } } } } break; case OPTION: if (includedOption > 0) { // inner case (multi level options) putOptionStack(currentOption); if (trace) { System.err.println("OPTION - included"); } } else if (trace) { System.err.println("OPTION - not included"); } includedOption++; currentOption = new SavotOption(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(NAME)) { currentOption.setName(attrValue); } else if (attrName.equalsIgnoreCase(VALUE)) { currentOption.setValue(attrValue); } } } } break; case GROUP: // new since VOTable 1.1 stats.iGroupsGlobalInc(); if (includedGroup > 0) { // inner case (multi level groups) putGroupStack(currentGroup); if (trace) { System.err.println("GROUP - included"); } } else if (trace) { System.err.println("GROUP - not included"); } includedGroup++; currentGroup = new SavotGroup(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(REF)) { currentGroup.setRef(attrValue); } else if (attrName.equalsIgnoreCase(NAME)) { currentGroup.setName(attrValue); } else if (attrName.equalsIgnoreCase(UCD)) { currentGroup.setUcd(attrValue); } else if (attrName.equalsIgnoreCase(UTYPE)) { currentGroup.setUtype(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentGroup.setId(attrValue); idRefLinks.put(attrValue, currentGroup); } } } } break; case COOSYS: // deprecated since VOTable 1.2 currentCoosys = new SavotCoosys(); counter = parser.getAttributeCount(); if (counter != 0) { for (i = 0; i < counter; i++) { attrValue = parser.getAttributeValue(i); if (attrValue.length() != 0) { attrName = parser.getAttributeLocalName(i); if (attrName.equalsIgnoreCase(EQUINOX)) { currentCoosys.setEquinox(attrValue); } else if (attrName.equalsIgnoreCase(EPOCH)) { currentCoosys.setEpoch(attrValue); } else if (attrName.equalsIgnoreCase(SYSTEM)) { currentCoosys.setSystem(attrValue); } else if (attrName.equalsIgnoreCase(ID)) { currentCoosys.setId(attrValue); idRefLinks.put(attrValue, currentCoosys); } } } } break; case DEFINITIONS: currentDefinitions = new SavotDefinitions(); break; default: System.err.println("VOTable markup error " + operation + " : " + tag + " at line " + lineNumber); } // Anyway define currentMarkup: currentMarkup = tag; } break; // if an end tag is reach case XMLEvent.END_ELEMENT: operation = "END_ELEMENT"; // the name of the current tag name = parser.getLocalName(); if (name != null) { if (trace) { System.err.println("End ---> " + name); } tag = VOTableTag.parseTag(name); if (trace) { System.err.println(tag + " end"); } // use most probable tags FIRST (performance) i.e TD / TR first : switch (tag) { case TD: stats.iTDInc(); // reduce SavotTD instances: tdSet.addItem((currentTD == null) ? emptyTD : currentTD); break; case TR: stats.iTRInc(); stats.iTDLocalReset(); // trim TDset (reduce memory footprint): tdSet.trim(); if (parsingType != ROWREAD) { // add the row to the table currentTableData.getTRs().addItem(currentTR); currentTR = null; // used so do not recycle it } else { // TR will be used without storage in the model TRComplete = true; // update reference: _currentTR = currentTR; } if (doStats) { // for statistics only rowCount++; } if (trace) { System.err.println("ADD row"); } break; case DESCRIPTION: // DESCRIPTION - several fathers are possible switch (lastFather()) { case VOTABLE: _currentVOTable.setDescription(currentDescription); break; case RESOURCE: _currentResource.setDescription(currentDescription); break; case PARAM: currentParam.setDescription(currentDescription); break; case TABLE: currentTable.setDescription(currentDescription); break; case FIELD: currentField.setDescription(currentDescription); break; case GROUP: currentGroup.setDescription(currentDescription); break; default: } currentDescription = null; break; case TABLE: // avoid duplicates: if (parsingType != ROWREAD) { _currentResource.getTables().addItem(currentTable); if (trace) { System.err.println("TABLE " + currentTable.getName() + " added"); } } break; case FIELD: if (trace) { System.err.println("FIELD from father = " + lastFather()); } if (lastFather() == VOTableTag.TABLE) { currentTable.getFields().addItem(currentField); if (trace) { System.err.println("FIELD from TABLE father = " + father); } } break; case FIELDREF: if (lastFather() == VOTableTag.GROUP) { currentGroup.getFieldsRef().addItem(currentFieldRef); if (trace) { System.err.println("FIELDRef from GROUP father = " + father); } } break; case DATA: currentTable.setData(currentData); break; case RESOURCE: if (includedResource > 1) { final SavotResource tmp = _currentResource; _currentResource = getResourceStack(); _currentResource.getResources().addItem(tmp); } else { if (parsingType == FULL) { _currentVOTable.getResources().addItem(_currentResource); } if (trace) { System.err.println(">>>>>>>> RESOURCE COMPLETED"); } resourceComplete = true; } includedResource--; break; case OPTION: if (includedOption > 1) { final SavotOption tmp = currentOption; currentOption = getOptionStack(); currentOption.getOptions().addItem(tmp); includedOption--; } else { if (lastFather() == VOTableTag.VALUES) { currentValues.getOptions().addItem(currentOption); if (trace) { System.err.println("OPTION from VALUES father = " + father); } includedOption--; } } break; case GROUP: if (includedGroup > 1) { final SavotGroup tmp = currentGroup; currentGroup = getGroupStack(); currentGroup.getGroups().addItem(tmp); includedGroup--; } else { if (lastFather() == VOTableTag.TABLE) { currentTable.getGroups().addItem(currentGroup); if (trace) { System.err.println("GROUP from TABLE father = " + father); } includedGroup--; } } break; case TABLEDATA: stats.iTRLocalReset(); // trim TRset (reduce memory footprint): currentTableData.getTRs().trim(); currentData.setTableData(currentTableData); if (trace) { System.err.println("TABLEDATA " + currentTable.getName() + " added"); } break; case COOSYS: // COOSYS - several fathers are possible switch (lastFather()) { case DEFINITIONS: // deprecated since VOTable 1.1 currentDefinitions.getCoosys().addItem(currentCoosys); if (trace) { System.err.println("COOSYS from DEFINITIONS father = " + father); } break; case RESOURCE: _currentResource.getCoosys().addItem(currentCoosys); if (trace) { System.err.println("COOSYS from RESOURCE father = " + father); } break; case VOTABLE: _currentVOTable.getCoosys().addItem(currentCoosys); if (trace) { System.err.println("COOSYS from VOTABLE father = " + father); } break; default: } break; case PARAM: // PARAM - several fathers are possible switch (lastFather()) { case DEFINITIONS: // deprecated since VOTable 1.1 currentDefinitions.getParams().addItem(currentParam); if (trace) { System.err.println("PARAM from DEFINITIONS father = " + father); } break; case RESOURCE: _currentResource.getParams().addItem(currentParam); if (trace) { System.err.println("PARAM from RESOURCE father = " + father); } break; case TABLE: currentTable.getParams().addItem(currentParam); if (trace) { System.err.println("PARAM from TABLE father = " + father); } break; case GROUP: currentGroup.getParams().addItem(currentParam); if (trace) { System.err.println("PARAM from GROUP father = " + father); } break; case VOTABLE: _currentVOTable.getParams().addItem(currentParam); if (trace) { System.err.println("PARAM from VOTABLE father = " + father); } break; default: } break; case PARAMREF: if (lastFather() == VOTableTag.GROUP) { currentGroup.getParamsRef().addItem(currentParamRef); if (trace) { System.err.println("PARAMRef from GROUP father = " + father); } } break; case LINK: // LINK - several fathers are possible switch (lastFather()) { case RESOURCE: _currentResource.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from RESOURCE father = " + father); } break; case TABLE: currentTable.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from TABLE father = " + father); } break; case FIELD: currentField.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from FIELD father = " + father); } break; case PARAM: currentParam.getLinks().addItem(currentLink); if (trace) { System.err.println("LINK from PARAM father = " + father); } break; default: } break; case VALUES: // VALUES - several fathers are possible switch (lastFather()) { case PARAM: currentParam.setValues(currentValues); if (trace) { System.err.println("VALUES from PARAM father = " + father + " ID : " + currentValues.getId()); } break; case FIELD: currentField.setValues(currentValues); if (trace) { System.err.println("VALUES from FIELD father = " + father + " ID : " + currentValues.getId()); } break; default: } break; case MIN: currentValues.setMin(currentMin); break; case MAX: currentValues.setMax(currentMax); break; case STREAM: // STREAM - several fathers are possible switch (lastFather()) { case BINARY: currentBinary.setStream(currentStream); if (trace) { System.err.println("STREAM from BINARY father = " + father); } break; case FITS: currentFits.setStream(currentStream); if (trace) { System.err.println("STREAM from FITS father = " + father); } break; default: } break; case BINARY: currentData.setBinary(currentBinary); break; case FITS: currentData.setFits(currentFits); break; case INFO: if (trace) { System.err.println("INFO father = " + father); } // INFO - several fathers are possible switch (lastFather()) { case VOTABLE: // since VOTable 1.2 - if RESOURCE then INFO at the end if (_currentVOTable.getResources() != null && _currentVOTable.getResources().getItemCount() != 0) { _currentVOTable.getInfosAtEnd().addItem(currentInfo); } else { _currentVOTable.getInfos().addItem(currentInfo); } if (trace) { System.err.println("INFO from VOTABLE father = " + father); } break; case RESOURCE: // since VOTable 1.2 - if RESOURCE or LINK or TABLE then INFO at the end if ((_currentResource.getResources() != null && _currentResource.getResources().getItemCount() != 0) || (_currentResource.getTables() != null && _currentResource.getTables().getItemCount() != 0) || (_currentResource.getLinks() != null && _currentResource.getLinks().getItemCount() != 0)) { _currentResource.getInfosAtEnd().addItem(currentInfo); } else { _currentResource.getInfos().addItem(currentInfo); } if (trace) { System.err.println("INFO from RESOURCE father = " + father); } break; case TABLE: // since VOTable 1.2 currentTable.getInfosAtEnd().addItem(currentInfo); if (trace) { System.err.println("INFO from TABLE father = " + father); } break; default: } break; case DEFINITIONS: // deprecated since VOTable 1.1 _currentVOTable.setDefinitions(currentDefinitions); break; case VOTABLE: break; default: System.err.println("VOTable markup error " + operation + " : " + tag + " at line " + lineNumber); } // Anyway reset currentMarkup: currentMarkup = VOTableTag.UNDEFINED; } break; case XMLEvent.CHARACTERS: operation = "CHARACTERS"; // avoid parser creating empty String if (!parser.isWhiteSpace()) { // Get new String from parser: textValue = parser.getText(); if (doTrimValues) { textValue = textValue.trim(); } // only store not empty content: if (textValue.length() != 0) { if (trace) { System.err.println(currentMarkup + " : " + textValue); } // use most probable tags FIRST (performance) i.e TD / TR first : switch (currentMarkup) { case TD: // create a new data currentTD = new SavotTD(textValue); break; case DESCRIPTION: currentDescription = textValue; break; case INFO: currentInfo.setContent(textValue); break; case LINK: currentLink.setContent(textValue); break; case COOSYS: currentCoosys.setContent(textValue); break; case MIN: currentMin.setContent(textValue); break; case MAX: currentMax.setContent(textValue); break; case STREAM: currentStream.setContent(textValue); break; default: } } } break; case XMLEvent.START_DOCUMENT: operation = "START_DOCUMENT"; if (trace) { System.err.println("Document start."); } break; default: operation = "UNDEFINED"; if (trace) { System.err.println("Ignoring some other (legacy) event at line : " + lineNumber); } } // reset name and tag: tag = null; // new values from parser: eventType = parser.next(); // treatment depending on event type switch (eventType) { case XMLEvent.START_ELEMENT: operation = "START_ELEMENT"; // the name of the current tag name = parser.getLocalName(); if (trace) { System.err.println("> FATHER, add : " + name); } tag = VOTableTag.parseTag(name); father.add(tag); break; case XMLEvent.END_ELEMENT: operation = "END_ELEMENT"; // the name of the current tag name = parser.getLocalName(); if (name != null) { if (trace) { System.err.println("> FATHER, remove : " + name); } father.remove(father.size() - 1); } else if (trace) { // when a lf or cd is reached System.err.println("> FATHER, case null"); } break; // if an end document is reached: case XMLEvent.END_DOCUMENT: operation = "END_DOCUMENT"; if (trace) { System.err.println("Document end reached!"); } // Anyway: if (parsingType == ROWREAD) { // terminate now (return TR null) to indicate that the complete document is done: _currentTR = null; } // Close the stream anyway: close(); break; default: // do nothing } if (TRComplete && (parsingType == ROWREAD)) { eventType = XMLEvent.END_DOCUMENT; if (trace) { System.err.println(">>>>>>>>>>>>>>> ROWREAD case : TR end"); } } else if (resourceComplete && (parsingType == RESOURCEREAD)) { eventType = XMLEvent.END_DOCUMENT; if (trace) { System.err.println(">>>>>>>>>>>>>>> RESOURCEREAD case : RESOURCE end"); } } } } catch (RuntimeException re) { logger.log(Level.SEVERE, "Exception " + operation + " - TAG (" + tag + ") : parse : " + re + " at line " + lineNumber, re); throw re; } if (doStats) { // update statistics: rowCounter = rowCount; dataCounter = dataCount; } } /** * Get the next Resource (warning : RESOURCEREAD mode only) * * @return a SavotResource (always NULL if other mode) */ public SavotResource getNextResource() { _currentResource = null; try { parse(RESOURCEREAD); } catch (IOException ioe) { logger.log(Level.SEVERE, "Exception getNextResource : ", ioe); _currentResource = null; } catch (Exception e) { logger.log(Level.SEVERE, "Exception getNextResource : ", e); _currentResource = null; } return _currentResource; } /** * Get the next TR (warning : ROWREAD mode only) * * @return a SavotTR (always NULL if other mode) */ public SavotTR getNextTR() { // note: currentTR is not null as it can be recycled try { parse(ROWREAD); } catch (IOException ioe) { logger.log(Level.SEVERE, "Exception getNextTR : ", ioe); _currentTR = null; } catch (Exception e) { logger.log(Level.SEVERE, "Exception getNextTR : ", e); _currentTR = null; } return _currentTR; } /** * Get a reference to V0TABLE object * * @return SavotVOTable */ public SavotVOTable getVOTable() { return _currentVOTable; } /** * Get the number of RESOURCE elements in the document (for statistics) * * @return a long value */ public int getResourceCount() { return resourceCounter; } /** * Get the number of TABLE elements in the document (for statistics) * * @return a long value */ public int getTableCount() { return tableCounter; } /** * Get the number of TR elements in the document (for statistics) * * @return a long value */ public int getTRCount() { return rowCounter; } /** * Get the number of DATA elements in the document (for statistics) * * @return a long value */ public int getDataCount() { return dataCounter; } /** * Get a reference on the Hashtable containing the link between ID and ref * * @return a refernce to the Hashtable */ public Map getIdRefLinks() { return idRefLinks; } /** * Search a RESOURCE corresponding to an ID ref * * @param ref * @return a reference to a SavotResource object */ public SavotResource getResourceFromRef(final String ref) { return (SavotResource) idRefLinks.get(ref); } /** * Search a FIELD corresponding to an ID ref * * @param ref * @return SavotField */ public SavotField getFieldFromRef(final String ref) { return (SavotField) idRefLinks.get(ref); } /** * Search a FIELDref corresponding to an ID ref * * @param ref * @return SavotFieldRef */ public SavotFieldRef getFieldRefFromRef(final String ref) { return (SavotFieldRef) idRefLinks.get(ref); } /** * Search a PARAM corresponding to an ID ref * * @param ref * @return SavotParam */ public SavotParam getParamFromRef(final String ref) { return (SavotParam) idRefLinks.get(ref); } /** * Search a PARAMref corresponding to an ID ref * * @param ref * @return SavotParamRef */ public SavotParamRef getParamRefFromRef(final String ref) { return (SavotParamRef) idRefLinks.get(ref); } /** * Search a TABLE corresponding to an ID ref * * @param ref * @return SavotTable */ public SavotTable getTableFromRef(final String ref) { return (SavotTable) idRefLinks.get(ref); } /** * Search a GROUP corresponding to an ID ref * * @param ref * @return SavotGROUP */ public SavotGroup getGroupFromRef(final String ref) { return (SavotGroup) idRefLinks.get(ref); } /** * Search a RESOURCE corresponding to an ID ref * * @param ref * @return SavotInfo */ public SavotInfo getInfoFromRef(final String ref) { return (SavotInfo) idRefLinks.get(ref); } /** * Search a VALUES corresponding to an ID ref * * @param ref * @return SavotValues */ public SavotValues getValuesFromRef(final String ref) { return (SavotValues) idRefLinks.get(ref); } /** * Search a LINK corresponding to an ID ref * * @param ref * @return SavotLink */ public SavotLink getLinkFromRef(final String ref) { return (SavotLink) idRefLinks.get(ref); } /** * Search a COOSYS corresponding to an ID ref * * @param ref * @return SavotCoosys */ public SavotCoosys getCoosysFromRef(final String ref) { return (SavotCoosys) idRefLinks.get(ref); } /** * Get current VOTable (all resources) * * @return SavotVOTable */ public SavotVOTable getAllResources() { return _currentVOTable; } /** * Enable debug mode * * @param debug * boolean */ public void enableDebug(boolean debug) { debugMode = debug; } /** * Returns the statistics * * @return statistics */ public SavotStatistics getStatistics() { return statistics; } /** * Get Parser Version * * @return String */ public String getVersion() { return SavotStaxParser.SAVOTPARSER; } /** * For test only * */ public void sequentialTester() { SavotResource currentResource; do { currentResource = getNextResource(); } while (currentResource != null); } /** * Main * * @param argv * @throws Exception */ public static void main(String[] argv) throws Exception { if (argv.length == 0) { System.out.println("Usage: java SavotPullParser document"); } else { new SavotStaxParser(argv[0], SavotStaxParser.FULL); } } } libcds-savot-java/src/main/java/cds/savot/writer/0000775000175000017500000000000012724035712021547 5ustar sladensladenlibcds-savot-java/src/main/java/cds/savot/writer/SavotWriter.java0000664000175000017500000013445512724035712024717 0ustar sladensladenpackage cds.savot.writer; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import cds.savot.model.CoosysSet; import cds.savot.model.FieldRefSet; import cds.savot.model.FieldSet; import cds.savot.model.GroupSet; import cds.savot.model.InfoSet; import cds.savot.model.LinkSet; import cds.savot.model.OptionSet; import cds.savot.model.ParamRefSet; import cds.savot.model.ParamSet; import cds.savot.model.ResourceSet; import cds.savot.model.SavotBinary; import cds.savot.model.SavotCoosys; import cds.savot.model.SavotData; import cds.savot.model.SavotField; import cds.savot.model.SavotFieldRef; import cds.savot.model.SavotFits; import cds.savot.model.SavotGroup; import cds.savot.model.SavotInfo; import cds.savot.model.SavotLink; import cds.savot.model.SavotMax; import cds.savot.model.SavotMin; import cds.savot.model.SavotOption; import cds.savot.model.SavotParam; import cds.savot.model.SavotParamRef; import cds.savot.model.SavotResource; import cds.savot.model.SavotStream; import cds.savot.model.SavotTD; import cds.savot.model.SavotTR; import cds.savot.model.SavotTable; import cds.savot.model.SavotTableData; import cds.savot.model.SavotVOTable; import cds.savot.model.SavotValues; import cds.savot.model.TRSet; import cds.savot.model.TableSet; import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.util.List; import java.util.regex.Pattern; import java.util.zip.GZIPOutputStream; /** *

* VOTable document generation from memory *

* * * @author Andre Schaaff * * 6 June 2005 : the user can now write a VOTable document flow step by * step, the previous method is available too (writing of a whole * document) (kickoff 31 May 02) */ @SuppressWarnings({"deprecation", "UseOfSystemOutOrSystemErr"}) public final class SavotWriter { private static final String tdempty = ""; private static final String tdbegin = ""; private static final String tdend = ""; private static final String trbegin = ""; private static final String trend = "\n"; private static final String tabledatabegin = "\n\n"; private static final String tabledataend = ""; private static final String databegin = "\n"; private static final String dataend = "\n"; private static final String tableend = "\n"; private static final String resourceend = "\n"; private static final String descriptionbegin = "\n"; private static final String descriptionend = ""; private static final String groupend = "\n"; private static final String definitionsbegin = "\n"; private static final String definitionsend = "\n"; private static final String paramend = "\n"; private static final String fieldend = "\n"; private static final String linkend = ""; private static final String valuesend = "\n"; private static final String fitsend = "\n"; private static final String binarybegin = "\n"; private static final String binaryend = "\n"; private static final String coosysend = ""; private static final String streamend = "\n"; private static final String minend = ""; private static final String maxend = ""; private static final String optionend = "\n"; /* members */ // default xml top private String top1 = ""; private String styleSheet = ""; private boolean attributeEntities = true; private boolean elementEntities = true; /** buffered writer */ private Writer bw = null; /* Regexp matchers */ private final Pattern patternAMP = Pattern.compile("&"); private final Pattern patternQUOT = Pattern.compile("\""); private final Pattern patternLT = Pattern.compile("<"); private final Pattern patternGT = Pattern.compile(">"); /** * Public constructor */ public SavotWriter() { // nop } /** * Change the default XML document head Default value * * @param top1 * @since VOTable 1.2 * */ public void setTop1(final String top1) { this.top1 = top1; } /** * Set a stylesheet Also possible with setTop1 * * @param href * @since VOTable 1.2 * */ public void setStyleSheet(final String href) { this.styleSheet = href; } /** * Enable or disable Attribute entities mapping * * @param entities * true if Attribute entities are taken into account */ public void enableAttributeEntities(final boolean entities) { this.attributeEntities = entities; } /** * Enable or disable Element entities mapping * * @param entities * true if Element entities are taken into account */ public void enableElementEntities(final boolean entities) { this.elementEntities = entities; } /** * Enable or disable Attribute and Element entities mapping * * @param entities * true if all entities are taken into account */ public void enableEntities(final boolean entities) { this.attributeEntities = entities; this.elementEntities = entities; } /** * Encode special characters to entities * @param src * @return src */ public String encodeAttribute(final String src) { if (attributeEntities) { String out = patternAMP.matcher(src).replaceAll("&"); // Character [&] (xml restriction) out = patternLT.matcher(out).replaceAll("<"); // Character [<] (xml restriction) out = patternGT.matcher(out).replaceAll(">"); // Character [>] (xml restriction) out = patternQUOT.matcher(out).replaceAll("""); // Character ["] (attribute delimiter) return out; } return src; } /** * Encode special characters to entities * @param src * @return src */ public String encodeElement(final String src) { if (elementEntities) { String out = patternAMP.matcher(src).replaceAll("&"); // Character [&] (xml restriction) out = patternLT.matcher(out).replaceAll("<"); // Character [<] (xml restriction) out = patternGT.matcher(out).replaceAll(">"); // Character [>] (xml restriction) return out; } return src; } /** * Generates a VOTable XML document corresponding to the internal model The * result is sent to the standard output * * @param votable * object corresponding to the savot internal model * @throws IOException */ public void generateDocument(final SavotVOTable votable) throws IOException { generateDocument(votable, null, null); } /** * Generates a VOTable XML document corresponding to the internal model * * @param votable * object corresponding to the savot internal model * @param stream * the result is sent to this stream * @throws IOException */ public void generateDocument(final SavotVOTable votable, final OutputStream stream) throws IOException { generateDocument(votable, null, stream); } /** * Generates a VOTable XML document corresponding to the internal model * * @param votable * object corresponding to the savot internal model * @param file * is sent to this file * @throws IOException */ public void generateDocument(final SavotVOTable votable, final String file) throws IOException { generateDocument(votable, file, null); } /** * Generates a VOTable XML document corresponding to the internal model * * @param votable * SavotVOTable * @param file * String * @param stream * OutputStream * @throws IOException */ public void generateDocument(final SavotVOTable votable, final String file, final OutputStream stream) throws IOException { if (file != null) { initStream(file); } else if (stream != null) { initStream(stream); } else { initStream(new PrintWriter(System.out)); } writeDocumentHead(votable); // write COOSYS elements - deprecated since VOTable 1.2 writeCoosys(votable.getCoosys()); // write INFO elements writeInfo(votable.getInfos()); // write PARAM elements writeParam(votable.getParams()); // write GROUP elements - since VOTable 1.2 writeGroup(votable.getGroups()); // RESOURCE writeResource(votable.getResources()); // write INFO elements - since VOTable 1.2 writeInfo(votable.getInfosAtEnd()); writeDocumentEnd(); } /** * Init the Stream for the output * * @param file * String * @throws IOException */ public void initStream(final String file) throws IOException { final boolean compressed = file.endsWith("gz"); final OutputStream outStream = getOutputStream(new FileOutputStream(file), compressed); initStream(new OutputStreamWriter(outStream)); } /** * Init the Stream for the output * * @param stream * OutputStream * @throws IOException */ public void initStream(final OutputStream stream) throws IOException { final OutputStream outStream = getOutputStream(stream, false); initStream(new OutputStreamWriter(outStream)); } /** * Init the Stream for the output using the given Writer * * @param writer writer implementation to write into */ public void initStream(final Writer writer) { bw = new BufferedWriter(writer, 64 * 1024); // 64K text buffer } /** * Get a buffered output stream or a gzip output stream * @param outstream stream to wrap * @param compressed true to indicate to use a gzip input stream * @return input stream * @throws IOException useless */ private OutputStream getOutputStream(final OutputStream outstream, final boolean compressed) throws IOException { final int bufferSize = 64 * 1024; // 64K write buffer final OutputStream out; if (compressed) { out = new GZIPOutputStream(outstream, bufferSize); // 512 by default } else { out = new BufferedOutputStream(outstream, bufferSize); } return out; } /** * Write a comment * * @param comment * String * @throws IOException */ public void writeComment(final String comment) throws IOException { if (comment.length() != 0) { bw.append("\n\n"); } } /** * Write a description * * @param description * @throws IOException * */ public void writeDescription(final String description) throws IOException { if (description.length() != 0) { // DESCRIPTION bw.append(descriptionbegin).append(encodeElement(description)).append(descriptionend); } } /** * Write a VOTable XML head * * @param votable * @throws IOException */ public void writeDocumentHead(final SavotVOTable votable) throws IOException { final Writer w = bw; // local copy w.write(top1); writeComment(votable.getAbove()); // XSL stylesheet if (styleSheet.length() != 0) { w.append("\n"); } w.write("\n'); } else { w.append('"').append(votable.getVersion()).append('"').append('>'); } } else { if (votable.getId().length() != 0) { w.append('"').append("1.2").append('"').append(" ID=\"").append(votable.getId()).append('"').append('>'); } else { w.append('"').append("1.2").append('"').append('>'); } } writeComment(votable.getBelow()); // write DESCRIPTION element writeDescription(votable.getDescription()); // deprecated since VOTable 1.1 if (votable.getDefinitions() != null) { // DEFINITIONS begin w.write(definitionsbegin); // write COOSYS elements writeCoosys(votable.getDefinitions().getCoosys()); // write PARAM elements writeParam(votable.getDefinitions().getParams()); // DEFINITIONS end w.write(definitionsend); } w.flush(); } /** * Write a VOTable XML end * * @throws IOException */ public void writeDocumentEnd() throws IOException { bw.write("\n
\n"); bw.flush(); bw.close(); bw = null; } /** * Write a COOSYS set * * @param coosysSet * @throws IOException */ public void writeCoosys(final CoosysSet coosysSet) throws IOException { final Writer w = bw; // local copy SavotCoosys coosys; for (int i = 0, len = coosysSet.getItemCount(); i < len; i++) { coosys = coosysSet.getItemAt(i); writeComment(coosys.getAbove()); w.write("\n"); writeComment(coosys.getBelow()); w.write(coosys.getContent()); w.write(coosysend); } else { /* no content */ w.write("/>"); writeComment(coosys.getBelow()); } } } /** * Write a PARAM set * * @param params * @throws IOException */ public void writeParam(final ParamSet params) throws IOException { if (params != null) { final Writer w = bw; // local copy SavotParam param; for (int i = 0, len = params.getItemCount(); i < len; i++) { param = params.getItemAt(i); writeComment(param.getAbove()); w.write("\n"); writeComment(param.getBelow()); // write DESCRIPTION element writeDescription(param.getDescription()); // write VALUES element writeValues(param.getValues()); // write LINK elements writeLink(param.getLinks()); // write PARAM end w.write(paramend); } else { w.write("/>"); writeComment(param.getBelow()); } } } } /** * Write a PARAMref set * * @param refparams * @throws IOException */ public void writeParamRef(final ParamRefSet refparams) throws IOException { if (refparams != null) { final Writer w = bw; // local copy SavotParamRef paramref; for (int i = 0, len = refparams.getItemCount(); i < len; i++) { paramref = refparams.getItemAt(i); writeComment(paramref.getAbove()); w.write("\n"); writeComment(paramref.getBelow()); } } } /** * Write a LINK set * * @param linkSet * @throws IOException */ public void writeLink(final LinkSet linkSet) throws IOException { final Writer w = bw; // local copy SavotLink link; for (int i = 0, len = linkSet.getItemCount(); i < len; i++) { link = linkSet.getItemAt(i); writeComment(link.getAbove()); w.write("\n"); writeComment(link.getBelow()); w.write(link.getContent()); w.write(linkend); } else { /* no content */ w.write("/>"); writeComment(link.getBelow()); } } } /** * Write an INFO set * * @param infoSet * @throws IOException */ public void writeInfo(final InfoSet infoSet) throws IOException { if (infoSet != null) { final Writer w = bw; // local copy SavotInfo info; for (int i = 0, len = infoSet.getItemCount(); i < len; i++) { info = infoSet.getItemAt(i); // INFO writeComment(info.getAbove()); w.write("\n"); writeComment(info.getBelow()); w.append(encodeElement(info.getContent())).append(""); } else { // from VOTable 1.2 if (info.getDescription().length() != 0 || info.getValues() != null || info.getLinks().getItemCount() != 0) { w.write(">"); writeComment(info.getBelow()); // write DESCRIPTION element writeDescription(info.getDescription()); // write VALUES element writeValues(info.getValues()); // write LINK elements writeLink(info.getLinks()); w.write(""); } else { w.write("/>"); } } } } } /** * Write a FIELD set * * @param fieldSet * @throws IOException */ public void writeField(final FieldSet fieldSet) throws IOException { final Writer w = bw; // local copy SavotField field; for (int i = 0, len = fieldSet.getItemCount(); i < len; i++) { field = fieldSet.getItemAt(i); writeComment(field.getAbove()); w.write("\n"); writeComment(field.getBelow()); // write DESCRIPTION element writeDescription(field.getDescription()); // write VALUES element writeValues(field.getValues()); // write LINK elements writeLink(field.getLinks()); w.write(fieldend); } else { w.write("/>"); } } } /** * Write a FIELD set * * @param fieldRefSet * @throws IOException */ public void writeFieldRef(final FieldRefSet fieldRefSet) throws IOException { final Writer w = bw; // local copy SavotFieldRef fieldref; for (int i = 0, len = fieldRefSet.getItemCount(); i < len; i++) { fieldref = fieldRefSet.getItemAt(i); writeComment(fieldref.getAbove()); w.write("\n"); } } /** * Write a STREAM element * * @param stream * @throws IOException */ public void writeStream(final SavotStream stream) throws IOException { final Writer w = bw; // local copy writeComment(stream.getAbove()); w.write("\n"); writeComment(stream.getBelow()); if (stream.getContent().length() != 0) { w.write(stream.getContent()); } w.write(streamend); } /** * Write a BINARY element * * @param binary * @throws IOException */ public void writeBinary(final SavotBinary binary) throws IOException { if (binary.getStream() != null) { final Writer w = bw; // local copy writeComment(binary.getAbove()); w.write(binarybegin); writeComment(binary.getBelow()); writeStream(binary.getStream()); w.write(binaryend); } } /** * Write a VALUES element * * @param values * @throws IOException */ public void writeValues(final SavotValues values) throws IOException { if (values != null) { final Writer w = bw; // local copy writeComment(values.getAbove()); w.write("\n"); writeComment(values.getBelow()); // MIN element if (values.getMin() != null) { SavotMin min = values.getMin(); writeMin(min); } // MAX element if (values.getMax() != null) { SavotMax max = values.getMax(); writeMax(max); } // write OPTION elements writeOption(values.getOptions()); w.write(valuesend); } } /** * Write a FITS element * * @param fits * @throws IOException */ public void writeFits(final SavotFits fits) throws IOException { final Writer w = bw; // local copy writeComment(fits.getAbove()); w.write("\n"); writeComment(fits.getBelow()); // STREAM element if (fits.getStream() != null) { // write STREAM element writeStream(fits.getStream()); } w.write(fitsend); } /** * Write a MIN element * * @param min * @throws IOException */ public void writeMin(final SavotMin min) throws IOException { final Writer w = bw; // local copy writeComment(min.getAbove()); w.write("\n"); writeComment(min.getBelow()); w.write(min.getContent()); w.write(minend); } else { /* no content */ w.write("/>"); writeComment(min.getBelow()); } } /** * Write a MAX element * * @param max * @throws IOException */ public void writeMax(final SavotMax max) throws IOException { final Writer w = bw; // local copy writeComment(max.getAbove()); w.write("\n"); writeComment(max.getBelow()); w.write(max.getContent()); w.write(maxend); } else { /* no content */ w.write("/>"); writeComment(max.getBelow()); } } /** * Write an OPTION set * * @param optionSet * @throws IOException */ public void writeOption(final OptionSet optionSet) throws IOException { final Writer w = bw; // local copy SavotOption option; for (int i = 0, len = optionSet.getItemCount(); i < len; i++) { option = optionSet.getItemAt(i); writeComment(option.getAbove()); w.write("\n"); writeComment(option.getBelow()); writeOption(option.getOptions()); w.write(optionend); } else { w.write("/>"); writeComment(option.getBelow()); } } } /** * Write a GROUP set * * @param groupSet * @throws IOException */ public void writeGroup(final GroupSet groupSet) throws IOException { final Writer w = bw; // local copy SavotGroup group; for (int i = 0, len = groupSet.getItemCount(); i < len; i++) { group = groupSet.getItemAt(i); writeComment(group.getAbove()); w.write("\n"); writeComment(group.getBelow()); // write DESCRIPTION element writeDescription(group.getDescription()); // write FIELDref elements writeFieldRef(group.getFieldsRef()); // write PARAMref elements writeParamRef(group.getParamsRef()); // write PARAM elements writeParam(group.getParams()); // write recursive groups writeGroup(group.getGroups()); w.write(groupend); } } /** * Write a TABLE begin * * @param table * SavotTable * @throws IOException */ public void writeTableBegin(final SavotTable table) throws IOException { final Writer w = bw; // local copy writeComment(table.getAbove()); // TABLE w.write("\n"); writeComment(table.getBelow()); // write DESCRIPTION element writeDescription(table.getDescription()); } /** * Write a TABLE end * @throws IOException */ public void writeTableEnd() throws IOException { // bw.write(tableend); } /** * Write a RESOURCE begin * * @param resource * SavotResource * @throws IOException */ public void writeResourceBegin(final SavotResource resource) throws IOException { final Writer w = bw; // local copy // RESOURCE writeComment(resource.getAbove()); w.write("\n"); writeComment(resource.getBelow()); // write DESCRIPTION element writeDescription(resource.getDescription()); } /** * Write a RESOURCE end * @throws IOException */ public void writeResourceEnd() throws IOException { // bw.write(resourceend); } /** * Write a TABLEDATA begin * @throws IOException */ public void writeTableDataBegin() throws IOException { // bw.write(tabledatabegin); } /** * Write a TABLEDATA end * @throws IOException */ public void writeTableDataEnd() throws IOException { // bw.write(tabledataend); } /** * Write a DATA begin * @throws IOException */ public void writeDataBegin() throws IOException { // bw.write(databegin); } /** * Write a DATA end * @throws IOException */ public void writeDataEnd() throws IOException { // bw.write(dataend); } /** * Write a TR * @param tr * @throws IOException */ public void writeTR(final SavotTR tr) throws IOException { final Writer w = bw; // local copy final boolean doEncode = elementEntities; String v; // w.write(trbegin); final List tds = tr.getTDSet().getItems(); SavotTD td; for (int i = 0, tdLen = tds.size(); i < tdLen; i++) { td = tds.get(i); // use raw values to test null values efficiently: v = td.getRawContent(); if (v != null) { // w.write(tdbegin); w.write((doEncode) ? encodeElement(v) : v); // w.write(tdend); } else { w.write(tdempty); } } // w.write(trend); } /** * Write a RESOURCE set * * @param resourceset * ResourceSet * @throws IOException */ public void writeResource(final ResourceSet resourceset) throws IOException { if (resourceset != null) { SavotResource resource; TableSet tableSet; SavotTable table; SavotData data; SavotTableData tableData; TRSet trs; for (int i = 0, len = resourceset.getItemCount(); i < len; i++) { resource = resourceset.getItemAt(i); // writeResourceBegin(resource); // write INFO elements writeInfo(resource.getInfos()); // write COOSYS elements writeCoosys(resource.getCoosys()); // write GROUP elements - since VOTable 1.2 writeGroup(resource.getGroups()); // write PARAM elements writeParam(resource.getParams()); // write LINK elements writeLink(resource.getLinks()); // TABLE elements tableSet = resource.getTables(); for (int j = 0, tableLen = tableSet.getItemCount(); j < tableLen; j++) { table = tableSet.getItemAt(j); // writeTableBegin(table); // write FIELD elements writeField(table.getFields()); // write PARAM elements writeParam(table.getParams()); // write GROUP elements writeGroup(table.getGroups()); // write LINK elements writeLink(table.getLinks()); data = table.getData(); if (data != null) { // writeDataBegin(); tableData = data.getTableData(); if (tableData != null) { // writeTableDataBegin(); trs = tableData.getTRs(); for (int r = 0, trLen = trs.getItemCount(); r < trLen; r++) { // writeTR(trs.getItemAt(r)); } //
writeTableDataEnd(); } // TABLE / DATA / TABLEDATA // write BINARY element if (data.getBinary() != null) { writeBinary(data.getBinary()); } // write FITS element if (data.getFits() != null) { writeFits(data.getFits()); } // writeDataEnd(); } // TABLE / DATA // write INFO (at End) elements - since VOTable 1.2 writeInfo(table.getInfosAtEnd()); // writeTableEnd(); } // TABLE writeResource(resource.getResources()); // write INFO (at End) elements - since VOTable 1.2 writeInfo(resource.getInfosAtEnd()); //
writeResourceEnd(); } } } } libcds-savot-java/src/main/java/cds/savot/tools/0000775000175000017500000000000012724035712021373 5ustar sladensladenlibcds-savot-java/src/main/java/cds/savot/tools/SimpleVoTableTransformer.java0000664000175000017500000002131412724035712027170 0ustar sladensladenpackage cds.savot.tools; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import cds.savot.model.FieldSet; import cds.savot.model.ParamSet; import cds.savot.model.ResourceSet; import cds.savot.model.SavotField; import cds.savot.model.SavotParam; import cds.savot.model.SavotResource; import cds.savot.model.SavotTR; import cds.savot.model.SavotTable; import cds.savot.model.SavotVOTable; import cds.savot.model.TDSet; import cds.savot.stax.SavotStaxParser; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.StringTokenizer; import java.util.logging.Level; import javax.xml.stream.XMLStreamException; /** * Very simple VOTable converter to CSV (comma) or TSV (tab) * but very efficient for large tables (ROWREAD parsing mode: row per row processing) *

* Designed to use with JSR-173 compliant (Streaming Api for XML) *

* * @author bourgesl */ public final class SimpleVoTableTransformer { /** Logger associated to SavotStaxParser classes */ private final static java.util.logging.Logger logger = java.util.logging.Logger.getLogger(SimpleVoTableTransformer.class.getName()); /** table size threshold to show progress information */ private final static int LARGE_TABLE_THRESHOLD = 5000; /** * @return new VOTable converter to CSV format */ public static SimpleVoTableTransformer newCSVTransformer() { return new SimpleVoTableTransformer(','); } /** * @return new VOTable converter to TSV format */ public static SimpleVoTableTransformer newTSVTransformer() { return new SimpleVoTableTransformer('\t'); } /** * Basic TSV transformer * @param argv file paths: [inputFile] [outputFile] */ public static void main(String[] argv) { if (argv.length < 2) { logger.log(Level.SEVERE, "Missing args: {0} !", SimpleVoTableTransformer.class.getName()); return; } final String inputFile = argv[0]; final String outputFile = argv[1]; logger.info(String.format("Transforming '%s' to '%s' ...", inputFile, outputFile)); try { newTSVTransformer().transform(inputFile, outputFile); } catch (Exception e) { logger.log(Level.SEVERE, "fatal error", e); } } /* members */ private final char separator; /** * Public constructor * @param separator any separator character between values */ public SimpleVoTableTransformer(final char separator) { this.separator = separator; } private void transform(final String inFile, final String outputFile) throws IOException, XMLStreamException { final long start = System.nanoTime(); final SavotStaxParser parser = new SavotStaxParser(inFile, SavotStaxParser.ROWREAD); // start parsing document and get first TR if data are present: SavotTR tr = parser.getNextTR(); // Get the VOTable final SavotVOTable savotVoTable = parser.getVOTable(); final ResourceSet resources = savotVoTable.getResources(); SavotResource resource = null; SavotTable table = null; if (resources.getItemCount() == 1) { // VOTable must have 1 resource: resource = resources.getItemAt(0); if (resource.getTables().getItemCount() == 1) { // resource must have ony 1 table: table = resource.getTables().getItemAt(0); } } // check that the votable has one resource / table containing groups and fields: if (resource == null || table == null) { throw new IllegalArgumentException("Incorrect VOTable format (1 mandatory table) !"); } final char sep = separator; final FileOutputStream outputStream = new FileOutputStream(new File(outputFile)); final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream), 64 * 1024); // 64K text buffer try { bw.append("#TABLE: ").append(inFile).write("\n"); writeDescription(bw, table.getDescription()); writeParamSet(bw, table.getParams()); final FieldSet fields = table.getFields(); writeFieldSet(bw, fields); final int tableRows = table.getNrowsValue(); // optional final int rowLen = fields.getItemCount(); int nRow = 0, i, tdLen; String value; TDSet row; // step for progress info for very large tables: final int step = (tableRows > LARGE_TABLE_THRESHOLD) ? tableRows / 20 : Integer.MAX_VALUE; // Iterate on rows: do { if ((nRow % step == 0) && (nRow != 0)) { // progress bar: logger.info(String.format("processing row: %d / %d ...", nRow, tableRows)); } // Get the data corresponding to the current row // note: use TDSet that ensures range checks row = tr.getTDSet(); tdLen = row.getItemCount(); for (i = 0; i < rowLen; i++) { // Add separator if (i != 0) { bw.write(sep); } if (i < tdLen) { // write the value directly: value = row.getRawContent(i); if (value != null) { bw.write(value); } } } bw.write('\n'); nRow++; } while ((tr = parser.getNextTR()) != null); logger.info(String.format("transform: %d rows processed in %.3f ms.", nRow, 1e-6d * (System.nanoTime() - start))); } finally { parser.close(); bw.close(); } } private void writeDescription(final BufferedWriter bw, final String description) throws IOException { if (description.length() != 0) { final StringTokenizer t = new StringTokenizer(description, "\n"); while (t.hasMoreTokens()) { bw.append("# ").append(t.nextToken()).write('\n'); } } } private void writeParamSet(final BufferedWriter bw, final ParamSet paramSet) throws IOException { bw.write("#\n#PARAMS:\n"); final int len = paramSet.getItemCount(); if (len == 0) { return; } SavotParam param; // 1. write param IDs: for (int i = 0; i < len; i++) { param = paramSet.getItemAt(i); bw.append("# ").append(param.getName()).append(" = ").append(param.getValue()).write('\n'); writeDescription(bw, param.getDescription()); } } private void writeFieldSet(final BufferedWriter bw, final FieldSet fieldSet) throws IOException { bw.write("#\n#FIELDS:\n"); final int len = fieldSet.getItemCount(); if (len == 0) { return; } final char sep = separator; SavotField field; // 1. write field IDs: bw.write("# "); for (int i = 0; i < len; i++) { field = fieldSet.getItemAt(i); bw.append(field.getId()).write(sep); } bw.write('\n'); // 2. write field names: for (int i = 0; i < len; i++) { field = fieldSet.getItemAt(i); bw.append(field.getName()).write(sep); } bw.write('\n'); // 3. write field UCD: bw.write("# "); for (int i = 0; i < len; i++) { field = fieldSet.getItemAt(i); bw.append(field.getUcd()).write(sep); } bw.write('\n'); // 4. write field unit: bw.write("# "); for (int i = 0; i < len; i++) { field = fieldSet.getItemAt(i); bw.append(field.getUnit()).write(sep); } bw.write('\n'); } } libcds-savot-java/src/main/java/cds/table/0000775000175000017500000000000012724035712020166 5ustar sladensladenlibcds-savot-java/src/main/java/cds/table/TableModel.java0000664000175000017500000001507412724035712023050 0ustar sladensladenpackage cds.table; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.util.ArrayList; public final class TableModel { // resource properties // private String resource_description; // Astrores // private String resource_name; // Astrores // private String resource_title;// Astrores // table properties private String id; private String description; private String name; // private String title; // private String info; private String[] properties; private ArrayList propertyNames = new ArrayList(); // in each element a table of property private ArrayList propertyValues = new ArrayList(); // in each element a table of property private final ArrayList rows = new ArrayList(); // in each row a table of values ( char [] ) // data about resource /** * */ public TableModel() { } /** * Returns the Table properties (description, resource) * * @return String[] */ public String[] getTableProperties() { return properties; } /** * Sets the Table properties (description, resource) */ public void setTableProperties(String[] properties) { this.properties = properties; } /** * * @param fieldPropertyNames * Vector * @param fieldPropertyValues * Vector */ @SuppressWarnings("unchecked") public void setTableProperties(ArrayList fieldPropertyNames, ArrayList fieldPropertyValues) { this.propertyNames = (ArrayList) fieldPropertyNames.clone(); this.propertyValues = (ArrayList) fieldPropertyValues.clone(); } /** * Returns a property value * * @param tablePropName * String * @return String */ public String getTableProperty(String tablePropName) { return null; } /** * Sets a property value * * @param tablePropName * String * @param value * String */ public void setTableProperty(String tablePropName, String value) { } /** * Returns a row value of the table * * @param index * int * @return String[] */ public String[] getRow(int index) { return (String[]) rows.get(index); } /** * Adds a row to the table * * @param row * String[] */ public void addRow(String[] row) { // System.out.println("une de plus"); rows.add(row); } /** * Adds a row to the table * * @param values * String[] */ public void addRow(ArrayList values) { // System.out.println("une de plus"); rows.add(values.toArray()); } /** * Sets (replace) a row value of the table * * @param index * int * @param values * String[] */ public void setRow(int index, String[] values) { rows.set(index, values); } /** * Returns the value of a cell * * @param row * int * @param col * int * @return String */ public String getValueAt(int row, int col) { String[] localrow; localrow = (String[]) rows.get(row); return localrow[col]; } /** * Sets the value of a cell * * @param row * int * @param col * int * @param value * String */ @SuppressWarnings("unchecked") public void setValueAt(int row, int col, String value) { String[] localrow; localrow = (String[]) rows.get(row); localrow[col] = value; rows.set(row, localrow); } /** * Returns the property name list of a column (VOTable FIELD content for * example (name, ID, unit, description, UCD, ...) * * @param col * int * @return String[] */ public String[] getProperties(int col) { return null; } /** * Sets the property name list of a column (VOTable FIELD content for * example (name, ID, unit, description, UCD, ...) * * @param col * int * @param values * String[] */ public void getProperties(int col, String[] values) { } /** * Returns the value of a given column * * @param col * int * @param propName * String * @return String */ public String getProperties(int col, String propName) { return null; } /** * Returns the value of a given column * * @param col * int * @param propName * String * @param value * String */ public void setProperty(int col, String propName, String value) { } // Le tout serait accessible via une classe TableParser qui pourrait fournir // qq chose comme : // Object creation // TableParser pt = new TableParser(InputStream in); // Lancement de l'analyse // Table table[] = pt.parse(); public void setDescription(String description) { this.description = description; } /** * * @return String */ public String getDescription() { return description; } /** * * @param id * String */ public void setId(String id) { this.id = id; } /** * * @return String */ public String getId() { return id; } /** * * @param name * String */ public void setName(String name) { this.name = name; } /** * * @return String */ public String getName() { return name; } /** * * @return int */ public int getRowCount() { return rows.size(); } } libcds-savot-java/src/test/0000775000175000017500000000000012724035712015440 5ustar sladensladenlibcds-savot-java/src/test/java/0000775000175000017500000000000012724035712016361 5ustar sladensladenlibcds-savot-java/src/test/java/samples/0000775000175000017500000000000012724035712020025 5ustar sladensladenlibcds-savot-java/src/test/java/samples/VotableReader_SavotBinary.java0000664000175000017500000001470512724035712025737 0ustar sladensladenpackage samples; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // //SAVOT 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, version 3 of the License. // //SAVOT 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. // //The GNU General Public License is available in COPYING file //along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import java.io.File; import java.io.PrintStream; import java.util.Date; import cds.savot.binary.DataBinaryReader; import cds.savot.model.FieldSet; import cds.savot.model.SavotBinary; import cds.savot.pull.SavotPullEngine; import cds.savot.stax.SavotStaxParser; /** * Tests the parsing of a "binary" VOTable by Savot + DataBinaryReader. * * The Savot parser used is SavotPullParser in mode SEQUENTIAL. * * @author Gregory Mantelet * @since 21/09/2011 * * @see DataBinaryReader */ public class VotableReader_SavotBinary { SavotStaxParser sb = null; public static final void main(String[] args) throws Exception { VotableReader_SavotBinary parser = new VotableReader_SavotBinary(); parser.parse(VOTABLE_PATH); } // REQUIRED PARAMETERS: private static final String PARENT_DIRECTORY = "/Users/andre/MesDossiers/EnCours/SAVOT/VOTable-Tests-V4.0"; private static final String VOTABLE_PATH = PARENT_DIRECTORY + File.separatorChar + "vizier_votable9.b64"; // OPTIONAL PARAMETERS: /** Path of the file in which decoded data must be written. "null" means System.out. */ private static final String DATA_OUTPUT = null; public VotableReader_SavotBinary() {; } @SuppressWarnings("deprecation") public void parse(final String fileOrUrl) throws Exception { System.out.println("Parsing begin "); Date dates = new Date(); // begin the parsing sb = new SavotStaxParser(fileOrUrl, SavotPullEngine.FULL); // sb = new SavotPullParser(fileOrUrl, SavotPullEngine.FULL); System.out.println("item count : " + sb.getAllResources().getResources().getItemCount()); // SavotStaxParser sb = new SavotStaxParser(fileOrUrl, SavotPullEngine.SEQUENTIAL); /* // get the next resource of the VOTable file SavotResource currentResource = sb.getNextResource(); // while a resource is available while (currentResource != null) { System.out.println("*"); // for each table of this resource for (int i = 0; i < currentResource.getTableCount(); i++) { System.out.println("*** COLUMNS ***"); FieldSet fields = currentResource.getFieldSet(i); for(int j=0 ; j "); for(int j=0; j "); for (int j = 0; j < fields.getItemCount(); j++) { output.print(parser.getCellAsString(j) + " ; "); } output.println(); } } else { System.out.println("no binary"); } } /* for (int i = 0 ; i < sb.getAllResources().getResources().getItemAt(0).getTables().getItemCount(); i++) { System.out.print(sb.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getName() + " avec le nb de Fields : "); System.out.print(sb.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getFields().getItemCount()); System.out.println(" et de nom : " + sb.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getFields().getItemAt(0).getName()); System.out.println(" et de nb de lignes : " + sb.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getData().getTableData().getTRs().getItemCount()); System.out.println(" ayant chacune nb data : " + sb.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getData().getTableData().getTRs().getItemAt(0).getTDs().getItemCount()); // System.out.println(parser.getAllResources().getInfos().getItemAt(0).getContent()); }*/ } } libcds-savot-java/src/test/java/tests/0000775000175000017500000000000012724035712017523 5ustar sladensladenlibcds-savot-java/src/test/java/tests/TestStax.java0000664000175000017500000000634112724035712022151 0ustar sladensladenpackage tests; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.OutputStreamWriter; import java.util.Calendar; import java.util.Date; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.events.XMLEvent; public class TestStax { public static void main(String args[]) throws Exception { XMLInputFactory xmlif = XMLInputFactory.newInstance(); XMLStreamReader xmlsr = xmlif.createXMLStreamReader(new FileReader("/Users/andre/MesDossiers/EnCours/SAVOT/VOTable-Tests-V4.0/vizier_votable1.vot")); int eventType; Date date = new Date(); Long start = date.getTime(); File file = new File("/Users/andre/MesDossiers/EnCours/SAVOT/VOTable-Tests-V4.0/vizier_votable1bis.vot"); FileOutputStream outStream = new FileOutputStream(file); BufferedWriter dataBuffWriter = new BufferedWriter(new OutputStreamWriter(outStream)); while (xmlsr.hasNext()) { eventType = xmlsr.next(); switch (eventType) { case XMLEvent.START_DOCUMENT: //System.out.println(""); break; case XMLEvent.CDATA: //System.out.println(xmlsr.); break; case XMLEvent.COMMENT: //System.out.println("comment --> " + xmlsr.getText()); dataBuffWriter.write(""); break; case XMLEvent.START_ELEMENT: //System.out.print("<" + xmlsr.getLocalName() + ">"); dataBuffWriter.write("<" + xmlsr.getLocalName() + ">"); break; case XMLEvent.ATTRIBUTE: //System.out.println(""); break; case XMLEvent.END_ELEMENT: //System.out.println(""); if (xmlsr.getLocalName().equalsIgnoreCase("TD")) { dataBuffWriter.write(""); } else { dataBuffWriter.write(""); } break; case XMLEvent.CHARACTERS: //String chaine = xmlsr.getText(); //if (!xmlsr.isWhiteSpace()) { // System.out.print(chaine); //} break; case XMLEvent.END_DOCUMENT: //System.out.println(""); break; case XMLEvent.NAMESPACE: //System.out.println(""); break; case XMLEvent.SPACE: //System.out.println(""); break; default: break; } } Date date2 = new Date(); System.out.println((double) (date2.getTime() - start) / 1000); outStream.close(); } } libcds-savot-java/src/test/java/tests/StaxOfInputOutput.java0000664000175000017500000000540712724035712024041 0ustar sladensladenpackage tests; import java.util.Date; import cds.savot.stax.*; import cds.savot.writer.*; public class StaxOfInputOutput { public StaxOfInputOutput() { } @SuppressWarnings("deprecation") public void test(String file) throws Exception { System.out.println("Parsing begin "); Date dates = new Date(); SavotStaxParser parser = new SavotStaxParser(file, SavotStaxParser.FULL, false); Date datef = new Date(); System.out.println("Parsing ends with a duration of " + ((datef.getHours() * 3600 + datef.getMinutes() * 60 + datef.getSeconds()) - (dates.getHours() * 3600 + dates.getMinutes() * 60 + dates.getSeconds())) + " s"); System.out.println("============================== Table =============================="); System.out.println("Il y a " + parser.getAllResources().getResources().getItemAt(0).getTables().getItemCount() + " tables"); for (int i = 0; i < parser.getAllResources().getResources().getItemAt(0).getTables().getItemCount(); i++) { System.out.print(parser.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getName() + " avec le nb de Fields : "); System.out.print(parser.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getFields().getItemCount()); System.out.println(" et de nom : " + parser.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getFields().getItemAt(0).getName()); System.out.println(" et de nb de lignes : " + parser.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getData().getTableData().getTRs().getItemCount()); System.out.println(" ayant chacune nb data : " + parser.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getData().getTableData().getTRs().getItemAt(0).getTDs().getItemCount()); System.out.println(parser.getAllResources().getInfos().getItemAt(0).getContent()); } System.out.println("============================== Table end =============================="); System.out.println("Writing begin"); dates = new Date(); SavotWriter writer = new SavotWriter(); writer.generateDocument(parser.getAllResources(), "/Users/andre/MesDossiers/EnCours/SAVOT/VOTable-Tests-V4.0/vizier_votable3Bis.vot"); datef = new Date(); System.out.println("Writing ends with a duration of " + ((datef.getHours() * 3600 + datef.getMinutes() * 60 + datef.getSeconds()) - (dates.getHours() * 3600 + dates.getMinutes() * 60 + dates.getSeconds())) + " s"); } public static void main(String[] argv) throws Exception { new StaxOfInputOutput().test("/Users/andre/MesDossiers/EnCours/SAVOT/VOTable-Tests-V4.0/vizier_votable3.vot"); System.exit(0); } } libcds-savot-java/src/test/java/tests/InputOutput.java0000664000175000017500000000542512724035712022714 0ustar sladensladenpackage tests; import java.io.IOException; import java.util.Calendar; import java.util.Date; import cds.savot.pull.*; import cds.savot.writer.*; public class InputOutput { /** * * @param file * @throws IOException */ @SuppressWarnings("deprecation") public InputOutput(String file) throws IOException { System.out.println("Parsing begin "); Date dates = new Date(); SavotPullParser parser = new SavotPullParser(file, SavotPullEngine.FULL, false); Date datef = new Date(); System.out.println("Parsing ends with a duration of " + ((datef.getHours() * 3600 + datef.getMinutes() * 60 + datef.getSeconds()) - (dates.getHours() * 3600 + dates.getMinutes() * 60 + dates.getSeconds())) + " s"); System.out.println("============================== Table =============================="); System.out.println("Il y a " + parser.getAllResources().getResources().getItemAt(0).getTables().getItemCount() + " tables"); for (int i = 0; i < parser.getAllResources().getResources().getItemAt(0).getTables().getItemCount(); i++) { System.out.print(parser.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getName() + " avec le nb de Fields : "); System.out.print(parser.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getFields().getItemCount()); System.out.println(" et de nom : " + parser.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getFields().getItemAt(0).getName()); System.out.println(parser.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getData().getTableData().getTRs().getItemCount()); System.out.println(parser.getAllResources().getResources().getItemAt(0).getTables().getItemAt(i).getData().getTableData().getTRs().getItemAt(0).getTDs().getItemCount()); System.out.println(parser.getAllResources().getInfos().getItemAt(0).getContent()); } System.out.println("============================== Table end =============================="); System.out.println("Writing begin"); dates = new Date(); SavotWriter writer = new SavotWriter(); writer.generateDocument(parser.getAllResources(), "/Users/andre/MesDossiers/EnCours/SAVOT/VOTable-Tests-V4.0/vizier_votable7Bis.vot"); datef = new Date(); System.out.println("Writing ends with a duration of " + ((datef.getHours() * 3600 + datef.getMinutes() * 60 + datef.getSeconds()) - (dates.getHours() * 3600 + dates.getMinutes() * 60 + dates.getSeconds())) + " s"); } public static void main(String[] argv) throws IOException { new InputOutput("/Users/andre/MesDossiers/EnCours/SAVOT/VOTable-Tests-V4.0/vizier_votable7.vot"); System.exit(0); } } libcds-savot-java/src/test/java/tests/sax/0000775000175000017500000000000012724035712020316 5ustar sladensladenlibcds-savot-java/src/test/java/tests/sax/AstroresSAXSample.java0000664000175000017500000001152312724035712024503 0ustar sladensladenpackage tests.sax; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // // SAVOT 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, version 3 of the License. // // SAVOT 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. // // The GNU General Public License is available in COPYING file // along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import cds.astrores.sax.AstroresSAXConsumer; import java.util.ArrayList; import java.util.Vector; /** *

* Astrores SAX Sample, this sample shows how to use the Astrores SAX parser *

* @author Andre Schaaff */ public class AstroresSAXSample implements AstroresSAXConsumer { public AstroresSAXSample() { } // attributes is a Vector containing couples of (attribute name, attribute // value) // exemple : (attributes.elementAt(0), attributes.elementAt(1)), // (attributes.elementAt(2), attributes.elementAt(3)), ... // start elements public void startAstrores(@SuppressWarnings("rawtypes") Vector attributes) { } public void startDescription() { } public void startResource(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startTable(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startField(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startFieldref(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startValues(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startStream(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startTR() { System.out.println("Start new ROW"); } public void startTD(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startData() { } public void startBinary() { } public void startFits(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startTableData() { } public void startParam(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startParamRef(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startLink(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startInfo(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startMin(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startMax(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startOption(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startGroup(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startCoosys(@SuppressWarnings("rawtypes") ArrayList attributes) { } public void startDefinitions() { } // end elements @Override public void endAstrores() { } public void endDescription() { } public void endResource() { } public void endTable() { } public void endField() { } public void endFieldref() { } public void endValues() { } public void endStream() { } public void endTR() { } public void endTD() { } public void endData() { } public void endBinary() { } public void endFits() { } public void endTableData() { } public void endParam() { } public void endParamRef() { } public void endLink() { } public void endInfo() { } public void endMin() { } public void endMax() { } public void endOption() { } public void endGroup() { } public void endCoosys() { } public void endDefinitions() { } // TEXT public void textTD(String text) { System.out.println(text); } public void textMin(String text) { } public void textMax(String text) { } public void textCoosys(String text) { } public void textLink(String text) { } public void textOption(String text) { } public void textGroup(String text) { } public void textInfo(String text) { } public void textDescription(String text) { } // document @Override public void startDocument() { } @Override public void endDocument() { } @Override public void startAstrores(@SuppressWarnings("rawtypes") ArrayList attributes) { // TODO Auto-generated method stub } } libcds-savot-java/src/test/java/tests/sax/TestSAX.java0000664000175000017500000000454412724035712022463 0ustar sladensladenpackage tests.sax; //Copyright 2002-2014 - UDS/CNRS //The SAVOT library is distributed under the terms //of the GNU General Public License version 3. // //This file is part of SAVOT. // // SAVOT 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, version 3 of the License. // // SAVOT 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. // // The GNU General Public License is available in COPYING file // along with SAVOT. // //SAVOT - Simple Access to VOTable - Parser // //Author, Co-Author: Andre Schaaff (CDS), Laurent Bourges (JMMC) import cds.astrores.sax.AstroresSAXParser; import java.io.IOException; /** *

* Astrores SAX Parser Tester, a sample designed to show the SAX usage of the * parser *

* @author Andre Schaaff */ public class TestSAX { static long freeMemory = 0; static long freeMemory2 = 0; public static boolean statistics = true; /** * Constructor * * @param file */ public TestSAX(String file) { try { System.err.println("Total memory : " + Runtime.getRuntime().totalMemory()); freeMemory = Runtime.getRuntime().freeMemory(); System.err.println("Free memory (Begin) : " + freeMemory); AstroresSAXSample consumer = new AstroresSAXSample(); @SuppressWarnings("unused") AstroresSAXParser sb = new AstroresSAXParser(consumer, file); } catch (Exception e) { System.err.println("TestSAX : " + e); } ; } /** * Main method * * @param argv * @throws IOException */ public static void main(String[] argv) throws IOException { if (argv.length == 0) { System.err.println("Usage: java TestSAX "); } else { System.err.println("Total memory : " + Runtime.getRuntime().totalMemory()); double freeMemory = Runtime.getRuntime().freeMemory(); System.err.println("Free memory (Begin) : " + freeMemory); new TestSAX(argv[0]); } } } libcds-savot-java/src/test/java/tests/LM19072011.java0000664000175000017500000000223112724035712021521 0ustar sladensladenpackage tests; import cds.savot.model.*; import cds.savot.pull.*; import cds.savot.writer.*; /** Pour tester la methode getType de SavotResource */ public class LM19072011 { public LM19072011() { } public void test(String file) throws Exception { SavotPullParser parser = new SavotPullParser(file, SavotPullEngine.ROWREAD); SavotVOTable voTable = parser.getVOTable(); //SavotTR currentTR = parser.getNextTR(); /* * Current Saada Release only read the first resource */ System.out.println(voTable.getResources().getItemCount()); SavotResource currentResource = (SavotResource) voTable.getResources().getItemAt(0); if (currentResource == null) { throw new Exception("File <" + file + "> is not a VOTable"); } SavotWriter writer = new SavotWriter(); writer.generateDocument(parser.getAllResources(), "/Users/andre/MesDossiers/EnCours/SAVOT/VOTable/LM/bin_result_out.xml"); } public static void main(String[] argv) throws Exception { new LM19072011().test("/Users/andre/MesDossiers/EnCours/SAVOT/VOTable/LM/bin_result.xml"); } }