Package org.xml.sax.helpers

Examples of org.xml.sax.helpers.AttributeListImpl



    public void produce( DocumentHandler docHandler )
  throws SAXException
    {
  AttributeListImpl attrList;
  int               policy;
  Enumeration       enumeration;
  String            name;

  attrList = new AttributeListImpl();
  docHandler.startElement( XML.Namespace.Root, attrList );
  attrList = new AttributeListImpl();
  docHandler.startElement( Names.Element.Policies, attrList );

  enumeration = listDNs();
  while ( enumeration.hasMoreElements() ) {
      name = (String) enumeration.nextElement();
      policy = getDirectPolicy( name );
      attrList = new AttributeListImpl();
      attrList.addAttribute( Names.Attribute.DN, "ID", name );
      if ( ( policy & Policy.DeleteEmpty ) != 0 )
    attrList.addAttribute( Names.Attribute.DeleteEmpty, null, "true" );
      if ( ( policy & Policy.ReplaceAttr ) != 0 )
    attrList.addAttribute( Names.Attribute.ReplaceAttr, null, "true" );
      if ( ( policy & Policy.RefreshOnly ) != 0 )
    attrList.addAttribute( Names.Attribute.RefreshOnly, null, "true" );
      if ( ( policy & Policy.UpdateOnly ) != 0 )
    attrList.addAttribute( Names.Attribute.UpdateOnly, null, "true" );
      if ( ( policy & Policy.NewAttrOnly ) != 0 )
    attrList.addAttribute( Names.Attribute.NewAttrOnly, null, "true" );
      docHandler.startElement( Names.Element.Policy, attrList );
      docHandler.endElement( Names.Element.Policy );
  }

  docHandler.endElement( Names.Element.Policies );
View Full Code Here



    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 ) );
View Full Code Here


    public void produce( DocumentHandler docHandler )
  throws SAXException
    {
  AttributeListImpl attrList;
  Enumeration       enumeration;

  attrList = new AttributeListImpl();
  docHandler.startElement( XML.Namespace.Root, attrList );

  attrList = new AttributeListImpl();
  if ( _baseDN != null )
      attrList.addAttribute( Names.Attribute.BaseDN, "CDATA", _baseDN );
  if ( _filter != null )
      attrList.addAttribute( Names.Attribute.Filter, "CDATA", _filter );
  switch ( _scope ) {
  case Scope.OneLevel:
      attrList.addAttribute( Names.Attribute.Scope, null,
           Names.Attribute.ScopeOneLevel );
      break;
  case Scope.Base:
      attrList.addAttribute( Names.Attribute.Scope, null,
           Names.Attribute.ScopeBase );
      break;
  case Scope.SubTree:
      attrList.addAttribute( Names.Attribute.Scope, null,
           Names.Attribute.ScopeSubTree );
      break;
  }
  docHandler.startElement( Names.Element.Search, attrList );

  if ( _returnAttrs != null ) {
      enumeration = _returnAttrs.elements();
      while ( enumeration.hasMoreElements() ) {
    attrList = new AttributeListImpl();
    attrList.addAttribute( Names.Attribute.AttrName, "NMTOKEN",
               (String) enumeration.nextElement() );
    docHandler.startElement( Names.Element.ReturnAttr, attrList );
    docHandler.endElement( Names.Element.ReturnAttr );
      }
  }
View Full Code Here

                _handler.startDocument();
            }

            String idVal = rs.getString(idColNum.intValue());

            AttributeListImpl attrs = new AttributeListImpl();

            for (int i = 0; i < attrCols.length; i++) {
                String attrCol = attrCols[i];
                Integer attrColNum = (Integer) _cols.get(attrCol);
                FieldMapping field = desc.getAttr(attrCol);
                String attrName = null;
                if (field.getBindXml() == null || field.getBindXml().getName() == null) {
                attrName = field.getName();
                } else {
                attrName = field.getBindXml().getName();
                }

                String attrValue = rs.getString(attrColNum.intValue());
                attrs.addAttribute(attrName, "CDATA", attrValue);
            }

            _handler.startElement(elementName, attrs);

            for (int j = 0; j < simpleElementCols.length; j++) {
                String simpleElementCol = simpleElementCols[j];
                Integer elementColNum = (Integer) _cols.get(simpleElementCol);
                FieldMapping elField = desc.getSimpleElement(simpleElementCol);
                String elName = null;
                if (elField.getBindXml() == null || elField.getBindXml().getName() == null) {
                elName = elField.getName();
                } else {
                elName = elField.getBindXml().getName();
                }

                String elValue = rs.getString(elementColNum.intValue());
                _handler.startElement(elName, new AttributeListImpl());
                _handler.characters(elValue.toCharArray(), 0, elValue.length());
                _handler.endElement(elName);
            }

            if (idIndex < _ids.size() - 1) {
View Full Code Here

        }

        public void startElement(String name, AttributeList list)
            throws SAXException {

            AttributeListImpl replaced = new AttributeListImpl();
            for (int i = 0; i < list.getLength(); i++) {
                String value = expand(list.getName(i), list.getValue(i));
                replaced.addAttribute(list.getName(i), list.getType(i), value);
            }
            _handler.startElement(name, replaced);
        }
View Full Code Here


    public void produce( LDAPEntry entry )
  throws SAXException
    {
  AttributeListImpl attrList;
  LDAPAttributeSet  attrSet;
  LDAPAttribute     attr;
  Enumeration       enumeration;
  Enumeration       values;
  byte[]            value;

  leaveSchema();
  enterDirectory();

  // dsml:entry dn
  attrList = new AttributeListImpl();
  attrList.addAttribute( XML.Entries.Attributes.DN, "CDATA", entry.getDN() );
  // dsml:entry
  _docHandler.startElement( prefix( XML.Entries.Elements.Entry ), attrList );
 
  attrSet = entry.getAttributeSet();
  if ( attrSet != null ) {
     
      attr = attrSet.getAttribute( "objectclass" );
      if ( attr != null ) {
    // dsml:objectclass
    attrList = new AttributeListImpl();
    _docHandler.startElement( prefix( XML.Entries.Elements.ObjectClass ), attrList );
    values = attr.getStringValues();
    while ( values.hasMoreElements() ) {
        char[] chars;
       
        // dsml:oc-value
        chars = ( (String) values.nextElement() ).toCharArray();
        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 = attrSet.getAttributes();
      while ( enumeration.hasMoreElements() ) {
    // dsml:attr
    attr = (LDAPAttribute) enumeration.nextElement();
    if ( attr.getName().equals( "objectclass" ) )
        continue;
    attrList = new AttributeListImpl();
    attrList.addAttribute( XML.Entries.Attributes.Name, "CDATA", attr.getName() );
    _docHandler.startElement( prefix( XML.Entries.Elements.Attribute ), attrList );
   
    values = attr.getByteValues();
    while ( values.hasMoreElements() ) {
        char[] chars;
        int    i;

        // dsml:value
        value = (byte[]) values.nextElement();
        attrList = new AttributeListImpl();
        if ( value == null ) {
      chars = new char[ 0 ];
        } else {
      // XXX We have no way of knowing if the attribute is
      //     string or binary, so we do this stupid check
      //     to determine and print it as ASCII text or
      //     base 64 encoding.
      //     (note: OpenLDAP does not provide the attributes
      //     schema as one would hope)
      for ( i = 0 ; i < value.length ; ++i ) {
          if ( value[ i ] < 0x20 || value[ i ] == 0x7f )
        break;
      }
      if ( i == value.length ) {
          chars = new char[ value.length ];
          for ( i = 0 ; i < value.length ; ++i )
        chars[ i ] = (char) value[ i ];
      } else {
                chars = Base64Encoder.encode(value);
          attrList.addAttribute( XML.Entries.Attributes.Encoding, "NMTOKEN",
               XML.Entries.Attributes.Encodings.Base64 );
      }
        }

        _docHandler.startElement( prefix( XML.Entries.Elements.Value ), attrList );
View Full Code Here


    public void produce( LDAPObjectClassSchema schema )
  throws SAXException
    {
  AttributeListImpl attrList;
  String            superiors[];
  String            superior;
  int               i;
  Enumeration       enumeration;

  leaveDirectory();
  enterSchema();
 
  attrList = new AttributeListImpl();
  // dsml:class id
  attrList.addAttribute( XML.Schema.Attributes.Id, "ID", schema.getName() );
  // dsml:class superior
  superiors = schema.getSuperiors();
  superior = null;
  for ( i = 0 ; i < superiors.length ; ++i ) {
      if ( i == 0 )
    superior = superiors[ i ];
      else
    superior = superior + "," + superiors[ i ];
  }
  if ( i > 0 )
      attrList.addAttribute( XML.Schema.Attributes.Superior, "CDATA", superior );
  // dsml:class obsolete
  attrList.addAttribute( XML.Schema.Attributes.Obsolete, null,
             schema.isObsolete() ? "true" : "false" );
  // dsml:class type
  switch ( schema.getType() ) {
  case LDAPObjectClassSchema.STRUCTURAL:
      attrList.addAttribute( XML.Schema.Attributes.Type, null,
           XML.Schema.Attributes.Types.Structural );
      break;
  case LDAPObjectClassSchema.ABSTRACT:
      attrList.addAttribute( XML.Schema.Attributes.Type, null,
           XML.Schema.Attributes.Types.Abstract );
      break;
  case LDAPObjectClassSchema.AUXILIARY:
      attrList.addAttribute( XML.Schema.Attributes.Type, null,
           XML.Schema.Attributes.Types.Auxiliary );
      break;
  }

  // dsml:class
  _docHandler.startElement( prefix( XML.Schema.Elements.Class ), attrList );

  // dsml:class name
  if ( schema.getName() != null ) {
      attrList = new AttributeListImpl();
      _docHandler.startElement( prefix( XML.Schema.Elements.Name ), attrList );
      _docHandler.characters( schema.getName().toCharArray(), 0,
            schema.getName().length() );
      _docHandler.endElement( prefix( XML.Schema.Elements.Name ) );
  }
  // dsml:class description
  if ( schema.getDescription() != null ) {
      attrList = new AttributeListImpl();
      _docHandler.startElement( prefix( XML.Schema.Elements.Description ), attrList );
      _docHandler.characters( schema.getDescription().toCharArray(), 0,
            schema.getDescription().length() );
      _docHandler.endElement( prefix( XML.Schema.Elements.Description ) );
  }
  // dsml:class object-identifier
  if ( schema.getID() != null ) {
      attrList = new AttributeListImpl();
      _docHandler.startElement( prefix( XML.Schema.Elements.OID ), attrList );
      _docHandler.characters( schema.getID().toCharArray(), 0,
            schema.getID().length() );
      _docHandler.endElement( prefix( XML.Schema.Elements.OID ) );
  }

  // dsml:class attribute required=false
  enumeration = schema.getOptionalAttributes();
  while ( enumeration.hasMoreElements() ) {
      attrList = new AttributeListImpl();
      attrList.addAttribute( XML.Schema.Attributes.Ref, "CDATA",
           "#" + (String) enumeration.nextElement() );
      attrList.addAttribute( XML.Schema.Attributes.Required, null, "false" );
      _docHandler.startElement( prefix( XML.Schema.Elements.Attribute) , attrList );
      _docHandler.endElement( prefix( XML.Schema.Elements.Attribute ) );
  }
  // dsml:class attribute required=true
  enumeration = schema.getRequiredAttributes();
  while ( enumeration.hasMoreElements() ) {
      attrList = new AttributeListImpl();
      attrList.addAttribute( XML.Schema.Attributes.Ref, "CDATA",
           "#" + (String) enumeration.nextElement() );
      attrList.addAttribute( XML.Schema.Attributes.Required, null, "true" );
      _docHandler.startElement( prefix( XML.Schema.Elements.Attribute) , attrList );
      _docHandler.endElement( prefix( XML.Schema.Elements.Attribute ) );
  }

  _docHandler.endElement( prefix( XML.Schema.Elements.Class ) );
View Full Code Here


    public void produce( LDAPAttributeSchema schema )
  throws SAXException
    {
  AttributeListImpl attrList;

  leaveDirectory();
  enterSchema();
  attrList = new AttributeListImpl();
  // dsml:attribute id
  attrList.addAttribute( XML.Schema.Attributes.Id, "ID", schema.getName() );
  // dsml:attribute superior
  if ( schema.getSuperior() != null ) {
      attrList.addAttribute( XML.Schema.Attributes.Superior, "CDATA", "#" + schema.getSuperior() );
  }
  // dsml:attribute obsolete
  attrList.addAttribute( XML.Schema.Attributes.Obsolete, null,
             schema.isObsolete() ? "true" : "false" );
  // dsml:attribute single-value
  attrList.addAttribute( XML.Schema.Attributes.SingleValue, null,
             schema.isSingleValued() ? "true" : "false" );
  // dsml:attribute user-modification
  // XXX

  // dsml:attribute
  _docHandler.startElement( prefix( XML.Schema.Elements.AttributeType) , attrList );

  // dsml:attribute name
  if ( schema.getName() != null ) {
      attrList = new AttributeListImpl();
      _docHandler.startElement( prefix( XML.Schema.Elements.Name ), attrList );
      _docHandler.characters( schema.getName().toCharArray(), 0,
            schema.getName().length() );
      _docHandler.endElement( prefix( XML.Schema.Elements.Name ) );
  }
  // dsml:attribute description
  if ( schema.getDescription() != null ) {
      attrList = new AttributeListImpl();
      _docHandler.startElement( prefix( XML.Schema.Elements.Description ), attrList );
      _docHandler.characters( schema.getDescription().toCharArray(), 0,
            schema.getDescription().length() );
      _docHandler.endElement( prefix( XML.Schema.Elements.Description ) );
  }
  // dsml:attribute object-identifier
  if ( schema.getID() != null ) {
      attrList = new AttributeListImpl();
      _docHandler.startElement( prefix( XML.Schema.Elements.OID ), attrList );
      _docHandler.characters( schema.getID().toCharArray(), 0,
            schema.getID().length() );
      _docHandler.endElement( prefix( XML.Schema.Elements.OID ) );
  }
  // dsml:attribute syntax
  if ( schema.getSyntaxString() != null ) {
      attrList = new AttributeListImpl();
      _docHandler.startElement( prefix( XML.Schema.Elements.Syntax ), attrList );
      _docHandler.characters( schema.getSyntaxString().toCharArray(), 0,
            schema.getSyntaxString().length() );
      _docHandler.endElement( prefix( XML.Schema.Elements.Syntax ) );
  }
View Full Code Here

        if (node.getNodeType() == AnyNode.ELEMENT) {
            String name = node.getLocalName();

            //-- retrieve the attributes and handle them
            AttributeListImpl atts = new AttributeListImpl();
            AnyNode tempNode = node.getFirstAttribute();
            String xmlName = null;
            String value = null;
            String attUri = null;
            String attPrefix = null;

            while (tempNode != null) {
                xmlName = tempNode.getLocalName();
                //--retrieve a prefix?
                attUri = tempNode.getNamespaceURI();
                if (attUri != null) {
                    attPrefix = _context.getNamespacePrefix(attUri);
                }
                if (attPrefix != null && attPrefix.length() > 0) {
                    xmlName = attPrefix + ':' + xmlName;
                }
                value = tempNode.getStringValue();
                atts.addAttribute(xmlName, "CDATA", value);
                tempNode = tempNode.getNextSibling();
            } //attributes

            //-- namespace management
            _context = _context.createNamespaces();
View Full Code Here

     * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
     */
    public void startElement(String uri, String localName, String qName, Attributes atts)
        throws SAXException
    {
        AttributeListImpl attList = new AttributeListImpl();

        //-- Create a new namespace scope if necessary and
        //-- make sure the flag is reset to true
        if (_createNamespaceScope) {
            //-- no current namespaces, but we create a new scope
            //-- to make things easier in the endElement method
            _namespaces = _namespaces.createNamespaces();
        }
        else {
            _createNamespaceScope = true;
            _namespaces.declareAsAttributes(attList, true);
        }

        //-- copy Attributes to AttributeList
        for (int i = 0; i < atts.getLength(); i++) {
            attList.addAttribute(atts.getQName(i), CDATA, atts.getValue(i));
        }

        _handler.startElement(qName, attList);

    }
View Full Code Here

TOP

Related Classes of org.xml.sax.helpers.AttributeListImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.