Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/LICENSE.txt
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/LICENSE.txt	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/LICENSE.txt	(revision 7248)
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ 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 <http://www.gnu.org/licenses/>.
+
+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:
+
+    <program>  Copyright (C) <year>  <name of author>
+    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
+<http://www.gnu.org/licenses/>.
+
+  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
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/pom.xml
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/pom.xml	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/pom.xml	(revision 7248)
@@ -0,0 +1,159 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>eu.clarin.sru.fcs</groupId>
+    <artifactId>fcs-simple-endpoint</artifactId>
+    <version>1.6.0</version>
+    <packaging>jar</packaging>
+    <name>A simple CLARIN FCS endpoint</name>
+    <description>
+        A simple CLARIN FCS endpoint implementation to ease the development of CLARIN FCS endpoints.
+    </description>
+
+    <properties>
+        <!-- project settings -->
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <!-- plug-in settings -->
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+        <!-- versions of common dependencies -->
+        <slf4j.version>1.7.32</slf4j.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.5</version>
+            <type>jar</type>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>eu.clarin.sru</groupId>
+            <artifactId>sru-server</artifactId>
+            <version>1.8.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>eu.clarin.sru.fcs</groupId>
+            <artifactId>fcs-ql</artifactId>
+            <version>0.2-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.codehaus.woodstox</groupId>
+            <artifactId>woodstox-core-lgpl</artifactId>
+            <version>4.4.1</version>
+			<exclusions>
+				<!-- StAX comes with Java 1.6 -->
+				<exclusion>
+					<artifactId>stax-api</artifactId>
+					<groupId>javax.xml.stream</groupId>
+				</exclusion>
+				<exclusion>
+					<artifactId>stax-api</artifactId>
+					<groupId>stax</groupId>
+				</exclusion>
+			</exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>${slf4j.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.slf4j</groupId>
+                <artifactId>slf4j-api</artifactId>
+                <version>${slf4j.version}</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <source>${maven.compiler.source}</source>
+                    <target>${maven.compiler.target}</target>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <version>3.3.1</version>
+                <executions>
+                    <execution>
+                        <id>attach-javadoc</id>
+                        <goals>
+                            <goal>jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-source-plugin</artifactId>
+                <version>3.2.1</version>
+                <executions>
+                    <execution>
+                        <id>attach-source</id>
+                        <goals>
+                            <goal>jar-no-fork</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <repositories>
+        <repository>
+            <id>CLARIN</id>
+            <name>CLARIN Repository</name>
+            <url>https://nexus.clarin.eu/content/repositories/Clarin</url>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+        </repository>
+
+        <repository>
+            <id>CLARIN-snapshot</id>
+            <name>CLARIN Snapshot Repository</name>
+            <url>https://nexus.clarin.eu/content/repositories/clarin-snapshot</url>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+        </repository>
+    </repositories>
+
+    <distributionManagement>
+        <snapshotRepository>
+            <id>CLARIN-Snapshot</id>
+            <url>https://nexus.clarin.eu/content/repositories/clarin-snapshot</url>
+        </snapshotRepository>
+
+        <repository>
+            <id>CLARIN</id>
+            <url>https://nexus.clarin.eu/content/repositories/Clarin</url>
+        </repository>
+    </distributionManagement>
+</project>
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/AdvancedDataViewWriter.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/AdvancedDataViewWriter.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/AdvancedDataViewWriter.java	(revision 7248)
@@ -0,0 +1,375 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+
+/**
+ * Helper class for serializing Advanced Data Views. It can be used for writing
+ * more than once, but it is <em>not thread-save</em>. This helper can also
+ * serialize HITS Data Views.
+ */
+public class AdvancedDataViewWriter {
+    public enum Unit {
+        ITEM, TIMESTAMP
+    }
+    private static final long INITIAL_SEGMENT_ID = 1;
+    public static final int NO_HIGHLIGHT = -1;
+    private static final String ADV_PREFIX = "adv";
+    private static final String ADV_NS =
+            "http://clarin.eu/fcs/dataview/advanced";
+    private static final String ADV_MIME_TYPE =
+            "application/x-clarin-fcs-adv+xml";
+    private static final String HITS_MIME_TYPE =
+            "application/x-clarin-fcs-hits+xml";
+    private static final String FCS_HITS_PREFIX = "hits";
+    private static final String FCS_HITS_NS =
+            "http://clarin.eu/fcs/dataview/hits";
+    private final Unit unit;
+    private final List<Segment> segments = new ArrayList<Segment>();
+    private final Map<URI, List<Span>> layers = new HashMap<URI, List<Span>>();
+    private long nextSegmentId = INITIAL_SEGMENT_ID;
+
+
+    /**
+     * Constructor.
+     *
+     * @param unit
+     *            the unit to be used for span offsets
+     * @see Unit
+     */
+    public AdvancedDataViewWriter(Unit unit) {
+        if (unit == null) {
+            throw new NullPointerException("unit == null");
+        }
+        this.unit = unit;
+    }
+
+
+    /**
+     * Reset the writer for writing a new data view (instance).
+     */
+    public void reset() {
+        nextSegmentId = INITIAL_SEGMENT_ID;
+    }
+
+
+    /**
+     * Add a span.
+     *
+     * @param layerId
+     *            the span's layer id
+     * @param start
+     *            the span's start offset
+     * @param end
+     *            the span's end offset
+     * @param value
+     *            the span's content value or <code>null</code> if none
+     * @throws IllegalArgumentException
+     *             if any argument is invalid
+     */
+    public void addSpan(URI layerId, long start, long end, String value) {
+        addSpan(layerId, start, end, value, null, NO_HIGHLIGHT);
+    }
+
+
+    /**
+     * Add a span.
+     *
+     * @param layerId
+     *            the span's layer id
+     * @param start
+     *            the span's start offset
+     * @param end
+     *            the span's end offset
+     * @param value
+     *            the span's content value or <code>null</code> if none
+     * @param highlight
+     *            the highlight group
+     * @throws IllegalArgumentException
+     *             if any argument is invalid
+     */
+    public void addSpan(URI layerId, long start, long end, String value,
+            int highlight) {
+        addSpan(layerId, start, end, value, null, highlight);
+    }
+
+
+    /**
+     * Add a span.
+     *
+     * @param layerId
+     *            the span's layer id
+     * @param start
+     *            the span's start offset
+     * @param end
+     *            the span's end offset
+     * @param value
+     *            the span's content value or <code>null</code> if none
+     * @param altValue
+     *            the span's alternate value or <code>null</code> if none
+     */
+    public void addSpan(URI layerId, long start, long end, String value,
+            String altValue) {
+        addSpan(layerId, start, end, value, altValue, NO_HIGHLIGHT);
+    }
+
+
+    /**
+     * Add a span.
+     *
+     * @param layerId
+     *            the span's layer id
+     * @param start
+     *            the span's start offset
+     * @param end
+     *            the span's end offset
+     * @param value
+     *            the span's content value or <code>null</code> if none
+     * @param altValue
+     *            the span's alternate value or <code>null</code> if none
+     * @param highlight
+     *            the span's alternate value or <code>null</code> if none
+     * @param highlight
+     *            the highlight group
+     * @throws IllegalArgumentException
+     *             if any argument is invalid
+     */
+    public void addSpan(URI layerId, long start, long end, String value,
+            String altValue, int highlight) {
+        if (layerId == null) {
+            throw new NullPointerException("layerId == null");
+        }
+        if (start < 0) {
+            throw new IllegalArgumentException("start < 0");
+        }
+        if (end < start) {
+            throw new IllegalArgumentException("end < start");
+        }
+        if (highlight <= 0) {
+            highlight = NO_HIGHLIGHT;
+        }
+
+        // find segment or create a new one
+        Segment segment = null;
+        for (Segment seg : segments) {
+            if ((seg.start == start) && (seg.end == end)) {
+                segment = seg;
+                break;
+            }
+        }
+        if (segment == null) {
+            segment = new Segment(nextSegmentId++, start, end);
+            segments.add(segment);
+        }
+
+        // find layer or create a new one
+        List<Span> layer = layers.get(layerId);
+        if (layer == null) {
+            layer = new ArrayList<Span>();
+            layers.put(layerId, layer);
+        }
+
+        // sanity check (better overlap check?)
+        for (Span span : layer) {
+            if (segment.equals(span.segment)) {
+                // FIXME: better exception!
+                throw new IllegalArgumentException(
+                        "segment already exists in layer");
+            }
+        }
+        layer.add(new Span(segment, value, altValue, highlight));
+    }
+
+
+    /**
+     * Write the Advanced Data View to the output stream.
+     *
+     * @param writer
+     *            the writer to write to
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public void writeAdvancedDataView(XMLStreamWriter writer)
+            throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+
+        XMLStreamWriterHelper.writeStartDataView(writer, ADV_MIME_TYPE);
+        writer.setPrefix(ADV_PREFIX, ADV_NS);
+        writer.writeStartElement(ADV_NS, "Advanced");
+        writer.writeNamespace(ADV_PREFIX, ADV_NS);
+        if (unit == Unit.ITEM) {
+            writer.writeAttribute("unit", "item");
+        } else if (unit == Unit.TIMESTAMP) {
+            writer.writeAttribute("unit", "timestamp");
+        }
+
+        // segments
+        writer.writeStartElement(ADV_NS, "Segments");
+        for (Segment segment : segments) {
+            // FIXME: unit translation (long -> time)
+            writer.writeEmptyElement(ADV_NS, "Segment");
+            writer.writeAttribute("id", segment.id);
+            writer.writeAttribute("start", Long.toString(segment.start));
+            writer.writeAttribute("end", Long.toString(segment.end));
+            if (segment.ref != null) {
+                writer.writeAttribute("ref", segment.ref.toString());
+            }
+        }
+        writer.writeEndElement(); // "Segments" element
+
+        // layers
+        writer.writeStartElement(ADV_NS, "Layers");
+        for (Map.Entry<URI, List<Span>> layer : layers.entrySet()) {
+            writer.writeStartElement(ADV_NS, "Layer");
+            writer.writeAttribute("id", layer.getKey().toString());
+            for (Span span : layer.getValue()) {
+                if ((span.value != null) && !span.value.isEmpty()) {
+                    writer.writeStartElement(ADV_NS, "Span");
+                    writer.writeAttribute("ref", span.segment.id);
+                    if (span.highlight != null) {
+                        writer.writeAttribute("highlight", span.highlight);
+                    }
+                    if (span.altValue != null) {
+                        writer.writeAttribute("alt-value", span.altValue);
+                    }
+                    writer.writeCharacters(span.value);
+                    writer.writeEndElement(); // "Span" element
+                } else {
+                    writer.writeEmptyElement(ADV_NS, "Span");
+                    writer.writeAttribute("ref", span.segment.id);
+                    if (span.highlight != null) {
+                        writer.writeAttribute("highlight", span.highlight);
+                    }
+                    if (span.altValue != null) {
+                        writer.writeAttribute("alt-value", span.altValue);
+                    }
+                }
+            }
+            writer.writeEndElement(); // "Layer" element
+        }
+        writer.writeEndElement(); // "Layers" element
+
+        writer.writeEndElement(); // "Advanced" element
+        XMLStreamWriterHelper.writeEndDataView(writer);
+    }
+
+
+    /**
+     * Convenience method to write HITS Data View.
+     *
+     * @param writer
+     *            the writer to write to
+     * @param layerId
+     *            the layer id of the layer to be serialized as HITS Data View
+     * @throws XMLStreamException
+     *             if an error occurred
+     * @throws IllegalArgumentException
+     *             if an invalid layer id was provided
+     */
+    public void writeHitsDataView(XMLStreamWriter writer, URI layerId)
+            throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+        if (layerId == null) {
+            throw new NullPointerException("layerId == null");
+        }
+
+        final List<Span> spans = layers.get(layerId);
+        if (spans == null) {
+            throw new IllegalArgumentException(
+                    "layer with id'" + layerId + "' does not exist");
+        }
+        XMLStreamWriterHelper.writeStartDataView(writer, HITS_MIME_TYPE);
+        writer.setPrefix(FCS_HITS_PREFIX, FCS_HITS_NS);
+        writer.writeStartElement(FCS_HITS_NS, "Result");
+        writer.writeNamespace(FCS_HITS_PREFIX, FCS_HITS_NS);
+        boolean needSpace = false;
+        for (Span span : spans) {
+            if (span.value.length() > 0) {
+                if (needSpace) {
+                    writer.writeCharacters(" ");
+                    needSpace = false;
+                }
+                if (span.highlight != null) {
+                    writer.writeStartElement(FCS_HITS_NS, "Hit");
+                    writer.writeCharacters(span.value);
+                    writer.writeEndElement(); // "Hit" element
+                    needSpace = true;
+                } else {
+                    writer.writeCharacters(span.value);
+                    if (!Character.isWhitespace(
+                            (span.value.charAt(span.value.length() - 1)))) {
+                        needSpace = true;
+                    }
+                }
+            }
+        }
+        writer.writeEndElement(); // "Result" element
+        XMLStreamWriterHelper.writeEndDataView(writer);
+    }
+
+    private static final class Segment {
+        private final String id;
+        private final long start;
+        private final long end;
+        private final URI ref;
+
+
+        private Segment(long id, long start, long end) {
+            this.id = "s" + Long.toHexString(id);
+            this.start = start;
+            this.end = end;
+            /*
+             * FIXME: add API to set reference
+             */
+            this.ref = null;
+        }
+    }
+
+    private static final class Span {
+        private final Segment segment;
+        private final String value;
+        private final String altValue;
+        private final String highlight;
+
+
+        private Span(Segment segment, String value, String altValue,
+                int highlight) {
+            this.segment = segment;
+            this.value = value;
+            this.altValue = altValue;
+            if (highlight != NO_HIGHLIGHT) {
+                this.highlight = "h" + Integer.toHexString(highlight);
+            } else {
+                this.highlight = null;
+            }
+        }
+    }
+
+} // class AdvancedDataViewWriter
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/Constants.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/Constants.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/Constants.java	(revision 7248)
@@ -0,0 +1,66 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs;
+
+import eu.clarin.sru.server.SRUConstants;
+
+/**
+ * Various useful constants for CLARIN-FCS endpoints.
+ */
+public final class Constants {
+
+    /* diagnostics */
+    private static final String FCS_DIAGNOSTIC_URI_PREFIX =
+            "http://clarin.eu/fcs/diagnostic/";
+
+    public static final String FCS_DIAGNOSTIC_PERSISTENT_IDENTIFIER_INVALID =
+            FCS_DIAGNOSTIC_URI_PREFIX + 1;
+    public static final String FCS_DIAGNOSTIC_RESOURCE_TOO_LARGE_CONTEXT_ADJUSTED =
+            FCS_DIAGNOSTIC_URI_PREFIX + 2;
+    public static final String FCS_DIAGNOSTIC_RESOURCE_TOO_LARGE_CANNOT_PERFORM_QUERY =
+            FCS_DIAGNOSTIC_URI_PREFIX + 3;
+    public static final String FCS_DIAGNOSTIC_REQUESTED_DATA_VIEW_INVALID =
+            FCS_DIAGNOSTIC_URI_PREFIX + 4;
+    public static final String FCS_DIAGNOSTIC_GENERAL_QUERY_SYNTAX_ERROR =
+            FCS_DIAGNOSTIC_URI_PREFIX + 10;
+    public static final String FCS_DIAGNOSTIC_GENERAL_QUERY_TOO_COMPLEX_CANNOT_PERFORM_QUERY =
+            FCS_DIAGNOSTIC_URI_PREFIX + 11;
+    public static final String FCS_DIAGNOSTIC_QUERY_WAS_REWRITTEN =
+            FCS_DIAGNOSTIC_URI_PREFIX + 12;
+    public static final String FCS_DIAGNOSTIC_GENERAL_PROCESSING_HINT =
+            FCS_DIAGNOSTIC_URI_PREFIX + 13;
+
+
+    public static final String FCS_QUERY_TYPE_FCS          = "fcs";
+    public static final String FCS_QUERY_TYPE_CQL          =
+            SRUConstants.SRU_QUERY_TYPE_CQL;
+    public static final String FCS_QUERY_TYPE_SEARCH_TERMS =
+            SRUConstants.SRU_QUERY_TYPE_SEARCH_TERMS;
+
+    public static final String FCS_LAYER_TYPE_TEXT = "text";
+    public static final String FCS_LAYER_TYPE_LEMMA = "lemma";
+    public static final String FCS_LAYER_TYPE_POS = "pos";
+    public static final String FCS_LAYER_TYPE_ORTH = "orth";
+    public static final String FCS_LAYER_TYPE_NORM = "norm";
+    public static final String FCS_LAYER_TYPE_PHONETIC = "phonetic";
+
+
+    /* hide constructor */
+    private Constants() {
+    }
+
+} // final class Constants
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/DataView.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/DataView.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/DataView.java	(revision 7248)
@@ -0,0 +1,119 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs;
+
+/**
+ * This class is used to hold information about a data view that is implemented
+ * by the endpoint.
+ */
+public class DataView {
+    /**
+     * Enumeration to indicate the delivery policy of a data view.
+     */
+    public enum DeliveryPolicy {
+        /**
+         * The data view is sent automatically  by the endpoint.
+         */
+        SEND_BY_DEFAULT,
+        /**
+         * A client must explicitly request the endpoint.
+         */
+        NEED_TO_REQUEST;
+    } // enum PayloadDelivery
+    private final String identifier;
+    private final String mimeType;
+    private final DeliveryPolicy deliveryPolicy;
+
+
+    /**
+     * Constructor.
+     *
+     * @param identifier
+     *            a unique short identifier for the data view
+     * @param mimeType
+     *            the MIME type of the data view
+     * @param deliveryPolicy
+     *            the delivery policy for this data view
+     */
+    public DataView(String identifier, String mimeType,
+            DeliveryPolicy deliveryPolicy) {
+        if (identifier == null) {
+            throw new NullPointerException("identifier == null");
+        }
+        if (identifier.isEmpty()) {
+            throw new IllegalArgumentException("identifier is empty");
+        }
+        this.identifier = identifier;
+
+        if (mimeType == null) {
+            throw new NullPointerException("mimeType == null");
+        }
+        if (mimeType.isEmpty()) {
+            throw new IllegalArgumentException("mimeType is empty");
+        }
+        this.mimeType = mimeType;
+
+        if (deliveryPolicy == null) {
+            throw new NullPointerException("deliveryPolicy == null");
+        }
+        this.deliveryPolicy = deliveryPolicy;
+    }
+
+
+    /**
+     * Get the identifier of this data view.
+     *
+     * @return the identifier of the data view
+     */
+    public String getIdentifier() {
+        return identifier;
+    }
+
+
+    /**
+     * Get the MIME type of this data view.
+     *
+     * @return the MIME type of this data view
+     */
+    public String getMimeType() {
+        return mimeType;
+    }
+
+
+    /**
+     * Get the delivery policy for this data view.
+     *
+     * @return the delivery policy of this data view
+     * @see DeliveryPolicy
+     */
+    public DeliveryPolicy getDeliveryPolicy() {
+        return deliveryPolicy;
+    }
+
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append("[");
+        sb.append("identifier=").append(identifier);
+        sb.append(", mimeType=").append(mimeType);
+        sb.append("]");
+        return sb.toString();
+    }
+
+} // class DataView
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/EndpointDescription.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/EndpointDescription.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/EndpointDescription.java	(revision 7248)
@@ -0,0 +1,136 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs;
+
+import java.net.URI;
+import java.util.List;
+
+import eu.clarin.sru.server.SRUException;
+
+
+/**
+ * An interface for abstracting resource endpoint descriptions. This interface
+ * allows you to provide a version of a endpoint description tailored to your
+ * environment.
+ * <p>
+ * The implementation of this interface <em>must</em> be thread-safe.
+ * </p>
+ */
+public interface EndpointDescription {
+    /**
+     * Constant for endpoint description version number for FCS 1.0
+     */
+    public static final int VERSION_1 = 1;
+    /**
+     * Constant for endpoint description version number for FCS 1.0
+     */
+    public static final int VERSION_2 = 2;
+    
+    /**
+     * Constant for a (synthetic) persistent identifier identifying the top-most
+     * (= root) resources in the resource inventory.
+     */
+    public static final String PID_ROOT = "root";
+
+
+    /**
+     * Destroy the resource info inventory. Use this method for any cleanup the
+     * resource info inventory needs to perform upon termination, i.e. closing
+     * of persistent database connections, etc.
+     */
+    public void destroy();
+
+
+    /**
+     * Get the version number of this endpoint description. <br>
+     * Valid version are 1 for FCS 1.0 and 2 fpr FCS 2.0.
+     * 
+     * @return the version number for this endpoint description
+     */
+    public int getVersion();
+
+
+    /**
+     * Check if this endpoint description is in a certain version.
+     * 
+     * @param version
+     *            the version to check for
+     * 
+     * @return <code>true</code>, if version number matches
+     */
+    public boolean isVersion(int version);
+
+    
+    /**
+     * Get the list of capabilities supported by this endpoint. The list
+     * contains the appropriate URIs defined by the CLARIN-FCS specification to
+     * indicate support for certain capabilities. This list <em>must</em> always
+     * contain at least
+     * <code>http://clarin.eu/fcs/capability/basic-search</code> for the
+     * <em>Basic Search</em> capability.
+     * <p>
+     * The implementation of this method <em>must</em> be thread-safe.
+     * </p>
+     *
+     * @return the list of capabilities supported by this endpoint
+     */
+    public List<URI> getCapabilities();
+
+
+    /**
+     * Get the list of data views supported by this endpoint. This list
+     * <em>must</em> always contain an entry for the
+     * <em>Generic Hits (HITS)</em> data view.
+     * <p>
+     * The implementation of this method <em>must</em> be thread-safe.
+     * </p>
+     *
+     * @return the list of data views supported by this endpoint
+     */
+    public List<DataView> getSupportedDataViews();
+
+
+    /**
+     * Get the list of layers that are supported in Advanced Search by this
+     * endpoint.
+     * <p>
+     * The implementation of this method <em>must</em> be thread-safe.
+     * </p>
+     *
+     * @return the list of layers supported in Advanced Search by this endpoint
+     */
+    public List<Layer> getSupportedLayers();
+
+
+    /**
+     * Get a list of all resources sub-ordinate to a resource identified by a
+     * given persistent identifier.
+     * <p>
+     * The implementation of this method <em>must</em> be thread-safe.
+     * </p>
+     *
+     * @param pid
+     *            the persistent identifier of the superior resource
+     * @return a list of all sub-ordinate ResourceInfo or <code>null</code> if
+     *         not applicable
+     * @throws SRUException
+     *             if an error occurred
+     */
+    public List<ResourceInfo> getResourceList(String pid)
+            throws SRUException;
+
+} // interface EndpointDescription
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/FCSQueryParser.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/FCSQueryParser.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/FCSQueryParser.java	(revision 7248)
@@ -0,0 +1,117 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import eu.clarin.sru.server.SRUConstants;
+import eu.clarin.sru.server.SRUDiagnosticList;
+import eu.clarin.sru.server.SRUQuery;
+import eu.clarin.sru.server.SRUQueryBase;
+import eu.clarin.sru.server.SRUQueryParser;
+import eu.clarin.sru.server.SRUVersion;
+import eu.clarin.sru.server.fcs.parser.QueryNode;
+import eu.clarin.sru.server.fcs.parser.QueryParser;
+import eu.clarin.sru.server.fcs.parser.QueryParserException;
+
+public class FCSQueryParser implements SRUQueryParser<QueryNode> {
+    private static final String PARAM_QUERY = "query";
+    private static final List<String> QUERY_PARAMETER_NAMES =
+            Collections.unmodifiableList(Arrays.asList(PARAM_QUERY));
+    private final QueryParser parser = new QueryParser();
+
+
+    @Override
+    public String getQueryType() {
+        return Constants.FCS_QUERY_TYPE_FCS;
+    }
+
+
+    @Override
+    public boolean supportsVersion(SRUVersion version) {
+        if (version == null) {
+            throw new NullPointerException("version == null");
+        }
+        /*
+         * FCS-QL is only supported by SRU 2.0
+         */
+        return version.compareTo(SRUVersion.VERSION_2_0) >= 0;
+    }
+
+
+    @Override
+    public String getQueryTypeDefintion() {
+        return null;
+    }
+
+
+    @Override
+    public List<String> getQueryParameterNames() {
+        return QUERY_PARAMETER_NAMES;
+    }
+
+
+    @Override
+    public SRUQuery<QueryNode> parseQuery(SRUVersion version,
+            Map<String, String> parameters, SRUDiagnosticList diagnostics) {
+        FCSQuery result = null;
+
+        final String rawQuery = parameters.get(PARAM_QUERY);
+        if (rawQuery == null) {
+            diagnostics.addDiagnostic(
+                    SRUConstants.SRU_GENERAL_SYSTEM_ERROR,
+                    null,
+                    "No query passed to query parser.");
+            return null;
+        }
+
+        try {
+            QueryNode parsedQuery = parser.parse(rawQuery);
+            result = new FCSQuery(rawQuery, parsedQuery);
+        } catch (QueryParserException e) {
+            diagnostics.addDiagnostic(
+                    Constants.FCS_DIAGNOSTIC_GENERAL_QUERY_SYNTAX_ERROR,
+                    null,
+                    e.getMessage());
+        } catch (Exception e) {
+            diagnostics.addDiagnostic(
+                    SRUConstants.SRU_GENERAL_SYSTEM_ERROR,
+                    null,
+                    "Unexpected error while parsing query.");
+        }
+        return result;
+    }
+
+
+    public static final class FCSQuery extends SRUQueryBase<QueryNode> {
+
+        private FCSQuery(String rawQuery, QueryNode parsedQuery) {
+            super(rawQuery, parsedQuery);
+        }
+
+
+        @Override
+        public String getQueryType() {
+            return Constants.FCS_QUERY_TYPE_FCS;
+        }
+    }
+
+} // class FCSQueryParser
+
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/Layer.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/Layer.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/Layer.java	(revision 7248)
@@ -0,0 +1,201 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs;
+
+import java.net.URI;
+
+/**
+ * This class is used to information about a Layers that is available by the
+ * Endpoint.
+ */
+public class Layer {
+    /**
+     * The content encoding policy for a Layer
+     */
+    public enum ContentEncoding {
+        /**
+         * Value information is encoded as element content in this layer.
+         */
+        VALUE,
+        /**
+         * No additional value information is encoded for this layer.
+         */
+        EMPTY
+    }
+    private final String id;
+    private final URI resultId;
+    private final String type;
+    private final ContentEncoding encoding;
+    private final String qualifier;
+    private final String altValueInfo;
+    private final URI altValueInfoURI;
+
+
+    /**
+     * Constructor.
+     *
+     * @param id
+     *            the identifier of the layer
+     * @param resultId
+     *            the unique URI that used in the Advanced Data View to refer to
+     *            this layer
+     * @param type
+     *            the type identifier for the layer
+     * @param encoding
+     *            the content encoding for this layer
+     * @param qualifier
+     *            an optional layer qualifier to be used in FCS-QL to refer to
+     *            this layer or <code>null</code>
+     * @param altValueInfo
+     *            an additional information about the layer or <code>null</code>
+     * @param altValueInfoURI
+     *            an additional URI for pointing to more information about the
+     *            layer or <code>null</code>
+     */
+    public Layer(String id, URI resultId, String type,
+            ContentEncoding encoding, String qualifier, String altValueInfo,
+            URI altValueInfoURI) {
+        if (id == null) {
+            throw new NullPointerException("id == null");
+        }
+        this.id = id;
+
+        if (resultId == null) {
+            throw new NullPointerException("resultId == null");
+        }
+        this.resultId = resultId;
+
+        if (type == null) {
+            throw new NullPointerException("type == null");
+        }
+        this.type = type;
+
+        if (encoding == null) {
+            throw new NullPointerException("encoding == null");
+        }
+        this.encoding = encoding;
+
+        this.qualifier       = qualifier;
+        this.altValueInfo    = altValueInfo;
+        this.altValueInfoURI = altValueInfoURI;
+    }
+
+
+    /**
+     * Constructor.
+     *
+     * @param id
+     *            the identifier of the layer
+     * @param resultId
+     *            the unique URI that used in the Advanced Data View to refer to
+     *            this layer
+     * @param type
+     *            the type identifier for the layer
+     */
+    public Layer(String id, URI resultId, String type) {
+        this(id, resultId, type, ContentEncoding.VALUE, null, null, null);
+    }
+
+
+    /**
+     * Get the identifier for the layer.
+     *
+     * @return the identifier for the layer
+     */
+    public String getId() {
+        return id;
+    }
+
+
+    /**
+     * Get the unique URI that used in the Advanced Data View to refer to this
+     * layer
+     *
+     * @return the URI for referring to this layer in the Advanced Data View
+     */
+    public URI getResultId() {
+        return resultId;
+    }
+
+
+    /**
+     * Get the type identifier for this layer.
+     *
+     * @return the type identifier of the layer
+     */
+    public String getType() {
+        return type;
+    }
+
+
+    /**
+     * Get the content encoding mode for this layer.
+     *
+     * @return the content encoding mode
+     */
+    public ContentEncoding getContentEncoding() {
+        return encoding;
+    }
+
+
+    /**
+     * Get the optional layer qualifier to be used in FCS-QL
+     *
+     * @return the layer qualifier or <code>null</code>
+     */
+    public String getQualifier() {
+        return qualifier;
+    }
+
+
+    /**
+     * Get the additional information about this layer.
+     *
+     * @return an additional information about the layer or <code>null</code>
+     */
+    public String getAltValueInfo() {
+        return altValueInfo;
+    }
+
+
+    /**
+     * Get an additional URI for pointing to more information about this layer.
+     *
+     * @return an additional URI for pointing to more information about the
+     *         layer or <code>null</code>
+     */
+    public URI getAltValueInfoURI() {
+        return altValueInfoURI;
+    }
+
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append("[");
+        sb.append("id=").append(id);
+        sb.append(", result-id=").append(resultId);
+        sb.append(", type=").append(type);
+        if (qualifier != null) {
+            sb.append(", qualifier=").append(qualifier);
+        }
+        sb.append("]");
+        return sb.toString();
+    }
+
+} // class Layer
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java	(revision 7248)
@@ -0,0 +1,253 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * This class implements a resource info record, which provides supplementary
+ * information about a resource that is available at the endpoint.
+ *
+ * @see EndpointDescription
+ */
+public class ResourceInfo {
+    private final String pid;
+    private final Map<String, String> title;
+    private final Map<String, String> description;
+    private final String landingPageURI;
+    private final List<String> languages;
+    private final List<DataView> availableDataViews;
+    private final List<Layer> availableLayers;
+    private final List<ResourceInfo> subResources;
+
+
+    /**
+     * Constructor.
+     *
+     * @param pid
+     *            the persistent identifier of the resource
+     * @param title
+     *            the title of the resource represented as a map with pairs of
+     *            language code and title
+     * @param description
+     *            the description of the resource represented as a map with
+     *            pairs of language code and description or <code>null</code> if
+     *            not applicable
+     * @param landingPageURI
+     *            a URI to the landing page of the resource or <code>null</code>
+     *            if not applicable
+     * @param languages
+     *            the languages represented within this resource represented as
+     *            a list of ISO-632-3 three letter language codes
+     * @param availableDataViews
+     *            the list of available data views for this resource
+     * @param availableLayers
+     *            the list if layers available for Advanced Search or
+     *            <code>null</code> if not applicable
+     * @param subResources
+     *            a list of resource sub-ordinate to this resource or
+     *            <code>null</code> if not applicable
+     */
+    public ResourceInfo(String pid, Map<String, String> title,
+            Map<String, String> description, String landingPageURI,
+            List<String> languages, List<DataView> availableDataViews,
+            List<Layer> availableLayers,
+            List<ResourceInfo> subResources) {
+        if (pid == null) {
+            throw new NullPointerException("pid == null");
+        }
+        this.pid = pid;
+
+        if (title == null) {
+            throw new NullPointerException("title == null");
+        }
+        if (title.isEmpty()) {
+            throw new IllegalArgumentException("title is empty");
+        }
+        this.title = Collections.unmodifiableMap(title);
+        if ((description != null) && !description.isEmpty()) {
+            this.description = Collections.unmodifiableMap(description);
+        } else {
+            this.description = null;
+        }
+
+        this.landingPageURI = landingPageURI;
+        if (languages == null) {
+            throw new NullPointerException("languages == null");
+        }
+        if (languages.isEmpty()) {
+            throw new IllegalArgumentException("languages is empty");
+        }
+        this.languages = languages;
+
+        if (availableDataViews == null) {
+            throw new IllegalArgumentException("availableDataViews == null");
+        }
+        this.availableDataViews =
+                Collections.unmodifiableList(availableDataViews);
+
+        if ((availableLayers != null) && !availableDataViews.isEmpty()) {
+            this.availableLayers =
+                    Collections.unmodifiableList(availableLayers);
+        } else {
+            this.availableLayers = null;
+        }
+
+        if ((subResources != null) && !subResources.isEmpty()) {
+            this.subResources = Collections.unmodifiableList(subResources);
+        } else {
+            this.subResources = null;
+        }
+    }
+
+
+    /**
+     * Get the persistent identifier of this resource.
+     *
+     * @return a string representing the persistent identifier of this resource
+     */
+    public String getPid() {
+        return pid;
+    }
+
+
+    /**
+     * Determine, if this resource has sub-resources.
+     *
+     * @return <code>true</code> if the resource has sub-resources,
+     *         <code>false</code> otherwise
+     */
+    public boolean hasSubResources() {
+        return subResources != null;
+    }
+
+
+    /**
+     * Get the title of this resource.
+     *
+     * @return a Map of titles keyed by language code
+     */
+    public Map<String, String> getTitle() {
+        return title;
+    }
+
+
+    /**
+     * Get the title of the resource for a specific language code.
+     *
+     * @param language
+     *            the language code
+     * @return the title for the language code or <code>null</code> if no title
+     *         for this language code exists
+     */
+    public String getTitle(String language) {
+        return title.get(language);
+    }
+
+
+    /**
+     * Get the description of this resource.
+     *
+     * @return a Map of descriptions keyed by language code
+     */
+    public Map<String, String> getDescription() {
+        return description;
+    }
+
+
+    /**
+     * Get the description of the resource for a specific language code.
+     *
+     * @param language
+     *            the language code
+     * @return the description for the language code or <code>null</code> if no
+     *         title for this language code exists
+     */
+    public String getDescription(String language) {
+        return (description != null) ? description.get(language) : null;
+    }
+
+
+    /**
+     * Get the landing page of this resource.
+     *
+     * @return the landing page of this resource or <code>null</code> if not
+     *         applicable
+     */
+    public String getLandingPageURI() {
+        return landingPageURI;
+    }
+
+
+    /**
+     * Get the list of languages in this resource represented as ISO-632-3 three
+     * letter language code.
+     *
+     * @return the list of languages in this resource as a list of ISO-632-3
+     *         three letter language codes.
+     */
+    public List<String> getLanguages() {
+        return languages;
+    }
+
+
+    /**
+     * Get the list of data views that are available for this resource.
+     *
+     * @return the list of data views
+     */
+    public List<DataView> getAvailableDataViews() {
+        return availableDataViews;
+    }
+
+
+    /**
+     * Get the list of layers that are available in Advanced Search for this
+     * resource.
+     *
+     * @return the list of layers or <code>null</code>
+     */
+    public List<Layer> getAvailableLayers() {
+        return availableLayers;
+    }
+
+
+    /**
+     * Check if any layers are available for Advanced Search
+     *
+     * @return <code>true</code> if any layer for Advanced Search is available,
+     *         <code>false</code> otherwise
+     */
+    public boolean hasAvailableLayers() {
+        return (availableLayers != null);
+    }
+
+
+    /**
+     * Get the direct sub-ordinate resources of this resource.
+     *
+     * @return a list of resources or <code>null</code> if this resource has no
+     *         sub-ordinate resources
+     */
+    public List<ResourceInfo> getSubResources() {
+        return subResources;
+    }
+
+} // class ResourceInfo
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java	(revision 7248)
@@ -0,0 +1,434 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.xml.XMLConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.z3950.zing.cql.CQLNode;
+import org.z3950.zing.cql.CQLTermNode;
+import eu.clarin.sru.server.SRUConfigException;
+import eu.clarin.sru.server.SRUConstants;
+import eu.clarin.sru.server.SRUDiagnosticList;
+import eu.clarin.sru.server.SRUException;
+import eu.clarin.sru.server.SRUExplainResult;
+import eu.clarin.sru.server.SRUQueryParserRegistry;
+import eu.clarin.sru.server.SRURequest;
+import eu.clarin.sru.server.SRUScanResultSet;
+import eu.clarin.sru.server.SRUSearchEngine;
+import eu.clarin.sru.server.SRUServer;
+import eu.clarin.sru.server.SRUServerConfig;
+import eu.clarin.sru.server.utils.SRUSearchEngineBase;
+
+
+/**
+ * A base class for implementing a simple search engine to be used as a
+ * CLARIN-FCS endpoint.
+ *
+ */
+public abstract class SimpleEndpointSearchEngineBase extends
+        SRUSearchEngineBase {
+    private static final String X_FCS_ENDPOINT_DESCRIPTION =
+            "x-fcs-endpoint-description";
+    private static final String ED_NS =
+            "http://clarin.eu/fcs/endpoint-description";
+    private static final String ED_PREFIX = "ed";
+    private static final Logger logger =
+            LoggerFactory.getLogger(SimpleEndpointSearchEngineBase.class);
+    protected EndpointDescription endpointDescription;
+
+
+    /**
+     * This method should not be overridden. Perform your custom initialization
+     * in the
+     * {@link #doInit(ServletContext, SRUServerConfig, eu.clarin.sru.server.SRUQueryParserRegistry.Builder, Map)}
+     * method instead.
+     *
+     * @see #doInit(ServletContext, SRUServerConfig,
+     *      eu.clarin.sru.server.SRUQueryParserRegistry.Builder, Map)
+     */
+    @Override
+    public final void init(ServletContext context,
+            SRUServerConfig config,
+            SRUQueryParserRegistry.Builder parserReqistryBuilder,
+            Map<String, String> params) throws SRUConfigException {
+        logger.debug("initializing");
+        super.init(context, config, parserReqistryBuilder, params);
+
+        parserReqistryBuilder.register(new FCSQueryParser());
+
+        logger.debug("initializing search engine implementation");
+        doInit(context, config, parserReqistryBuilder, params);
+
+        logger.debug("initizalizing endpoint description");
+        this.endpointDescription =
+                createEndpointDescription(context, config, params);
+        if (this.endpointDescription == null) {
+            logger.error("SimpleEndpointSearchEngineBase implementation " +
+                    "error: createEndpointDescription() returned null");
+            throw new SRUConfigException("createEndpointDescription() " +
+                    "returned no valid implementation of an EndpointDescription");
+        }
+    }
+
+
+    /**
+     * This method should not be overridden. Perform you custom cleanup in the
+     * {@link #doDestroy()} method.
+     *
+     * @see #doDestroy()
+     */
+    @Override
+    public final void destroy() {
+        logger.debug("performing cleanup of endpoint description");
+        endpointDescription.destroy();
+        logger.debug("performing cleanup of search engine");
+        doDestroy();
+        super.destroy();
+    }
+
+
+    @Override
+    public final SRUExplainResult explain(SRUServerConfig config,
+            SRURequest request, SRUDiagnosticList diagnostics)
+            throws SRUException {
+
+        final boolean provideEndpointDescription =
+                parseBoolean(request.getExtraRequestData(
+                        X_FCS_ENDPOINT_DESCRIPTION));
+
+        if (provideEndpointDescription) {
+            return new SRUExplainResult(diagnostics) {
+                @Override
+                public boolean hasExtraResponseData() {
+                    return provideEndpointDescription;
+                }
+
+
+                @Override
+                public void writeExtraResponseData(XMLStreamWriter writer)
+                        throws XMLStreamException {
+                    writeEndpointDescription(writer);
+                }
+            };
+        } else {
+            return null;
+        }
+    }
+
+
+    /**
+     * Handle a <em>scan</em> operation. This implementation provides support to
+     * CLARIN FCS resource enumeration. If you want to provide custom scan
+     * behavior for a different index, override the
+     * {@link #doScan(SRUServerConfig, SRURequest, SRUDiagnosticList)} method.
+     *
+     * @see #doScan(SRUServerConfig, SRURequest, SRUDiagnosticList)
+     */
+    @Override
+    public final SRUScanResultSet scan(SRUServerConfig config,
+            SRURequest request, SRUDiagnosticList diagnostics)
+            throws SRUException {
+        return doScan(config, request, diagnostics);
+    }
+
+
+    protected abstract EndpointDescription createEndpointDescription(
+            ServletContext context, SRUServerConfig config,
+            Map<String, String> params) throws SRUConfigException;
+
+
+    /**
+     * Initialize the search engine. This initialization should be tailed
+     * towards your environment and needs.
+     *
+     * @param context
+     *            the {@link ServletContext} for the Servlet
+     * @param config
+     *            the {@link SRUServerConfig} object for this search engine
+     * @param queryParsersBuilder
+     *            the {@link SRUQueryParserRegistry.Builder} object to be used
+     *            for this search engine. Use to register additional query
+     *            parsers with the {@link SRUServer}.
+     * @param params
+     *            additional parameters gathered from the Servlet configuration
+     *            and Servlet context.
+     * @throws SRUConfigException
+     *             if an error occurred
+     */
+    protected abstract void doInit(ServletContext context,
+            SRUServerConfig config,
+            SRUQueryParserRegistry.Builder queryParsersBuilder,
+            Map<String, String> params) throws SRUConfigException;
+
+
+    /**
+     * Destroy the search engine. Override this method for any cleanup the
+     * search engine needs to perform upon termination.
+     */
+    protected void doDestroy() {
+    }
+
+
+    /**
+     * Handle a <em>scan</em> operation. The default implementation is a no-op.
+     * Override this method, if you want to provide a custom behavior.
+     *
+     * @param config
+     *            the <code>SRUEndpointConfig</code> object that contains the
+     *            endpoint configuration
+     * @param request
+     *            the <code>SRURequest</code> object that contains the request
+     *            made to the endpoint
+     * @param diagnostics
+     *            the <code>SRUDiagnosticList</code> object for storing
+     *            non-fatal diagnostics
+     * @return a <code>SRUScanResultSet</code> object or <code>null</code> if
+     *         this operation is not supported by this search engine
+     * @throws SRUException
+     *             if an fatal error occurred
+     * @see SRUSearchEngine#scan(SRUServerConfig, SRURequest, SRUDiagnosticList)
+     * @deprecated override
+     *             {@link #scan(SRUServerConfig, SRURequest, SRUDiagnosticList)}
+     */
+    @Deprecated
+    protected SRUScanResultSet doScan(SRUServerConfig config,
+            SRURequest request, SRUDiagnosticList diagnostics)
+            throws SRUException {
+        final CQLNode scanClause = request.getScanClause();
+        if (scanClause instanceof CQLTermNode) {
+            final CQLTermNode root = (CQLTermNode) scanClause;
+            final String index = root.getIndex();
+            throw new SRUException(SRUConstants.SRU_UNSUPPORTED_INDEX, index,
+                    "scan operation on index '" + index + "' is not supported");
+        } else {
+            throw new SRUException(SRUConstants.SRU_QUERY_FEATURE_UNSUPPORTED,
+                    "Scan clause too complex.");
+        }
+    }
+
+
+    /**
+     * Convince method for parsing a string to boolean. Values <code>1</code>,
+     * <code>true</code>, <code>yes</code> yield a <em>true</em> boolean value
+     * as a result, all others (including <code>null</code>) a <em>false</em>
+     * boolean value.
+     *
+     * @param value
+     *            the string to parse
+     * @return <code>true</code> if the supplied string was considered something
+     *         representing a <em>true</em> boolean value, <code>false</code>
+     *         otherwise
+     */
+    protected static boolean parseBoolean(String value) {
+        if (value != null) {
+            return value.equals("1") || Boolean.parseBoolean(value);
+        }
+        return false;
+    }
+
+
+    private void writeEndpointDescription(XMLStreamWriter writer)
+            throws XMLStreamException {
+        writer.setPrefix(ED_PREFIX, ED_NS);
+        writer.writeStartElement(ED_NS, "EndpointDescription");
+        writer.writeNamespace(ED_PREFIX, ED_NS);
+        writer.writeAttribute("version",
+                Integer.toString(endpointDescription.getVersion()));
+
+        // Capabilities
+        writer.writeStartElement(ED_NS, "Capabilities");
+        for (URI capability : endpointDescription.getCapabilities()) {
+            writer.writeStartElement(ED_NS, "Capability");
+            writer.writeCharacters(capability.toString());
+            writer.writeEndElement(); // "Capability" element
+        }
+        writer.writeEndElement(); // "Capabilities" element
+
+        // SupportedDataViews
+        writer.writeStartElement(ED_NS, "SupportedDataViews");
+        for (DataView dataView : endpointDescription.getSupportedDataViews()) {
+            writer.writeStartElement(ED_NS, "SupportedDataView");
+            writer.writeAttribute("id", dataView.getIdentifier());
+            String s;
+            switch (dataView.getDeliveryPolicy()) {
+            case SEND_BY_DEFAULT:
+                s = "send-by-default";
+                break;
+            case NEED_TO_REQUEST:
+                s = "need-to-request";
+                break;
+            default:
+                throw new XMLStreamException(
+                        "invalid value for payload delivery policy: " +
+                                dataView.getDeliveryPolicy());
+            } // switch
+            writer.writeAttribute("delivery-policy", s);
+            writer.writeCharacters(dataView.getMimeType());
+            writer.writeEndElement(); // "SupportedDataView" element
+        }
+        writer.writeEndElement(); // "SupportedDataViews" element
+
+        if (endpointDescription.isVersion(EndpointDescription.VERSION_2)) {
+            // SupportedLayers
+            final List<Layer> layers = endpointDescription.getSupportedLayers();
+            if (layers != null) {
+                writer.writeStartElement(ED_NS, "SupportedLayers");
+                for (Layer layer : layers) {
+                    writer.writeStartElement(ED_NS, "SupportedLayer");
+                    writer.writeAttribute("id", layer.getId());
+                    writer.writeAttribute("result-id",
+                            layer.getResultId().toString());
+                    if (layer.getContentEncoding() ==
+                            Layer.ContentEncoding.EMPTY) {
+                        writer.writeAttribute("type", "empty");
+                    }
+                    if (layer.getQualifier() != null) {
+                        writer.writeAttribute("qualifier",
+                                layer.getQualifier());
+                    }
+                    if (layer.getAltValueInfo() != null) {
+                        writer.writeAttribute("alt-value-info",
+                                layer.getAltValueInfo());
+                        if (layer.getAltValueInfoURI() != null) {
+                            writer.writeAttribute("alt-value-info-uri",
+                                    layer.getAltValueInfoURI().toString());
+                        }
+                    }
+                    writer.writeCharacters(layer.getType());
+                    writer.writeEndElement(); // "SupportedLayer" element
+                }
+                writer.writeEndElement(); // "SupportedLayers" element
+            }
+        }
+
+        // Resources
+        try {
+            List<ResourceInfo> resources =
+                    endpointDescription.getResourceList(
+                            EndpointDescription.PID_ROOT);
+            writeResourceInfos(writer, resources);
+        } catch (SRUException e) {
+            throw new XMLStreamException(
+                    "error retriving top-level resources", e);
+        }
+        writer.writeEndElement(); // "EndpointDescription" element
+    }
+
+
+    private void writeResourceInfos(XMLStreamWriter writer,
+            List<ResourceInfo> resources) throws XMLStreamException {
+        if (resources == null) {
+            throw new NullPointerException("resources == null");
+        }
+        if (!resources.isEmpty()) {
+            writer.writeStartElement(ED_NS, "Resources");
+
+            for (ResourceInfo resource : resources) {
+                writer.writeStartElement(ED_NS, "Resource");
+                writer.writeAttribute("pid", resource.getPid());
+
+                // title
+                final Map<String, String> title = resource.getTitle();
+                for (Map.Entry<String, String> i : title.entrySet()) {
+                    writer.setPrefix(XMLConstants.XML_NS_PREFIX,
+                            XMLConstants.XML_NS_URI);
+                    writer.writeStartElement(ED_NS, "Title");
+                    writer.writeAttribute(XMLConstants.XML_NS_URI, "lang", i.getKey());
+                    writer.writeCharacters(i.getValue());
+                    writer.writeEndElement(); // "title" element
+                }
+
+                // description
+                final Map<String, String> description = resource.getDescription();
+                if (description != null) {
+                    for (Map.Entry<String, String> i : description.entrySet()) {
+                        writer.writeStartElement(ED_NS, "Description");
+                        writer.writeAttribute(XMLConstants.XML_NS_URI, "lang",
+                                i.getKey());
+                        writer.writeCharacters(i.getValue());
+                        writer.writeEndElement(); // "Description" element
+                    }
+                }
+
+                // landing page
+                final String landingPageURI = resource.getLandingPageURI();
+                if (landingPageURI != null) {
+                    writer.writeStartElement(ED_NS, "LandingPageURI");
+                    writer.writeCharacters(landingPageURI);
+                    writer.writeEndElement(); // "LandingPageURI" element
+                }
+
+                // languages
+                final List<String> languages = resource.getLanguages();
+                writer.writeStartElement(ED_NS, "Languages");
+                for (String i : languages) {
+                    writer.writeStartElement(ED_NS, "Language");
+                    writer.writeCharacters(i);
+                    writer.writeEndElement(); // "Language" element
+
+                }
+                writer.writeEndElement(); // "Languages" element
+
+                // available data views
+                StringBuilder sb = new StringBuilder();
+                for (DataView dataview : resource.getAvailableDataViews()) {
+                    if (sb.length() > 0) {
+                        sb.append(" ");
+                    }
+                    sb.append(dataview.getIdentifier());
+                }
+                writer.writeEmptyElement(ED_NS, "AvailableDataViews");
+                writer.writeAttribute("ref", sb.toString());
+
+                if (endpointDescription.isVersion(
+                        EndpointDescription.VERSION_2)) {
+                    final List<Layer> layers = resource.getAvailableLayers();
+                    if (layers != null) {
+                        sb = new StringBuilder();
+                        for (Layer layer : resource.getAvailableLayers()) {
+                            if (sb.length() > 0) {
+                                sb.append(" ");
+                            }
+                            sb.append(layer.getId());
+                        }
+                        writer.writeEmptyElement(ED_NS, "AvailableLayers");
+                        writer.writeAttribute("ref", sb.toString());
+                    }
+                }
+
+                // child resources
+                List<ResourceInfo> subs = resource.getSubResources();
+                if ((subs != null) && !subs.isEmpty()) {
+                    writeResourceInfos(writer, subs);
+                }
+
+                writer.writeEndElement(); // "Resource" element
+            }
+            writer.writeEndElement(); // "Resources" element
+        }
+    }
+
+} // class SimpleEndpointSearchEngineBase
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/XMLStreamWriterHelper.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/XMLStreamWriterHelper.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/XMLStreamWriterHelper.java	(revision 7248)
@@ -0,0 +1,601 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+
+/**
+ * This class provides several helper methods for writing records in the
+ * CLARIN-FCS record schema. These methods <em>do not</em> cover the full
+ * spectrum of all variations of records that are permitted by the CLARIN-FCS
+ * specification.
+ *
+ * @see <a
+ *      href="https://trac.clarin.eu/wiki/FCS/Specification">
+ *      CLARIN FCS specification, section "Operation searchRetrieve"</a>
+ */
+public class XMLStreamWriterHelper {
+    protected static final String FCS_NS          =
+            "http://clarin.eu/fcs/resource";
+    protected static final String FCS_PREFIX      =
+            "fcs";
+    protected static final String FCS_KWIC_NS     =
+            "http://clarin.eu/fcs/1.0/kwic";
+    protected static final String FCS_KWIC_PREFIX =
+            "kwic";
+    protected static final String FCS_KWIC_MIMETYPE =
+            "application/x-clarin-fcs-kwic+xml";
+    protected static final String FCS_HITS_NS =
+            "http://clarin.eu/fcs/dataview/hits";
+    protected static final String FCS_HITS_PREFIX =
+            "hits";
+    protected static final String FCS_HITS_MIMETYPE =
+            "application/x-clarin-fcs-hits+xml";
+
+
+    /**
+     * Write the start of a resource (i.e. the <code>&lt;Resource&gt;</code>
+     * element). Calls to this method need to be balanced with calls to the
+     * {@link #writeEndResource(XMLStreamWriter)} method.
+     *
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @param pid
+     *            the persistent identifier of this resource or
+     *            <code>null</code>, if not applicable
+     * @param ref
+     *            the reference of this resource or <code>null</code>, if not
+     *            applicable
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public static void writeStartResource(XMLStreamWriter writer, String pid,
+            String ref) throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+
+        writer.setPrefix(FCS_PREFIX, FCS_NS);
+        writer.writeStartElement(FCS_NS, "Resource");
+        writer.writeNamespace(FCS_PREFIX, FCS_NS);
+        if ((pid != null) && !pid.isEmpty()) {
+            writer.writeAttribute("pid", pid);
+        }
+        if ((ref != null) && !ref.isEmpty()) {
+            writer.writeAttribute("ref", ref);
+        }
+    }
+
+
+    /**
+     * Write the end of a resource (i.e. the <code>&lt;/Resource&gt;</code>
+     * element). Calls to this method need to be balanced with calls to the
+     * {@link #writeStartResource(XMLStreamWriter, String, String)} method.
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public static void writeEndResource(XMLStreamWriter writer)
+            throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+
+        writer.writeEndElement(); // "Resource" element
+    }
+
+
+    /**
+     * Write the start of a resource fragment (i.e. the
+     * <code>&lt;ResourceFragment&gt;</code> element). Calls to this method need
+     * to be balanced with calls to the
+     * {@link #writeEndResourceFragment(XMLStreamWriter)} method.
+     *
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @param pid
+     *            the persistent identifier of this resource or
+     *            <code>null</code>, if not applicable
+     * @param ref
+     *            the reference of this resource or <code>null</code>, if not
+     *            applicable
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public static void writeStartResourceFragment(XMLStreamWriter writer,
+            String pid, String ref) throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+
+        writer.writeStartElement(FCS_NS, "ResourceFragment");
+        if ((pid != null) && !pid.isEmpty()) {
+            writer.writeAttribute("pid", pid);
+        }
+        if ((ref != null) && !ref.isEmpty()) {
+            writer.writeAttribute("ref", ref);
+        }
+    }
+
+
+    /**
+     * Write the end of a resource fragment (i.e. the
+     * <code>&lt;/ResourceFragment&gt;</code> element). Calls to this method
+     * need to be balanced with calls to the
+     * {@link #writeStartResourceFragment(XMLStreamWriter, String, String)}
+     * method.
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public static void writeEndResourceFragment(XMLStreamWriter writer)
+            throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+
+        writer.writeEndElement(); // "ResourceFragment" element
+    }
+
+
+    /**
+     * Write the start of a data view (i.e. the
+     * <code>&lt;DataView&gt;</code> element). Calls to this method need
+     * to be balanced with calls to the
+     * {@link #writeEndResource(XMLStreamWriter)} method.
+     *
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @param mimetype
+     *            the MIME type of this data view
+     *            applicable
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public static void writeStartDataView(XMLStreamWriter writer,
+            String mimetype) throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+        if (mimetype == null) {
+            throw new NullPointerException("mimetype == null");
+        }
+        if (mimetype.isEmpty()) {
+            throw new IllegalArgumentException("mimetype is empty");
+        }
+
+        writer.writeStartElement(FCS_NS, "DataView");
+        writer.writeAttribute("type", mimetype);
+    }
+
+
+    /**
+     * Write the end of a data view (i.e. the <code>&lt;/DataView&gt;</code>
+     * element). Calls to this method need to be balanced with calls to the
+     * {@link #writeStartDataView(XMLStreamWriter, String)} method.
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public static void writeEndDataView(XMLStreamWriter writer)
+            throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+
+        writer.writeEndElement(); // "DataView" element
+    }
+
+
+    /**
+     * Convince method to write a KWIC data view. It automatically performs the
+     * calls to {@link #writeStartDataView(XMLStreamWriter, String)} and
+     * {@link #writeEndDataView(XMLStreamWriter)}.
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @param left
+     *            the left context of the KWIC or <code>null</code> if not
+     *            applicable
+     * @param keyword
+     *            the keyword of the KWIC
+     * @param right
+     *            the right context of the KWIC or <code>null</code> if not
+     *            applicable
+     * @throws XMLStreamException
+     *             if an error occurred
+     * @deprecated Use the HITS data view instead.
+     */
+    @Deprecated
+    public static void writeKWICDataView(XMLStreamWriter writer, String left,
+            String keyword, String right) throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+        if (keyword == null) {
+            throw new NullPointerException("keyword == null");
+        }
+
+        writeStartDataView(writer, FCS_KWIC_MIMETYPE);
+
+        // actual "kwic" data view
+        writer.setPrefix(FCS_KWIC_PREFIX, FCS_KWIC_NS);
+        writer.writeStartElement(FCS_KWIC_NS, "kwic");
+        writer.writeNamespace(FCS_KWIC_PREFIX, FCS_KWIC_NS);
+
+        writer.writeStartElement(FCS_KWIC_NS, "c");
+        writer.writeAttribute("type", "left");
+        if (left != null) {
+            writer.writeCharacters(left);
+        }
+        writer.writeEndElement(); // "c" element
+
+        writer.writeStartElement(FCS_KWIC_NS, "kw");
+        writer.writeCharacters(keyword);
+        writer.writeEndElement(); // "kw" element
+
+        writer.writeStartElement(FCS_KWIC_NS, "c");
+        writer.writeAttribute("type", "right");
+        if (right != null) {
+            writer.writeCharacters(right);
+        }
+        writer.writeEndElement(); // "c" element
+
+        writer.writeEndElement(); // "kwic" element
+
+        writeEndDataView(writer);
+    }
+
+
+    /**
+     * Convince method for writing a record with a KWIC data view. The following
+     * code (arguments omitted) would accomplish the same result:
+     *
+     * <pre>
+     * ...
+     * writeStartResource(...);
+     * writeKWICDataView(...);
+     * writeEndResource(...);
+     * ...
+     * </pre>
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @param pid
+     *            the persistent identifier of this resource or
+     *            <code>null</code>, if not applicable
+     * @param ref
+     *            the reference of this resource or <code>null</code>, if not
+     *            applicable
+     * @param left
+     *            the left context of the KWIC or <code>null</code> if not
+     *            applicable
+     * @param keyword
+     *            the keyword of the KWIC
+     * @param right
+     *            the right context of the KWIC or <code>null</code> if not
+     *            applicable
+     * @throws XMLStreamException
+     *             if an error occurred
+     * @deprecated The the HITS data view instead.
+     */
+    @Deprecated
+    public static void writeResourceWithKWICDataView(XMLStreamWriter writer,
+            String pid, String ref, String left, String keyword, String right)
+            throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+
+        writeStartResource(writer, pid, ref);
+        writeKWICDataView(writer, left, keyword, right);
+        writeEndResource(writer);
+    }
+
+
+
+    /**
+     * Convince method to write a simple HITS data view. It automatically
+     * performs the calls to
+     * {@link #writeStartDataView(XMLStreamWriter, String)} and
+     * {@link #writeEndDataView(XMLStreamWriter)}.
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @param left
+     *            the left context of the hit or <code>null</code> if not
+     *            applicable
+     * @param hit
+     *            the actual hit, that will be highlighted
+     * @param right
+     *            the right context of the hit or <code>null</code> if not
+     *            applicable
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public static void writeHitsDataView(XMLStreamWriter writer, String left,
+            String hit, String right) throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+        if (hit == null) {
+            throw new NullPointerException("hit == null");
+        }
+
+        writeStartDataView(writer, FCS_HITS_MIMETYPE);
+
+        // actual "hits" data view
+        writer.setPrefix(FCS_HITS_PREFIX, FCS_HITS_NS);
+        writer.writeStartElement(FCS_HITS_NS, "Result");
+        writer.writeNamespace(FCS_HITS_PREFIX, FCS_HITS_NS);
+
+        if ((left != null) && !left.isEmpty()) {
+            writer.writeCharacters(left);
+        }
+
+        writer.writeStartElement(FCS_HITS_NS, "Hit");
+        writer.writeCharacters(hit);
+        writer.writeEndElement(); // "Hit" element
+
+        if ((right != null) && !right.isEmpty()) {
+            writer.writeCharacters(right);
+        }
+
+        writer.writeEndElement(); // "Result" element
+
+        writeEndDataView(writer);
+    }
+
+
+    /**
+     * Convince method for writing a record with a HITS data view. The following
+     * code (arguments omitted) would accomplish the same result:
+     *
+     * <pre>
+     * ...
+     * writeStartResource(...);
+     * writeHitsDataView(...);
+     * writeEndResource(...);
+     * ...
+     * </pre>
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @param pid
+     *            the persistent identifier of this resource or
+     *            <code>null</code>, if not applicable
+     * @param ref
+     *            the reference of this resource or <code>null</code>, if not
+     *            applicable
+     * @param left
+     *            the left context of the hit or <code>null</code> if not
+     *            applicable
+     * @param hit
+     *            the actual hit, that will be highlighted
+     * @param right
+     *            the right context of the hit or <code>null</code> if not
+     *            applicable
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public static void writeResourceWithHitsDataView(XMLStreamWriter writer,
+            String pid, String ref, String left, String hit, String right)
+            throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+
+        writeStartResource(writer, pid, ref);
+        writeHitsDataView(writer, left, hit, right);
+        writeEndResource(writer);
+    }
+
+
+    /**
+     * Convince method to write a simple HITS data view. It automatically
+     * performs the calls to
+     * {@link #writeStartDataView(XMLStreamWriter, String)} and
+     * {@link #writeEndDataView(XMLStreamWriter)}.
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @param text
+     *            the text content of the hit
+     * @param hits
+     *            an even-element array containing tuples for the hit markers in
+     *            the text content
+     * @param secondIsLength
+     *            if <code>true</code> the second element of each tuple in this
+     *            <code>hits</code> array is interpreted as an length; if
+     *            <code>false</code> it is interpreted as an end-offset
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public static void writeHitsDataView(XMLStreamWriter writer, String text,
+            int[] hits, boolean secondIsLength) throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+        if (text == null) {
+            throw new NullPointerException("text == null");
+        }
+        if (hits == null) {
+            throw new NullPointerException("text == null");
+        }
+        if ((hits.length == 0) || ((hits.length % 2) != 0)) {
+            throw new NullPointerException("length of hits array must " +
+                    "contain an even number of elements");
+        }
+
+        writeStartDataView(writer, FCS_HITS_MIMETYPE);
+
+        // actual "hits" data view
+        writer.setPrefix(FCS_HITS_PREFIX, FCS_HITS_NS);
+        writer.writeStartElement(FCS_HITS_NS, "Result");
+        writer.writeNamespace(FCS_HITS_PREFIX, FCS_HITS_NS);
+
+        int pos = 0;
+        for (int i = 0; i < hits.length; i += 2) {
+            int start  = hits[i];
+            int end    = hits[i + 1];
+
+            if ((start < 0) && (start > text.length())) {
+                throw new IllegalArgumentException("start index out of " +
+                        "bounds: start=" + start);
+            }
+            if (secondIsLength) {
+                if (end < 1) {
+                    throw new IllegalArgumentException(
+                            "length must be larger than 0: length = " + end);
+                }
+                end += start;
+            }
+            if (start >= end) {
+                throw new IllegalArgumentException("end offset must be " +
+                        "larger then start offset: start=" + start +
+                        ", end="+ end);
+            }
+
+            if (start > pos) {
+                String s = text.substring(pos, start);
+                writer.writeCharacters(s);
+            }
+            writer.writeStartElement(FCS_HITS_NS, "Hit");
+            writer.writeCharacters(text.substring(start, end));
+            writer.writeEndElement(); // "Hits" element
+            pos = end;
+        }
+        if (pos < text.length() - 1) {
+            writer.writeCharacters(text.substring(pos));
+        }
+
+        writer.writeEndElement(); // "Result" element
+
+        writeEndDataView(writer);
+    }
+
+
+    /**
+     * Convince method to write a simple HITS data view. It automatically
+     * performs the calls to
+     * {@link #writeStartDataView(XMLStreamWriter, String)} and
+     * {@link #writeEndDataView(XMLStreamWriter)}.
+     *
+     * <pre>
+     * ...
+     * writeStartResource(...);
+     * writeHitsDataView(...);
+     * writeEndResource(...);
+     * ...
+     * </pre>
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @param pid
+     *            the persistent identifier of this resource or
+     *            <code>null</code>, if not applicable
+     * @param ref
+     *            the reference of this resource or <code>null</code>, if not
+     *            applicable
+     * @param text
+     *            the text content of the hit
+     * @param hits
+     *            an even-element array containing tuples for the hit markers in
+     *            the text content
+     * @param secondIsLength
+     *            if <code>true</code> the second element of each tuple in this
+     *            <code>hits</code> array is interpreted as an length; if
+     *            <code>false</code> it is interpreted as an end-offset
+     * @throws XMLStreamException
+     *             if an error occurred
+     */
+    public static void writeResourceWithHitsDataView(XMLStreamWriter writer,
+            String pid, String ref, String text,
+            int[] hits, boolean secondIsLength)
+            throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+
+        writeStartResource(writer, pid, ref);
+        writeHitsDataView(writer, text, hits, secondIsLength);
+        writeEndResource(writer);
+    }
+
+
+    /**
+     * Convince method for writing a record with a HITS and a KWIC data view.
+     * This method is intended for applications that want ensure computability
+     * to legacy CLARIN-FCS clients The following code (arguments omitted) would
+     * accomplish the same result:
+     *
+     * <pre>
+     * ...
+     * writeStartResource(...);
+     * writeHitsDataView(...);
+     * writeKWICDataView(...);
+     * writeEndResource(...);
+     * ...
+     * </pre>
+     *
+     * @param writer
+     *            the {@link XMLStreamWriter} to be used
+     * @param pid
+     *            the persistent identifier of this resource or
+     *            <code>null</code>, if not applicable
+     * @param ref
+     *            the reference of this resource or <code>null</code>, if not
+     *            applicable
+     * @param left
+     *            the left context of the hit or <code>null</code> if not
+     *            applicable
+     * @param hit
+     *            the actual hit, that will be highlighted
+     * @param right
+     *            the right context of the hit or <code>null</code> if not
+     *            applicable
+     * @throws XMLStreamException
+     *             if an error occurred
+     * @deprecated Only use, if you want compatability to legacy FCS
+     *             applications.
+     */
+    @Deprecated
+    public static void writeResourceWithHitsDataViewLegacy(XMLStreamWriter writer,
+            String pid, String ref, String left, String hit, String right)
+            throws XMLStreamException {
+        if (writer == null) {
+            throw new NullPointerException("writer == null");
+        }
+
+        writeStartResource(writer, pid, ref);
+        writeHitsDataView(writer, left, hit, right);
+        writeKWICDataView(writer, left, hit, right);
+        writeEndResource(writer);
+    }
+
+} // class XMLStreamWriterHelper
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/Expression.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/Expression.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/Expression.java	(revision 7248)
@@ -0,0 +1,269 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+import java.util.Collections;
+import java.util.Set;
+
+
+/**
+ * A FCS-QL expression tree SIMPLE expression node.
+ */
+public class Expression extends QueryNode {
+    private final String qualifier;
+    private final String identifier;
+    private final Operator operator;
+    private final String regex;
+    private final Set<RegexFlag> regex_flags;
+
+
+    /**
+     * Constructor.
+     *
+     * @param qualifier
+     *            the layer identifier qualifier or <code>null</code> if none
+     * @param identifier
+     *            the layer identifier
+     * @param operator
+     *            the operator
+     * @param regex
+     *            the regular expression
+     * @param regex_flags
+     *            the regular expression flags or <code>null</code> of none
+     */
+    Expression(String qualifier, String identifier, Operator operator,
+            String regex, Set<RegexFlag> regex_flags) {
+        super(QueryNodeType.EXPRESSION);
+        if ((qualifier != null) && !qualifier.isEmpty()) {
+            this.qualifier = qualifier;
+        } else {
+            this.qualifier = null;
+        }
+        this.identifier = identifier;
+        this.operator = operator;
+        this.regex = regex;
+        if ((regex_flags != null) && !regex_flags.isEmpty()) {
+            this.regex_flags = Collections.unmodifiableSet(regex_flags);
+        } else {
+            this.regex_flags = null;
+        }
+    }
+
+
+    /**
+     * Get the layer identifier.
+     *
+     * @return the layer identifier
+     */
+    public String getLayerIdentifier() {
+        return identifier;
+    }
+
+
+    /**
+     * Check if the expression used a given <em>Layer Type Identifier</em>.
+     *
+     * @param identifier
+     *            the Layer Type Identifier to check against
+     * @return <code>true</code> if this identifier was used, <code>false</code>
+     *         otherwise
+     */
+    public boolean hasLayerIdentifier(String identifier) {
+        if (identifier == null) {
+            throw new NullPointerException("identifier == null");
+        }
+        return this.identifier.equals(identifier);
+    }
+
+
+    /**
+     * Get the Layer Type Identifier qualifier.
+     *
+     * @return the Layer Type Identifier qualifier or <code>null</code> if none
+     *         was used in this expression
+     */
+    public String getLayerQualifier() {
+        return qualifier;
+    }
+
+
+    /**
+     * Check if the Layer Type Identifier qualifier is empty.
+     *
+     * @return <code>true</code> if no Layer Type Identifier qualifier was set,
+     *         <code>false</code> otherwise
+     */
+    public boolean isLayerQualifierEmpty() {
+        return (qualifier == null);
+    }
+
+
+    /**
+     * Check if the expression used a given qualifier for the Layer Type
+     * Identifier.
+     *
+     * @param qualifier
+     *            the qualifier to check against
+     * @return <code>true</code> if this identifier was used, <code>false</code>
+     *         otherwise
+     */
+    public boolean hasLayerQualifier(String qualifier) {
+        if (qualifier == null) {
+            throw new NullPointerException("qualifier == null");
+        }
+        if (this.qualifier != null) {
+            return this.qualifier.equals(qualifier);
+        } else {
+            return false;
+        }
+    }
+
+
+    /**
+     * Get the operator.
+     *
+     * @return the operator
+     */
+    public Operator getOperator() {
+        return operator;
+    }
+
+
+    /**
+     * Check if expression used a given operator.
+     *
+     * @param operator
+     *            the operator to check
+     * @return <code>true</code> if the given operator was used,
+     *         <code>false</code> otherwise
+     */
+    public boolean hasOperator(Operator operator) {
+        if (operator == null) {
+            throw new NullPointerException("operator == null");
+        }
+        return this.operator == operator;
+    }
+
+
+    /**
+     * Get the regex value.
+     *
+     * @return the regex value
+     */
+    public String getRegexValue() {
+        return regex;
+    }
+
+
+    /**
+     * Get the regex flags set.
+     *
+     * @return the regex flags set or <code>null</code> if no flags were used
+     *         in this expression
+     */
+    public Set<RegexFlag> getRegexFlags() {
+        return regex_flags;
+    }
+
+
+    /**
+     * Check if a regex flag set is empty.
+     *
+     * @return <code>true</code> if no regex flags where set, <code>false</code>
+     *         otherwise
+     */
+    public boolean isRegexFlagsEmpty() {
+        return (regex_flags == null);
+    }
+
+
+    /**
+     * Check if a regex flag is set.
+     *
+     * @param flag
+     *            the flag to be checked
+     * @return <code>true</code> if the flag is set, <code>false</code>
+     *         otherwise
+     */
+    public boolean hasRegexFlag(RegexFlag flag) {
+        if (flag == null) {
+            throw new NullPointerException("flag == null");
+        }
+        if (regex_flags != null) {
+            return regex_flags.contains(flag);
+        } else {
+            return false;
+        }
+    }
+
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("(");
+        sb.append(nodeType.toDisplayString());
+        sb.append(" ");
+        if (qualifier != null) {
+            sb.append(qualifier).append(":");
+        }
+        sb.append(identifier);
+        sb.append(" ");
+        sb.append(operator.toDisplayString());
+        sb.append(" \"");
+        for (int i = 0; i < regex.length(); i++) {
+            char ch = regex.charAt(i);
+            switch (ch) {
+            case '\n':
+                sb.append("\\n");
+                break;
+            case '\r':
+                sb.append("\\r");
+                break;
+            case '\t':
+                sb.append("\\t");
+                break;
+            default:
+                sb.append(ch);
+            }
+        }
+        sb.append("\"");
+        if (regex_flags != null) {
+            sb.append("/");
+            if (regex_flags.contains(RegexFlag.CASE_INSENSITIVE)) {
+                sb.append("i");
+            }
+            if (regex_flags.contains(RegexFlag.CASE_SENSITIVE)) {
+                sb.append("I");
+            }
+            if (regex_flags.contains(RegexFlag.LITERAL_MATCHING)) {
+                sb.append("l");
+            }
+            if (regex_flags.contains(RegexFlag.IGNORE_DIACRITICS)) {
+                sb.append("d");
+            }
+        }
+        sb.append(")");
+        return sb.toString();
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        visitor.visit(this);
+    }
+
+} // class Expression
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionAnd.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionAnd.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionAnd.java	(revision 7248)
@@ -0,0 +1,47 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+import java.util.List;
+
+
+/**
+ * A FCS-QL expression tree AND expression node.
+ */
+public class ExpressionAnd extends QueryNode {
+
+    /**
+     * Constructor.
+     *
+     * @param children child elements covered by AND expression.
+     */
+    ExpressionAnd(List<QueryNode> children) {
+        super(QueryNodeType.EXPRESSION_AND, children);
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        if (!children.isEmpty()) {
+            for (QueryNode child : children) {
+                child.accept(visitor);
+            }
+        }
+        visitor.visit(this);
+    }
+
+} // class ExpressionAnd
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionGroup.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionGroup.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionGroup.java	(revision 7248)
@@ -0,0 +1,57 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * A FCS-QL expression tree GROUP expression node.
+ */
+public class ExpressionGroup extends QueryNode {
+
+    /**
+     * Constructor.
+     *
+     * @param content
+     *            the group content
+     */
+    ExpressionGroup(QueryNode content) {
+        super(QueryNodeType.EXPRESSION_GROUP, content);
+    }
+
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("(")
+            .append(nodeType.toDisplayString())
+            .append(children.get(0))
+            .append(")");
+        return sb.toString();
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        if (!children.isEmpty()) {
+            for (QueryNode child : children) {
+                child.accept(visitor);
+            }
+        }
+        visitor.visit(this);
+    }
+
+} // class ExpressionGroup
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionNot.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionNot.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionNot.java	(revision 7248)
@@ -0,0 +1,53 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * A FCS-QL expression tree NOT expression node.
+ */
+public class ExpressionNot extends QueryNode {
+
+    /**
+     * Constructor.
+     *
+     * @param child
+     *            the child expression
+     */
+    ExpressionNot(QueryNode child) {
+        super(QueryNodeType.EXPRESSION_NOT, child);
+    }
+
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("(")
+            .append(nodeType.toDisplayString())
+            .append(children.get(0))
+            .append(")");
+        return sb.toString();
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        children.get(0).accept(visitor);
+        visitor.visit(this);
+    }
+
+} // class ExpressionNot
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionOr.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionOr.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionOr.java	(revision 7248)
@@ -0,0 +1,57 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+import java.util.List;
+
+
+/**
+ * A FCS-QL expression tree OR expression node.
+ */
+public class ExpressionOr extends QueryNode {
+
+    /**
+     * Constructor.
+     *
+     * @param children the children
+     */
+    ExpressionOr(List<QueryNode> children) {
+        super(QueryNodeType.EXPRESSION_OR, children);
+    }
+
+
+    /**
+     * Get the OR expression operands
+     *
+     * @return a list of expressions
+     */
+    public List<QueryNode> getOperands() {
+        return children;
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        if (!children.isEmpty()) {
+            for (QueryNode child : children) {
+                child.accept(visitor);
+            }
+        }
+        visitor.visit(this);
+    }
+
+} // class ExpressionOr
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionWildcard.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionWildcard.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/ExpressionWildcard.java	(revision 7248)
@@ -0,0 +1,35 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * A FCS-QL expression tree WILDCARD expression node.
+ */
+public class ExpressionWildcard extends QueryNode {
+
+    ExpressionWildcard() {
+        super(QueryNodeType.EXPRESSION_WILDCARD);
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        visitor.visit(this);
+    }
+
+} // class ExpressionWildcard
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/Operator.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/Operator.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/Operator.java	(revision 7248)
@@ -0,0 +1,45 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * FCS-QL operators.
+ */
+public enum Operator {
+    /**
+     * EQUALS operator.
+     */
+    EQUALS {
+        @Override
+        String toDisplayString() {
+            return "Eq";
+        }
+    },
+    /**
+     * NOT-EQUALS operator.
+     */
+    NOT_EQUALS {
+        @Override
+        String toDisplayString() {
+            return "Ne";
+        }
+    };
+
+    abstract String toDisplayString();
+
+} // enum Operator
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryDisjunction.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryDisjunction.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryDisjunction.java	(revision 7248)
@@ -0,0 +1,47 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+import java.util.List;
+
+
+/**
+ * A FCS-QL expression tree QR query
+ */
+public class QueryDisjunction extends QueryNode {
+    /**
+     * Constructor.
+     *
+     * @param children
+     *            the children
+     */
+    QueryDisjunction(List<QueryNode> children) {
+        super(QueryNodeType.QUERY_DISJUNCTION, children);
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        if (!children.isEmpty()) {
+            for (QueryNode child : children) {
+                child.accept(visitor);
+            }
+        }
+        visitor.visit(this);
+    }
+
+} // class QueryDisjunction
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryGroup.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryGroup.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryGroup.java	(revision 7248)
@@ -0,0 +1,118 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * A FCS-QL expression tree GROUP query node.
+ */
+public class QueryGroup extends QueryNode {
+    private final int minOccurs;
+    private final int maxOccurs;
+
+
+    /**
+     * Constructor.
+     *
+     * @param content
+     *            the child
+     * @param minOccurs
+     *            the minimum occurrence
+     * @param maxOccurs
+     *            the maximum occurrence
+     */
+    QueryGroup(QueryNode content, int minOccurs, int maxOccurs) {
+        super(QueryNodeType.QUERY_GROUP, content);
+        this.minOccurs = minOccurs;
+        this.maxOccurs = maxOccurs;
+    }
+
+
+    /**
+     * Get the group content.
+     *
+     * @return the content of the GROUP query
+     */
+    public QueryNode getContent() {
+        return children.get(0);
+    }
+
+
+    /**
+     * Get the minimum occurrence of group content.
+     *
+     * @return the minimum occurrence
+     *
+     */
+    public int getMinOccurs() {
+        return minOccurs;
+    }
+
+
+    /**
+     * Get the maximum occurrence of group content.
+     *
+     * @return the maximum occurrence
+     *
+     */
+    public int getMaxOccurs() {
+        return maxOccurs;
+    }
+
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("(")
+            .append(nodeType.toDisplayString())
+            .append(" ");
+        if (minOccurs != 1) {
+            sb.append("@min=");
+            if (minOccurs == QueryNode.OCCURS_UNBOUNDED) {
+                sb.append("*");
+            } else {
+                sb.append(minOccurs);
+            }
+            sb.append(" ");
+        }
+        if (maxOccurs != 1) {
+            sb.append("@max=");
+            if (maxOccurs == QueryNode.OCCURS_UNBOUNDED) {
+                sb.append("*");
+            } else {
+                sb.append(maxOccurs);
+            }
+            sb.append(" ");
+
+        }
+        sb.append(children.get(0));
+        sb.append(")");
+        return sb.toString();
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        if (!children.isEmpty()) {
+            for (QueryNode child : children) {
+                child.accept(visitor);
+            }
+        }
+        visitor.visit(this);
+    }
+
+} // class QueryGroup
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryNode.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryNode.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryNode.java	(revision 7248)
@@ -0,0 +1,251 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+import java.util.Collections;
+import java.util.List;
+
+
+/**
+ * base class for FCS-QL expression tree nodes.
+ *
+ */
+public abstract class QueryNode {
+    /**
+     * Atom occurrence it not bound.
+     */
+    public static final int OCCURS_UNBOUNDED = -1;
+    protected final QueryNodeType nodeType;
+    protected final List<QueryNode> children;
+    protected QueryNode parent;
+
+
+    /**
+     * Constructor.
+     *
+     * @param nodeType
+     *            the type of the node
+     * @param children
+     *            the children of this node or <code>null</code> if none
+     */
+    protected QueryNode(QueryNodeType nodeType, List<QueryNode> children) {
+        this.nodeType = nodeType;
+        if ((children != null) && !children.isEmpty()) {
+            for (QueryNode child : children) {
+                child.setParent(this);
+            }
+            this.children = Collections.unmodifiableList(children);
+        } else {
+            this.children = Collections.emptyList();
+        }
+    }
+
+
+    /**
+     * Constructor.
+     *
+     * @param nodeType
+     *            the type of the node
+     * @param child
+     *            the child of this node or <code>null</code> if none
+     */
+    protected QueryNode(QueryNodeType nodeType, QueryNode child) {
+        this.nodeType = nodeType;
+        if (child != null) {
+            child.setParent(this);
+            this.children = Collections.singletonList(child);
+        } else {
+            this.children = Collections.emptyList();
+        }
+    }
+
+
+    /**
+     * Constructor.
+     *
+     * @param nodeType
+     *            the type of the node
+     */
+    protected QueryNode(QueryNodeType nodeType) {
+        this.nodeType = nodeType;
+        this.children = Collections.emptyList();
+    }
+
+
+    /**
+     * Get the node type of this node.
+     *
+     * @return the node type
+     */
+    public QueryNodeType getNodeType() {
+        return nodeType;
+    }
+
+
+    /**
+     * Check, if node if of given type.
+     *
+     * @param nodeType
+     *            type to check against
+     * @return <code>true</code> if node is of given type, <code>false</code>
+     *         otherwise
+     */
+    public boolean hasNodeType(QueryNodeType nodeType) {
+        if (nodeType == null) {
+            throw new NullPointerException("nodeType == null");
+        }
+        return this.nodeType == nodeType;
+    }
+
+
+    /**
+     * Get the parent node of this node.
+     *
+     * @return the parent node or <code>null</code> if this is the root node
+     */
+    public QueryNode getParent() {
+        return parent;
+    }
+
+
+    /**
+     * The children of this node.
+     *
+     * @return the list of children of this node
+     */
+    public List<QueryNode> getChildren() {
+        return children;
+    }
+
+
+    /**
+     * Get the number of children of this node.
+     *
+     * @return the number of children of this node
+     */
+    public int getChildCount() {
+        final List<QueryNode> children = getChildren();
+        return (children != null) ? children.size() : 0;
+    }
+
+
+    /**
+     * Get a child node by index.
+     *
+     * @param idx
+     *            the index of the child node
+     * @return the child node of this node or <code>null</code> if index is out
+     *         of bounds
+     */
+    public QueryNode getChild(int idx) {
+        final List<QueryNode> children = getChildren();
+        if ((children != null) && !children.isEmpty()) {
+            if ((idx >= 0) && (idx < children.size())) {
+                return children.get(idx);
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * Get this first child node.
+     *
+     * @return the first child node of this node or <code>null</code> if none
+     */
+    public QueryNode getFirstChild() {
+        return getChild(0);
+    }
+
+
+    /**
+     * Get this last child node.
+     *
+     * @return the last child node of this node or <code>null</code> if none
+     */
+    public QueryNode getLastChild() {
+        return getChild(getChildCount() - 1);
+    }
+
+
+    /**
+     * Get a child node of specified type by index. Only child nodes of the
+     * requested type are counted.
+     *
+     * @param <T>
+     *            the class of the nodes to be considered
+     * @param clazz
+     *            the type to nodes to be considered
+     * @param idx
+     *            the index of the child node
+     * @return the child node of this node or <code>null</code> if no child was
+     *         found
+     */
+    public <T extends QueryNode> T getChild(Class<T> clazz, int idx) {
+        final List<QueryNode> children = getChildren();
+        if (!children.isEmpty()) {
+            int pos = 0;
+            for (QueryNode child : children) {
+                if (clazz.isInstance(child)) {
+                    if (pos == idx) {
+                        return clazz.cast(child);
+                    }
+                    pos++;
+                }
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * Get a first child node of specified type.
+     *
+     * @param <T>
+     *            the class of the nodes to be considered
+     * @param clazz
+     *            the type to nodes to be considered
+     * @return the child node of this node or <code>null</code> if no child was
+     *         found
+     */
+    public <T extends QueryNode> T getFirstChild(Class<T> clazz) {
+            return getChild(clazz, 0);
+    }
+
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("(").append(nodeType.toDisplayString());
+        if (!children.isEmpty()) {
+            for (QueryNode child : children) {
+                sb.append(" ").append(child);
+            }
+        }
+        sb.append(")");
+        return sb.toString();
+    }
+
+
+    public abstract void accept(QueryVisitor visitor);
+
+
+    protected final void setParent(QueryNode parent) {
+        this.parent = parent;
+    }
+
+} // abstract class QueryNode
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryNodeType.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryNodeType.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryNodeType.java	(revision 7248)
@@ -0,0 +1,135 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * Node types of FCS-QL expression tree nodes.
+ */
+public enum QueryNodeType {
+    /**
+     * segment query
+     */
+    QUERY_SEGMENT {
+        @Override
+        String toDisplayString() {
+            return "QuerySegment";
+        }
+    },
+    /**
+     * group query
+     */
+    QUERY_GROUP {
+        @Override
+        String toDisplayString() {
+            return "QueryGroup";
+        }
+    },
+    /**
+     * sequence query
+     */
+    QUERY_SEQUENCE {
+        @Override
+        String toDisplayString() {
+            return "QuerySequence";
+        }
+    },
+    /**
+     * or query
+     */
+    QUERY_DISJUNCTION {
+        @Override
+        String toDisplayString() {
+            return "QueryDisjunction";
+        }
+    },
+    /**
+     * query with within part
+     */
+    QUERY_WITH_WITHIN {
+        @Override
+        String toDisplayString() {
+            return "QueryWithWithin";
+        }
+    },
+    /**
+     * simple expression
+     */
+    EXPRESSION {
+        @Override
+        String toDisplayString() {
+            return "Expression";
+        }
+    },
+    /**
+     * wildcard expression
+     */
+    EXPRESSION_WILDCARD {
+        @Override
+        String toDisplayString() {
+            return "Wildcard";
+        }
+    },
+    /**
+     * group expression
+     */
+    EXPRESSION_GROUP {
+        @Override
+        String toDisplayString() {
+            return "Group";
+        }
+    },
+    /**
+     * or expression
+     */
+    EXPRESSION_OR {
+        @Override
+        String toDisplayString() {
+            return "Or";
+        }
+    },
+    /**
+     * and expression
+     */
+    EXPRESSION_AND {
+        @Override
+        String toDisplayString() {
+            return "And";
+        }
+    },
+    /**
+     * not expression
+     */
+    EXPRESSION_NOT {
+        @Override
+        String toDisplayString() {
+            return "Not";
+        }
+    },
+    /**
+     * simple within part
+     */
+    SIMPLE_WITHIN {
+        @Override
+        String toDisplayString() {
+            return "SimpleWithin";
+        }
+    };
+
+    abstract String toDisplayString();
+
+} // enum QueryNodeType
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryParser.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryParser.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryParser.java	(revision 7248)
@@ -0,0 +1,1054 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+import java.text.Normalizer;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.BaseErrorListener;
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.CharStreams;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.RecognitionException;
+import org.antlr.v4.runtime.Recognizer;
+import org.antlr.v4.runtime.Token;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.antlr.v4.runtime.tree.TerminalNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.clarin.sru.fcs.qlparser.FCSLexer;
+import eu.clarin.sru.fcs.qlparser.FCSParser;
+import eu.clarin.sru.fcs.qlparser.FCSParserBaseVisitor;
+import eu.clarin.sru.fcs.qlparser.FCSParser.AttributeContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Expression_andContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Expression_basicContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Expression_groupContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Expression_notContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Expression_orContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.IdentifierContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Main_queryContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.QualifierContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.QuantifierContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.QueryContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Query_disjunctionContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Query_groupContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Query_implicitContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Query_segmentContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Query_sequenceContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Query_simpleContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.RegexpContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Regexp_flagContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Regexp_patternContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Within_partContext;
+import eu.clarin.sru.fcs.qlparser.FCSParser.Within_part_simpleContext;
+
+
+/**
+ * A FCS-QL query parser that produces FCS-QL expression trees.
+ */
+public class QueryParser {
+    private static final int[] REP_ZERO_OR_MORE =
+            new int[] { 0, QueryNode.OCCURS_UNBOUNDED };
+    private static final int[] REP_ONE_OR_MORE =
+            new int[] { 1, QueryNode.OCCURS_UNBOUNDED };
+    private static final int[] REP_ZERO_OR_ONE =
+            new int[] { 0, 1 };
+    private static final String EMPTY_STRING = "";
+    private static final int DEFAULT_INITIAL_STACK_SIZE = 32;
+    private static final Logger logger =
+            LoggerFactory.getLogger(ExpressionTreeBuilder.class);
+    private static final String DEFAULT_IDENTIFIER = "text";
+    private static final Operator DEFAULT_OPERATOR = Operator.EQUALS;
+    private static final Normalizer.Form DEFAULT_UNICODE_NORMALIZATION_FORM =
+            Normalizer.Form.NFC;
+    private final String defaultIdentifier;
+    private final Operator defaultOperator;
+    private final Normalizer.Form unicodeNormalizationForm;
+
+
+    /**
+     * Constructor.
+     */
+    public QueryParser() {
+        this(DEFAULT_IDENTIFIER, DEFAULT_UNICODE_NORMALIZATION_FORM);
+    }
+
+
+    /**
+     * Constructor.
+     *
+     * @param defaultIdentifier
+     *            the default identifier to be used for simple expressions
+     */
+    public QueryParser(String defaultIdentifier) {
+        this.defaultIdentifier = defaultIdentifier;
+        this.defaultOperator = DEFAULT_OPERATOR;
+        this.unicodeNormalizationForm = DEFAULT_UNICODE_NORMALIZATION_FORM;
+    }
+
+
+    /**
+     * Constructor.
+     *
+     * @param defaultIdentifier
+     *            the default identifier to be used for simple expressions
+     * @param unicodeNormaliztionForm
+     *            the Unicode normalization form to be used or <code>null</code>
+     *            to not perform normalization
+     */
+    public QueryParser(String defaultIdentifier,
+            Normalizer.Form unicodeNormaliztionForm) {
+        this.defaultIdentifier = defaultIdentifier;
+        this.defaultOperator = DEFAULT_OPERATOR;
+        this.unicodeNormalizationForm = unicodeNormaliztionForm;
+    }
+
+
+    /**
+     * Parse query.
+     *
+     * @param query
+     *            the FCS-QL query
+     * @return a FCS-QL expression tree
+     * @throws QueryParserException
+     *             if an error occurred
+     */
+    public QueryNode parse(String query) throws QueryParserException {
+        final ErrorListener errorListener = new ErrorListener(query);
+        try {
+//            ANTLRInputStream input = new ANTLRInputStream(query);
+            CharStream input = CharStreams.fromString(query);
+            FCSLexer lexer = new FCSLexer(input);
+            CommonTokenStream tokens = new CommonTokenStream(lexer);
+            FCSParser parser = new FCSParser(tokens);
+            /*
+             * clear (possible) default error listeners and set our own!
+             */
+            lexer.removeErrorListeners();
+            lexer.addErrorListener(errorListener);
+            parser.removeErrorListeners();
+            parser.addErrorListener(errorListener);
+
+            /*
+             * commence parsing ...
+             */
+            ParseTree tree = parser.query();
+            if (parser.isMatchedEOF() &&
+                    !errorListener.hasErrors() &&
+                    (parser.getNumberOfSyntaxErrors() == 0)) {
+                if (logger.isTraceEnabled()) {
+                    logger.trace("ANTLR parse tree: {}",
+                            tree.toStringTree(parser));
+                }
+                ExpressionTreeBuilder v =
+                        new ExpressionTreeBuilder(DEFAULT_INITIAL_STACK_SIZE);
+                v.visit(tree);
+                return (QueryNode) v.stack.pop();
+            } else {
+                if (logger.isTraceEnabled()) {
+                    for (String msg : errorListener.getErrors()) {
+                        logger.trace("ERROR: {}", msg);
+                    }
+                }
+
+                /*
+                 * FIXME: (include additional error information)
+                 */
+                String message = errorListener.hasErrors()
+                        ? errorListener.getErrors().get(0)
+                        : "unspecified error";
+                throw new QueryParserException(message);
+            }
+        } catch (ExpressionTreeBuilderException e) {
+            throw new QueryParserException(e.getMessage(), e.getCause());
+        } catch (QueryParserException e) {
+            throw e;
+        } catch (Throwable t) {
+            throw new QueryParserException(
+                    "an unexpected exception occured while parsing", t);
+        }
+    }
+
+
+    /*
+     * hide the expression tree builder implementation in nested private class ...
+     */
+    private final class ExpressionTreeBuilder
+            extends FCSParserBaseVisitor<Void> {
+        private final Deque<Object> stack;
+        /*
+         * pre-allocate buffer to store chars returned by Character.toChars in
+         * unescapeString()
+         */
+        private final char[] buf = new char[2];
+
+
+        private ExpressionTreeBuilder(int initStackSize) {
+            if (initStackSize < 1) {
+                throw new IllegalArgumentException("initStackSize < 1");
+            }
+            this.stack = new ArrayDeque<Object>(initStackSize);
+        }
+
+
+        @Override
+        public Void visitQuery(QueryContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            super.visitQuery(ctx);
+
+            Within_partContext w_ctx = ctx.getChild(Within_partContext.class, 0);
+            if (w_ctx != null) {
+                QueryNode within = (QueryNode) stack.pop();
+                QueryNode query  = (QueryNode) stack.pop();;
+                stack.push(new QueryWithWithin(query, within));
+            }
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitMain_query(Main_queryContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitMain_query/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            super.visitMain_query(ctx);
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitMain_query/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitQuery_disjunction(Query_disjunctionContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_disjunction/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            final int pos = stack.size();
+            super.visitQuery_disjunction(ctx);
+            if (stack.size() > pos) {
+                List<QueryNode> items = new ArrayList<QueryNode>();
+                while (stack.size() > pos) {
+                    items.add(0, (QueryNode) stack.pop());
+                }
+                stack.push(new QueryDisjunction(items));
+            } else {
+                throw new ExpressionTreeBuilderException(
+                        "visitQuery_disjunction is empty!");
+            }
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_disjunction/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+
+        @Override
+        public Void visitQuery_sequence(Query_sequenceContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_sequence/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            final int pos = stack.size();
+            super.visitQuery_sequence(ctx);
+            if (stack.size() > pos) {
+                List<QueryNode> items = new ArrayList<QueryNode>();
+                while (stack.size() > pos) {
+                    items.add(0, (QueryNode) stack.pop());
+                }
+                stack.push(new QuerySequence(items));
+            } else {
+                throw new ExpressionTreeBuilderException(
+                        "visitQuery_sequence is empty!");
+            }
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_sequence/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitQuery_group(Query_groupContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_group/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            super.visitQuery_group(ctx);
+
+            /*
+             * handle repetition (if any)
+             */
+            int min = 1;
+            int max = 1;
+
+            // fetch *first* child of type QuantifierContext, therefore idx=0
+            final QuantifierContext q_ctx =
+                    ctx.getChild(QuantifierContext.class, 0);
+            if (q_ctx != null) {
+                int[] r = processRepetition(q_ctx);
+                min = r[0];
+                max = r[1];
+            }
+
+            QueryNode content = (QueryNode) stack.pop();
+            stack.push(new QueryGroup(content, min, max));
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_group/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitQuery_simple(Query_simpleContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_simple/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            super.visitQuery_simple(ctx);
+
+            /*
+             * handle repetition (if any)
+             */
+            int min = 1;
+            int max = 1;
+
+            // fetch *first* child of type QuantifierContext, therefore idx=0
+            final QuantifierContext q_ctx =
+                    ctx.getChild(QuantifierContext.class, 0);
+            if (q_ctx != null) {
+                int[] r = processRepetition(q_ctx);
+                min = r[0];
+                max = r[1];
+            }
+
+            QueryNode expression = (QueryNode) stack.pop();
+            stack.push(new QuerySegment(expression, min, max));
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_simple/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitQuery_implicit(Query_implicitContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_implicit/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            stack.push(defaultOperator);
+            stack.push(defaultIdentifier);
+            stack.push(EMPTY_STRING);
+            super.visitQuery_implicit(ctx);
+
+            @SuppressWarnings("unchecked")
+            Set<RegexFlag> regex_flags = (Set<RegexFlag>) stack.pop();
+            String regex_value         = (String) stack.pop();
+            String qualifier           = (String) stack.pop();
+            String identifier          = (String) stack.pop();
+            Operator operator          = (Operator) stack.pop();
+
+            Expression exp = new Expression(qualifier, identifier, operator,
+                    regex_value, regex_flags);
+            stack.push(exp);
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_implicit/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitQuery_segment(Query_segmentContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_segment/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+
+            /*
+             * if the context contains only two children, they must be
+             * '[' and ']' thus we are dealing with a wildcard segment
+             */
+            if (ctx.getChildCount() == 2) {
+                stack.push(new ExpressionWildcard());
+            } else {
+                super.visitQuery_segment(ctx);
+            }
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitQuery_segment/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitExpression_basic(Expression_basicContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitExpression_basic/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            final Token tok_op = ((TerminalNode) ctx.getChild(1)).getSymbol();
+            switch (tok_op.getType()) {
+            case FCSLexer.OPERATOR_EQ:
+                stack.push(Operator.EQUALS);
+                break;
+            case FCSLexer.OPERATOR_NE:
+                stack.push(Operator.NOT_EQUALS);
+                break;
+            default:
+                throw new ExpressionTreeBuilderException(
+                        "invalid operator type: " + tok_op.getText());
+            }
+            super.visitExpression_basic(ctx);
+
+            @SuppressWarnings("unchecked")
+            Set<RegexFlag> regex_flags = (Set<RegexFlag>) stack.pop();
+            String regex_value         = (String) stack.pop();
+            String qualifier           = (String) stack.pop();
+            String identifer           = (String) stack.pop();
+            Operator operator          = (Operator) stack.pop();
+
+            Expression exp = new Expression(qualifier, identifer, operator,
+                    regex_value, regex_flags);
+            stack.push(exp);
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitExpression_basic/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitExpression_not(Expression_notContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitExpression_not/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            super.visitExpression_not(ctx);
+
+            QueryNode expression = (QueryNode) stack.pop();
+            stack.push(new ExpressionNot(expression));
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitExpression_not/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitExpression_group(Expression_groupContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitExpression_group/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            super.visitExpression_group(ctx);
+
+            QueryNode expression = (QueryNode) stack.pop();
+            stack.push( new ExpressionGroup(expression));
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitExpression_group/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitExpression_or(Expression_orContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitExpression_or/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            final int pos = stack.size();
+            super.visitExpression_or(ctx);
+            if (stack.size() > pos) {
+                final List<QueryNode> children = new ArrayList<QueryNode>();
+                while (stack.size() > pos) {
+                    children.add(0, (QueryNode) stack.pop());
+                }
+                stack.push( new ExpressionOr(children));
+            } else {
+                throw new ExpressionTreeBuilderException(
+                        "visitExpression_or is empty!");
+            }
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitExpression_or/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitExpression_and(Expression_andContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitExpression_and/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+            final int pos = stack.size();
+            super.visitExpression_and(ctx);
+            if (stack.size() > pos) {
+                final List<QueryNode> children = new ArrayList<QueryNode>();
+                while (stack.size() > pos) {
+                    children.add(0, (QueryNode) stack.pop());
+                }
+                stack.push(new ExpressionAnd(children));
+            } else {
+                throw new ExpressionTreeBuilderException(
+                        "visitExpression_and is empty!");
+            }
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitExpression_and/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitAttribute(AttributeContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitAttribute/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+
+            // handle optional qualifier
+            QualifierContext q_ctx = ctx.getChild(QualifierContext.class, 0);
+            String qualifier = (q_ctx != null) ? q_ctx.getText() : EMPTY_STRING;
+
+            stack.push(ctx.getChild(IdentifierContext.class, 0).getText());
+            stack.push(qualifier);
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitAttribute/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitRegexp(RegexpContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitRegexp/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+
+            final Regexp_patternContext p_ctx =
+                    ctx.getChild(Regexp_patternContext.class, 0);
+            String regex = stripQuotes(p_ctx.getText());
+
+            /* process escape sequences, if present */
+            if (regex.indexOf('\\') != -1) {
+                regex = unescapeString(regex, buf);
+            }
+
+            /* perform unicode normalization, if requested */
+            if (unicodeNormalizationForm != null) {
+                regex = Normalizer.normalize(regex, unicodeNormalizationForm);
+            }
+
+            // FIXME: validate regex?
+            stack.push(regex);
+
+            // handle regex flags, if any
+            final Regexp_flagContext f_ctx =
+                    ctx.getChild(Regexp_flagContext.class, 0);
+            if (f_ctx != null) {
+                final String s = f_ctx.getText();
+
+                Set<RegexFlag> flags = new HashSet<RegexFlag>();
+                for (int i = 0; i < s.length(); i++) {
+                    switch (s.charAt(i)) {
+                    case 'i':
+                        /* $FALL-THROUGH$ */
+                    case 'c':
+                        flags.add(RegexFlag.CASE_INSENSITIVE);
+                        break;
+                    case 'I':
+                        /* $FALL-THROUGH$ */
+                    case 'C':
+                        flags.add(RegexFlag.CASE_SENSITIVE);
+                        break;
+                    case 'l':
+                        flags.add(RegexFlag.LITERAL_MATCHING);
+                        break;
+                    case 'd':
+                        flags.add(RegexFlag.IGNORE_DIACRITICS);
+                        break;
+                    default:
+                        throw new ExpressionTreeBuilderException(
+                                "unknown regex modifier flag: " + s.charAt(i));
+                    } // switch
+                }
+
+                // validate regex flags
+                if (flags.contains(RegexFlag.CASE_SENSITIVE) &&
+                        flags.contains(RegexFlag.CASE_INSENSITIVE)) {
+                    throw new ExpressionTreeBuilderException(
+                            "invalid combination of regex modifier flags: " +
+                            "'i' or 'c' and 'I' or 'C' are mutually exclusive");
+                }
+                if (flags.contains(RegexFlag.LITERAL_MATCHING) &&
+                            (flags.contains(RegexFlag.CASE_SENSITIVE) ||
+                             flags.contains(RegexFlag.CASE_INSENSITIVE) ||
+                             flags.contains(RegexFlag.IGNORE_DIACRITICS))) {
+                    throw new ExpressionTreeBuilderException(
+                            "invalid combination of regex modifier flags: 'l' " +
+                            "is mutually exclusive with 'i', 'c', 'I', 'C' or 'd'");
+                }
+
+                stack.push(flags);
+            } else {
+                // regex without flags, so push 'empty' flags on stack
+                stack.push(Collections.emptySet());
+            }
+            if (logger.isTraceEnabled()) {
+                logger.trace("visitRegexp/exit: stack={}", stack);
+            }
+            return null;
+        }
+
+
+        @Override
+        public Void visitWithin_part_simple(Within_part_simpleContext ctx) {
+            if (logger.isTraceEnabled()) {
+                logger.trace("Within_part_simpleContext/enter: children={} / cnt={} / text={}",
+                        ctx.children,
+                        ctx.getChildCount(),
+                        ctx.getText());
+            }
+
+            SimpleWithin.Scope scope = null;
+            String s = ctx.getChild(0).getText();
+            if ("sentence".equals(s) || "s".equals(s)) {
+                scope = SimpleWithin.Scope.SENTENCE;
+            } else if ("utterance".equals(s) || "u".equals(s)) {
+                scope = SimpleWithin.Scope.UTTERANCE;
+            } else if ("paragraph".equals(s) || "p".equals(s)) {
+                scope = SimpleWithin.Scope.PARAGRAPH;
+            } else if ("turn".equals(s)|| "t".equals(s)) {
+                scope = SimpleWithin.Scope.TURN;
+            } else if ("text".equals(s)) {
+                scope = SimpleWithin.Scope.TEXT;
+            } else if ("session".equals(s)) {
+                scope = SimpleWithin.Scope.SESSION;
+            } else {
+                throw new ExpressionTreeBuilderException(
+                        "invalid scope for simple 'within' clause: " + s);
+            }
+            stack.push(new SimpleWithin(scope));
+            if (logger.isTraceEnabled()) {
+                logger.trace("Within_part_simpleContext/exit: stack={}", stack);
+            }
+            return null;
+        }
+    }
+
+
+    private static int[] processRepetition(QuantifierContext ctx) {
+        final Token tok =
+                ctx.getChild(TerminalNode.class, 0).getSymbol();
+        switch (tok.getType()) {
+        case FCSParser.Q_ZERO_OR_MORE: /* "*" */
+            return REP_ZERO_OR_MORE;
+        case FCSParser.Q_ONE_OR_MORE:  /* "+" */
+            return REP_ONE_OR_MORE;
+        case FCSParser.Q_ZERO_OR_ONE:  /* "?" */
+            return REP_ZERO_OR_ONE;
+        case FCSParser.L_CURLY_BRACKET: /* "{x, y}" variants */
+            return processRepetition2(ctx);
+        default:
+            throw new ExpressionTreeBuilderException(
+                    "unexpected symbol in repetition quantifier: " +
+                            tok.getText());
+        } // switch
+    }
+
+
+    private static int[] processRepetition2(QuantifierContext ctx) {
+        int commaIdx = getChildIndex(ctx, FCSParser.Q_COMMA, 0);
+        int int1Idx = getChildIndex(ctx, FCSParser.INTEGER, 0);
+        int int2Idx = getChildIndex(ctx, FCSParser.INTEGER, int1Idx + 1);
+        int min = 0;
+        int max = QueryNode.OCCURS_UNBOUNDED;
+        if (commaIdx != -1) {
+            if (int1Idx < commaIdx) {
+                min = parseInteger(ctx.getChild(int1Idx).getText());
+            }
+            if (commaIdx < int1Idx) {
+                max = parseInteger(ctx.getChild(int1Idx).getText());
+            } else if (commaIdx < int2Idx) {
+                max = parseInteger(ctx.getChild(int2Idx).getText());
+            }
+        } else {
+            if (int1Idx == -1) {
+                throw new ExpressionTreeBuilderException("int1Idx == -1");
+            }
+            min = parseInteger(ctx.getChild(int1Idx).getText());
+            max = min;
+        }
+        if ((max != QueryNode.OCCURS_UNBOUNDED) && (min > max)) {
+            throw new ExpressionTreeBuilderException(
+                    "bad qualifier: min > max (" + min + " > " + max + ")");
+        }
+        return new int[] { min, max };
+    }
+
+
+    private static int getChildIndex(ParserRuleContext ctx,
+            int tokenType, int start) {
+        if ((start >= 0) && (start < ctx.getChildCount())) {
+            for (int i = start; i < ctx.getChildCount(); i++) {
+                final ParseTree o = ctx.getChild(i);
+                if (o instanceof TerminalNode) {
+                    if (((TerminalNode) o).getSymbol().getType() == tokenType) {
+                        return i;
+                    }
+                }
+            }
+        }
+        return -1;
+    }
+
+
+    private static int parseInteger(String s) {
+        try {
+            return Integer.parseInt(s);
+        } catch (NumberFormatException e) {
+            throw new ExpressionTreeBuilderException(
+                    "invalid integer: " + s, e);
+        }
+    }
+
+
+    private static String stripQuotes(String s) {
+        if (s.startsWith("\"")) {
+            if (s.endsWith("\"")) {
+                s = s.substring(1, s.length() - 1);
+            } else {
+                throw new ExpressionTreeBuilderException(
+                        "value not properly quoted; invalid closing quote");
+            }
+        } else if (s.startsWith("'")) {
+            if (s.endsWith("'")) {
+                s = s.substring(1, s.length() - 1);
+            } else {
+                throw new ExpressionTreeBuilderException(
+                        "value not properly quoted; invalid closing quote");
+            }
+        } else {
+            throw new ExpressionTreeBuilderException(
+                    "value not properly quoted; expected \" (double quote) " +
+                            "or ' (single qoute) character");
+        }
+        return s;
+    }
+
+
+    private static String unescapeString(String s, char[] buf) {
+        final StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < s.length(); i++) {
+            int cp = s.codePointAt(i);
+            if (cp == '\\') {
+                i++; // skip slash
+                cp = s.codePointAt(i);
+
+                switch (cp) {
+                case '\\': /* slash */
+                    sb.append("\\");
+                    break;
+                case '"':   /* double quote */
+                    sb.append("\"");
+                    break;
+                case '\'':  /* single quote */
+                    sb.append("'");
+                    break;
+                case 'n':   /* new line */
+                    sb.append("\n");
+                    break;
+                case 't':   /* tabulator */
+                    sb.append("\t");
+                    break;
+                case '.':   /* regex: dot */
+                    sb.append("\\.");
+                    break;
+                case '^':   /* regex: caret */
+                    sb.append("\\^");
+                    break;
+                case '$':   /* regex: dollar */
+                    sb.append("\\$");
+                    break;
+                case '*':   /* regex: asterisk */
+                    sb.append("\\*");
+                    break;
+                case '+':   /* regex: plus */
+                    sb.append("\\+");
+                    break;
+                case '?':   /* regex: question mark */
+                    sb.append("\\?");
+                    break;
+                case '(':   /* regex: opening parenthesis */
+                    sb.append("\\(");
+                    break;
+                case ')':   /* regex: closing parenthesis */
+                    sb.append("\\)");
+                    break;
+                case '{':   /* regex: opening curly brace */
+                    sb.append("\\{");
+                    break;
+                case '[':   /* regex: opening square bracket */
+                    sb.append("\\[");
+                    break;
+                case '|':   /* regex: vertical bar */
+                    sb.append("\\|");
+                    break;
+                case 'x':   /* x HEX HEX */
+                    i = unescapeUnicode(s, i, 2, sb, buf);
+                    break;
+                case 'u':   /* u HEX HEX HEX HEX */
+                    i = unescapeUnicode(s, i, 4, sb, buf);
+                    break;
+                case 'U':   /* U HEX HEX HEX HEX HEX HEX HEX HEX */
+                    i = unescapeUnicode(s, i, 8, sb, buf);
+                    break;
+                default:
+                    throw new ExpressionTreeBuilderException(
+                            "invalid escape sequence: \\" +
+                                    new String(Character.toChars(cp)));
+                }
+            } else {
+                try {
+                    final int len = Character.toChars(cp, buf, 0);
+                    sb.append(buf, 0, len);
+                } catch (IllegalArgumentException e) {
+                    throw new ExpressionTreeBuilderException(
+                            "invalid codepoint: U+" +
+                                    Integer.toHexString(cp).toUpperCase());
+                }
+            }
+        }
+        return sb.toString();
+    }
+
+
+    private static final int unescapeUnicode(String s, int i, int size,
+            StringBuilder sb, char[] buf) {
+        if ((s.length() - i - 1) >= size) {
+            int cp = 0;
+            for (int j = 0; j < size; j++) {
+                i++;
+                if (j > 0) {
+                    cp = cp << 4;
+                }
+                cp |= parseHexString(s.codePointAt(i));
+            }
+            try {
+                final int len = Character.toChars(cp, buf, 0);
+                sb.append(buf, 0, len);
+            } catch (IllegalArgumentException e) {
+                throw new ExpressionTreeBuilderException(
+                        "invalid codepoint: U+" +
+                                Integer.toHexString(cp).toUpperCase());
+            }
+            return i;
+        } else {
+            throw new ExpressionTreeBuilderException(
+                    "truncated escape sequence: \\" + s.substring(i));
+        }
+    }
+
+
+    private static final int parseHexString(int c) {
+        switch (c) {
+        case '0':
+            return 0;
+        case '1':
+            return 1;
+        case '2':
+            return 2;
+        case '3':
+            return 3;
+        case '4':
+            return 4;
+        case '5':
+            return 5;
+        case '6':
+            return 6;
+        case '7':
+            return 7;
+        case '8':
+            return 8;
+        case '9':
+            return 9;
+        case 'a':
+            /* FALL-THROUGH */
+        case 'A':
+            return 10;
+        case 'b':
+            /* FALL-THROUGH */
+        case 'B':
+            return 11;
+        case 'c':
+            /* FALL-THROUGH */
+        case 'C':
+            return 12;
+        case 'd':
+            /* FALL-THROUGH */
+        case 'D':
+            return 13;
+        case 'e':
+            /* FALL-THROUGH */
+        case 'E':
+            return 14;
+        case 'f':
+            /* FALL-THROUGH */
+        case 'F':
+            return 15;
+        default:
+            /*
+             * actually, this should never happen, as ANTLR's lexer should catch
+             * illegal HEX characters
+             */
+            throw new ExpressionTreeBuilderException(
+                    "invalud hex character: " +
+                            new String(Character.toChars(c)));
+        }
+    }
+
+
+    private static final class ErrorListener extends BaseErrorListener {
+        private final String query;
+        private List<String> errors = null;
+
+
+        private ErrorListener(String query) {
+            this.query = query;
+        }
+
+
+        @Override
+        public void syntaxError(Recognizer<?, ?> recognizer,
+                Object offendingSymbol, int line, int charPositionInLine,
+                String msg, RecognitionException e) {
+            if (errors == null) {
+                errors = new ArrayList<String>();
+            }
+
+            /*
+             * FIXME: additional information of error should not be logged
+             * but added to the list of errors; that list probably needs
+             * to be enhanced to store supplementary information
+             * Furthermore, a sophisticated errorlist implementation could
+             * also be used by the QueryVistor to add addition query error
+             * information
+             */
+            if (logger.isDebugEnabled()) {
+                if (offendingSymbol instanceof Token) {
+                    final Token t = (Token) offendingSymbol;
+                    int pos = t.getStartIndex();
+                    if (pos != -1) {
+                        StringBuilder x = new StringBuilder();
+                        while (pos-- > 0) {
+                            x.append(" ");
+                        }
+                        x.append("^- ").append(msg);
+                        logger.debug("query: {}", query);
+                        logger.debug("       {}", x.toString());
+                    }
+                }
+            }
+
+            errors.add(msg);
+        }
+
+
+        public boolean hasErrors() {
+            return (errors != null) && !errors.isEmpty();
+        }
+
+
+        public List<String> getErrors() {
+            if (errors != null) {
+                return errors;
+            } else {
+                return Collections.emptyList();
+            }
+        }
+    }
+
+
+    @SuppressWarnings("serial")
+    private static final class ExpressionTreeBuilderException
+            extends RuntimeException {
+        private ExpressionTreeBuilderException(String message,
+                Throwable cause) {
+            super(message, cause);
+        }
+
+
+        private ExpressionTreeBuilderException(String message) {
+            this(message, null);
+        }
+    }
+
+} // class QueryParser
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryParserException.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryParserException.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryParserException.java	(revision 7248)
@@ -0,0 +1,49 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * Query parser exception.
+ *
+ */
+@SuppressWarnings("serial")
+public class QueryParserException extends Exception {
+    /**
+     * Constrctur.
+     *
+     * @param message
+     *            an error message
+     * @param cause
+     *            the underlying cause for the error
+     */
+    public QueryParserException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+
+    /**
+     * Constructor.
+     *
+     * @param message
+     *            an error message
+     */
+    public QueryParserException(String message) {
+        this(message, null);
+    }
+
+} // class QueryParserException
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QuerySegment.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QuerySegment.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QuerySegment.java	(revision 7248)
@@ -0,0 +1,114 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * A FCS-QL expression tree query segment node.
+ */
+public class QuerySegment extends QueryNode {
+    private final int minOccurs;
+    private final int maxOccurs;
+
+
+    /**
+     * Constructor.
+     *
+     * @param expression
+     *            the expression
+     * @param minOccurs
+     *            the minimum occurrence
+     * @param maxOccurs
+     *            the maximum occurrence
+     */
+    QuerySegment(QueryNode expression, int minOccurs, int maxOccurs) {
+        super(QueryNodeType.QUERY_SEGMENT, expression);
+        this.minOccurs = minOccurs;
+        this.maxOccurs = maxOccurs;
+    }
+
+
+    /**
+     * Get the expression for this segment.
+     *
+     * @return the expression
+     */
+    public QueryNode getExpression() {
+        return children.get(0);
+    }
+
+
+    /**
+     * Get the minimum occurrence of this segment.
+     *
+     * @return the minimum occurrence
+     *
+     */
+    public int getMinOccurs() {
+        return minOccurs;
+    }
+
+
+    /**
+     * Get the maximum occurrence of this segment.
+     *
+     * @return the maximum occurrence
+     *
+     */
+    public int getMaxOccurs() {
+        return maxOccurs;
+    }
+
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("(");
+        sb.append(nodeType.toDisplayString());
+        sb.append(" ");
+        if (minOccurs != 1) {
+            sb.append("@min=");
+            if (minOccurs == QueryNode.OCCURS_UNBOUNDED) {
+                sb.append("*");
+            } else {
+                sb.append(minOccurs);
+            }
+            sb.append(" ");
+        }
+        if (maxOccurs != 1) {
+            sb.append("@max=");
+            if (maxOccurs == QueryNode.OCCURS_UNBOUNDED) {
+                sb.append("*");
+            } else {
+                sb.append(maxOccurs);
+            }
+            sb.append(" ");
+
+        }
+        sb.append(children.get(0));
+        sb.append(")");
+        return sb.toString();
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        children.get(0).accept(visitor);
+        visitor.visit(this);
+    }
+
+} // class QuerySegment
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QuerySequence.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QuerySequence.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QuerySequence.java	(revision 7248)
@@ -0,0 +1,48 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+import java.util.List;
+
+
+/**
+ * A FCS-QL expression tree query sequence node.
+ */
+public class QuerySequence extends QueryNode {
+
+    /**
+     * Constructor.
+     *
+     * @param children
+     *            the children for this node
+     */
+    QuerySequence(List<QueryNode> children) {
+        super(QueryNodeType.QUERY_SEQUENCE, children);
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        if (!children.isEmpty()) {
+            for (QueryNode child : children) {
+                child.accept(visitor);
+            }
+        }
+        visitor.visit(this);
+    }
+
+} // class QuerySequence
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryVisitor.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryVisitor.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryVisitor.java	(revision 7248)
@@ -0,0 +1,131 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * Interface implementing a Visitor pattern for FCS-QL expression trees.
+ */
+public interface QueryVisitor {
+    /**
+     * Visit a <em>segment</em> query node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(QuerySegment node);
+
+
+    /**
+     * Visit a <em>group</em> query node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(QueryGroup node);
+
+
+    /**
+     * Visit a <em>sequence</em> query node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(QuerySequence node);
+
+
+    /**
+     * Visit a <em>or</em> query node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(QueryDisjunction node);
+
+
+    /**
+     * Visit a <em>query</em> with within node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(QueryWithWithin node);
+
+
+    /**
+     * Visit a <em>simple</em> expression node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(Expression node);
+
+
+    /**
+     * Visit a <em>wildcard</em> expression node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(ExpressionWildcard node);
+
+
+    /**
+     * Visit a <em>group</em> expression node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(ExpressionGroup node);
+
+
+    /**
+     * Visit a <em>or</em> expression node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(ExpressionOr node);
+
+
+    /**
+     * Visit a <em>and</em> expression node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(ExpressionAnd node);
+
+
+    /**
+     * Visit a <em>not</em> expression node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(ExpressionNot node);
+
+
+    /**
+     * Visit a <em>simple within</em> node.
+     *
+     * @param node
+     *            the node to visit
+     */
+    public void visit(SimpleWithin node);
+
+} // interface QueryVisitor
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryVisitorAdapter.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryVisitorAdapter.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryVisitorAdapter.java	(revision 7248)
@@ -0,0 +1,85 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * Convenience class to implement FCS-QL expression tree visitors. Default
+ * method implementations do nothing.
+ */
+public class QueryVisitorAdapter implements QueryVisitor {
+
+    @Override
+    public void visit(QuerySegment node) {
+    }
+
+
+    @Override
+    public void visit(QueryGroup node) {
+    }
+
+
+    @Override
+    public void visit(QuerySequence node) {
+    }
+
+
+    @Override
+    public void visit(QueryDisjunction node) {
+    }
+
+
+    @Override
+    public void visit(QueryWithWithin node) {
+    }
+
+
+    @Override
+    public void visit(Expression node) {
+    }
+
+
+    @Override
+    public void visit(ExpressionWildcard node) {
+    }
+
+
+    @Override
+    public void visit(ExpressionGroup node) {
+    }
+
+
+    @Override
+    public void visit(ExpressionOr node) {
+    }
+
+
+    @Override
+    public void visit(ExpressionAnd node) {
+    }
+
+
+    @Override
+    public void visit(ExpressionNot node) {
+    }
+
+
+    @Override
+    public void visit(SimpleWithin node) {
+    }
+
+} // class QueryVistorAdapter
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryWithWithin.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryWithWithin.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/QueryWithWithin.java	(revision 7248)
@@ -0,0 +1,69 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+import java.util.Arrays;
+
+
+/**
+ * FCS-QL expression tree QUERY-WITH-WITHIN node.
+ */
+public class QueryWithWithin extends QueryNode {
+
+    /**
+     * Constructor.
+     *
+     * @param query
+     *            the query node
+     * @param within
+     *            the within node
+     */
+    QueryWithWithin(QueryNode query, QueryNode within) {
+        super(QueryNodeType.QUERY_WITH_WITHIN, Arrays.asList(query, within));
+    }
+
+
+    /**
+     * Get the query clause.
+     *
+     * @return the query clause
+     */
+    public QueryNode getQuery() {
+        return getChild(0);
+    }
+
+
+    /**
+     * Get the within clause (= search context)
+     *
+     * @return the witin clause
+     */
+    public QueryNode getWithin() {
+        return getChild(1);
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        children.get(0).accept(visitor);
+        if (children.size() > 1) {
+            children.get(1).accept(visitor);
+        }
+        visitor.visit(this);
+    }
+
+} // class QueryWithWithin
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/RegexFlag.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/RegexFlag.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/RegexFlag.java	(revision 7248)
@@ -0,0 +1,41 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * FCS-QL expression tree regex flags.
+ */
+public enum RegexFlag {
+    /**
+     * case insensitive.
+     */
+    CASE_INSENSITIVE,
+    /**
+     * case sensitive.
+     */
+    CASE_SENSITIVE,
+    /**
+     * match exactly (= literally).
+     */
+    LITERAL_MATCHING,
+    /**
+     * ignore all diacritics
+     */
+    IGNORE_DIACRITICS
+
+} // enum RegexFlag
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/SimpleWithin.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/SimpleWithin.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/parser/SimpleWithin.java	(revision 7248)
@@ -0,0 +1,130 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.parser;
+
+
+/**
+ * A FCS-QL expression tree SIMPLE WITHIN query node.
+ */
+public class SimpleWithin extends QueryNode {
+    /**
+     * The within scope.
+     */
+    public enum Scope {
+        /**
+         * sentence scope (small).
+         */
+        SENTENCE {
+            @Override
+            public String toDisplayString() {
+                return "Sentence";
+            }
+
+        },
+        /**
+         * utterance scope (small).
+         */
+        UTTERANCE {
+            @Override
+            public String toDisplayString() {
+                return "Utterance";
+            }
+
+        },
+        /**
+         * paragraph scope (medium).
+         */
+        PARAGRAPH {
+            @Override
+            public String toDisplayString() {
+                return "Paragraph";
+            }
+
+        },
+        /**
+         * turn scope (medium).
+         */
+        TURN {
+            @Override
+            public String toDisplayString() {
+                return "Turn";
+            }
+        },
+        /**
+         * text scope (large).
+         */
+        TEXT {
+            @Override
+            public String toDisplayString() {
+                return "Text";
+            }
+        },
+        /**
+         * session scope (large).
+         */
+        SESSION {
+            @Override
+            public String toDisplayString() {
+                return "Session";
+            }
+        };
+
+        abstract String toDisplayString();
+    }
+    private final Scope scope;
+
+
+    /**
+     * Constructor.
+     *
+     * @param scope
+     *            the scope
+     */
+    SimpleWithin(Scope scope) {
+        super(QueryNodeType.SIMPLE_WITHIN);
+        this.scope = scope;
+    }
+
+
+    /**
+     * Get the simple within scope
+     *
+     * @return the simple within scope
+     */
+    public Scope getScope() {
+        return scope;
+    }
+
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("(")
+            .append(nodeType.toDisplayString())
+            .append(" ")
+            .append(scope.toDisplayString())
+            .append(")");
+        return sb.toString();
+    }
+
+
+    @Override
+    public void accept(QueryVisitor visitor) {
+        visitor.visit(this);
+    }
+
+} // class SimpleWithin
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/utils/AbstractEndpointDescriptionBase.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/utils/AbstractEndpointDescriptionBase.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/utils/AbstractEndpointDescriptionBase.java	(revision 7248)
@@ -0,0 +1,136 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.utils;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+
+import eu.clarin.sru.server.fcs.DataView;
+import eu.clarin.sru.server.fcs.EndpointDescription;
+import eu.clarin.sru.server.fcs.Layer;
+
+
+/**
+ * An abstract base class for implementing endpoint descriptions. It already
+ * implements the methods required for capabilities and supported data views.
+ *
+ * @see EndpointDescription
+ *
+ */
+public abstract class AbstractEndpointDescriptionBase
+        implements EndpointDescription {
+    protected final int version;
+    protected final List<URI> capabilities;
+    protected final List<DataView> supportedDataViews;
+    protected final List<Layer> supportedLayers;
+
+
+    /**
+     * Constructor.
+     *
+     * @param version
+     *            version of this endpoint description
+     * @param capabilities
+     *            a list of capabilities supported by this endpoint
+     * @param supportedDataViews
+     *            a list of data views that are supported by this endpoint
+     * @param supportedLayers
+     *            a list of layers that are supported by this endpoint
+     */
+    protected AbstractEndpointDescriptionBase(int version,
+            List<URI> capabilities, List<DataView> supportedDataViews,
+            List<Layer> supportedLayers) {
+        if ((version != 1) && (version != 2)) {
+            throw new IllegalArgumentException("version must be either 1 or 2");
+        }
+        this.version = version;
+
+        if (capabilities == null) {
+            throw new NullPointerException("capabilities == null");
+        }
+        if (capabilities.isEmpty()) {
+            throw new IllegalArgumentException("capabilities are empty");
+        }
+        for (URI capability : capabilities) {
+            if (capability == null) {
+                throw new IllegalArgumentException(
+                        "capabilities must not contain a 'null' item");
+            }
+        }
+        this.capabilities = Collections.unmodifiableList(capabilities);
+
+        if (supportedDataViews == null) {
+            throw new NullPointerException("supportedDataViews == null");
+        }
+        if (supportedDataViews.isEmpty()) {
+            throw new IllegalArgumentException("supportedDataViews are empty");
+        }
+        for (DataView supportedDataView : supportedDataViews) {
+            if (supportedDataView == null) {
+                throw new IllegalArgumentException(
+                        "supportedDataViews must not contain a 'null' item");
+            }
+        }
+        this.supportedDataViews =
+                Collections.unmodifiableList(supportedDataViews);
+
+        if ((supportedLayers != null) && !supportedLayers.isEmpty()) {
+            for (Layer layer : supportedLayers) {
+                if (layer == null) {
+                    throw new IllegalArgumentException(
+                            "supportedLayers must not contain a 'null' item");
+                }
+            }
+            this.supportedLayers =
+                    Collections.unmodifiableList(supportedLayers);
+        } else {
+            this.supportedLayers = null;
+        }
+    }
+
+
+    @Override
+    public int getVersion() {
+        return version;
+    }
+
+
+    @Override
+    public boolean isVersion(int version) {
+        return this.version == version;
+    }
+
+
+    @Override
+    public List<URI> getCapabilities() {
+        return capabilities;
+    }
+
+
+    @Override
+    public List<DataView> getSupportedDataViews() {
+        return supportedDataViews;
+    }
+
+
+    @Override
+    public List<Layer> getSupportedLayers() {
+        return supportedLayers;
+    }
+
+} // abstract class EndpointDescriptionBase
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescription.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescription.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescription.java	(revision 7248)
@@ -0,0 +1,130 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.utils;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+
+import eu.clarin.sru.server.SRUException;
+import eu.clarin.sru.server.fcs.DataView;
+import eu.clarin.sru.server.fcs.EndpointDescription;
+import eu.clarin.sru.server.fcs.Layer;
+import eu.clarin.sru.server.fcs.ResourceInfo;
+
+
+/**
+ * A very simple implementation of an endpoint description that is initialized
+ * from static information supplied at construction time. Mostly used together
+ * with {@link SimpleEndpointDescriptionParser}, but it is agnostic how the
+ * static list of resource info records is generated.
+ *
+ * @see EndpointDescription
+ * @see SimpleEndpointDescriptionParser
+ */
+public class SimpleEndpointDescription extends AbstractEndpointDescriptionBase {
+    private final boolean pidCaseSensitive;
+    private final List<ResourceInfo> entries;
+
+
+    /**
+     * Constructor.
+     *
+     * @param version
+     *            version of this endpoint description
+     * @param capabilities
+     *            a list of capabilities supported by this endpoint
+     * @param supportedDataViews
+     *            a list of data views that are supported by this endpoint
+     * @param supportedLayers
+     *            a list of layers supported for Advanced Search by this
+     *            endpoint or <code>null</code>
+     * @param resources
+     *            a static list of resource info records
+     * @param pidCaseSensitive
+     *            <code>true</code> if comparison of persistent identifiers
+     *            should be performed case-sensitive, <code>false</code>
+     *            otherwise
+     */
+    public SimpleEndpointDescription(int version, List<URI> capabilities,
+            List<DataView> supportedDataViews,
+            List<Layer> supportedLayers,
+            List<ResourceInfo> resources,
+            boolean pidCaseSensitive) {
+        super(version, capabilities, supportedDataViews, supportedLayers);
+
+        if (resources == null) {
+            throw new NullPointerException("entries == null");
+        }
+        this.entries = Collections.unmodifiableList(resources);
+        this.pidCaseSensitive = pidCaseSensitive;
+    }
+
+
+    @Override
+    public void destroy() {
+    }
+
+
+    @Override
+    public List<ResourceInfo> getResourceList(String pid) throws SRUException {
+        if (pid == null) {
+            throw new NullPointerException("pid == null");
+        }
+        if (pid.isEmpty()) {
+            throw new IllegalArgumentException("pid is empty");
+        }
+        if (!pidCaseSensitive) {
+            pid = pid.toLowerCase();
+        }
+        if (pid.equals(PID_ROOT)) {
+            return entries;
+        } else {
+            ResourceInfo ri = findRecursive(entries, pid);
+            if (ri != null) {
+                return ri.getSubResources();
+            }
+        }
+        return null;
+    }
+
+
+    private ResourceInfo findRecursive(List<ResourceInfo> items, String pid) {
+        if ((items != null) && !items.isEmpty()) {
+            for (ResourceInfo item : items) {
+                if (pidCaseSensitive) {
+                    if (pid.equals(item.getPid())) {
+                        return item;
+                    }
+                } else {
+                    if (pid.equalsIgnoreCase(item.getPid())) {
+                        return item;
+                    }
+                }
+                if (item.hasSubResources()) {
+                    ResourceInfo ri =
+                            findRecursive(item.getSubResources(), pid);
+                    if (ri != null) {
+                        return ri;
+                    }
+                }
+            } // for
+        }
+        return null;
+    }
+
+} // class SimpleEndpointDescription
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescriptionParser.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescriptionParser.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescriptionParser.java	(revision 7248)
@@ -0,0 +1,781 @@
+/**
+ * This software is copyright (c) 2013-2016 by
+ *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ * This is free software. You can redistribute it
+ * and/or modify it under the terms described in
+ * the GNU General Public License v3 of which you
+ * should have received a copy. Otherwise you can download
+ * it from
+ *
+ *   http://www.gnu.org/licenses/gpl-3.0.txt
+ *
+ * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
+ *
+ * @license http://www.gnu.org/licenses/gpl-3.0.txt
+ *  GNU General Public License v3
+ */
+package eu.clarin.sru.server.fcs.utils;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import eu.clarin.sru.server.SRUConfigException;
+import eu.clarin.sru.server.fcs.DataView;
+import eu.clarin.sru.server.fcs.DataView.DeliveryPolicy;
+import eu.clarin.sru.server.fcs.EndpointDescription;
+import eu.clarin.sru.server.fcs.Layer;
+import eu.clarin.sru.server.fcs.ResourceInfo;
+
+
+/**
+ * A parser, that parses an XML file and produces a endpoint description with
+ * static list of resource info records. The XML file has the same format as the
+ * result format defined for endpoint description of the CLARIN-FCS
+ * specification. The {@link #parse(URL)} returns a
+ * {@link SimpleEndpointDescription} instance.
+ *
+ * @see EndpointDescription
+ * @see SimpleEndpointDescription
+ */
+public class SimpleEndpointDescriptionParser {
+    private static final String NS =
+            "http://clarin.eu/fcs/endpoint-description";
+    private static final String NS_LEGACY =
+            "http://clarin.eu/fcs/1.0/resource-info";
+    private static final URI CAP_BASIC_SEARCH =
+            URI.create("http://clarin.eu/fcs/capability/basic-search");
+    private static final URI CAP_ADVANCED_SEARCH =
+            URI.create("http://clarin.eu/fcs/capability/advanced-search");
+    private static final String MIMETYPE_HITS = "application/x-clarin-fcs-hits+xml";
+    private static final String MIMETYPE_ADV = "application/x-clarin-fcs-adv+xml";
+    private static final String LANG_EN = "en";
+    private static final String POLICY_SEND_DEFAULT = "send-by-default";
+    private static final String POLICY_NEED_REQUEST = "need-to-request";
+    private static final String LAYER_ENCODING_VALUE = "value";
+    private static final String LAYER_ENCODING_EMPTY = "empty";
+    private static final Logger logger =
+            LoggerFactory.getLogger(SimpleEndpointDescriptionParser.class);
+
+
+    /**
+     * Parse an XML file and return a static list of resource info records.
+     *
+     * @param url
+     *            the URI pointing to the file to be parsed
+     * @return an {@link EndpointDescription} instance
+     * @throws SRUConfigException
+     *             if an error occurred
+     */
+    public static EndpointDescription parse(URL url) throws SRUConfigException {
+        if (url == null) {
+            throw new NullPointerException("url == null");
+        }
+
+        logger.debug("parsing endpoint description from: {}", url);
+
+        try {
+            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            dbf.setNamespaceAware(true);
+            dbf.setCoalescing(true);
+            DocumentBuilder db = dbf.newDocumentBuilder();
+            Document doc = db.parse(url.openStream());
+
+            /*
+             * Detect for deprecated resource-info catalog files and bail, if necessary
+             */
+            checkLegacyMode(doc, url);
+
+            /*
+             * Parse on and create endpoint description ...
+             */
+            return parseEndpointDescription(doc);
+        } catch (ParserConfigurationException e) {
+            throw new SRUConfigException("internal error", e);
+        } catch (SAXException e) {
+            throw new SRUConfigException("parsing error", e);
+        } catch (IOException e) {
+            throw new SRUConfigException("error reading file", e);
+        } catch (XPathExpressionException e) {
+            throw new SRUConfigException("internal error", e);
+        }
+    }
+
+
+    private static EndpointDescription parseEndpointDescription(Document doc)
+            throws SRUConfigException, XPathExpressionException {
+        XPathFactory factory = XPathFactory.newInstance();
+        XPath xpath = factory.newXPath();
+
+        xpath.setNamespaceContext(new NamespaceContext() {
+            @Override
+            public Iterator<String> getPrefixes(String namespaceURI) {
+                throw new UnsupportedOperationException();
+            }
+
+            @Override
+            public String getPrefix(String namespaceURI) {
+                throw new UnsupportedOperationException();
+            }
+
+            @Override
+            public String getNamespaceURI(String prefix) {
+                if (prefix == null) {
+                    throw new NullPointerException("prefix == null");
+                }
+                if (prefix.equals("ed")) {
+                    return NS;
+                } else if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
+                    return XMLConstants.XML_NS_URI;
+                } else {
+                    return XMLConstants.NULL_NS_URI;
+                }
+            }
+        });
+
+        // version
+        int version = -1;
+        XPathExpression exp =
+                xpath.compile("//ed:EndpointDescription/@version");
+        String v = (String) exp.evaluate(doc, XPathConstants.STRING);
+        if (v != null) {
+            try {
+                version = Integer.parseInt(v);
+                if ((version != 1) && (version != 2)) {
+                    throw new SRUConfigException("Attribute @version " +
+                            "element <EndpointDescription> must have a " +
+                            "value of either '1' or '2' ");
+                }
+            } catch (NumberFormatException e) {
+                throw new SRUConfigException("Cannot parse version number", e);
+            }
+        }
+        if (version == -1) {
+            throw new SRUConfigException("Attribute @version missing on "+
+                    "element <EndpointDescription>");
+        }
+        logger.debug("endpoint description version is {}", version);
+
+        // capabilities
+        List<URI> capabilities = new ArrayList<URI>();
+        exp = xpath.compile("//ed:Capabilities/ed:Capability");
+        NodeList list =
+                (NodeList) exp.evaluate(doc, XPathConstants.NODESET);
+        if ((list != null) && (list.getLength() > 0)) {
+            logger.debug("parsing capabilities");
+            for (int i = 0; i < list.getLength(); i++) {
+                String s = list.item(i).getTextContent().trim();
+                try {
+                    URI uri = new URI(s);
+                    if (!capabilities.contains(uri)) {
+                        capabilities.add(uri);
+                    } else {
+                        logger.warn("ignoring duplicate capability " +
+                                "entry for '{}'", uri);
+                    }
+                } catch (URISyntaxException e) {
+                    throw new SRUConfigException("capability is not encoded " +
+                            "as a proper URI: " + s);
+                }
+            }
+        } else {
+            logger.warn("No capabilities where defined in " +
+                    "endpoint configuration");
+        }
+        if (!capabilities.contains(CAP_BASIC_SEARCH)) {
+            logger.warn("capability '{}' was not defined in endpoint " +
+                    "description; it was added to meet the specification. Please " +
+                    "update your endpoint description!", CAP_BASIC_SEARCH);
+            capabilities.add(CAP_BASIC_SEARCH);
+        }
+        if (capabilities.contains(CAP_ADVANCED_SEARCH) && (version < 2)) {
+            logger.warn("Endpoint description is declared as version " +
+                    "FCS 1.0 (@version = 1), but contains support for " +
+                    "Advanced Search in capabilities list! FCS 1.0 only " +
+                    "supports Basic Search");
+        }
+        logger.debug("CAPS:'{}'", capabilities);
+
+        // used to check for uniqueness of id attribute
+        final Set<String> xml_ids = new HashSet<String>();
+
+        // supported data views
+        List<DataView> supportedDataViews = new ArrayList<DataView>();
+        exp = xpath.compile("//ed:SupportedDataViews/ed:SupportedDataView");
+        list = (NodeList) exp.evaluate(doc, XPathConstants.NODESET);
+        if ((list != null) && (list.getLength() > 0)) {
+            logger.debug("parsing supported data views");
+            for (int i = 0; i < list.getLength(); i++) {
+                Element item = (Element) list.item(i);
+                String id = getAttribute(item, "id");
+                if (id == null) {
+                    throw new SRUConfigException("Element <SupportedDataView> "
+                            + "must have a proper 'id' attribute");
+                }
+
+                if (xml_ids.contains(id)) {
+                    throw new SRUConfigException("The value of attribute " +
+                            "'id' of element <SupportedDataView> must be " +
+                            "unique: " + id);
+                }
+                xml_ids.add(id);
+
+                String p = getAttribute(item, "delivery-policy");
+                if (p == null) {
+                    throw new SRUConfigException("Element <SupportedDataView> "
+                            + "must have a 'delivery-policy' attribute");
+                }
+                DeliveryPolicy policy = null;
+                if (POLICY_SEND_DEFAULT.equals(p)) {
+                    policy = DeliveryPolicy.SEND_BY_DEFAULT;
+                } else if (POLICY_NEED_REQUEST.equals(p)) {
+                    policy = DeliveryPolicy.NEED_TO_REQUEST;
+                } else {
+                    throw new SRUConfigException("Invalid value '" + p +
+                            "' for attribute 'delivery-policy' on element " +
+                            "<SupportedDataView>");
+                }
+                String mimeType = item.getTextContent();
+                if (mimeType != null) {
+                    mimeType = mimeType.trim();
+                    if (mimeType.isEmpty()) {
+                        mimeType = null;
+                    }
+                }
+                if (mimeType == null) {
+                    throw new SRUConfigException("Element <SupportedDataView> "
+                            + "must contain a MIME-type as content");
+                }
+                // check for duplicate entries ...
+                for (DataView dataView : supportedDataViews) {
+                    if (id.equals(dataView.getIdentifier())) {
+                        throw new SRUConfigException(
+                                "A <SupportedDataView> with " + "the id '" +
+                                        id + "' is already defined!");
+                    }
+                    if (mimeType.equals(dataView.getMimeType())) {
+                        throw new SRUConfigException(
+                                "A <SupportedDataView> with " +
+                                        "the MIME-type '" + mimeType +
+                                        "' is already defined!");
+                    }
+                }
+                supportedDataViews.add(new DataView(id, mimeType, policy));
+            }
+        } else {
+            logger.error("Endpoint configuration contains no valid " +
+                    "information about supported data views");
+            throw new SRUConfigException("Endpoint configuration contains " +
+                    "no valid information about supported data views");
+        }
+
+        logger.debug("DV: {}", supportedDataViews);
+
+        // sanity check on data views
+        boolean hasHitsView = false;
+        boolean hasAdvView = false;
+
+        for (DataView dataView : supportedDataViews) {
+            if (dataView.getMimeType().equals(MIMETYPE_HITS)) {
+                hasHitsView = true;
+            } else if (dataView.getMimeType().equals(MIMETYPE_ADV)) {
+                hasAdvView = true;
+            }
+        }
+        if (!hasHitsView) {
+            throw new SRUConfigException("Generic Hits Data View (" +
+                    MIMETYPE_HITS + ") was not declared in <SupportedDataViews>");
+        }
+        if (capabilities.contains(CAP_ADVANCED_SEARCH) && !hasAdvView) {
+            throw new SRUConfigException("Endpoint claimes to support " +
+                    "Advanced FCS but does not declare Advanced Data View (" +
+                    MIMETYPE_ADV + ") in <SupportedDataViews>");
+        }
+
+        // supported layers
+        List<Layer> supportedLayers = null;
+        exp = xpath.compile("//ed:SupportedLayers/ed:SupportedLayer");
+        list = (NodeList) exp.evaluate(doc, XPathConstants.NODESET);
+        if ((list != null) && (list.getLength() > 0)) {
+            logger.debug("parsing supported layers");
+            for (int i = 0; i < list.getLength(); i++) {
+                Element item = (Element) list.item(i);
+                String id = getAttribute(item, "id");
+                if (id == null) {
+                    throw new SRUConfigException("Element <SupportedLayer> "
+                            + "must have a proper 'id' attribute");
+                }
+
+                if (xml_ids.contains(id)) {
+                    throw new SRUConfigException("The value of attribute " +
+                            "'id' of element <SupportedLayer> must be " +
+                            "unique: " + id);
+                }
+                xml_ids.add(id);
+
+                String s = getAttribute(item, "result-id");
+                if (s == null) {
+                    throw new SRUConfigException("Element <SupportedLayer> "
+                            + "must have a proper 'result-id' attribute");
+                }
+                URI resultId = null;
+                try {
+                    resultId = new URI(s);
+                } catch (URISyntaxException e) {
+                    throw new SRUConfigException("Attribute 'result-id' on " +
+                            "Element <SupportedLayer> is not encoded " +
+                            "as proper URI: " + s);
+                }
+
+                String type = cleanString(item.getTextContent());
+                if ((type != null) && !type.isEmpty()) {
+                    // sanity check on layer types
+                    if (!(type.equals("text") ||
+                            type.equals("lemma") ||
+                            type.equals("pos") ||
+                            type.equals("orth") ||
+                            type.equals("norm") ||
+                            type.equals("phonetic") ||
+                            type.startsWith("x-"))) {
+                        logger.warn("layer type '{}' is not defined by specification", type);
+                    }
+                } else {
+                    throw new SRUConfigException("Element <SupportedLayer> " +
+                            "does not define a proper layer type");
+                }
+
+                String qualifier = getAttribute(item, "qualifier");
+
+                Layer.ContentEncoding encoding =
+                        Layer.ContentEncoding.VALUE;
+                s = getAttribute(item, "type");
+                if (s != null) {
+                    if (LAYER_ENCODING_VALUE.equals(s)) {
+                        encoding = Layer.ContentEncoding.VALUE;
+                    } else if (LAYER_ENCODING_EMPTY.equals(s)) {
+                        encoding = Layer.ContentEncoding.EMPTY;
+                    } else {
+                        throw new SRUConfigException(
+                                "invalid layer encoding: " + s);
+                    }
+                }
+
+
+                String altValueInfo = getAttribute(item, "alt-value-info");
+                URI altValueInfoURI = null;
+                if (altValueInfo != null) {
+                    s = getAttribute(item, "alt-value-info-uri");
+                    if (s != null) {
+                        try {
+                          altValueInfoURI = new URI(s);
+                        } catch (URISyntaxException e) {
+                            throw new SRUConfigException("Attribute " +
+                                    "'alt-value-info-uri' on Element " +
+                                    "<SupportedLayer> is not encoded " +
+                                    "as proper URI: " + s);
+                        }
+                    }
+                }
+
+                if (supportedLayers == null) {
+                    supportedLayers = new ArrayList<Layer>(list.getLength());
+                }
+                supportedLayers.add(new Layer(id, resultId, type, encoding,
+                        qualifier, altValueInfo, altValueInfoURI));
+            }
+        }
+
+        if ((supportedLayers != null) &&
+                !capabilities.contains(CAP_ADVANCED_SEARCH)) {
+                logger.warn("Endpoint description has <SupportedLayer> but " +
+                        "does not indicate support for Advanced Search. " +
+                        "Please consider adding capability ({}) to " +
+                        "your endpoint description to make use of layers!",
+                        CAP_ADVANCED_SEARCH);
+        } // necessary
+        logger.debug("L: {}", supportedLayers);
+
+        // resources
+        exp = xpath.compile("/ed:EndpointDescription/ed:Resources/ed:Resource");
+        list = (NodeList) exp.evaluate(doc, XPathConstants.NODESET);
+        final Set<String> pids = new HashSet<String>();
+        List<ResourceInfo> resources = parseResources(xpath, list, pids,
+                supportedDataViews, supportedLayers, version, hasAdvView);
+        if ((resources == null) || resources.isEmpty()) {
+            throw new SRUConfigException("No resources where " +
+                    "defined in endpoint description");
+        }
+        if (logger.isDebugEnabled()) {
+            logger.debug("Dumping ResourceInfo:");
+            dumpResourceInfo(1, resources);
+        }
+
+        return new SimpleEndpointDescription(version,
+                capabilities,
+                supportedDataViews,
+                supportedLayers,
+                resources,
+                false);
+    }
+
+
+    private static void dumpResourceInfo(int depth, List<ResourceInfo> ris) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < depth; i++) {
+            sb.append("--");
+        }
+        String pfx = sb.toString();
+        for (ResourceInfo ri : ris) {
+            List<ResourceInfo> sris = ri.getSubResources();
+            logger.debug("{} {} (level={})", pfx, ri.getPid(), depth);
+            if (sris != null) {
+                dumpResourceInfo(depth + 1, sris);
+            }
+        }
+    }
+
+
+    private static List<ResourceInfo> parseResources(XPath xpath,
+            NodeList nodes, Set<String> pids, List<DataView> supportedDataViews,
+            List<Layer> supportedLayers, int version, boolean hasAdv)
+                    throws SRUConfigException, XPathExpressionException {
+        List<ResourceInfo> ris = null;
+        for (int k = 0; k < nodes.getLength(); k++) {
+            final Element node = (Element) nodes.item(k);
+            String pid = null;
+            Map<String, String> titles = null;
+            Map<String, String> descrs = null;
+            String link = null;
+            List<String> langs = null;
+            List<DataView> availableDataViews = null;
+            List<Layer> availableLayers = null;
+            List<ResourceInfo> sub = null;
+
+            pid = getAttribute(node, "pid");
+            if (pid == null) {
+                throw new SRUConfigException("Element <ResourceInfo> " +
+                        "must have a proper 'pid' attribute");
+            }
+            if (pids.contains(pid)) {
+                throw new SRUConfigException("Another element <Resource> " +
+                        "with pid '" + pid + "' already exists");
+            }
+            pids.add(pid);
+            logger.debug("Processing resource with pid '{}'", pid);
+
+            XPathExpression exp = xpath.compile("ed:Title");
+            NodeList list = (NodeList) exp.evaluate(node,
+                    XPathConstants.NODESET);
+            if ((list != null) && (list.getLength() > 0)) {
+                for (int i = 0; i < list.getLength(); i++) {
+                    final Element n = (Element) list.item(i);
+
+                    final String lang = getLangAttribute(n);
+                    if (lang == null) {
+                        throw new SRUConfigException("Element <Title> " +
+                                "must have a proper 'xml:lang' attribute");
+                    }
+
+                    final String title = cleanString(n.getTextContent());
+                    if (title == null) {
+                        throw new SRUConfigException("Element <Title> " +
+                                "must have a non-empty 'xml:lang' attribute");
+                    }
+
+                    if (titles == null) {
+                        titles = new HashMap<String, String>();
+                    }
+                    if (titles.containsKey(lang)) {
+                        logger.warn("title with language '{}' already exists",
+                                lang);
+                    } else {
+                        logger.debug("title: '{}' '{}'", lang, title);
+                        titles.put(lang, title);
+                    }
+                }
+                if ((titles != null) && !titles.containsKey(LANG_EN)) {
+                    throw new SRUConfigException(
+                            "A <Title> with language 'en' is mandatory");
+                }
+            }
+
+            exp = xpath.compile("ed:Description");
+            list = (NodeList) exp.evaluate(node, XPathConstants.NODESET);
+            if ((list != null) && (list.getLength() > 0)) {
+                for (int i = 0; i < list.getLength(); i++) {
+                    Element n = (Element) list.item(i);
+
+                    String lang = getLangAttribute(n);
+                    if (lang == null) {
+                        throw new SRUConfigException("Element <Description> " +
+                                "must have a proper 'xml:lang' attribute");
+
+                    }
+                    String desc = cleanString(n.getTextContent());
+
+                    if (descrs == null) {
+                        descrs = new HashMap<String, String>();
+                    }
+
+                    if (descrs.containsKey(lang)) {
+                        logger.warn("description with language '{}' " +
+                                "already exists", lang);
+                    } else {
+                        logger.debug("description: '{}' '{}'", lang, desc);
+                        descrs.put(lang, desc);
+                    }
+                }
+                if ((descrs != null) && !descrs.containsKey(LANG_EN)) {
+                    throw new SRUConfigException(
+                            "A <Description> with language 'en' is mandatory");
+                }
+            }
+
+            exp = xpath.compile("ed:LandingPageURI");
+            list = (NodeList) exp.evaluate(node, XPathConstants.NODESET);
+            if ((list != null) && (list.getLength() > 0)) {
+                for (int i = 0; i < list.getLength(); i++) {
+                    Element n = (Element) list.item(i);
+                    link = cleanString(n.getTextContent());
+                }
+            }
+
+            exp = xpath.compile("ed:Languages/ed:Language");
+            list = (NodeList) exp.evaluate(node, XPathConstants.NODESET);
+            if ((list != null) && (list.getLength() > 0)) {
+                for (int i = 0; i < list.getLength(); i++) {
+                    Element n = (Element) list.item(i);
+
+                    String s = n.getTextContent();
+                    if (s != null) {
+                        s = s.trim();
+                        if (s.isEmpty()) {
+                            s = null;
+                        }
+                    }
+
+                    /*
+                     * enforce three letter codes
+                     */
+                    if ((s == null) || (s.length() != 3)) {
+                        throw new SRUConfigException("Element <Language> " +
+                                "must use ISO-639-3 three letter " +
+                                "language codes");
+                    }
+
+                    if (langs == null) {
+                        langs = new ArrayList<String>();
+                    }
+                    langs.add(s);
+                }
+            }
+
+            exp = xpath.compile("ed:AvailableDataViews");
+            Node n = (Node) exp.evaluate(node, XPathConstants.NODE);
+            if ((n != null) && (n instanceof Element)) {
+                String ref = getAttribute((Element) n, "ref");
+                if (ref == null) {
+                    throw new SRUConfigException(
+                            "Element <AvailableDataViews> " +
+                                    "must have a 'ref' attribute");
+                }
+                String[] refs = ref.split("\\s+");
+                if ((refs == null) || (refs.length < 1)) {
+                    throw new SRUConfigException("Attribute 'ref' on element " +
+                            "<AvailableDataViews> must contain a whitespace " +
+                            "seperated list of data view references");
+                }
+
+                for (int i = 0; i < refs.length; i++) {
+                    DataView dataview = null;
+                    for (DataView dv : supportedDataViews) {
+                        if (refs[i].equals(dv.getIdentifier())) {
+                            dataview = dv;
+                            break;
+                        }
+                    }
+                    if (dataview != null) {
+                        if (availableDataViews == null) {
+                            availableDataViews = new ArrayList<DataView>();
+                        }
+                        availableDataViews.add(dataview);
+                    } else {
+                        throw new SRUConfigException(
+                                "A data view with " + "identifier '" + refs[i] +
+                                        "' was not defined " +
+                                        "in <SupportedDataViews>");
+                    }
+                }
+            } else {
+                throw new SRUConfigException(
+                        "missing element <AvailableDataViews>");
+            }
+            if (availableDataViews == null) {
+                throw new SRUConfigException("No available data views where " +
+                        "defined for resource with PID '" + pid + "'");
+            }
+
+            exp = xpath.compile("ed:AvailableLayers");
+            n = (Node) exp.evaluate(node, XPathConstants.NODE);
+            if ((n != null) && (n instanceof Element)) {
+                String ref = getAttribute((Element) n, "ref");
+                if (ref == null) {
+                    throw new SRUConfigException("Element <AvailableLayers> " +
+                            "must have a 'ref' attribute");
+                }
+                String[] refs = ref.split("\\s+");
+                if ((refs == null) || (refs.length < 1)) {
+                    throw new SRUConfigException("Attribute 'ref' on element " +
+                            "<AvailableLayers> must contain a whitespace " +
+                            "seperated list of data view references");
+                }
+
+                for (int i = 0; i < refs.length; i++) {
+                    Layer layer = null;
+                    for (Layer l : supportedLayers) {
+                        if (refs[i].equals(l.getId())) {
+                            layer = l;
+                            break;
+                        }
+                    }
+                    if (layer != null) {
+                        if (availableLayers == null) {
+                            availableLayers = new ArrayList<Layer>();
+                        }
+                        availableLayers.add(layer);
+                    } else {
+                        throw new SRUConfigException("A layer with " +
+                                "identifier '" + refs[i] +
+                                "' was not defined " + "in <SupportedLayers>");
+                    }
+                }
+            } else {
+                if (hasAdv) {
+                    logger.debug("no <SupportedLayers> for ressource '{}'",
+                            pid);
+                }
+            }
+
+            exp = xpath.compile("ed:Resources/ed:Resource");
+            list = (NodeList) exp.evaluate(node, XPathConstants.NODESET);
+            if ((list != null) && (list.getLength() > 0)) {
+                sub = parseResources(xpath, list, pids, supportedDataViews,
+                        supportedLayers, version, hasAdv);
+            }
+
+            if (ris == null) {
+                ris = new ArrayList<ResourceInfo>();
+            }
+            if ((availableLayers != null) && (version < 1)) {
+                logger.warn("Endpoint claims to support FCS 1.0, but " +
+                        "includes information about <AvailableLayers> for " +
+                        "resource with pid '{}'", pid);
+            }
+            ris.add(new ResourceInfo(pid, titles, descrs, link, langs,
+                    availableDataViews, availableLayers, sub));
+        }
+        return ris;
+    }
+
+
+    private static String getAttribute(Element el, String localName) {
+        String value = el.getAttribute(localName);
+        if (value != null) {
+            value = value.trim();
+            if (!value.isEmpty()) {
+                return value;
+            }
+        }
+        return null;
+    }
+
+
+    private static String getLangAttribute(Element el) {
+        String lang = el.getAttributeNS(XMLConstants.XML_NS_URI, "lang");
+        if (lang != null) {
+            lang = lang.trim();
+            if (!lang.isEmpty()) {
+                return lang;
+            }
+        }
+        return null;
+    }
+
+
+    private static String cleanString(String s) {
+        if (s != null) {
+            s = s.trim();
+            if (!s.isEmpty()) {
+                StringBuilder sb = new StringBuilder();
+                for (String z : s.split("\\s*\\n+\\s*")) {
+                    z = z.trim();
+                    if (!z.isEmpty()) {
+                        if (sb.length() > 0) {
+                            sb.append(' ');
+                        }
+                        sb.append(z);
+                    }
+                }
+                if (sb.length() > 0) {
+                    return sb.toString();
+                }
+            }
+        }
+        return null;
+    }
+
+
+    private static void checkLegacyMode(Document doc, URL url)
+            throws SRUConfigException {
+        Element root = doc.getDocumentElement();
+        if (root != null) {
+            String ns = root.getNamespaceURI();
+            if (ns != null) {
+                if (ns.equals(NS_LEGACY)) {
+                    logger.error("Detected out-dated " +
+                            "resource info catalog file '" + url +
+                            "'. Please update to the " +
+                            "current version");
+                    throw new SRUConfigException("unsupport file format: " + ns);
+                } else if (!ns.equals(NS)) {
+                    logger.error("Detected unsupported resource info " +
+                            "catalog file '" + url + "' with namespace '" + ns + '"');
+                    throw new SRUConfigException("unsupport file format: " + ns);
+                }
+            } else {
+                throw new SRUConfigException("No namespace URI was detected " +
+                        "for resource info catalog file '" + url +"'!");
+            }
+        } else {
+            throw new SRUConfigException("Error retrieving root element");
+        }
+    }
+
+} // class SimpleResourceInfoInventoryParser
Index: FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/test/java/eu/clarin/sru/server/fcs/parser/QueryParserRunner.java
===================================================================
--- FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/test/java/eu/clarin/sru/server/fcs/parser/QueryParserRunner.java	(revision 7248)
+++ FCSSimpleEndpoint/tags/FCSSimpleEndpoint-1.6.0/src/test/java/eu/clarin/sru/server/fcs/parser/QueryParserRunner.java	(revision 7248)
@@ -0,0 +1,75 @@
+package eu.clarin.sru.server.fcs.parser;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class QueryParserRunner {
+    private static final Logger logger = LoggerFactory
+            .getLogger(QueryParserRunner.class);
+
+
+    public static void main(String[] args) {
+        if ((args != null) && (args.length > 0)) {
+            File file = new File(args[0]);
+            if (file.exists() || file.isFile()) {
+                BufferedReader reader = null;
+                try {
+                    reader = new BufferedReader(new FileReader(file));
+
+                    String line;
+                    while ((line = reader.readLine()) != null) {
+                        line = line.trim();
+                        if (line.isEmpty()) {
+                            continue;
+                        }
+                        try {
+                            logger.info("PARSING QUERY: >>>{}<<<", line);
+                            QueryParser parser = new QueryParser();
+                            QueryNode tree = parser.parse(line);
+                            logger.info("{}", tree);
+                            logger.info("... PARSED OK");
+                        } catch (QueryParserException e) {
+                            logger.error(
+                                    "error parsing query: " + e.getMessage(),
+                                    e);
+                        }
+
+                    }
+                } catch (IOException e) {
+                    logger.error("error reading file", e);
+                } finally {
+                    if (reader != null) {
+                        try {
+                            reader.close();
+                        } catch (IOException e) {
+                            /* IGNORE */
+                        }
+                    }
+                }
+            } else {
+                logger.error("DOES NOT EXIST OR IS NOT A FILE: {}", args[0]);
+            }
+        } else {
+            logger.error("NEED QUERY-FILE");
+        }
+    }
+
+    static {
+        org.apache.log4j.BasicConfigurator
+                .configure(new org.apache.log4j.ConsoleAppender(
+                        new org.apache.log4j.PatternLayout("%-5p [%t] %m%n"),
+                        org.apache.log4j.ConsoleAppender.SYSTEM_ERR));
+        org.apache.log4j.Logger logger = org.apache.log4j.Logger
+                .getRootLogger();
+        logger.setLevel(org.apache.log4j.Level.INFO);
+        logger.getLoggerRepository().getLogger("eu.clarin")
+                .setLevel(org.apache.log4j.Level.DEBUG);
+    }
+
+}
