Hello world!

欢迎使用 WordPress。这是您的第一篇日志。您可以编辑它或是删除它,然后开始写您自己的博客。

Posted in 未分类 | Leave a comment

DSpace中数据的管理

DSpace中数据的管理没有采用现有的一些框架(如Hibernate等),而是自己封装了一个简单的框架,根据整个系统的运行情况来看,这个框架还是不错的,现在将其核心的部分记录一下,便于以后在其他的项目中使用它。
RMDB模块是DSpace中处理数据库的核心模块,也属于DSpace2个最底层的支持模块之一。在RMDB中,DSpace除了使用到指定数据库的驱动(这里采用postgresql.jar),只导入了dbcp包,这是基于效率上的考虑。

Posted in 未分类 | Leave a comment

半年没有来了

都有大半年没有来自己的博客了(主要是前段时间博客网速度太烂了)
留个脚印~~
这半年来主要是从事Java开发了。

Posted in 未分类 | Leave a comment

最简便的ajax类

其实题目有点言过其实了,应该是最简便XmlHttpRequest封装之一才对,很久没有更新了,做回标题党吧~~
前段时间一直都在忙于java/web开发,涉及到异步访问,由于只是简单的状态调用和信息查询,使用成熟的ajax框架就显得太大动干戈了,所以自己写了一个很小的对象,放在这里给有类似需要,又不愿意载入ajax库的朋友使用。
代码如下:

thinajax = function() {    var xmlobject;  
function createXMLHttpRequest() { var obj; try { obj = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { obj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { try { obj = new XMLHttpRequest(); } catch (Exception) { raise; } } } return obj; }
this.get = function (URL) { var tmpobject = this; xmlobject.onreadystatechange = function (){ if (xmlobject.readyState == 4) if ((xmlobject.status >= 200) && (xmlobject.status < 300)) tmpobject.onSuccess(xmlobject.responseText); else tmpobject.onFail(xmlobject.status); } xmlobject.open("GET", URL, true); xmlobject.send(null); }
{ xmlobject = createXMLHttpRequest(); }}


说明:类thinajax只有一个方法get(url),有两个事件onFail和onSuccess,使用的时候用这些就够了,因为我只需要GET数据,所以没有加入POST方法,如果需要POST方法,可以自己加入其中~~下面是调用部分的代码:
function startConfirm(){ var checker = new thinajax(); checker.onSuccess = function (response) { if (response == "Found.") alert("已经存在这个Email的用户,请选择其他Email注册"); else alert("可以使用该Email注册"); };
checker.onFail = function () { alert("获取信息失败!"); }; checker.get("<%= request.getContextPath()%>/simplelogin?action=emailcheck&email=" + document.getElementById("emailid").value + "&epersonid=3");}
在按钮事件中调用该函数即可eg: <input type="button" name="confirm" onclick="startConfirm();" value="Confirm"/>好了,简单的一篇文章,当是这么就没有更新之后冒个泡吧~~
Posted in 未分类 | Leave a comment

好久没有更新了

很久没有更新博客了,这段时间研究的内容是DSpace,从编译,安装,测试,感觉还是不错。
前段时间也研究了Lucene全文检索的实现,打算在此基础上写一个桌面搜索软件。但最近一段时间比较忙,等闲下来再实现吧~~

Posted in 未分类 | Leave a comment

我&同事们

捐款

Posted in 未分类 | Leave a comment

脚本解析器相关下载地址

脚本解析器的开发工具和脚本源代码下载地址:
http://tufeiping.googlepages.com/
Posted in 未分类 | 3 Comments

脚本解析器

经过两个月的业余时间的不断敲敲打打,慢慢修改,一个类似JavaScript的脚本解析器终于初见端倪了。这个脚本解析器可以解析函数、支持if...else,while,do...while,for等结构,支持简单的对象定义,外部函数导入和对象的导入。支持脚本创建ActiveX对象并调用它,支持数组操作和各种字符串操作,数值操作等。打算2009年元月份公开所有的源代码(等再完善点吧)。
本来想写一个脚本的简单教程(大致与JavaScript一致,但要求的一些结构还是有点区别的)。
下面是一段可以直接执行的脚本示例:
program Ajax; 
 
var httprequest;

function MyBytesToString(V){
  var VInf, BSTR;
  VInf = CreateObject("Adodb.Stream");
  VInf.Type = 1;
  VInf.Mode = 3;
  VInf.Open();
  VInf.Write(V);
  VInf.Position = 0;
  VInf.Type = 2;
  VInf.Charset = "GB2312";
  BSTR = VInf.ReadText;
  VInf.Close();
  return BSTR;
}

function EventCallBack(){
  debug("httprequest.readyState = " & httprequest.readyState);
  if (httprequest.readyState==4){
    if (httprequest.status==200){
      StringToFile("D:demo.html", MyBytesToString(httprequest.responseBody));
    }
    else{
      debug("httprequest.responseText = " & httprequest.responseText);
    }
    debug("httprequest.status = " & httprequest.statusText);
  }
}

function main(){
  httprequest = CreateObject("Microsoft.XMLHTTP.1.0");
  httprequest.open("GET", "http://www.sina.com.cn/", true);
  httprequest.setRequestHeader("Content-Type", "text/xml");
  httprequest.onReadyStateChange = EventCallBack;
  httprequest.send();
}         
运行的结果正常。

SScript

这个东西虽然没有SpiderMonkey那么强大完善,但已经有了一般虚拟机所有需要的结构了。
需要下载的可以到http://tufeiping.googlepages.com/ScriptIDE.exe中下载到IDE的可执行程序。如果需要代码(还不很完善的代码)可以来Email索取 tufeiping@gmail.com

Posted in 未分类 | 7 Comments

一个表达式计算器的代码

昨天突然想写一个表达式计算器,幸好原来有段算法说明,然后温习一番,今天抽空将它简单实现出来。下面是源代码,直接编译后就可以了。

{*******************************************************}
{                                                       }
{               Expression Calculate                    }
{                                                       }
{       版权所有 (C) 2003-2008                          }
{                                                       }
{*******************************************************}

program demo;

{===============================================================================
* 软件名称:demo  /Expression
* 单元名称:表达式计算demo
* 单元作者:涂飞平
* 备    注:2008-10-16
* 开发平台:PWin2000SP4 + Delphi 11
===============================================================================}

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes,Math;

const SplitFlag=#13#10;
      MaxArray=255;
var
  CurrLevel,CurrPos:Integer;
 
  CharArray:array [0..MaxArray] of Char;
  ByteArray:array [0..MaxArray] of Byte;
  RealArray:array [0..MaxArray] of Real;

procedure PushEx(value:real);
begin               
  if CurrPos>MaxArray then  Exception.Create('PushEx Error:Out of Range 255');
  RealArray[CurrPos]:=value;
  CurrPos:=CurrPos+1;
end;

function PopEx():Real;
begin
  CurrPos:=CurrPos-1;
  if CurrPos<0 then raise Exception.Create('PopEx Error:Out of Range -1');
  Result:=RealArray[CurrPos];
end;

procedure Push(oprator:Char;level:Byte);
begin               
  if CurrPos>MaxArray then  Exception.Create('Push Error:Out of Range 255');
  CharArray[CurrPos]:=oprator;
  ByteArray[CurrPos]:=level;
  CurrPos:=CurrPos+1;
end;

function Pop(var level:Byte):Char;
begin
  CurrPos:=CurrPos-1;
  if CurrPos<0 then raise Exception.Create('Pop Error:Out of Range -1');
  Result:=CharArray[CurrPos];
  level:=ByteArray[CurrPos];
end;

function GetOpratorIndex(oprator:Char):Integer;
begin
  Result:=0;
  case oprator of
    '#':Result:=-1;
    '+','-':Result:=0;
    '*','/':Result:=1;
    '^':Result:=2; 
  end;
end;

function TestPop(oprator:Char):Boolean;
var
  tmp:Char;level:Byte;
begin
  tmp:=Pop(level);
  Result:=False;
  if (GetOpratorIndex(oprator)+CurrLevel)>(GetOpratorIndex(tmp)+Level) then
    Result:=True;
  Push(tmp,level);
end;

function depoland(S:string):string;
var
  i:Integer;
  tmp:Char;level:Byte;
begin
  CurrLevel:=0;
  CurrPos:=0;
  Push('#',0);
  for  i:= 1 to Length(S) do
  begin
     case S[i] of
       '+','-','*','/','^':
       begin 
          Result:=Result+SplitFlag;
          if TestPop(S[i]) then
            Push(S[i],GetOpratorIndex(S[i])+CurrLevel)
          else
          begin
             While not TestPop(S[i]) do
               Result:=Result+Pop(level)+SplitFlag;
             Push(S[i],GetOpratorIndex(S[i])+CurrLevel);
          end;
          Continue;
       end;
       '(':begin
          Inc(CurrLevel,4);
          Continue;
       end;
       ')':begin
         Result:=Result+SplitFlag;
         Dec(CurrLevel,4);
         Continue;
       end;
       else
         Result:=Result+S[i];
     end;
  end;
  tmp:=Pop(level);
  while tmp<>'#' do
  begin
    Result:=Result+SplitFlag+tmp+SplitFlag;
    tmp:=Pop(level);
  end;
end;

function isDigit(S:string):Boolean;
begin
  Result:=True;
  if (S='+')or (S='-') or (S='*') or (S='/') or (S='^') then
    Result:=False;
end;

function Calculate(S:string):Real;
var
  StrList:TStringList;
  i:Integer;
  tmp:string;
  xr1,xr2:Real;
begin
  StrList:=TStringList.Create;
  CurrPos:=0;
  try
    StrList.Text:=S;
    for i := 0 to StrList.Count-1 do
    begin
      if Trim(StrList[i])='' then
        Continue;
      if isDigit(StrList[i]) then
        PushEx(StrToFloat(StrList[i]))
      else
      begin
        tmp:=StrList[i];
        case Char(tmp[1]) of
          '+':begin
            xr1:=PopEx();
            xr2:=PopEx();
            xr1:=xr1+xr2;
            PushEx(xr1);
          end;
          '-':begin
            xr1:=PopEx();
            xr2:=PopEx();
            xr1:=xr2-xr1;
            PushEx(xr1);
          end;
          '*':begin
            xr1:=PopEx();
            xr2:=PopEx();
            xr1:=xr1*xr2;
            PushEx(xr1);
          end;
          '/':begin
            xr1:=PopEx();
            xr2:=PopEx();
            xr1:=xr2/xr1;
            PushEx(xr1);
          end;
          '^':begin
            xr1:=PopEx();
            xr2:=PopEx();
            xr1:=Power(xr2,xr1);
            PushEx(xr1);
          end;
        end;
      end;
    end;
    Result:=PopEx;
  finally
    StrList.Free;
  end;
end;

var
  input:array [0..MaxArray] of Char;
begin
  try
    { TODO -oUser -cConsole Main : Insert code here }
    Writeln('输入算术表达式:');
    Readln(input);
    if StrPas(input)<>'' then
      Writeln('运算结果:'+format('%f',[Calculate(depoland(input))]));
    Writeln('');
    Writeln('按回车键退出');
    Readln(input);
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
end.

Calculate

支持()运算级,+-*/四则运算,还支持^指数运算,通过对这个例子的扩展,可以支持更多的运算类型,也可以将程序逻辑之类的也做后缀处理,这样就可以写出简单的解析器了,呵呵 希望对大家有用。(已经修改好了同优先级运算符右结合的问题了)

下面这个采用的是EBNF表示法来求表达式的值。
{*******************************************************}
{                                                       }
{               Expression Calculate                    }
{                                                       }
{       版权所有 (C) 2003-2008                          }
{                                                       }
{*******************************************************}

unit CalcUnit;

{===============================================================================
* 软件名称:demo  /Expression2
* 单元名称:表达式计算demo2
* 单元作者:涂飞平
* 备    注:2008-10-26
* 开发平台:PWin2000SP4 + Delphi 11
===============================================================================}

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TCalcForm = class(TForm)
    calcbtn: TButton;
    exitbtn: TButton;
    expressionmmo: TMemo;
    resultedt: TEdit;
    toplbl: TLabel;
    centerlbl: TLabel;
    procedure exitbtnClick(Sender: TObject);
    procedure calcbtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TCalculation=class
  private
    FCurrPos:Integer;
    FExpression:string;
  protected
    function getToken:string;
    function Match(S:string):Boolean;
    function _Expression():Real;
    function Term():Real;
    function Pow():Real;
    function Factor():Real;
  public
    constructor Create(aStr:string='');
    destructor Destroy;override;
    function Calculate:Real;
    property Expression:string read FExpression write FExpression;
  end;

var
  CalcForm: TCalcForm;

implementation

uses Math;

{$R *.dfm}

const spaceset = ['+','-','*','/','(',')','^'];

procedure TCalcForm.calcbtnClick(Sender: TObject);
var
  calcobj:TCalculation;
begin
  if expressionmmo.Text='' then  Exit;
  calcobj:=TCalculation.Create(expressionmmo.Text);
  try
    resultedt.Text:=Format('%f' ,[calcobj.Calculate()]);
  finally
    calcobj.Free();
  end;
end;

procedure TCalcForm.exitbtnClick(Sender: TObject);
begin
  Close();
end;

{ TCalculation }

constructor TCalculation.Create(aStr: string='');
begin
  FCurrPos:=1;
  FExpression:=aStr;
end;

destructor TCalculation.Destroy;
begin
  inherited Destroy;
end;

function TCalculation.Calculate: Real;
begin
  Result:=0;
  if FExpression='' then  Exit;
  FCurrPos:=1;
  Result:=_Expression();
end; 

function TCalculation.getToken: string;
var
  i,ipos:integer;
begin
  ipos:=Fcurrpos;
  Result:='';
  for i :=0  to 100 do
  begin
     if Result='' then
     begin
        if FExpression[ipos+i] in spaceset then
        begin
           Result:=FExpression[ipos+i];
           Exit;
        end;
     end;
     if ipos+i>Length(FExpression) then
        Exit;
     if FExpression[ipos+i] in spaceset then
        Exit;
     Result:=Result+FExpression[ipos+i];
  end;
end;

function TCalculation.Match(S: string): Boolean;
begin
  if getToken()<>S then
    raise Exception.Create('Match error.');
  Fcurrpos:=Fcurrpos+Length(S);
end;

function TCalculation._Expression: Real;
var
  tmp:Real;
begin
   tmp:=Term();
   while (getToken()='+') or (getToken()='-') do
   begin
     if getToken()='+' then
     begin
        Match('+');
        tmp:=tmp+Term();
     end
     else  if getToken()='-' then
     begin
        Match('-');
        tmp:=tmp-Term();
     end;
   end;
   Result:=tmp;
end; 

function TCalculation.Term: Real;
var
  tmp:Real;
begin
  tmp:=Pow();
  while (getToken()='*') or (getToken()='/') do
  begin
    if getToken()='*' then
    begin
        Match('*');
        tmp:=tmp*Pow();
    end
    else if getToken()='/' then
    begin
        Match('/');
        tmp:=tmp/Pow();
    end;
  end;
  Result:=tmp;
end; 

function TCalculation.Pow: Real;
var
  tmp:Real;
begin
  tmp:=Factor();
  while (getToken()='^') do
  begin
    if getToken()='^' then
    begin
        Match('^');
        tmp:=Power(tmp,Factor());
    end;
  end;
  Result:=tmp;
end;

function TCalculation.Factor: Real;
var
  tmp:Real;
  str:string;
begin
  if getToken()='(' then
  begin
    Match('(');
    tmp:=_Expression();
    Match(')');
  end
  else
  begin
     str:=getToken();
     tmp:=StrToFloat(str);
     Match(str);
  end;
  Result:=tmp;
end;

end.

Posted in 未分类 | 1 Comment

参加了盛大Widget开发大赛

十一假期期间参加了“盛大”的Widget设计大赛,自己也做了一个盛大圈圈的扩展插件,并展示出来了,希望大家下载使用(里面包含全部的源代码,其中包括delphi开发的插件部分所有代码),并投我的票啊 呵呵
地址为:
http://snda.csdn.net/sdo/display_ser.aspx?pointid=160

2008_10_03_1818935A
希望大家喜欢,谢谢了。

Posted in 未分类 | Leave a comment