## defs/AttributeSyntax.java

/* [<][>][^][v][top][bottom][index][help] */

## DEFINITIONS

This source file includes following functions.

1. AttributeSyntax
2. getText
3. getName
4. getDescription
5. getCoreRegex
6. getCoreReservedRegex
7. getCoreParserName
8. getFrontEndRegex
9. getFrontEndReservedRegex
10. getFrontEndParserName

       1 /******************
       2   Copyright (c) 2002                                        RIPE NCC
       3
       4   All Rights Reserved
       5
       6   Permission to use, copy, modify, and distribute this software and its
       7   documentation for any purpose and without fee is hereby granted,
       8   provided that the above copyright notice appear in all copies and that
       9   both that copyright notice and this permission notice appear in
      10   supporting documentation, and that the name of the author not be
      11   used in advertising or publicity pertaining to distribution of the
      12   software without specific, written prior permission.
      13
      14   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
      15   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
      16   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
      17   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
      18   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
      19   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
      20   ***************************************/
      21
      22 import javax.xml.parsers.*;
      23 import org.w3c.dom.*;
      24 import org.xml.sax.*;
      25
      26 public class AttributeSyntax {
         /* [<][>][^][v][top][bottom][index][help] */
      27
      28     // attribute syntax information
      29     private String name;             // name of the syntax, e.g. nic-handle
      30     private String description;      // explanatory description of syntax
      31
      32     // info for core processing (whois_rip)
      33     private String coreRegex;          // POSIX regular expression of match
      34     private String coreReservedRegex;  // POSIX regular expression of reserved
      35                                        // words (this must NOT match)
      36     private String coreParserName;     // Name used by lex, yacc, etc.
      37
      38     // info for front-end processing (dbupdate, etc.)
      39     private String frontEndRegex;         // POSIX regular expression of match
      40     private String frontEndReservedRegex; // POSIX regular expression of
      41                                           // reserved words (that may NOT match)
      42     private String frontEndParserName;    // Name used by lex, yacc, etc.
      43
      44     // constructor - call with an XML attribute_syntax node
      45     public AttributeSyntax(Node node)
      46     {
      47         // default values (these will be checked later)
      48         name = null;
      49         description = "";
      50         coreRegex = null;
      51         coreReservedRegex = null;
      52         coreParserName = null;
      53         frontEndRegex = null;
      54         frontEndReservedRegex = null;
      55         frontEndParserName = null;
      56
      57         Node nameNode = node.getAttributes().getNamedItem("name");
      58         if (nameNode == null)
      59         {
      60             System.err.println("Attribute syntax has no name");
      61             System.exit(1);
      62         }
      63         name = nameNode.getNodeValue();
      64
      65         // load values from the XML node
      66         Node kid = node.getFirstChild();
      67         while (kid != null)
      68         {
      69             String nodeName = kid.getNodeName();
      70             String nodeValue = getText(kid);
      71             if (nodeName.equals("description"))
      72             {
      73                 description += nodeValue;
      74             }
      75             else if (nodeName.equals("core"))
      76             {
      77                 Node core = kid.getFirstChild();
      78                 while (core != null)
      79                 {
      80                     String coreName = core.getNodeName();
      81                     String coreValue = getText(core);
      82                     if (coreName.equals("regex"))
      83                     {
      84                         coreRegex = coreValue;
      85                     }
      86                     else if (coreName.equals("reserved_regex"))
      87                     {
      88                         coreReservedRegex = coreValue;
      89                     }
      90                     else if (coreName.equals("parser_name"))
      91                     {
      92                         coreParserName = coreValue;
      93                     }
      94                     core = core.getNextSibling();
      95                 }
      96             }
      97             else if (nodeName.equals("front_end"))
      98             {
      99                 Node fe = kid.getFirstChild();
     100                 while (fe != null)
     101                 {
     102                     String feName = fe.getNodeName();
     103                     String feValue = getText(fe);
     104                     if (feName.equals("regex"))
     105                     {
     106                         frontEndRegex = feValue;
     107                     }
     108                     else if (feName.equals("reserved_regex"))
     109                     {
     110                         frontEndReservedRegex = feValue;
     111                     }
     112                     else if (feName.equals("parser_name"))
     113                     {
     114                         frontEndParserName = feValue;
     115                     }
     116                     fe = fe.getNextSibling();
     117                 }
     118             }
     119             kid = kid.getNextSibling();
     120         }
     121
     122     }
     123
     124     private String getText(Node node)
         /* [<][>][^][v][top][bottom][index][help] */
     125     {
     126         StringBuffer sb = new StringBuffer();
     127         Node kid = node.getFirstChild();
     128         while (kid != null) {
     129             if (kid.getNodeType() == Node.TEXT_NODE) {
     130                 sb.append(kid.getNodeValue());
     131             }
     132             kid = kid.getNextSibling();
     133         }
     134         return sb.toString();
     135     }
     136
     137     public String getName()
         /* [<][>][^][v][top][bottom][index][help] */
     138     {
     139         return name;
     140     }
     141
     142     public String getDescription()
         /* [<][>][^][v][top][bottom][index][help] */
     143     {
     144         return description;
     145     }
     146
     147     public String getCoreRegex()
         /* [<][>][^][v][top][bottom][index][help] */
     148     {
     149         return coreRegex;
     150     }
     151
     152     public String getCoreReservedRegex()
         /* [<][>][^][v][top][bottom][index][help] */
     153     {
     154         return coreReservedRegex;
     155     }
     156
     157     public String getCoreParserName()
         /* [<][>][^][v][top][bottom][index][help] */
     158     {
     159         return coreParserName;
     160     }
     161
     162     public String getFrontEndRegex()
         /* [<][>][^][v][top][bottom][index][help] */
     163     {
     164         return frontEndRegex;
     165     }
     166
     167     public String getFrontEndReservedRegex()
         /* [<][>][^][v][top][bottom][index][help] */
     168     {
     169         return frontEndReservedRegex;
     170     }
     171
     172     public String getFrontEndParserName()
         /* [<][>][^][v][top][bottom][index][help] */
     173     {
     174         return frontEndParserName;
     175     }
     176 }
     177

/* [<][>][^][v][top][bottom][index][help] */