⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commonutil.java

📁 招标投标网上系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     */
    public static String getName( String name, String reg )
    {
        String userid = "";
        if ( name.indexOf( reg ) != -1 )
        {
            name = name.substring( name.indexOf( reg ) + reg.length(), name.length() );
        }
        return name;
    }


    /**
     *  用于修改时将记录组成显示的名称
     *
     *@param  idlist   用户数据列表
     *@param  colname  表示用户的字段名
     *@return          一个长度为2的字符串数组,result[0]表示用户id,result[1]表示用户名称
     */
    /*
    public static String[] getMasterName( DataList idlist, String colname )
    {
        String[] result = new String[2];
        String token = ",";
        int count = idlist.getLength();
        result[0] = "";
        result[1] = "";
        for ( int i = 0; i < count; i++ )
        {
            if ( i == count - 1 )
            {
                token = "";
            }
            result[0] = result[0] + ( String ) idlist.get( i, colname ) + token;
            result[1] = result[1] + getMasterName( ( String ) idlist.get( i, colname ) ) + token;
        }
        return result;
    }


    /**
     *  load 属性文件
     *
     *@param  filename       参数描述
     *@return                描述返回值信息
     *@exception  Exception  异常描述
     */
    public static Properties Properties_load( String filename )
        throws Exception
    {
        Properties prop = new Properties();
        FileInputStream is = new FileInputStream( filename );
        prop.load( is );
        is.close();
        return prop;
    }
/*
    public static Object[] getUnitAllPersonId(String userid)
	{
	    LdapExtendTool ldapTool = new LdapExtendTool();
        ldapTool.connection();
        NWPerson nwPerson = ldapTool.getPersonByUid( userid );
        String departMent = nwPerson.getDepartment();

        if ( departMent == null )
        {
            departMent = "";
			return null ;
        }
		List ls = ldapTool.getPersonsByUnit(departMent) ;

		Object []ln = new Object[ls.size()] ;
        for(int i = 0 ;i<ls.size() ;i++)
		{
		   ln[i] =  ((NWPerson)ls.get(i)).getAccount();
		}
		//ldapTool.close();
        return ln ;
	}

    /**
     *  取得 CommonUtil class 的属性person
     *
     *@param  ulist          参数描述
     *@return                属性 person的值
     *@exception  Exception  异常描述
     */
    /*
    public static Object[] getPerson( DataList ulist )
        throws Exception
    {
        return getPersonDatail( ulist, 0 );
    }


    /**
     *  取得 CommonUtil class 的属性personDetail
     *
     *@param  ulist          参数描述
     *@return                属性 personDetail的值
     *@exception  Exception  异常描述
     */
    /*
    public static Object[] getPersonDetail( DataList ulist )
        throws Exception
    {
        return getPersonDatail( ulist, 1 );
    }


    /**
     *  根据岗位部门角色列表返回人员列表
     *
     *@param  ulist          参数描述
     *@param  flag           参数描述
     *@return                属性 person的值
     *@exception  Exception  异常描述
     */
    /*
    public static Object[] getPersonDatail( DataList ulist, int flag )
        throws Exception
    {

        ArrayList persons = getPersonList( ulist );
        HashMap personMap = null;

        if ( persons != null )
        {

            int pcount = persons.size();
            personMap = new HashMap();

            for ( int j = 0; j < pcount; j++ )
            {
                NWPerson person = ( NWPerson ) persons.get( j );
                personMap.put( person.getAccount(), person );
            }

			if ( flag == 0 )
			{
				return personMap.entrySet().toArray();
			}
			else
			{
				return personMap.values().toArray();
			}
		}

		return null;
    }


    /**
     *  取得 CommonUtil class 的属性personList
     *
     *@param  ulist          参数描述
     *@return                属性 personList的值
     *@exception  Exception  异常描述
     */
    /*
    private static ArrayList getPersonList( DataList ulist )
        throws Exception
    {
        LdapExtendTool ldap = new LdapExtendTool();
        ldap.connection();
        ArrayList persons = null;
        int count = ulist.getLength();
        if ( count > 0 )
        {
            persons = new ArrayList();
            for ( int i = 0; i < count; i++ )
            {
                String pitem = ulist.get( i, 0 );
                String pname = "";

                if ( pitem.indexOf( UNIT ) != -1 )
                {
                    pname = getName( pitem, UNIT );
                    persons.addAll( ldap.getPersonsByUnit( pname ) );
                }
				else if ( pitem.indexOf( POST ) != -1 )
                {
                    pname = getName( pitem, POST );
                    persons.addAll( ldap.getPersonsByPost( getPostUnitName( pitem ), pname ) );
                }
				else if ( pitem.indexOf( ROLE ) != -1 )
                {
                    pname = getName( pitem, POST );
                    persons.addAll( ldap.getPersonsByRole( pname ) );
                }
				else
                {
                    pname = getName( pitem, PERSON );
					persons.add( ldap.getPersonByUid(pname) );
                }
            }
        }
        return persons;
    }


    /**
     *  删除文件
     *
     *@param  strPathfile    文件路径
     *@exception  Exception  异常描述
     */
    public static void deleteFile( String strPathfile )
        throws Exception
    {
        try
        {
            File pathfile = new File( strPathfile );
            if ( pathfile.exists() )
            {
                pathfile.delete();
            }
            pathfile = null;
        } catch ( Exception ex )
        {
            ex.printStackTrace();
            throw new Exception( ex.getMessage() );
        }
    }



    /**
     *  函数说明: readLdapConfigFile
     *
     *@return    : []String String[0] --- LDAP DN String[1] --- LDAP PassWord
     *      String[2] --- LDAP Host null --- 出错 无异常抛出
     */
    public static String[] readLdapConfigFile() throws Exception
    {
        String[] ldapConfig = new String[4];
        //try
        //{
            //读文件
            RandomAccessFile ConfFile = new RandomAccessFile( System.getProperty("neuldap"), "r" );
            String ConfLine = ConfFile.readLine();
            while ( ConfLine != null )
            {
                ConfLine = ConfLine.trim();
                if ( ConfLine.startsWith( "ManagerDN" ) )
                {
                    //file :
                    //取 LDAP DN
                    ldapConfig[0] = ConfLine.substring( 9, ConfLine.length() ).trim();
                } else if ( ConfLine.startsWith( "ManagerPwd" ) )
                {
                   // file :
                    //GET LDAP PassWord
                    ldapConfig[1] = ConfLine.substring( 10, ConfLine.length() ).trim();
                } else if ( ConfLine.startsWith( "ldapHost" ) )
                {
                    //file :
                    //GET LDAP HOST
                    ldapConfig[2] = ConfLine.substring( 8, ConfLine.length() ).trim();
                    //System.out.println("read-host="+ldapConfig[2]);
                } else if ( ConfLine.startsWith( "baseDN" ) )
                {
                    ldapConfig[3] = ConfLine.substring( 6, ConfLine.length() ).trim();
                }
                ConfLine = ConfFile.readLine();
            }
            ConfFile.close();
       //}
       //catch ( IOException e )
       //{   e.printStackTrace();
          // ldapConfig = null;
          // throw new Exception(e.getMessage());
         //  //file :
            //异常返回
            //ldapConfig = null;

       //}
       return ldapConfig;
    }

    public String getHTMLbyURL(String strUrl,HttpServletRequest request) throws Exception {
             String  sTotalString;
              try{
                    String  sCurrentLine;

                sCurrentLine="";
                sTotalString="";
                java.io.InputStream  l_urlStream;
                java.net.URL  l_url  =  new  java.net.URL("http://"+request.getServerName()+":"+request.getServerPort()+strUrl);
                java.net.HttpURLConnection  l_connection  =  (java.net.HttpURLConnection)  l_url.openConnection();
                l_connection.connect();
                l_urlStream  =  l_connection.getInputStream();
                java.io.BufferedReader  l_reader  =  new  java.io.BufferedReader(new  java.io.InputStreamReader(l_urlStream));
                while  ((sCurrentLine  =  l_reader.readLine())  !=  null)
                {
                    sTotalString+=sCurrentLine+"\n";
                }

              }catch(Exception ex){
                           ex.printStackTrace();
                 throw new Exception("CommonUtil:getHTMLbyURL:"+ex.getMessage());
              }
                return sTotalString;
       }

    /**
     *  方法描述
     *
     *@param  args  参数描述
     */
    public static void main( String args[] )
    {
        try
        {
            String aa="2003-08-29 13:56:13";
            //System.out.println(CommonUtil.productDate(aa));
        } catch ( Exception ex )
        {
            System.out.println( ex.getMessage() );
        }
    }
       /**
        *  列出文件夹下的所有文件
        *
        *@param  req  request请求
        *@param  req  文件路径
        */

  public static String[] listfile(HttpServletRequest req, String strPath)throws Exception {
              String strRealPathfile=req.getRealPath(strPath);
              String[] files=null;
          try{
                  File pathdir=new File(strRealPathfile);
           if (pathdir.exists()) {
                     files=pathdir.list();
           }
         } finally{
           ;
         }
       return files;
     }
	/**
	 *按人员的帐号和保留字段1的信息排序
	 *@param
	 *@return
	 */
        /*
	public static Vector sortsPersonsByPosition(Vector vPersons)
	throws Exception
	{
		int vLength = vPersons.size();
		Object[] o = vPersons.toArray();
		Vector newPersons = new Vector();
		Comparator myCom1 = new UnitComparator(0);
		Comparator myCom2 = new UnitComparator(1);
		Arrays.sort(o,myCom1);
		Arrays.sort(o,myCom2);
		for(int i=0 ;i<vLength;i++)
		{
			newPersons.add(o[i]);
		}
		return newPersons ;
	}
	/**
	 *按岗位的描述信息中的前三位信息排序
	 *@param
	 *@return
	 */
        /*
	public static Vector sortsPostsByPosition(Vector vPosts)
	throws Exception
	{
		int vLength = vPosts.size();
		Object[] o = vPosts.toArray();
		Vector newPosts = new Vector();
		Comparator myCom = new UnitComparator(2);
		Arrays.sort(o,myCom);
		for(int i=0 ;i<vLength;i++)
		{
			newPosts.add(o[i]);
		}
		return newPosts ;
	}
        public static Vector sortsUnitsBySpelling(Vector vUnits)
        throws Exception
    {
           int vLength = vUnits.size();
           Object o[] = vUnits.toArray();
           Vector newUnits = new Vector();
           Comparator myCom3 = new UnitComparator(3);
           Arrays.sort(o, myCom3);
           for(int i = 0; i < vLength; i++)
               newUnits.add(o[i]);

            return newUnits;
    }
*/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -