Package org.apache.xindice.util

Examples of org.apache.xindice.util.ByteArrayInput


      return (("xmlns".equals(qName)) || qName.startsWith("xmlns:"));
   }

   public boolean processContainer(boolean element, int pos, int len) throws IOException, SAXException {
      ByteArrayInput bis = new ByteArrayInput(data, pos, len);
      XMLCompressedInput in = new XMLCompressedInput(bis, symbols);
      String elemName = null;
      String localName = null;
      String nsURI = null;
      String[] mappedPrefixes = null;
      int nsMapCount = 0;

      if ( element ) {
         in.readSignature();
         in.readContentSize();

         short elemSymbol = in.readShort();
         elemName = symbols.getName(elemSymbol);
         localName = getLocalName(elemName);
         nsURI = symbols.getNamespaceURI(elemSymbol);
         int attrCount = in.readAttributeCount();
         AttributesImpl attrs = new AttributesImpl();
         for ( int i = 0 ; i < attrCount; i++ ) {
            short symbol = in.readShort();
            short strLen = in.readShort();
            byte[] b = new byte[strLen];
            in.read(b);

            String attrName = symbols.getName(symbol);
            String attrURI = symbols.getNamespaceURI(symbol);
            String lclName = getLocalName(attrName);

          String attrValue = new String(b, "UTF8");

          // look for and buffer newly mapped namespace prefixes
            if (isNSAttr(attrName)) {

               // create the buffer if needed
               if (mappedPrefixes == null) {
                  mappedPrefixes = new String[XMLNS_MAP_INCREMENT];

               }

               // check the buffer's capacity
               if (nsMapCount >= mappedPrefixes.length) {

                  String[] newBuf = new String[mappedPrefixes.length + XMLNS_MAP_INCREMENT];
                  System.arraycopy(mappedPrefixes, 0, newBuf, 0, mappedPrefixes.length);
                  mappedPrefixes = newBuf;
               }

               /* The prefix is the attr "local name", unless this is the
                * default namespace, in which case the prefix is the empty
                * string
                */
               String prefix = ("xmlns".equals(attrName) ? "" : lclName);

               /*
                * Prefix mappings MAY always be reported, regardless of
                * feature settings.
                */
               content.startPrefixMapping(prefix, attrValue);
               mappedPrefixes[nsMapCount++] = prefix;

               if (hasSaxNamespacesPrefixes) {

                   /*
                    * According to SAX, the local name should be EMPTY
                    */
                   attrs.addAttribute("", "", attrName, "CDATA", attrValue);
               }
            } else {

                /* Regular attribute */
                attrs.addAttribute(attrURI != null ?
                   attrURI : "", lclName, attrName, "", attrValue);
            }
         }

         if ( comp != null ) {
            comp.symbolID(elemSymbol);
            comp.dataLocation(pos, len);
         }
         content.startElement(nsURI !=null ? nsURI : "", localName, elemName, attrs);
      }
      else
         in.readInt();

      while ( !interrupt && bis.available() > 0 ) {
         pos = bis.getPos();
         /* TODO why is it used for? byte signature = */ in.readSignature();
         len = in.readContentSize();
         if ( len == 0 )
            len = 1;

         int type = in.getNodeType();

         switch ( type ) {

            case Node.ELEMENT_NODE:
               processContainer(true, pos, len);
               break;

            case Node.TEXT_NODE:
            case Node.PROCESSING_INSTRUCTION_NODE:
            case Node.CDATA_SECTION_NODE:
            case Node.COMMENT_NODE: {

               ByteArrayInput tbis = new ByteArrayInput(data, pos, len);
               XMLCompressedInput tin = new XMLCompressedInput(tbis, symbols);

               tin.readSignature(); // Skip The Signature
               if ( type == Node.TEXT_NODE )
                  tin.readContentSize();
               else
                  tin.readInt();

               byte[] buf = new byte[tbis.available()];
               tin.read(buf);

               String value = new String(buf, "UTF-8");

               switch ( type ) {
View Full Code Here


      try {
         if ( data != null ) {
            DocumentImpl doc = (DocumentImpl)getOwnerDocument();
            SymbolTable st = doc.getSymbols();

            ByteArrayInput bis = new ByteArrayInput(data, pos, len);
            XMLCompressedInput xci = new XMLCompressedInput(bis, st);

            xci.readSignature();      // Skip The Signature
            /* TODO why is it used for? int size = */ xci.readInt();

            byte[] buf = new byte[bis.available()];
            xci.read(buf);

            String value = new String(buf, "UTF-8");
            int i = value.indexOf(' ');
            nodeName = value.substring(0, i);
View Full Code Here

      try {
         if ( data != null ) {
            DocumentImpl doc = (DocumentImpl)getOwnerDocument();
            SymbolTable st = doc.getSymbols();

            ByteArrayInput bis = new ByteArrayInput(data, pos, len);
            XMLCompressedInput xci = new XMLCompressedInput(bis, st);

            xci.readSignature(); // Skip The Signature
            if ( getNodeType() == TEXT_NODE)
               xci.readContentSize();
            else
               xci.readInt();

            byte[] buf = new byte[bis.available()];
            xci.read(buf);
            nodeValue = new String(buf, "UTF-8");
         }
      }
      catch ( Exception e ) {
View Full Code Here

         }
      }
   }

   protected final void loadChildren(SymbolTable st) throws IOException {
      ByteArrayInput bis = new ByteArrayInput(data, pos, len);
      XMLCompressedInput in = new XMLCompressedInput(bis, st);

      if ( getNodeType() == Node.ELEMENT_NODE ) {
         // Have to skip the attributes
         in.readSignature();
         in.readContentSize();
         in.readShort();             // Element Symbol
         int attrCount = in.readAttributeCount();
         for ( int i = 0 ; i < attrCount; i++ ) {
            in.readShort();          // Attribute Symbol
            in.skip(in.readShort()); // Attribute Length
         }
      }
      else {
         in.readInt();
      }

      while ( bis.available() > 0 ) {
         int pos = bis.getPos();
         /* TODO why is it used for? byte signature = */ in.readSignature();
         int len = in.readContentSize();
         if ( len == 0 )
            len = 1;

         switch ( in.getNodeType() ) {

            case Node.ELEMENT_NODE:
               childNodes.add(new ElementImpl(this, data, pos, len));
               break;

            case Node.TEXT_NODE:
               childNodes.add(new TextImpl(this, data, pos, len));
               break;

            case Node.CDATA_SECTION_NODE:
               childNodes.add(new CDATASectionImpl(this, data, pos, len));
               break;

            case Node.ENTITY_REFERENCE_NODE:
               childNodes.add(new EntityReferenceImpl(this, data, pos, len));
               break;

            case Node.ENTITY_NODE:
               childNodes.add(new EntityImpl(this, data, pos, len));
               break;

            case Node.PROCESSING_INSTRUCTION_NODE:
               childNodes.add(new ProcessingInstructionImpl(this, data, pos, len));
               break;

            case Node.COMMENT_NODE:
               childNodes.add(new CommentImpl(this, data, pos, len));
               break;

            case Node.NOTATION_NODE:
               childNodes.add(new NotationImpl(this, data, pos, len));
               break;
         }

         bis.setPos(pos);
         bis.skip(len);
      }
   }
View Full Code Here

      try {
         if ( data != null ) {
            DocumentImpl doc = (DocumentImpl)getOwnerDocument();
            SymbolTable st = doc.getSymbols();

            ByteArrayInput bis = new ByteArrayInput(data, pos, len);
            XMLCompressedInput in = new XMLCompressedInput(bis, st);

            in.readSignature();   // Skip The Signature
            in.readContentSize(); // Skip The Content Size
View Full Code Here

            setAttribute(SRC_KEY, k.toString());
      }
   }

   protected void loadAttributes(SymbolTable st) throws IOException {
      ByteArrayInput bis = new ByteArrayInput(data, pos, len);
      XMLCompressedInput in = new XMLCompressedInput(bis, st);

      in.readSignature();
      in.readContentSize();
      /* TODO why is it used for? short elemSymbol = */ in.readShort();
View Full Code Here

      try {
         if ( data != null ) {
            DocumentImpl doc = (DocumentImpl)getOwnerDocument();
            SymbolTable st = doc.getSymbols();

            ByteArrayInput bis = new ByteArrayInput(data, pos, len);
            XMLCompressedInput xci = new XMLCompressedInput(bis, st);

            byte signature = xci.readByte();
            byte entityType = (byte)(signature & 0x1F);
            switch ( entityType ) {
View Full Code Here

        try {
            if (data != null) {
                DocumentImpl doc = (DocumentImpl) getOwnerDocument();
                SymbolTable st = doc.getSymbols();

                ByteArrayInput bis = new ByteArrayInput(data, pos, len);
                XMLCompressedInput xci = new XMLCompressedInput(bis, st);

                xci.readSignature(); // Skip The Signature
                if (getNodeType() == TEXT_NODE) {
                    xci.readContentSize();
                } else {
                    xci.readInt();
                }

                byte[] buf = new byte[bis.available()];
                xci.read(buf);
                nodeValue = new String(buf, "UTF-8");
            }
        } catch (Exception e) {
            if (log.isWarnEnabled()) {
View Full Code Here

        return result;
    }

    protected void loadAttributes(SymbolTable st) throws IOException {
        ByteArrayInput bis = new ByteArrayInput(data, pos, len);
        XMLCompressedInput in = new XMLCompressedInput(bis, st);

        in.readSignature();
        in.readContentSize();
        in.readShort(); // Some "elemSymbol" - symbol ID?
View Full Code Here

    private final boolean isNSAttr(final String qName) {
        return (("xmlns".equals(qName)) || qName.startsWith("xmlns:"));
    }

    public boolean processContainer(boolean element, int pos, int len) throws IOException, SAXException {
        ByteArrayInput bis = new ByteArrayInput(data, pos, len);
        XMLCompressedInput in = new XMLCompressedInput(bis, symbols);
        String elemName = null;
        String localName = null;
        String nsURI = null;
        String[] mappedPrefixes = null;
        int nsMapCount = 0;

        if (element) {
            in.readSignature();
            in.readContentSize();

            short elemSymbol = in.readShort();
            elemName = symbols.getName(elemSymbol);
            localName = getLocalName(elemName);
            nsURI = symbols.getNamespaceURI(elemSymbol);
            int attrCount = in.readAttributeCount();
            AttributesImpl attrs = new AttributesImpl();
            for (int i = 0; i < attrCount; i++) {
                short symbol = in.readShort();
                short strLen = in.readShort();
                byte[] b = new byte[strLen];
                in.read(b);

                String attrName = symbols.getName(symbol);
                String attrURI = symbols.getNamespaceURI(symbol);
                String lclName = getLocalName(attrName);

                String attrValue = new String(b, "UTF8");

                // look for and buffer newly mapped namespace prefixes
                if (isNSAttr(attrName)) {

                    // create the buffer if needed
                    if (mappedPrefixes == null) {
                        mappedPrefixes = new String[XMLNS_MAP_INCREMENT];

                    }

                    // check the buffer's capacity
                    if (nsMapCount >= mappedPrefixes.length) {
                        String[] newBuf = new String[mappedPrefixes.length + XMLNS_MAP_INCREMENT];
                        System.arraycopy(mappedPrefixes, 0, newBuf, 0, mappedPrefixes.length);
                        mappedPrefixes = newBuf;
                    }

                    // The prefix is the attr "local name", unless this is the
                    // default namespace, in which case the prefix is the empty
                    // string
                    String prefix = ("xmlns".equals(attrName) ? "" : lclName);

                    // Prefix mappings MAY always be reported, regardless of
                    // feature settings.
                    content.startPrefixMapping(prefix, attrValue);
                    mappedPrefixes[nsMapCount++] = prefix;

                    if (hasSaxNamespacesPrefixes) {
                        // According to SAX, the local name should be EMPTY
                        attrs.addAttribute("", "", attrName, "CDATA", attrValue);
                    }
                } else {
                    // Regular attribute
                    attrs.addAttribute(attrURI != null ? attrURI : "",
                                       lclName, attrName, "", attrValue);
                }
            }

            if (comp != null) {
                comp.symbolID(elemSymbol);
                comp.dataLocation(pos, len);
            }
            content.startElement(nsURI != null ? nsURI : "", localName, elemName, attrs);
        } else {
            in.readInt();
        }

        while (!interrupt && bis.available() > 0) {
            pos = bis.getPos();
            in.readSignature(); // Read signature
            len = in.readContentSize();
            if (len == 0) {
                len = 1;
            }

            int type = in.getNodeType();
            switch (type) {

                case Node.ELEMENT_NODE:
                    processContainer(true, pos, len);
                    break;

                case Node.TEXT_NODE:
                case Node.PROCESSING_INSTRUCTION_NODE:
                case Node.CDATA_SECTION_NODE:
                case Node.COMMENT_NODE:
                    {

                        ByteArrayInput tbis = new ByteArrayInput(data, pos, len);
                        XMLCompressedInput tin = new XMLCompressedInput(tbis, symbols);

                        tin.readSignature(); // Skip The Signature
                        if (type == Node.TEXT_NODE) {
                            tin.readContentSize();
                        } else {
                            tin.readInt();
                        }
                       
                        byte[] buf = new byte[tbis.available()];
                        tin.read(buf);

                        String value = new String(buf, "UTF-8");

                        switch (type) {
View Full Code Here

TOP

Related Classes of org.apache.xindice.util.ByteArrayInput

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.