Разработка контента курса дистанционного обучения "DB2 универсальная база данных", страница 49

                String value = null;

                for( int i = 0; i < partsCount; i++ ){

                      stopIndex = stopIndex + bounds.length() + 1;

                      startIndex = inStr.indexOf( "Content-Disposition: form-data;", stopIndex );

                      stopIndex = inStr.indexOf( bounds, startIndex );

                      temp = inStr.indexOf( "filename=\"", startIndex );

                      if( temp != -1 && temp < stopIndex ){

                        isFile = true;

                              temp = temp + "filename=\"".length();

                        name = inStr.substring( temp, inStr.indexOf( "\"", temp+1 ) );

                      } else {

                            temp = inStr.indexOf( "name=\"", startIndex );

                            temp = temp + "name=\"".length();

                        name = inStr.substring( temp, inStr.indexOf( "\"", temp+1 ) );

                      }

                      startIndex = inStr.indexOf( "\r\n\r\n", startIndex );

                      if( startIndex >= stopIndex ){

                        return null;

                      }

                      startIndex += 4;

                stopIndex -= 2;

                      if( !isFile ){

                        value = inStr.substring( startIndex, stopIndex );

                        returnMe[i] = new Part( name, value );

                      } else {

                        returnMe[i] = new Part( name, startIndex, stopIndex );

                      }

                      isFile = false;

                }

            }

            return returnMe;

      }

      public void saveFile(String path, Part part) throws IOException {

            saveFile( path, part.getName(), part );

      }

      public void saveFile(String path, String newFileName, Part part) throws IOException, FileNotFoundException {

            if( path.lastIndexOf( "\\" ) != path.length()-1 ){

                  path = path + "\\" + newFileName;

            } else {

                  path = path + newFileName;

            }

            BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream( path ) );

            int a1 = part.getStartIndex();

        int a2 = part.getStopIndex();

        bos.write( inBytes, a1, a2 - a1 );

        bos.close();

      }

    public void proceedXml(Part part) throws UnsupportedEncodingException, SAXException, IOException, NamingException, CreateException {

        RowSet rowSet = new RowSet();

        XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");

        reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", true);

        reader.setFeature("http://xml.org/sax/features/namespaces", true);

        reader.setFeature("http://xml.org/sax/features/validation", true);

        reader.setDTDHandler(rowSet);

        reader.setErrorHandler(rowSet);

        reader.setContentHandler(rowSet);

        int a1 = part.getStartIndex();

        int a2 = part.getStopIndex();

        ByteArrayInputStream in = new ByteArrayInputStream(inBytes, a1, a2 - a1);

        reader.parse(new InputSource(in));

//          Данный блок нужно использовать для доступа к EJB из приложения, работающего вне WebSphere

//        Hashtable env = new Hashtable();

//        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");

//        env.put(Context.URL_PKG_PREFIXES, "com.ibm.ws.naming");

//        Context ctx = new InitialContext(env);

//          Данный блок нужно использовать для доступа к EJB из приложения, развернутого в WebSphere

        Context ctx = new InitialContext();

        Object ejbHome = ctx.lookup("REPLICATOR");