Beispiel #1
0
  public void startDocument() throws SAXException {
    AttributeListImpl attrList;

    attrList = new AttributeListImpl();
    if (_namespace)
      attrList.addAttribute("xmlns:" + XML.Namespace.PREFIX, "CDATA", XML.Namespace.URI);
    else attrList.addAttribute("xmlns", "CDATA", XML.Namespace.URI);
    _docHandler.startElement(prefix(XML.Namespace.ROOT), attrList);
  }
Beispiel #2
0
  private static void writeParam(XMLPrettyPrinter pp, String name, String value) {
    if (value == null) return;

    AttributeListImpl atts = new AttributeListImpl();
    atts.addAttribute("name", "CDATA", name);
    atts.addAttribute("value", "CDATA", value);
    pp.startElement("param", atts);
    pp.endElement("param");
  }
 /*
  * 9 covered goals:
  * 1 nu.staldal.xmlutil.ContentHandlerAdapter.startElement(Ljava/lang/String;Lorg/xml/sax/AttributeList;)V: I45 Branch 3 IFLE L100 - true
  * 2 nu.staldal.xmlutil.ContentHandlerAdapter.startElement(Ljava/lang/String;Lorg/xml/sax/AttributeList;)V: I96 Branch 6 IFGT L111 - false
  * 3 nu.staldal.xmlutil.ContentHandlerAdapter.startElement(Ljava/lang/String;Lorg/xml/sax/AttributeList;)V: I13 Branch 1 IF_ICMPGE L93 - true
  * 4 nu.staldal.xmlutil.ContentHandlerAdapter.startElement(Ljava/lang/String;Lorg/xml/sax/AttributeList;)V: I13 Branch 1 IF_ICMPGE L93 - false
  * 5 nu.staldal.xmlutil.ContentHandlerAdapter.startElement(Ljava/lang/String;Lorg/xml/sax/AttributeList;)V: I26 Branch 2 IFLE L96 - true
  * 6 nu.staldal.xmlutil.ContentHandlerAdapter.startElement(Ljava/lang/String;Lorg/xml/sax/AttributeList;)V: I79 Branch 4 IF_ICMPGE L108 - true
  * 7 nu.staldal.xmlutil.ContentHandlerAdapter.startElement(Ljava/lang/String;Lorg/xml/sax/AttributeList;)V: I79 Branch 4 IF_ICMPGE L108 - false
  * 8 nu.staldal.xmlutil.ContentHandlerAdapter.startElement(Ljava/lang/String;Lorg/xml/sax/AttributeList;)V: I92 Branch 5 IFGT L111 - false
  * 9 nu.staldal.xmlutil.ContentHandlerAdapter.startElement(Ljava/lang/String;Lorg/xml/sax/AttributeList;)V: I138 Branch 7 IFEQ L121 - true
  */
 @Test
 public void test7() throws Throwable {
   DefaultHandler2 defaultHandler2_0 = new DefaultHandler2();
   ContentHandlerAdapter contentHandlerAdapter0 =
       new ContentHandlerAdapter((ContentHandler) defaultHandler2_0);
   AttributeListImpl attributeListImpl0 = new AttributeListImpl();
   attributeListImpl0.addAttribute("", "xmlns", "xmlns");
   contentHandlerAdapter0.startElement("xmlns", (AttributeList) attributeListImpl0);
   assertEquals(1, attributeListImpl0.getLength());
 }
Beispiel #4
0
  private static void writeDataSource(XMLPrettyPrinter pp, DataSource src) {
    String name = null;
    if (src instanceof JNDIDataSource) {
      name = "jndi";
      JNDIDataSource jndi = (JNDIDataSource) src;
      pp.startElement(name, null);

      writeParam(pp, "jndi-path", jndi.getJndiPath());
      writeParam(pp, "query", jndi.getQuery());
    } else if (src instanceof JDBCDataSource) {
      name = "jdbc";
      JDBCDataSource jdbc = (JDBCDataSource) src;
      pp.startElement(name, null);

      writeParam(pp, "driver-class", jdbc.getDriverClass());
      writeParam(pp, "connection-string", jdbc.getConnectionString());
      writeParam(pp, "user-name", jdbc.getUserName());
      writeParam(pp, "password", jdbc.getPassword());
      writeParam(pp, "query", jdbc.getQuery());
    } else if (src instanceof CSVDataSource) {
      name = "csv";
      CSVDataSource csv = (CSVDataSource) src;
      pp.startElement(name, null);

      writeParam(pp, "input-file", csv.getInputFile());
      writeParam(pp, "encoding", csv.getEncoding());
      writeParam(pp, "skip-lines", csv.getSkipLines());
      writeParam(pp, "header-line", csv.getHeaderLine());
      if (csv.getSeparator() != 0) writeParam(pp, "separator", csv.getSeparator());
    }

    if (src instanceof ColumnarDataSource) {
      // FIXME: this breaks the order...
      for (Column col : ((ColumnarDataSource) src).getColumns()) {
        AttributeListImpl atts = new AttributeListImpl();
        atts.addAttribute("name", "CDATA", col.getName());
        atts.addAttribute("property", "CDATA", col.getProperty());
        if (col.getPrefix() != null) atts.addAttribute("prefix", "CDATA", col.getPrefix());
        // FIXME: cleaner really requires object support ... :-(
        if (col.getCleaner() != null)
          atts.addAttribute("cleaner", "CDATA", col.getCleaner().getClass().getName());
        pp.startElement("column", atts);
        pp.endElement("column");
      }
    }

    pp.endElement(name);
  }
Beispiel #5
0
  private static void writeProperty(XMLPrettyPrinter pp, Property prop) {
    AttributeListImpl atts = new AttributeListImpl();
    if (prop.isIdProperty()) atts.addAttribute("type", "CDATA", "id");
    else if (prop.isIgnoreProperty()) atts.addAttribute("type", "CDATA", "ignore");

    if (!prop.isIdProperty() && prop.getLookupBehaviour() != Property.Lookup.DEFAULT) {
      String value = prop.getLookupBehaviour().toString().toLowerCase();
      atts.addAttribute("lookup", "CDATA", value);
    }

    pp.startElement("property", atts);
    writeElement(pp, "name", prop.getName());
    if (prop.getComparator() != null)
      writeElement(pp, "comparator", prop.getComparator().getClass().getName());
    if (prop.getLowProbability() != 0.0) writeElement(pp, "low", "" + prop.getLowProbability());
    if (prop.getHighProbability() != 0.0) writeElement(pp, "high", "" + prop.getHighProbability());
    pp.endElement("property");
  }
Beispiel #6
0
  /** Writes the given configuration to the given file. */
  public static void write(Configuration config, String file) throws IOException {
    FileOutputStream fos = new FileOutputStream(file);
    XMLPrettyPrinter pp = new XMLPrettyPrinter(fos);

    pp.startDocument();
    pp.startElement("duke", null);

    // FIXME: here we should write the objects, but that's not
    // possible with the current API. we don't need that for the
    // genetic algorithm at the moment, but it would be useful.

    pp.startElement("schema", null);

    writeElement(pp, "threshold", "" + config.getThreshold());
    if (config.getMaybeThreshold() != 0.0)
      writeElement(pp, "maybe-threshold", "" + config.getMaybeThreshold());

    for (Property p : config.getProperties()) writeProperty(pp, p);

    pp.endElement("schema");

    String dbclass = config.getDatabase(false).getClass().getName();
    AttributeListImpl atts = new AttributeListImpl();
    atts.addAttribute("class", "CDATA", dbclass);
    pp.startElement("database", atts);
    pp.endElement("database");

    if (config.isDeduplicationMode())
      for (DataSource src : config.getDataSources()) writeDataSource(pp, src);
    else {
      pp.startElement("group", null);
      for (DataSource src : config.getDataSources(1)) writeDataSource(pp, src);
      pp.endElement("group");

      pp.startElement("group", null);
      for (DataSource src : config.getDataSources(2)) writeDataSource(pp, src);
      pp.endElement("group");
    }

    pp.endElement("duke");
    pp.endDocument();

    fos.close();
  }
Beispiel #7
0
  public void produce(String name, Attributes attrs) throws SAXException, NamingException {
    AttributeListImpl attrList;
    Attribute attr;
    NamingEnumeration enumeration;
    NamingEnumeration values;
    Object value;

    leaveSchema();
    enterDirectory();

    // dsml:entry dn
    attrList = new AttributeListImpl();
    attrList.addAttribute(XML.Entries.Attributes.DN, "CDATA", name);
    // dsml:entry
    _docHandler.startElement(prefix(XML.Entries.Elements.Entry), attrList);

    if (attrs != null) {
      attr = attrs.get("objectclass");
      if (attr != null) {
        // dsml:objectclass
        attrList = new AttributeListImpl();
        _docHandler.startElement(prefix(XML.Entries.Elements.ObjectClass), attrList);
        values = attr.getAll();
        while (values.hasMore()) {
          char[] chars;

          // dsml:oc-value
          value = values.next();
          if (value != null) chars = value.toString().toCharArray();
          else chars = new char[0];
          attrList = new AttributeListImpl();
          _docHandler.startElement(prefix(XML.Entries.Elements.OCValue), attrList);
          _docHandler.characters(chars, 0, chars.length);
          _docHandler.endElement(prefix(XML.Entries.Elements.OCValue));
        }
        _docHandler.endElement(prefix(XML.Entries.Elements.ObjectClass));
      }

      enumeration = attrs.getAll();
      while (enumeration.hasMore()) {
        // dsml:attr
        attr = (Attribute) enumeration.next();
        if (attr.getID().equals("objectclass")) continue;
        attrList = new AttributeListImpl();
        attrList.addAttribute(XML.Entries.Attributes.Name, "CDATA", attr.getID());
        _docHandler.startElement(prefix(XML.Entries.Elements.Attribute), attrList);

        values = attr.getAll();
        while (values.hasMore()) {
          char[] chars = null;
          byte[] bytes = null;

          attrList = new AttributeListImpl();

          // dsml:value
          value = values.next();
          if (value == null) {
            chars = new char[0];
          } else if (value instanceof String) {
            chars = ((String) value).toCharArray();
          } else if (value instanceof byte[]) {
            bytes = (byte[]) value;
          } else {
            chars = value.toString().toCharArray();
          }
          if (chars != null) {
            boolean encode = false;
            boolean wchar = false;
            int i = 0;
            while (i < chars.length && !wchar) {
              char c = chars[i++];
              if (c >= '\u0100') encode = wchar = true;
              else if (c >= '\u0080' || (c < ' ' && c != '\n' && c != '\t')) encode = true;
            }
            if (encode) {
              if (wchar) {
                bytes = new byte[chars.length << 1];
                int j = 0;
                // bigendian
                for (i = 0; i < chars.length; i++) {
                  bytes[j++] = (byte) (chars[i] >> 8);
                  bytes[j++] = (byte) (0xff & chars[i]);
                }
              } else {
                bytes = new byte[chars.length];
                for (i = 0; i < chars.length; i++) {
                  bytes[i] = (byte) chars[i];
                }
              }
            }
          }

          if (bytes != null) {
            chars = Base64Encoder.encode(bytes);
            attrList.addAttribute(
                XML.Entries.Attributes.Encoding,
                "NMTOKEN",
                XML.Entries.Attributes.Encodings.Base64);
          }
          _docHandler.startElement(prefix(XML.Entries.Elements.Value), attrList);
          _docHandler.characters(chars, 0, chars.length);
          _docHandler.endElement(prefix(XML.Entries.Elements.Value));
        }
        _docHandler.endElement(prefix(XML.Entries.Elements.Attribute));
      }
    }
    _docHandler.endElement(prefix(XML.Entries.Elements.Entry));
  }