Saturday, November 7, 2009

一步一步学Silverlight 2系列(7):全屏模式支持 - TerryLee's Tech Space - 博客园

一步一步学Silverlight 2系列(7):全屏模式支持 - TerryLee's Tech Space - 博客园: "private void toggleButton_Click(object sender, RoutedEventArgs e) { Content contentObject = Application.Current.Host.Content; contentObject.IsFullScreen = !contentObject.IsFullScreen; }"

Silverlight Full Screen


private void toggleButton_Click(object sender, RoutedEventArgs e)
{
Content contentObject = Application.Current.Host.Content;
contentObject.IsFullScreen = !contentObject.IsFullScreen;
}

//Captch full screen event
public Page()
{
InitializeComponent();
Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
}

Silverlight mouse envent process




private void Rectangle_MouseMove(object sender, MouseEventArgs e)
{
Point p = e.GetPosition(e.Source as FrameworkElement); //get the position
Status.Text = String.Format("坐标位置({0}:{1})",p.X,p.Y);
}
private void ParentCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
String msg = "x:y = " + e.GetPosition(sender as FrameworkElement).ToString();
msg += " from " + (e.Source as FrameworkElement).Name;
Status.Text = msg;
}
void OnMouseUp(object sender, MouseButtonEventArgs e)
{
FrameworkElement element = sender as FrameworkElement;
trackingMouseMove = false;
element.ReleaseMouseCapture();

mousePosition.X = mousePosition.Y = 0;
element.Cursor = null;
}


Silverlight style



//Application scope style which can be used through the application





//Apply style



Add property to customized control


为用户控件添加属性

简单的修改一下上面示例中的XAML文件,添加一个文本块控件,用它来显示文字提示信息。


Opacity="0.7" Fill="#FF8A8A8A"/>









HorizontalAlignment="Left" VerticalAlignment="Center"
Margin="50 20 0 0"/>


Tuesday, November 3, 2009

My Works-Nov 3

9:00am-18:30pm
Have lunch with Xiaowei,jun and other teammates.

Compelte a solution for making sync call in silverlight.
1.Cross domain visit in silverlight:

test cross domain visit by creating a clientaccesspolicy.xml file and upload to my own web hosting udatasoft.com. In order to make a visit to another domain in silverlight by using WebClient, we need to upload a clientaccesspolicy.xml file to root directory of the remote domain. The following example is my test:



-
-
-
-


-







In this simple example, I set allow other site to visit api subpath and its subpaths, such as "http://www.udatasoft.com/api/order.html"., without this file in the root of udatasoft.com, we can not establish a http call from a silverlight program.

2.Sync http call.
In silverlight , we can only make a async http call as follow:

void MakeAsyncCall(string url)
{
WebClient wb = new WebClient();
wb.DownloadStringCompleted +=new DownloadStringCompletedEventHandler(wb_DownloadStringCompleted);
wb.DownloadStringAsync(new Uri(url));
}

void wb_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
DisplayResult(e.Result);
else
txtHtml.Text = e.Error.Message;
}

In order to make a sync call, we need use XMLHttpRequest as follow:


public class SyncCall
{
protected static System.Windows.Browser.ScriptObject XMLHttpRequest;
protected static System.String Result = System.String.Empty;

///
/// Makes XMLHttpRequest
///

/// relative or absolute url as string
/// GET or POST
public static void MakeSyncCall(string Url, string Method)
{
// Backward compat
System.Windows.Browser.HtmlPage.Window.Eval("if(typeof XMLHttpRequest==\"undefined\"){XMLHttpRequest=function(){var a=[\"Microsoft.XMLHTTP\",\"MSXML2.XMLHTTP\",\"MSXML2.XMLHTTP.3.0\",\"Msxml3.XMLHTTP\"];for(var b=0;b // create the instance
XMLHttpRequest = System.Windows.Browser.HtmlPage.Window.CreateInstance("XMLHttpRequest");
// request data from server
XMLHttpRequest.Invoke("open", Method.ToUpper(), Url, false);
// send. !!! do not replace it with "null" as it throws exception
XMLHttpRequest.Invoke("send", "");
// get result as string. as gecko based browsers does not return xml
Result = XMLHttpRequest.GetProperty("responseText").ToString();
}




///
/// Returns result from request as string
///

public static System.String GetResult()
{
return Result.ToString();
}

}

3. Sync call WCF webservice in silverlight:
In silverlight, there are no way to make a sync call, because silverlight only provide way to make a async call to a web service. In some circumtance, we may need may sync call to webservice, or we at least limit user operation before a web service call finishes. One way to do that is to block the UI thread before web service methods call finished, but it will make web service call never call back, because microsoft process web service call in UI thread, if you block UI thread, your web service async call never be run. To deal with it, we can create a second thread to make a async call and set a flag in the UI thread by using dispather class when web service finished. Here we should notice that we can not directly change UI thread variables in the second thread because of thread conflicts, but we can using dispather class to run a short program in UI thread as follow:

private void btnWCFSyn_Click(object sender, RoutedEventArgs e)
{
txtHtml.Text = "";
new Thread(new ThreadStart(delegate
{
ServiceReference1.Service1Client wclientsyn = new SilverlightSync.ServiceReference1.Service1Client();
wclientsyn.GetBooksCompleted += (sender1, args) => { mnREvent.Set(); DisplayHtml(args); };
mnREvent.Reset();
wclientsyn.GetBooksAsync();
mnREvent.WaitOne(); })).Start();


//mnREvent.WaitOne();
}

void DisplayHtml(System.ComponentModel.AsyncCompletedEventArgs e)
{
SilverlightSync.ServiceReference1.GetBooksCompletedEventArgs e1=(SilverlightSync.ServiceReference1.GetBooksCompletedEventArgs)e;
Dispatcher.BeginInvoke(delegate()
{
txtHtml.Text = "";
if (e1.Error == null)
{

for (int i = 0; i < e1.Result.Count; i++)
txtHtml.Text += e1.Result[i] + "\n";
}

else
txtHtml.Text = "error: " + e1.Error.Message;

}
);
}
}

Monday, November 2, 2009

My Works-Nov 2

8:30am-18:50, lunch break 12:30-13:20
In the morning, waiting for my computer to be setup.
Afternoon: install dev env and did a research how to do syn call in silverlight.

Tuesday, September 8, 2009

July 2008 - Posts - Guy Burstein's Blog

July 2008 - Posts - Guy Burstein's Blog: "How To: Call a Java EE Web Service from a .Net Client

Call a Java EE Web Service .Net InteroperabilityMany organizations have server side investments in Java technologies. While they want to build a compelling UI with Microsoft’s latest technologies, such as WPF and Silverlight, they still want to benefit from those existing investments instead of rewriting them. In order to do so, we have to bridge between those technologies and allow client side technologies consume Java web services.

This post is a step by step guide for building a Java EE Web Service, and a .Net client application that consumes it.

Before we get started with this walkthrough, make sure you have the following installed on your machine:

* Java Development Kit (JDK) 6
* Java EE 5 SDK
* NetBeans 6.1 IDE (Web & Java EE)

Create a Java Web Service (Java EE, JAX-WS)
1. Create a new Web Application

In the NetBeans 6.1 IDE, choose File –> New Project. In the New Project Dialog select the Web category, and choose Web Application from the projects list. Then, Click Next.

* If the web category is not available in this dialog, it means that the NetBeans version you have installed isn’t the Web and Java EE package.

Java EE Web Service .Net Client Interoperability

In the Name and Location page, set the location where you want to create the web application, and provide a name for the project. Click Next.

Java EE Web Service .Net Client Interoperability

In the Server and Settings page, leave the default settings (Java EE 5, Use GlassFish V2) and Click Finish.

Java EE Web Service .Net Client Interoperability

This creates the initial web application and opens the project for editing.

Java EE Web Service .Net Client Interoperability
2. Create the Web Service

Add a new web service to the project. Right click the project node and choose New –> Web Service.

Java EE Web Service .Net Client Interoperability

* Notice that the location of the Web Service option in the menu may change from this image and your IDE.

In the New Web Service dialog, provide the Web Service Name, and the Package. The name of the service will affect the final URL for calling the service, and the package name will be the namespace of the service contract. Click Finish.

Java EE Web Service .Net Client Interoperability

The Web Service now appears in the project tree.

Java EE Web Service .Net Client Interoperability

To implement the service, double click the service node in the project tree (in the figure above – CalculatorService). This will open the Web Service in Design mode, that lets you graphically design your service.

Java EE Web Service .Net Client Interoperability

Change to Source View by clicking on the Source button in the upper toolbar, and this will open the CalculatorService.Java file for editing. Here is a sample implementation of the service. Notice how Java Annotations are similar to .Net Attributes, especially how similar they are to the Web Services attributes we know…

package org.bursteg.calculator;



import javax.jws.WebMethod;

import javax.jws.WebParam;

import javax.jws.WebService;



@WebService

public class CalculatorService

{

@WebMethod

public int Add(@WebParam(name='a') int a,

@WebParam(name='b') int b)

{

return a + b;

}

}

Deploy the web service to the web application server. From the NetBeans IDE this is done by right clicking the project node, and choosing Undeploy and Deploy.

Java EE Web Service .Net Client Interoperability

After the web application has been deployed, just to make sure the web service works as expected, you can right click the web service node, and choose Test Web Service.

Java EE Web Service .Net Client Interoperability

This will open the browser and navigate to a test page with the url of the service (http://localhost:9232/Calculator/CalculatorServiceService) with a ?Tester suffix.
Call the Java Web Service from a .Net Client

In Visual Studio 2008, create a new console application.

Java EE Web Service .Net Client Interoperability

This creates a new solution with a single Console Application project in it.

Right click the project node and choose Add Service Reference.

Java EE Web Service .Net Client Interoperability

In the Add Service Reference Dialog, paste the address of the service metadata endpoint (service address + ?wsdl suffix: http://localhost:9232/Calculator/CalculatorServiceService?wsdl), and click Go. The dialog will get the service metadata and understand the service contract.

Java EE Web Service .Net Client Interoperability

Provide a namespace for the service reference, and click OK.

This will generate the client side proxy that lets you consume the service easily, and the required configuration settings into the configuration file.

Java EE Web Service .Net Client Interoperability

To call the service using the generated client side proxy, open Program.cs and use the following code:

static void Main(string[] args)

{

CalculatorServiceClient proxy = new CalculatorServiceClient();

int result = proxy.Add(2, 3);

Console.WriteLine('Calculator Service returned: ' + result.ToString());

}

Run the program and see that the web service is being called and the result is correct.
Conclusion

Since Java EE Web Services (JAX-WS) are standard SOAP services, they are easily interoperable from a .Net client application with only several clicks. Visual Studio generated a .Net client proxy that makes it very easy to connect and call the service.

Enjoy!"

Tuesday, July 21, 2009

VC application architecture

Win32 Application (if you don't want open console window when the application is running, you should not use console application).

Application
Windows class (MainWindows or Some kind of DialogWindows)
Thread Class(you can have several thread runing, controled by windows class);


APIENTRY wMain
Get and save some system information into globle varibles such as windows version, current module directory,cmd argv
Create MainWindow object or MainDialog object and make it showwindows
Enter Message dispatching
Exit

MainWindow or MainDialog
Save some program related parameters in the MainWindow class
create thread (if need)
Process message

Thread
do work
exit.
--------------------------------

Sunday, July 19, 2009

转换spool file 到 PDF RPGIV 源代码 - AS00 RPG编程技巧 - Passthru

转换spool file 到 PDF RPGIV 源代码 - AS00 RPG编程技巧 - Passthru: "转换spool file 到 PDF RPGIV 源代码
转换spool file 到 PDF RPGIV 源代码

******************************************************************
H
* Work files
Fcvtwork02 IF F 382 DISK
Fcvtwork01 UF A F 378 DISK
* Program parameter - report title
D paTitle S 50A
* Program parameter - spooled file information returned by API
D SplInfo DS
D saReturned 10I 0
D saAvailabl 10I 0
D saIntJobId 16A
D saSplfId 16A
D saJobName 10A
D saUser 10A
D saJobNbr 6A
D saSplFile 10A
D saSplNbr 10I 0
D saFormType 10A
D saUsrDta 10A
D saStatus 10A
D saFilAvail 10A
D saHold 10A
D saSave 10A
D siPages 10I 0
D siCurrPage 10I 0
D siFromPage 10I 0
D siToPage 10I 0
D siLastPage 10I 0
D siRestart 10I 0
D siCopies 10I 0
D siCopyRem 10I 0
D siLPI 10I 0
D siCPI 10I 0
D siOutPty 2A
D saOutq 10A
D saOutqLib 10A
D saOpenDate 7A
D saOpenTime 6A
D saPrtFile 10A
D saPrtfLib 10A
D saPgmName 10A
D saPgmLib 10A
D saAcgCode 15A
D saPrtTxt 30A
D siRcdLen 10I 0
D siMaxRcds 10I 0
D saDevType 10A
D saPrtType 10A
D saDocName 12A
D saFlrName 64A
D saS36Proc 8A
D saFidelity 10A
D saRplUnprt 1A
D saRplChar 1A
D siPageLen 10I 0
D siPageWdth 10I 0
D siSepartrs 10I 0
D siOvrFlw 10I 0
D saDBCS 10A
D saDBCSExt 10A
D saDBCSSOSI 10A
D saDBCSRotn 10A
D saDBCSCPI 10I 0
D saGraphics 10A
D saCodePage 10A
D saFormDf 10A
D saFormDfLb 10A
D siDrawer 10I 0
D saFont 10A
D saS36SplId 6A
D siRotation 10I 0
D siJustify 10I 0
D saDuplex 10A
D saFoldRcds 10A
D saCtlChar 10A
D saAlign 10A
D saPrtQlty 10A
D saFormFeed 10A
D saVolumes 71A
D saLabels 17A
D saExchange 10A
D saCharCode 10A
D siTotRcds 10I 0
D siMultiUp 10I 0
D saFrontOvl 10A
D saFrtOvlLb 10A
D snFOOffDwn 15P 5
D snFOOffAcr 15P 5
D saBackOvl 10A
D saBckOvlLb 10A
D snBOOffDwn 15P 5
D snBOOffAcr 15P 5
D saUOM 10A
D saPagDfn 10A
D saPagDfnLb 10A
D saSpacing 10A
D snPointSiz 15P 5
D snFMOffDwn 15P 5
D snFMOffAcr 15P 5
D snBMOffDwn 15P 5
D snBMOffAcr 15P 5
D snPageLen 15P 5
D snPageWdth 15P 5
D saMethod 10A
D saAFP 1A
D saChrSet 10A
D saChrSetLb 10A
D saCdePagNm 10A
D saCdePgeLb 10A
D saCdeFnt 10A
D saCdeFntLb 10A
D saDBCSFnt 10A
D saDBCSFntL 10A
D saUserDef 10A
D saReduce 10A
D saReserv1 1A
D siOutBin 10I 0
D siCCSID 10I 0
D saUserText 100A
D saSystem 8A
D saOrigId 8A
D saCreator 10A
* Program parameter - bookmark option
D paBookmark S 7A
* Program parameter - bookmark *POS option parameters
D BMarkPos DS
D siPosCount 5I 0
D snPosLine 3P 0
D snPosChar 3P 0
D snPosLen 3P 0
* Program parameter - bookmark *KEY option parameters
D BMarkKey DS
D siKeyCount 5I 0
D siLen 5I 0
D saKeyStr 378A
D snKeyOccur 3P 0
D snKeyOff 3P 0
D snKeyLen 3P 0
* PDF 'object' array
D aiObject S 10I 0 DIM(32767)
* Start position of PDF options
D aaStart S 10A DIM(32767)
* Current object number
D wiObject S 10I 0
* Current count of bytes written
D wiChrCount S 10I 0
* Current page number
D wiPage S 10I 0
* Start position of text
D wiStart S 10I 0
* Bookmark text
D waBookmark S 378A
* Count of occurrences of the bookmark key
D wiOccurs S 5I 0
* Input spooled file data including control characters
D InputData DS
D saSkipLine 3A
D ssSkipLine 3S 0 OVERLAY(saSkipLine:1)
D saSpceLine 1A
D ssSpceLine 1S 0 OVERLAY(saSpceLine:1)
D saInput 378A
* Output PDF-format data
D OutputData DS
D saOutput 378A
* Procedure prototypes
D WritePDF PR
D iaOutput 378A CONST OPTIONS(*VARSIZE)
D AddEscape PR 378A
D iaInput 378A
D PDFHeader PR
D PDFPages PR
D PDFTrailer PR
D NewPage PR
D EndPage PR
D NumToText PR 10A
D iiNum 10I 0 CONST
D NewObject PR
* Program parameters
C *ENTRY PLIST
C PARM paTitle
C PARM SplInfo
C PARM paBookmark
C PARM BMarkPos
C PARM BMarkKey
* Output a PDF header
C CALLP PDFHeader
* Create PDF page 'objects'
C CALLP PDFPages
* Output a PDF trailer
C CALLP PDFTrailer
C RETURN
**********************************************************************
* Procedure to create a PDF 'header' *
**********************************************************************
P PDFHeader B
D PDFHeader PI
D liPage S 10I 0
D liPageObj S 10I 0
* Create catalog object
C CALLP WritePDF('%PDF-1.0')
C CALLP WritePDF('%忏嫌')
C CALLP NewObject
C CALLP WritePDF(%trim(NumToText(wiObject))+' 0 obj')
C CALLP WritePDF('<<')
C CALLP WritePDF('/Type /Catalog')
C CALLP WritePDF('/Pages 5 0 R')
C CALLP WritePDF('/Outlines 2 0 R')
C CALLP WritePDF('/PageMode /UseOutlines')
C CALLP WritePDF('>>')
C CALLP WritePDF('endobj')
* Create outlines object
C CALLP NewObject
C CALLP WritePDF(%trim(NumToText(wiObject))+' 0 obj')
C CALLP WritePDF('<<')
C CALLP WritePDF('/Type /Outlines')
C CALLP WritePDF('/Count '+%trim(NumToText(siPages)))
C CALLP WritePDF( '/First 9 0 R')
C
C CALLP WritePDF( '/Last '
C + %trim(NumToText((siPages*4)+5))
C + ' 0 R')
C CALLP WritePDF('>>')
C CALLP WritePDF('endobj')
* Create procedures object
C CALLP NewObject
C CALLP WritePDF(%trim(NumToText(wiObject))+' 0 obj')
C CALLP WritePDF('[/PDF /Text]')
C CALLP WritePDF('endobj')
* Create fonts object
C CALLP NewObject
C CALLP WritePDF(%trim(NumToText(wiObject))+' 0 obj')
C CALLP WritePDF('<<')
C CALLP WritePDF ('/Type /Font')
C CALLP WritePDF ('/Subtype /Type1')
C CALLP WritePDF ('/Name /F1')
C CALLP WritePDF ('/BaseFont /Courier')
C CALLP WritePDF ('/Encoding /WinAnsiEncoding')
C CALLP WritePDF ('>>')
C CALLP WritePDF ('endobj')
* Create pages object
C CALLP NewObject
C CALLP WritePDF(%trim(NumToText(wiObject))+' 0 obj')
C CALLP WritePDF ('<<')
C CALLP WritePDF ('/Type /Pages')
C CALLP WritePDF('/Count '+%trim(NumToText(siPages)))
* Write list of child pages
C EVAL liPage = wiObject + 1
C EVAL liPageObj = liPage
C CALLP WritePDF ( '/Kids ['
C + %trim(NumToText(liPage))
C + ' 0 R')
C DOW liPage < siPages + wiObject
C EVAL liPage = liPage + 1
C EVAL liPageObj = liPageObj + 4
C CALLP WritePDF ( ' '
C + %trim(NumToText(liPageObj))
C + ' 0 R')
C ENDDO
C CALLP WritePDF (' ]')
C CALLP WritePDF ('>>')
C CALLP WritePDF ('endobj')
P PDFHeader E
**********************************************************************
* Procedure to create PDF pages *
**********************************************************************
P PDFPages B
D liLine S 10I 0
D liLength S 5I 0
D liChar S 5I 0
D liX S 5I 0
D liY S 5I 0
* Create page object for first page
C EVAL wiPage = 0
C EVAL liX = 0
* Read spooled file data from input work file
C READ cvtwork02 InputData LR
C DOW *INLR = *OFF
* Skip to a line if specified, handling page throw if it occurs
C IF saSkipLine <> *BLANKS
C IF ssSkipLine < liLine or liLine = 0
C IF wiPage <> 0
C CALLP EndPage
C ENDIF
C CALLP NewPage
C EVAL liLine = ssSkipLine
C EVAL liY
C = (612/siPageLen) * (siPagelen-liLine)
C ELSE
C EVAL liY
C = -((612/siPageLen) * (ssSkipLine-liLine))
C EVAL liLine = ssSkipLine
C ENDIF
C ENDIF
* Space a number of lines if specified
C IF saSpceLine <> *BLANKS
C EVAL liLine = liLine + ssSpceLine
C EVAL liY
C = -((612/siPageLen) * ssSpceLine)
C ENDIF
* Set up bookmark if position option specified
C IF paBookmark = '*POS'
C IF liLine = snPosLine and waBookmark = *BLANKS
C EVAL waBookmark = %trim(%subst(saInput :
C snPosChar:
C snPosLen ))
C ENDIF
C ENDIF
* Set up bookmark if key option specified
C IF paBookmark = '*KEY'
C saKeyStr:siLenSCAN saInput:1 liChar
C IF liChar > 0
C EVAL wiOccurs = wiOccurs + 1
C IF wiOccurs = snKeyOccur
C EVAL liChar = liChar + snKeyOff
C EVAL liLength = snKeyLen
C IF liChar + liLength > siPageWdth
C EVAL liLength = siPageWdth - liChar
C ENDIF
C IF liChar < 1
C EVAL liChar = 1
C ENDIF
C IF liChar + liLength <= siPageWdth
C EVAL waBookmark = %trim(%subst(saInput :
C liChar :
C liLength ))
C ENDIF
C ENDIF
C ENDIF
C ENDIF
* Add escape character before special characters \, ( and )
C EVAL saInput = AddEscape(saInput)
* Output the line of text
C CALLP WritePDF( %trim(NumToText(liX))
C + ' '
C + %trim(NumToText(liY))
C + ' Td ('
C + %trimr(saInput)
C + ') Tj')
C READ cvtwork02 InputData LR
C ENDDO
C CALLP EndPage
P PDFPages E
**********************************************************************
* Procedure to create a PDF trailer *
**********************************************************************
P PDFTrailer B
D PDFTrailer PI
D laDateTime S 14A
D i S 10I 0
D liXRef S 10I 0
* Create information object
C CALLP NewObject
C CALLP WritePDF(%trim(NumToText(wiObject))+' 0 obj')
C CALLP WritePDF('<<')
C CALLP WritePDF( '/Creator ('
C + %trim(saPgmLib)
C + '/'
C + %trim(saPgmName)
C + ')' )
C IF %subst(saOpenDate:1:1) = '0'
C EVAL laDateTime = '19' + %subst(saOpenDate:2:6)
C + saOpenTime
C ELSE
C EVAL laDateTime = '20' + %subst(saOpenDate:2:6)
C + saOpenTime
C ENDIF
C CALLP WritePDF( '/CreationDate (D:'
C + laDateTime + ')')
C CALLP WritePDF('/Title (' + %trim(paTitle) + ')')
C CALLP WritePDF('/Producer (CVTSPLPDF)')
C CALLP WritePDF('/Keywords ()')
C CALLP WritePDF( '/Author ('
C + %trim(saJobNbr)
C + '/'
C + %trim(saUser)
C + '/'
C + %trim(saJobName)
C + ')' )
C CALLP WritePDF('>>')
C CALLP WritePDF('endobj')
* Create cross-reference
C EVAL liXref = wiChrCount - 1
C CALLP WritePDF('xref 0 '
C + %trim(NumToText(wiObject+1)) )
C CALLP WritePDF('0000000000 65535 f')
C DO wiObject i
C CALLP WritePDF(aaStart(i) + ' 00000 n')
C ENDDO
* Write trailer
C CALLP WritePDF('trailer')
C CALLP WritePDF('<<')
C CALLP WritePDF('/Size '
C + %trim(NumToText(wiObject+1)))
C CALLP WritePDF('/Root 1 0 R')
C CALLP WritePDF('/Info '
C + %trim(NumToText(wiObject))
C + ' 0 R')
C CALLP WritePDF('>>')
C CALLP WritePDF('startxref')
C CALLP WritePDF(%trim(NumToText(liXref)))
C CALLP WritePDF('%%EOF')
P PDFTrailer E
**********************************************************************
* Procedure to create a new PDF 'object' *
**********************************************************************
P NewObject B
D NewObject PI
D lsDataLen S 10S 0
D i S 10I 0
C EVAL wiObject = wiObject + 1
C EVAL i = wiObject
C EVAL lsDataLen = wiChrCount
C MOVE lsDataLen aaStart(i)
P NewObject E
**********************************************************************
* Procedure to output PDF data
**********************************************************************
P WritePDF B
D WritePDF PI
D iaOutput 378A CONST OPTIONS(*VARSIZE)
D liLength S 5I 0
* Update byte count with length of data to be written
C ' ' CHECKR iaOutput liLength
C EVAL wiChrCount= wiChrCount + liLength + 2
* Output data to work file
C EVAL saOutput = %trimr(iaOutput)
C WRITE cvtwork01 OutputData
P WritePDF E
**********************************************************************
* Procedure to convert a number to text *
**********************************************************************
P NumToText B
D NumToText PI 10A
D iiNum 10I 0 CONST
D laSign S 1A
D laInput S 10A
D laOutput S 10A
D liIn S 5I 0
D liOut S 5I 0
D liNum S 10I 0
* Set up sign if and make number positive if number is negative
C IF iiNum < 0
C EVAL laSign = '-'
C EVAL liNum = -iiNum
C ELSE
C EVAL laSign = ' '
C EVAL liNum = iiNum
C ENDIF
* Number number to work character variable
C MOVE liNum laInput
* Skip over leading zeros
C EVAL liIn = 1
C EVAL liOut = 1
C DOW liIn < %size(laInput)
C and %subst(laInput:liIn:1) = '0'
C EVAL liIn = liIn + 1
C ENDDO
* Move digits to output area
C DOW liIn <= %size(laInput)
C and liOut <= %size(laOutput)
C EVAL %subst(laOutput:liOut:1)
C = %subst(laInput :liIn :1)
C EVAL liIn = liIn + 1
C EVAL liOut = liOut + 1
C ENDDO
* Add sign
C IF laSign = '-'
C EVAL laOutput = laSign + laOutput
C ENDIF
* Return number in text format
C RETURN laOutput
P NumToText E
**********************************************************************
* Procedure to add an escape character before special characters *
**********************************************************************
P AddEscape B
D AddEscape PI 378A
D iaInput 378A
D laOutput S 378A
D laChar S 1A
D i S 5I 0
D o S 5I 0
D liLength S 5I 0
* Determine length of input data
C ' ' CHECKR iaInput liLength
* Work through input data and prefix special characters with escape
C EVAL i = 1
C EVAL o = 0
C DOW i <= liLength
C EVAL laChar = %subst(iaInput:i:1)
C IF laChar = '\' or laChar = '(' or laChar = ')'
C EVAL o = o + 1
C EVAL %subst(laOutput:o:1) = '\'
C ENDIF
C EVAL o = o + 1
C EVAL %subst(laOutput:o:1) = laChar
C EVAL i = i + 1
C ENDDO
C RETURN laOutput
P AddEscape E
**********************************************************************
* Procedure to create a new page object *
**********************************************************************
P NewPage B
D NewPage PI
* Create a page object
C EVAL wiPage = wiPage + 1
C CALLP NewObject
C CALLP WritePDF(%trim(NumToText(wiObject))+' 0 obj')
C CALLP WritePDF('<<')
C CALLP WritePDF('/Type /Page')
C CALLP WritePDF('/Parent 5 0 R')
C CALLP WritePDF( '/Resources << /Font <<'
C + ' /F1 4 0 R >>'
C + ' /ProcSet 3 0 R >>')
C CALLP WritePDF('/MediaBox [0 0 792 612]')
C CALLP WritePDF( '/Contents '
C + %trim(NumToText(wiObject+1))
C + ' 0 R')
C CALLP WritePDF('>>')
C CALLP WritePDF('endobj')
* Set up bookmark if *PAGNBR option specified
C IF paBookmark = '*PAGNBR'
C EVAL waBookmark = 'Page '
C + %trim(NumToText(wiPage))
C ELSE
C EVAL waBookmark = *BLANKS
C EVAL wiOccurs = 0
C ENDIF
* Create a stream object
C CALLP NewObject
C CALLP WritePDF(%trim(NumToText(wiObject))+' 0 obj')
C CALLP WritePDF( '<< /Length '
C + %trim(NumToText(wiObject+1))
C + ' 0 R >>')
C CALLP WritePDF('stream')
C EVAL wiStart = wiChrCount
C CALLP WritePDF('BT')
* Determine font size to use from Characters per inch setting
C SELECT
C WHEN siCPI = 50
C CALLP WritePDF('/F1 20 Tf')
C WHEN siCPI = 120
C CALLP WritePDF('/F1 9 Tf')
C WHEN siCPI = 150
C CALLP WritePDF('/F1 8 Tf')
C WHEN siCPI = 167
C CALLP WritePDF('/F1 6 Tf')
C OTHER
C CALLP WritePDF('/F1 10 Tf')
C ENDSL
P NewPage E
**********************************************************************
* Procedure to finish a page object *
**********************************************************************
P EndPage B
D EndPage PI
D liLength S 10I 0
* End text stream
C CALLP WritePDF('ET')
C EVAL liLength = wiChrCount- wiStart
C CALLP WritePDF('endstream')
C CALLP WritePDF('endobj')
* Create indirect length object for stream
C CALLP NewObject
C CALLP WritePDF(%trim(NumToText(wiObject))+' 0 obj')
C CALLP WritePDF(%trim(NumToText(liLength)))
C CALLP WritePDF('endobj')
* Create outline object
C EVAL waBookmark = AddEscape(waBookMark)
C CALLP NewObject
C CALLP WritePDF(%trim(NumToText(wiObject))+' 0 obj')
C CALLP WritePDF('<<')
C CALLP WritePDF('/Parent 2 0 R')
C CALLP WritePDF( '/Title ('
C + %trimr(waBookmark) + ')')
C IF wiPage > 1
C CALLP WritePDF( '/Prev '
C + %trim(NumToText(wiObject-4))
C + ' 0 R')
C ENDIF
C IF wiPage < siPages
C CALLP WritePDF( '/Next '
C + %trim(NumToText(wiObject+4))
C + ' 0 R')
C ENDIF
C CALLP WritePDF('/Dest ['
C + %trim(NumToText(wiObject-3))
C + ' 0 R /XYZ 0 792 0]')
C CALLP WritePDF('>>')
C CALLP WritePDF('endobj')
P EndPage E"

希望PDF之家-技术文章-PDF开发篇 -一个简单的PDF文件结构的分析

希望PDF之家-技术文章-PDF开发篇 -一个简单的PDF文件结构的分析: "一个简单的PDF文件结构的分析

发布日期:2006-4-14 作者:pdfMaker 出处:CSDN

Adobe的PDF参考告诉我们一个PDF文件可以通过下面4个方面来理解:
1. 对象, 一个PDF文档是由一个由基本数据类型组成的数据结构。
2. 文件(物理结构), 决定对象是如何存放在一个PDF文件中的, 它们是如何被访问的,如何被更新的。这个结构是独立于对象的语义的。
3. 文档结构, 说明一些基本的对象类型是如何来表现PDF文档的成分的:页,字体,批注,和另外一些内容。
4. 内容流.一个PDF文件内容流包含一系列的指令,描述页面的外观或其他图形实体的外观和文件内容。
但是当时对我来说要看懂这几行字是有很大的困难的,需要了解确切含义,必须看完后面的几十页上百页的内容并且要分析一下一个实际的PDF文件才能完全领会它的意思。
后来经过长时间的文档阅读,相关开发,并且具体地分析PDF文件后才把PDF文件的语法,文件的解析搞清楚。虽然说学习是痛并快乐着,但是对于当时我来说真的希望有一个人能够告诉我一个简单的例子,通过一个简单的例子来描述PDF的基本组成,它的解析原理和过程。因此下面我主要将以一个简单的例子来说明PDF的主要特性并给出一个简单的PDF文件的全景。
在继续阅读该文章前,我们先问自己下面的几个问题:
l 你了解至少一种文件格式吗?(例如HTML)
l 为什么要学习PDF的相关知识?
如果你对第一个问题的答案为“是”, 并且第二个问题你能给出一个非常明确的答案,那么这篇短文是适合你的。否则,如果对任何一种格式都不了解,建议先了解一下HTML,或XML,你可以从这两种语言里得到很多启发,对学习PDF的构成有很大的好处;如果你不清楚你要学习是为了什么,那么我就认为你学习没有目的性和动力,说不定你今天学了以后明天就忘得一干二净。
1.PDF格式和HTML,XML格式:
一个PDF文档从根本上来说是一个8字节序。其实PDF格式和我们已经熟知的HTML,XML等结构化的文件格式一样,包含有关键字,分隔符,数据等等。
不同的是PDF文件是按照二进制流的方式保存的,而html文件则是文本方式保存的。XML文件一般只包含数据本身,并没有把如何显示的信息放在其中,因此要显示一个XML文件还需要一个Schema文件才能显示,否则看到的将是所有的字节流;HTML包含了数据的同时也包含了一些关于如何显示的信息,但是HTML是基于文本存放的,是可读的,你打开一个HTML文件就能知道所有显示在浏览器里得文字。 另外就是HTML不能包含二进制流,它对图像文件的引用都是通过链接的,全部是外部文件的方式来实现的。
2.PDF规范的发展
PDF规范从1993年到现在,已经有过7个版本,六次版本升级,从最初的pdf1.0.6版本到现在的PDF1.6, 每次的版本升级都会加入一些新的特性,PDF参考说明书也是从最初的100多页到现在的1000多页,但是PDF文件格式的主要特性还是没有改变,可以这么理解,PDF1.6是PDF1.0的扩展集,学习了PDF1.0以后也能基本上理解PDF1.6的内容。 因此说我下面的例子是基于一个PDF1.0的最简单的一个PDF文件的分析。
PDF规范的发展升级:
1.1 1995 加入了文档加密(40字节),线索树,名字树,链接,设备独立色彩资源。
1.2 1996 表单, 半色调屏幕,和其他的一些高级色彩特性, 对中文,日文和韩文的支持
1.3 2000 数字签名, 逻辑结构, JavaScript, 嵌入式文件,Masked Images, 平滑阴影, 支持 CID字体的附加色彩。
1.4 2001 文件加密 (128 字节), 标签式 PDF, 访问控制,透明,元数据流
1.5 2003 文档加密 (公钥), JPEG 2000 压缩, 可选的内容组,附加的注解类型
1.6 2005 文档加密 (AES),增加最大文件支持,加入3D支持,额外的注解类型

3.PDF文件的基本组成:
一个PDF文件从大的方面来说分4个部分:
l 文件头,指明了该文件所遵从的PDF规范的版本号,它出现在PDF文件的第一行。
l 文件体,PDF文件的主要部分,由一系列对象组成。
l 交叉引用表,为了能对间接对象进行随机存取而设立的一个间接对象的地址索引表。
l 文件尾,声明了交叉引用表的地址,即指明了文件体的根对象(Catalog),从而能够找到PDF文件中各个对象体的位置,达到随机访问。另外还保存了PDF文件的加密等安全信息(以后详细讨论)。
如下图:

图1

4.PDF文档的逻辑结构
作为一种结构化的文件格式,一个PDF文档是由一些称为“对象”的模块组成的。并且每个对象都有数字标号,这样的话可以这些对象就可以北其他的对象所引用。这些对象不需要按照顺序出现在PDF文档里面,出现的顺序可以是任意的,比如一个PDF文件有3页,第3页可以出现在第一页以前,对象按照顺序出现唯一的好处就是能够增加文件的可读性,如果你不会用文本编辑器来阅读PDF结构,那么大可不必关心。正是因为页与页之间的不相关性,就可以对PDF文件的页码进行随机的访问。
文件尾(Trail),说明根对象的对象号,并且说明交叉引用表的位置,通过对交叉引用表的查询可以目录对象(Catalog)。这个目录对象是该PDF文档的根对象,包含PDF文档的大纲(outline)和页面组对象(pages)引用。大纲对象是指PDF文件的书签树;页面组对象(pages)包含该文件的页面数,各个页面对象(page)的对象号。
一个PDF文档有下图所示的层次关系:

图2

页面(page)对象作为PDF中最重要的对象,包含如何显示该页面的信息,例如使用的字体,包含的内容(文字,图片等),页面的大小。当然里面的子项也可以是其他对象的引用。页面中包含的信息是包含在一个称为流(stream)的对象里,这个流的长度(字节数)必须直接给出或指向另外一个对象。如下图:

图3

5. PDF的基本语法:
文件的第一行是文件头,指明了该文件所遵从的PDF规范的版本号,它出现在PDF文件的第一行。
一个对象的第一行一般有两个数字和关键字“obj”。例如:

3 0 obj
<<

/Type /Pages
/Count 1
/Kids [4 0 R]
>>

endobj

第一个数字称为对象号,来唯一标识一个对象的,第二个是产生号,是来表明它在被创建后的第几次修改,所有新创建的PDF文件的对象号应该都是0,即第一次被创建以后没有被修改过。上面的例子就说明该对象的对象号是3,而且创建后没有被修改过。
对象的内容应该是包含在<< 和>>之间的,最后以关键字endobj结束.

6. 文件Hello World的文件分析:
6.1.文件的具体分析
%PDF-1.0
文件头,说明符合PDF1.0规范

1 0 obj
<<

/Type /Catalog
/Pages 3 0 R
/Outlines 2 0 R
>>

endobj
Catalog对象(根对象)

2 0 obj
<<

/Type /Outlines
/Count 0
>>

endobj
outline对象(此处它的计数为0,说明没有书签)

3 0 obj
<<

/Type /Pages
/Count 1
/Kids [4 0 R]
>>

endobj
pages对象(页面组对象),/Type /Pages 说明自身的属性,对象的类型为页码,/Count 1说明页码数量为1,/Kids [4 0 R]说明页的对象为4, 这里要说明的是如果有多个页面,就多个页面直接连续下去,比如说/Kids [4 0 R 10 0 R], 就说明该PDF的第一页的对象号是4,第二页的对象号是10。

4 0 obj
<<

/Type /Page
/Parent 3 0 R
/Resources << /Font << /F1 7 0 R >> /ProcSet 6 0 R >>
/MediaBox [0 0 612 792]
/Contents 5 0 R
>>

endobj
页对象,/Parent 3 0 R说明其父对象的对象号为3,/Resources << /Font << /F1 7 0 R >> /ProcSet 6 0 R >>说明该页所要包含的资源,包括字体和内容的类型,/MediaBox [0 0 612 792]说明页面的显示大小(以象素为单位),/Contents 5 0 R说明页面内容对象的对象号为5。

5 0 obj
<< /Length 44 >>
stream
BT
/F1 24 Tf
100 100 Td (Hello World) Tj
ET
endstream
endobj

<< /Length 44 >>说明stream对象为字节数,从BT开始,ET结束,包括中间的行结束符。
Stream说明一个流对象的开始。
BT说明一个文字对象的开始。
/F1 24 Tf,Tf说明True font对象,字体明为F1, 大小为24个象素。
100 150 Td (Hello World) Tj,100 100 说明这一行文字放置的位置,对于Td, 我们可以这样理解,我们的当前X,Y坐标分别加上100和150就是文本的位置,因为在该例子中只有一个对象,那么它的位置就是(100,150), 如果下个对象位置信息为100, 50 Td, 那么它的位置应该就是(100+100, 150+50)也就是(200,200)。(Hello World) Tj说明文本的内容,当然,如果这里是文本的内容可以写成16进制,用<>包含。
ET说明文字对象的结束
endstream流对象的结束

6 0 obj
[/PDF /Text]
Endobj
[/PDF /Text]说明PDF的内容类型仅仅为文本,如果有图片则为[/PDF /Image]

7 0 obj
<<

/Type /Font
/Subtype /Type1
/Name /F1
/BaseFont /Helvetica
>>

endobj
Object six defines the
字体对象,不再多作解释。

所有的对象之后是下面的交叉引用表:
xref
0 8
0000000000 65535 f
0000000009 00000 n
0000000074 00000 n
0000000120 00000 n
0000000179 00000 n
0000000322 00000 n
0000000415 00000 n
0000000445 00000 n
xref说明一个交叉引用表的开始,交叉引用表的第一行0 8 说明下面各行所描述的对象号是从0开始,并且有8个对象。
0000000000 65535 f,一般每个PDF文件都是以这一行开始交叉应用表的,说明对象0的起始地址为0000000000,产生号(generation number)为65535,也是最大产生号,不可以再进行更改,而且最后对象的表示是f,表明该对象为free, 这里,大家可以看到,其实这个对象可以看作是文件头。
0000000009 00000 n就是表示对象1,也就是catalog对象了,0000000009是其偏移地址,00000为5位产生号(最大为65535),0表明该对象未被修改过, n表示该对象在使用,区别与自由对象,不可以更改。
下面的几行相信大家就可以告诉我含义了。

Trailer
<<

/Size 8
/Root 1 0 R
>>

startxref
553
%%EOF
trailer
说明文件尾trailer对象的开始。
/Size 8说明该PDF文件的对象数目。
/Root 1 0 R说明根对象的对象号为1。
Startxref
553说明交叉引用表的偏移地址,从而可以找到PDF文档中所有的对象的相对地址,进而访问对象。
%%EOF为文件结束标志。

6.2.PDF解析过程

图4

7.结束语:
到这里,我们对一个最简单的PDF文件的介绍就结束了,我想大家对PDF文件的格式和特定应该已经有所了解了。
当然,我这里介绍的是不完整的,完整的信息,请访问adobe的网站下载:
http://partners.adobe.com/public/developer/pdf/index_reference.html
下次介绍PDF的加密过程及原理。"

用C#实现生成PDF文档(原码):数据挖掘研究院( China Data Mining Research ,ChinaKDD)

用C#实现生成PDF文档(原码):数据挖掘研究院( China Data Mining Research ,ChinaKDD): "用C#实现生成PDF文档(原码)

//write by wenhui.org
using System;
using System.IO;
using System.Text;
using System.Collections;

namespace PDFGenerator
{

public class PDFGenerator
{
static float pageWidth = 594.0f;
static float pageDepth = 828.0f;
static float pageMargin = 30.0f;
static float fontSize = 20.0f;
static float leadSize = 10.0f;


static StreamWriter pPDF=new StreamWriter('E:\myPDF.pdf');

static MemoryStream mPDF= new MemoryStream();

static void ConvertToByteAndAddtoStream(string strMsg)
{
Byte[] buffer=null;
buffer=ASCIIEncoding.ASCII.GetBytes(strMsg);
mPDF.Write(buffer,0,buffer.Length);
buffer=null;
}

static string xRefFormatting(long xValue)
{
string strMsg =xValue.ToString();
int iLen=strMsg.Length;
if (iLen<10)
{
StringBuilder s=new StringBuilder();
int i=10-iLen;
s.Append(′0′,i);
strMsg=s.ToString() + strMsg;
} 同徽B2B电子商务研究中心
return strMsg;
}

static void Main(string[] args)
{
ArrayList xRefs=new ArrayList();
//Byte[] buffer=null;
float yPos =0f;
long streamStart=0;
long streamEnd=0;
long streamLen =0;
string strPDFMessage=null;
//PDF文档头信息
strPDFMessage='%PDF-1.1 ';
ConvertToByteAndAddtoStream(strPDFMessage);

xRefs.Add(mPDF.Length);
strPDFMessage='1 0 obj ';
ConvertToByteAndAddtoStream(strPDFMessage);
strPDFMessage='<< /Length 2 0 R >> ';
ConvertToByteAndAddtoStream(strPDFMessage);
strPDFMessage='stream ';
ConvertToByteAndAddtoStream(strPDFMessage);
////////PDF文档描述
streamStart=mPDF.Length;
//字体
strPDFMessage='BT /F0 ' + fontSize +' Tf ';
ConvertToByteAndAddtoStream(strPDFMessage);
//PDF文档实体高度
yPos = pageDepth - pageMargin;
strPDFMessage=pageMargin + ' ' + yPos +' Td ' ;
ConvertToByteAndAddtoStream(strPDFMessage);
strPDFMessage= leadSize+' TL ' ;

数据挖掘商道

ConvertToByteAndAddtoStream(strPDFMessage);

//实体内容
strPDFMessage= '(http://www.wenhui.org)Tj ' ;
ConvertToByteAndAddtoStream(strPDFMessage);
strPDFMessage= 'ET ';
ConvertToByteAndAddtoStream(strPDFMessage);
streamEnd=mPDF.Length;

streamLen=streamEnd-streamStart;
strPDFMessage= 'endstream endobj ';
ConvertToByteAndAddtoStream(strPDFMessage);
//PDF文档的版本信息
xRefs.Add(mPDF.Length);
strPDFMessage='2 0 obj '+ streamLen + ' endobj ';
ConvertToByteAndAddtoStream(strPDFMessage);

xRefs.Add(mPDF.Length);
strPDFMessage='3 0 obj <</Type/Page/Parent 4 0 R/Contents 1 0 R>> endobj ';
ConvertToByteAndAddtoStream(strPDFMessage);

xRefs.Add(mPDF.Length);
strPDFMessage='4 0 obj <</Type /Pages /Count 1 ';
ConvertToByteAndAddtoStream(strPDFMessage);
strPDFMessage='/Kids[ 3 0 R ] ';
ConvertToByteAndAddtoStream(strPDFMessage);
strPDFMessage='/Resources<</ProcSet[/PDF/Text]/Font<</F0 5 0 R>> >> '; 同徽B2B电子商务研究中心
ConvertToByteAndAddtoStream(strPDFMessage);
strPDFMessage='/MediaBox [ 0 0 '+ pageWidth + ' ' + pageDepth + ' ] >> endobj ';
ConvertToByteAndAddtoStream(strPDFMessage);

xRefs.Add(mPDF.Length);
strPDFMessage='5 0 obj <</Type/Font/Subtype/Type1/BaseFont/Courier/Encoding/WinAnsiEncoding>> endobj ';
ConvertToByteAndAddtoStream(strPDFMessage);

xRefs.Add(mPDF.Length);
strPDFMessage='6 0 obj <</Type/Catalog/Pages 4 0 R>> endobj ';
ConvertToByteAndAddtoStream(strPDFMessage);

streamStart=mPDF.Length;
strPDFMessage='xref 0 7 0000000000 65535 f ';
for(int i=0;i<xRefs.Count;i++)
{
strPDFMessage+=xRefFormatting((long) xRefs[i])+' 00000 n ';
}
ConvertToByteAndAddtoStream(strPDFMessage);
strPDFMessage='trailer << /Size '+ (xRefs.Count+1)+' /Root 6 0 R >> ';
ConvertToByteAndAddtoStream(strPDFMessage);

strPDFMessage='startxref ' + streamStart+' %%EOF ';
ConvertToByteAndAddtoStream(strPDFMessage);

同徽B2B电子商务研究中心

mPDF.WriteTo(pPDF.BaseStream);

mPDF.Close();
pPDF.Close();
}
}"

Friday, July 17, 2009

VC express 编译错误问题

如不用MFC 则所有project中都设置不使用MFC,而是标准windows库,删除头文件afx....h之流的东西,否则编译时会报错,查找相当不易。

Tuesday, June 16, 2009

donsull

http://www.donsull.com

Sunday, June 14, 2009

正则表达式学习参考 - 雁过无痕 - CSDN博客

正则表达式学习参考 - 雁过无痕 - CSDN博客: "原创 正则表达式学习参考 收藏

1 概述

正则表达式(Regular Expression)是一种匹配模式,描述的是一串文本的特征。

正如自然语言中“高大”、“坚固”等词语抽象出来描述事物特征一样,正则表达式就是字符的高度抽象,用来描述字符串的特征。

正则表达式(以下简称正则,Regex)通常不独立存在,各种编程语言和工具作为宿主语言提供对正则的支持,并根据自身语言的特点,进行一定的剪裁或扩展。

正则入门很容易,有限的语法规则很容易掌握,但是目前正则的普及率并不高,主要是因为正则的流派众多,各种宿主语言提供的文档都过多的关注于自身的一些细节,而这些细节通常是初学者并不需要关注的。

当然,如果想要深入的了解正则表达式,这些细节又是必须被关注的,这是后话,让我们先从正则的基础开始,进入正则表达式的世界。



2 正则表达式基础

2.1 基本概念

2.1.1 字符串组成





对于字符串“a5”,是由两个字符“a”、“5”以及三个位置组成的,这一点对于正则表达式的匹配原理理解很重要。2.2.2 占有字符和零宽度



正则表达式匹配过程中,如果子表达式匹配到的是字符内容,而非位置,并被保存到最终的匹配结果中,那么就认为这个子表达式是占有字符的;如果子表达式匹配的仅仅是位置,或者匹配的内容并不保存到最终的匹配结果中,那么就认为这个子表达式是零宽度的。

占有字符还是零宽度,是针对匹配的内容是否保存到最终的匹配结果中而言的。

占有字符是互斥的,零宽度是非互斥的。也就是一个字符,同一时间只能由一个子表达式匹配,而一个位置,却可以同时由多个零宽度的子表达式匹配。

2.1.3 正则表达式构成



正则表达式由两种字符构成。一种是在正则表达式中具体特殊意义的“元字符”,另一种是普通的“文本字符”。

元字符可以是一个字符,如“^”,也可以是一个字符序列,如“\w”。

2.2 元字符(Meta Character)



2.2.1 […] 字符组(Character Classes)

字符组可以匹配[ ]中包含的任意一个字符。虽然可以是任意一个,但只能是一个。

字符组支持由连字符“-”来表示一个范围。当“-”前后构成范围时,要求前面字符的码位小于后面字符的码位。

[^…] 排除型字符组。排除型字符组表示任意一个未列出的字符,同样只能是一个。排除型字符组同样支持由连字符“-”来表示一个范围。

表达式


说明

[abc]


表示“a”或“b”或“c”

[0-9]


表示0~9中任意一个数字,等价于[0123456789]

[\u4e00-\u9fa5]


表示任意一个汉字

[^a1<]


表示除“a”、“1”、“<”外的其它任意一个字符

[^a-z]


表示除小写字母外的任意一个字符

举例:

“[0-9][0-9]”在匹配“Windows 2003”时,匹配成功,匹配的结果为“20”。

“[^inW]”在匹配“Windows 2003”时,匹配成功,匹配的结果为“d”。

2.2.2 常见字符范围缩写



对于一些常用的字符范围,如数字等,由于非常常用,即使使用[0-9]这样的字符组仍显得麻烦,所以定义了一些元字符,来表示常见的字符范围。

表达式


说明

\d


任意一个数字,相当于[0-9],即0~9 中的任意一个

\w


任意一个字母或数字或下划线,相当于[a-zA-Z0-9_]

\s


任意空白字符,相当于[ \r\n\f\t\v]

\D


任意一个非数字字符,\d取反,相当于[^0-9]

\W


\w取反,相当于[^a-zA-Z0-9_]

\S


任意非空白字符,\s取反,相当于[^ \r\n\f\t\v]

举例:

“\w\s\d”在匹配“Windows 2003”时,匹配成功,匹配的结果为“s 2”。

2.2.3 . 小数点

小数点可以匹配除“\n”以外的任意一个字符。如果要匹配包括“\n”在内的所有字符,一般用[\s\S],或者是用“.”加(?s)匹配模式来实现。

表达式


说明

.


匹配除了换行符 \n 以外的任意一个字符

2.2.4 其它元字符

表达式


说明

^


匹配字符串开始的位置,不匹配任何字符

$


匹配字符串结束的位置,不匹配任何字符

\b


匹配单词边界,不匹配任何字符

举例:

“^a”在匹配“cba”时,匹配失败,因为表达式要求开始位置后面是字符“a”,而“cba”显然是不满足的。

“\d$”在匹配“123”时,匹配成功,匹配结果为“3”,这个表达式要求匹配结尾处的数字,如果结尾处不是数字,如“123abc”,则是匹配失败的。

2.2.5 转义字符

一些不可见字符,或是在正则中具有特殊意义的元字符,如想匹配字符本身,需要用“\”对其进行转义。

表达式


说明

\r,\n


回车和换行

\\


匹配“\”本身

\^,\$,\.


分别匹配“^”、“$”和“.”

以下字符在匹配其本身时,通常需要进行转义。在实际应用中,根据具体情况,需要转义的字符可能不止如下所列字符

 . $ ^ { [ ( | ) * + ? \

2.2.6 量词(Quantifier)

量词表示一个子表达式可以匹配的次数。量词可以用来修饰一个字符、字符组,或是用()括起来的子表达式。一些常用的量词被定义成独立的元字符。

表达式


说明


举例

{m}


表达式匹配m次


“\d{3}”相当于“\d\d\d ”

“(abc){2}”相当于“abcabc”

{m,n}


表达式匹配最少m次,最多n次


“\d{2,3}”可以匹配“12”或“321”等2到3位的数字

{m,}


表达式至少匹配m次


“[a-z]{8,}”表示至少8位以上的字母

?


表达式匹配0次或1次,相当于{0,1}


“ab?”可以匹配“a”或“ab”

*


表达式匹配0次或任意多次,相当于{0,}


“<[^>]*>”中“[^>]*”表示0个或任意多个不是“>”的字符

+


表达式匹配1次或意多次,至少1次,相当于{1,}


“\d\s+\d”表示两个数字中间,至少有一个以上的空白字符

注意:在不是动态生成的正则表达式中,不要出现“{1}”这样的量词,如“\w{1}”在结果上等价于“\w”,但是会降低匹配效率和可读性,属于画蛇添足的做法。

2.2.7 分支结构(Alternation)

当一个字符串的某一子串具有多种可能时,采用分支结构来匹配,“|”表示多个子表达式之间“或”的关系,“|”是以()限定范围的,如果在“|”的左右两侧没有()来限定范围,那么它的作用范围即为“|”左右两侧整体。

表达式


说明

|


多个子表达式之间取“或”的关系

举例:

“^aa|b$”在匹配“cccb”时,是可以匹配成功的,匹配的结果是“b”,因为这个表达式表示匹配“^aa”或“b$”,而“b$”在匹配“cccb ”时是可以匹配成功的。

“^(aa|b)$”在区配“cccb”时,是匹配失败的,因为这个表达式表示在“开始”和“结束”位置之间只能是“aa”或“b”,而“cccb”显然是不满足的。

3 正则表达式进阶

3.1 捕获组(Capture Group)

捕获组就是把正则表达式中子表达式匹配的内容,保存到内存中以数字编号或手动命名的组里,以供后面引用。

表达式


说明

(Expression)


普通捕获组,将子表达式Expression匹配的内容保存到以数字编号的组里

(?<name> Expression)


命名捕获组,将子表达式Expression匹配的内容保存到以name命名的组里

普通捕获组(在不产生歧义的情况下,简称捕获组)是以数字进行编号的,编号规则是以“(”从左到右出现的顺序,从1开始进行编号。通常情况下,编号为0的组表示整个表达式匹配的内容。

命名捕获组可以通过捕获组名,而不是序号对捕获内容进行引用,提供了更便捷的引用方式,不用关注捕获组的序号,也不用担心表达式部分变更会导致引用错误的捕获组。

3.2 非捕获组

一些表达式中,不得不使用( ),但又不需要保存( )中子表达式匹配的内容,这时可以用非捕获组来抵消使用( )带来的副作用。

表达式


说明

(?:Expression)


进行子表达式Expression的匹配,并将匹配内容保存到最终的整个表达式的区配结果中,但Expression匹配的内容不单独保存到一个组内

3.3 反向引用

捕获组匹配的内容,可以在正则表达式的外部程序中进行引用,也可以在表达式中进行引用,表达式中引用的方式就是反向引用。

反向引用通常用来查找重复的子串,或是限定某一子串成对出现。

表达式


说明

\1,\2


对序号为1和2的捕获组的反向引用

\k<name>


对命名为name的捕获组的反向引用

举例:

“(a|b)\1”在匹配“abaa”时,匹配成功,匹配到的结果是“aa”。“(a|b)”在尝试匹配时,虽然既可以匹配“a”,也可以匹配“b”,但是在进行反向引用时,对应()中匹配的内容已经是固定的了。

3.4 环视(Look Around)

环视只进行子表达式的匹配,匹配内容不计入最终的匹配结果,是零宽度的。

环视按照方向划分有顺序和逆序两种,按照是否匹配有肯定和否定两种,组合起来就有四种环视。环视相当于对所在位置加了一个附加条件。



表达式


说明

(?<=Expression)


逆序肯定环视,表示所在位置左侧能够匹配Expression

(?<!Expression)


逆序否定环视,表示所在位置左侧不能匹配Expression

(?=Expression)


顺序肯定环视,表示所在位置右侧能够匹配Expression

(?!Expression)


顺序否定环视,表示所在位置右侧不能匹配Expression

举例:

“(?<=Windows )\d+”在匹配“Windows 2003”时,匹配成功,匹配结果为“2003”。我们知道“\d+”表示匹配一个以上的数字,而“(?<=Windows )”相当于一个附加条件,表示所在位置左侧必须为“Windows ”,它所匹配的内容并不计入匹配结果。同样的正则在匹配“Office 2003”时,匹配失败,因为这里任意一串数字子串的左侧都不是“Windows ”。

“(?!1)\d+”在匹配“123”时,匹配成功,匹配的结果为“23”。“\d+”匹配一个以上数字,但是附加条件“(?!1)”要求所在位置右侧不能是“1”,所以匹配成功的位置是“2”前面的位置。



3.5 忽略优先和匹配优先

或者叫做正则表达式匹配的贪婪与非贪婪模式。

标准量词修饰的子表达式,在可匹配可不匹配的情况下,总会先尝试进行匹配,称这种方式为匹配优先,或者贪婪模式。此前介绍的一些量词,“{m}”、“{m,n}”、“{m,}”、“?”、“*”和“+”都是匹配优先的。

一些NFA正则引擎支持忽略优先量词,也就是在标准量词后加一个“?”,此时,在可匹配可不匹配的情况下,总会先忽略匹配,只有在由忽略优先量词修饰的子表达式,必须进行匹配才能使整个表达式匹配成功时,才会进行匹配,称这种方式为忽略优先,或者非贪婪模式。忽略优先量词包括“{m}?”、“{m,n}?”、“{m,}?”、“??”、“*?”和“+?”。

举例:

源字符串:<div>aaa</div><div>bbb</div>

正则表达式1:<div>.*</div> 匹配结果:<div>aaa</div><div>bbb</div>

正则表达式2:<div>.*?</div> 匹配结果:<div>aaa</div>

本文只是一个总纲,后面会针对每一个知识点的细节展开讨论,本文也会随时更新,欢迎大家提供建议和意见。"

开发人员一定要加入收藏夹的网站 - Lee的专栏 - CSDN博客

开发人员一定要加入收藏夹的网站 - Lee的专栏 - CSDN博客: "转载 开发人员一定要加入收藏夹的网站收藏

http://www.gotapi.com/
语言:英语
简介:HTML,CSS,XPATH,XSL,JAVASCRIPT等API的查询网站。
http://www.w3schools.com/
语言:英语
简介:W3C制定的标准诸如XML,HTML,XSL等等的在线学习教程。
http://www.xml.org.cn/
语言:中文
简介:可以说是XML的中国官方网吧。W3C标准的翻译组织与XML系列技术交流社区.
http://www.connectionstrings.com/
语言:英语
简介:这里几乎收集了所有的数据库连接字符(connectionstring)了。
http://www.itpub.net/
语言:中文
简介:我个人认为是国内最专业的综合性行业性技术类社区.
http://www.netvtm.com/
语言:中文
简介:内容多翻译于w3schools.com,少有原创。不过还是应该鼓励精品翻译。
http://www.regexlib.com
语言:英语
简介:正则表达式库。搜索正则表达式用。
http://www.rexv.org/
语言:英语
简介:用Ajax开发的在线正则表达式验证器.
http://www.koders.com/
语言:英语
简介:代码搜索引擎,可以搜索几十种语言的代码。
http://www.123aspx.com/Rotor/
语言:英语
简介:.Net Frameworks的源代码。
http://dotnet.aspx.cc/
语言:中文
简介:孟宪会的资料站,虽资料大多比较简单,却解决了开发中的大部分问题?!
http://www.dofactory.com/Patterns/Patterns.aspx
语言:英语
简介:23种设计模式的实现参考。特点是UML+精练的示例代码+简洁的解说风格。
http://www.open-open.com/
语言:中文
简介:Java开源大全,如果你用.NET,照着它的名字前加N找找应该都有吧 ?!:)
http://www.riacn.com/
语言:中文
简介:我认为是国内少有的RIA专业技术站于交流社区.
http://www.cnpaf.net/
语言:中文
简介:中国协议分析网,很全面的协议资料网。
http://www.pinvoke.net/
语言:英语
简介:通过.net调用win32等非受控API的资料大全。
http://bbs.51js.com/
语言:中文
简介:无忧脚本,专业的脚本技术社区。
http://www.c-sharpcorner.com/
语言:英语
简介:C# Corner,学习c#的好地方.
http://blog.csdn.net/group/experts/
语言:中文
简介:CSDN专家群,汇集CSDN专家的电子报.
http://www.codeproject.com/
语言:英语
简介:有很多可学习的示例代码,特点是丰富,深入浅出.
http://www.gotdotnet.com/
语言:英语
简介:微软开发维护的关于.net framework交流社区.
http://www.sourceforge.net/
语言:英语
简介:全球最大的开源软体站点
http://www.asp.net/QuickStart/
语言:英语
简介:Microsoft .NET Framework SDK QuickStart Tutorials
http://www.matrix.org.cn/
语言:中文
简介:与 Java 共舞,Java优秀的专业社区,文章质量很高.做.Net的朋友也可以从其借鉴很多知识.

【来自】 http://www.cnblogs.com/kwklover/archive/2006/04/12/372747.html"

几个免费下载原版图书的网站 - SAP BLOG--Jack Wu(关注SAP应用) - CSDN博客

几个免费下载原版图书的网站 - SAP BLOG--Jack Wu(关注SAP应用) - CSDN博客: "原创 几个免费下载原版图书的网站收藏

http://www.ebooksbay.org/

http://freebooksource.com/

http://www.yinbiao1.com/post/yinbiaorumen2.html

http://cdshopvn.net/home/

http://goodownload.net/cat/ebooks

http://www.centralddl.com/other/6570-readers-digest-english-in-20-minutes-a-day.html

http://totme.com/categories/ebooks/English_Pronunciation_in_Use_Elementary_Book_5_Audio_CDs_090113013310328420684756f.html

http://www.google.com/search?q=english+book+download+audio+rapidshare&hl=en&newwindow=1&start=200&sa=N

http://www.dast2vom.com/IELTS.htm

http://www.dast2vom.com/IELTS.htm

http://sadrefl.blogfa.com/8711.aspx

http://www.rapidshare2download.com/blogsection/E%11Books.html

http://www.arab-eng.org/vb/t124472.html"

Wednesday, June 10, 2009

XOOPS China - Open Source Web Application Platform :: 自由 开源 共享

XOOPS China - Open Source Web Application Platform :: 自由 开源 共享

SourceForge.net: XOOPS Web Application Platform

SourceForge.net: XOOPS Web Application Platform

MovableType.org - Home of the MT Community

MovableType.org - Home of the MT Community

Facebook | Quantitative finance tool for everybody

Facebook | Quantitative finance tool for everybody: "online soon

the ultimative finance tool for everybody

Systematic equity trading

Issue of the traditional stock analysis

- With the flood of financial information it has become for the investor impossible to accurately filter and interpret all performance-relevant information.

- Analysis are mostly realized ad-hoc and therefore neglect ex-post performance-relevant information

- Decision making processes are often based by emotions. This affects adversely the performance.

The majority of the financial industry applies the traditional stock analysis. Because clients have not demanded higher added value so far, hardly any financial institution goes unconventional and progressive ways. But, this would be exactly necessary for delivering clients a high added value as possible.


The solution for investors

The prerequisite for archieving higher added value are disciplined processed of decision making,which analyse systematcally over the entire time-axis all performance-relevant factors of the financial markets and provide unambiguous trading instructions. This methodical approach avoids adverse emotional patterns and generates above average returns even in turbulent market conditions.

Furthermore, it enables a consistent and broad coverage of financial markets through which opportunities can be used on a global basis in an effective and efficient way.

All this is accomplished by combining comprehensive financial knowledge with most modern IT, which based on objective data and information delivers systematic evaluations.

Product description

Our tools increase your effectiveness

The product consists of two sophisticated investment tools:

- Equity Selector – for the selection of the most promising stocks
- Asset-class Selector – for the tactical asset allocation between stocks and bonds

Added value for you

- Dynamic testing the performance of Key Performance Indicators (KPI) and KPI-combinations

- Sustainable outperformance over market indices and over customized benchmark-portfolios

- Minimization of potential losses by KPI-diversification

- Protection against irrational investment process based on systematic data evaluation using most modern IT

- Transparent and understandable investment processes"

Saturday, February 14, 2009

Elgg 配置

Download Elgg from http://elgg.org

Unzip elgg1.2.zip to temp folder ;
>Cd ~
>unzip elgg1.2.zip
>cp -r elgg1.2 /var/www
>cd /var/www
>mv elgg1.2 elgg //rename folder name

Sudo chmod -R 777 elgg

Config Apache2 server, enable mod_write and .htaccess, like this:

Sudo vi /etc/apache2/sites-available/default

Add content below:


    AllowOverride All


Then enable Apache2 mod_write function:

>Sudo a2enmod rewrite

To disable this module it's just:
>sudo a2dismod rewrite

Then edit php.ini:

>sudo vi /etc/php5/apache2/php.ini
Add:
sendmail_path = /usr/sbin/sendmail -i -t


Then config mysql:

Mysql -u root -pxxxxxx
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY 'something' WITH GRANT OPTION;
Mqsql>FLUSH PREVILEGES;
Mqsql>Create database elgg
Mqsql>Quit

Then restart mysql server:

Sudo /etc/init.d/mysql restart

http://xxx.xxx.xxx.xxx/elgg/

Done!

Friday, February 13, 2009

Test Ez Publish 4.0.2

2009/2/13,In my ubutun server in VMware, I test install Ez publish 4.0.2 CMS system.
Download Ez Publish from http://ez.no, copy file to share directory, so my vmware ubutun can see the file.
config mysql database
mysql -u root -pmypassword //replace real passwd to mypassword, no space after'-p'.
Create new database:
CREATE DATABASE ezpublish CHARACTER SET utf8;

GRANT ALL ON ezpublish.* TO ezpublish@localhost IDENTIFIED BY 'ezpublishsqlpassword';
FLUSH PRIVILEGES;


Then I uncompress eZ Publish:
cd ~/share
tar zxvf ezpublish-4.0.0-gpl.tar.gz -C /var/www

This creates the directory ezpublish-4.0.0 in /var/www which I rename to ezpublish:
mv /var/www/ezpublish-4.0.0 /var/www/ezpublish
Then we should change 'Php.ini' , change 'mem_limits=16M' to 'mem_limits=64M', because Ez publish need 64M memory in PHP:
cd /etc/php5/apache2/
sudo vi php.ini

Then we need restart apache server:
/etc/init.d/apache2 restart
Next we need to install "imageMagick":
sudo apt-get install imagemagick
Next we set proper access permision:
cd /var/www/
sudo chmode -R a+rwx ezpublish

Now, we can visit "http://192.xxx.xxx.xxx/ezpublish/index.php" to continue install ezpublish. It really work.

Install Samba in Ubuntu

In my ubuntun server in VMWare, I test samba which I use to tranfer file between host XP system with VMware ubuntun server.
First, backup the original config file: /etc/samba/smb.conf like this:
> cd /etc/samba
> sudo cp smb.conf smb.conf.old
> sudo cp smb.conf smb.conf.master
> sudo vi smb.conf.master
Only Add a new share directory [share], don't change other contents.
Create a new subdirectory in your home directory, my home directory is /home/wjh,
I create a subdirectory 'share' under '/home/wjh', and change the access permit:
>cd /home/wjh
>mkdir share
>chmod 666

Edit '/etc/samba/smb.conf.master, add content below:
[share]
read only = no
locking = no
path = /home/wjh/share
guest ok = yes
browseable = yes

run ' testparm -s smb.conf.master >smb.conf '
restart samba server: /etc/init.d/samba restart

In the XP, you can search host, in address bar "//192.xxx.xxx.xxx/share", then you can visist sambar share directory

Saturday, January 17, 2009

[转载]VIM的剪贴板小技巧收藏

VIM是Linux下功能非常强大的一款字符处理软件,功能如何,在这里就不再做过多的评述了。很多朋友在使用VIM的时候,可能都会遇到一个非常简单,但是又很奇怪的问题,就是关于VIM的剪切板。

  我们先做这样一个小小的尝试,请打开浏览器,从网页上随便复制一段文字,然后打开VIM,用“p”粘贴一下,你会发现,什么都没有站贴过来,呵呵……原因是这样的,不同于Windows,VIM具有多个剪贴板,并且和系统剪贴板是完全独立的,所以当你复制浏览器里的文字的时候,这段文字保存在了系统剪贴板,当你是用“p”来粘贴的时候,实际上,他读取的是VIM的剪切板。

  那怎么方便的将系统剪贴板的内容复制过来呢?简单!用另外一个快捷方式“Shift+Insert”就可以了,如果你在使用Gvim的话,直接用鼠标中键也可起到相同的作用。是不是很简单?

  好了!现在您已经学习到了VIM剪贴板技巧的基础!OK!我们开始进阶!

  我们前面说过,VIM具有多个剪切板,目的是为了用户在做较复杂的字符处理的时候,可以更方便的复制粘贴。请现在使用一下“:reg”命令(先按ESC 键,退出编辑模式,然后按:进入命令模式,然后输入reg回车),看到了?屏幕上的输出结果!是不是特别眼熟,对了!就是您之前复制过的所有内容!也许这时候您还发现,VIM的剪切板原来有这么多个,按照数字还有符号一个一个的区分开的,这里举一个编号的例子——"5,看到了吗?是以"开头的。还有!有没有看到编号为"+的剪切板?里面的内容是不是刚才你在浏览器里复制的那段文字啊?呵呵……没错了!系统剪切板的编号就是"+。

  好了,这时候您已经知道了如何查看之前的所有剪贴板内容,我们现在就试着把某一个特定剪切板的内容复制进我们正在编辑的文件中。我们知道,vi的粘贴指令是 “p”,但是如果要粘贴一个特定的剪贴板,只是用p就不行了,那怎么办?简单!把剪贴板的编号带上不就可以了?现在先按ESC,退出编辑模式,然后一词按 "+p这三个字符(怎么按?不会吧!"和+怎么按?用Shift啊!),好了!你看看,之前在浏览器中复制的这段文本,是不是被粘贴进文档中了?

  如何将系统剪切板里的内容复制进VIM当中,您已经清楚了。那如何将ViM中复制的字符粘贴到其他地方呢?很简单,我们只需要把要复制的文字,复制进" +剪切板不就可以了?("+剪切板是系统剪切板,忘记了?)在VIM中,复制的指令是y(在非编辑模式下按y就可以了),那要将文本复制进指定的剪切板,和粘贴指定剪切板内容的方法一样,只需要加上剪切板的编号就可以了。举个例子,我们希望把VIM中的一段文本复制下来,然后粘贴到浏览器的地址栏中:第一步,现把需要复制的文字选中(非编辑模式下),然后在键盘上依次按"+y这三个字符,OK!已经复制下来了,现在用:reg命令看看,是不是在"+剪切板中了?

转自:http://blog.csdn.net/leibniz_zsu/archive/2007/08/02/1721984.aspx