package com.komponenty
{
import mx.resources.ResourceBundle;
import mx.resources.ResourceManager;
import mx.validators.ValidationResult;
import mx.validators.Validator;
public class KodPocztowyValidator extends Validator
{
loadResources();
[ResourceBundle("validators")]
private static var packageResources:ResourceBundle;
private static var resourceWrongFormatError:String;
private static var resourceInvalidCharError:String;
private static var resourceWrongLengthError:String;
//--------------------------------------------------------------------------
//
// Class methods
//
//--------------------------------------------------------------------------
/**
* @private
* Loads resources for this class.
*/
private static function loadResources():void
{
//ResourceManager.getInstance().localeChain = ["pl_PL"];
resourceInvalidCharError = ResourceManager.getInstance().getString("validators","InvalidCharError");
resourceWrongLengthError = ResourceManager.getInstance().getString("validators","wrongLengthError");
resourceWrongFormatError = ResourceManager.getInstance().getString("validators","wrongFormatError");
}
public static function validateKodPocztowy(validator:KodPocztowyValidator,
value:Object,
baseField:String):Array
{
var results:Array = [];
var zip:String = String(value);
var len:int = zip.length;
var n:int;
var i:int;
// Sprawdz czy jest ciąg znakow zawiera prawidłowy format
for (i = 0; i < len; i++)
{
if (DECIMAL_DIGITS.indexOf(zip.charAt(i)) == -1 && zip.charAt(i) != "-")
{
results.push(new ValidationResult(
true, baseField, "resourceInvalidCharError",
validator.invalidCharError));
return results;
}
}
//Sprawdz czy format jest prawidlowy
if (len == 6)
{
if ((DECIMAL_DIGITS.indexOf(zip.charAt(0)) == -1)||
(DECIMAL_DIGITS.indexOf(zip.charAt(1)) == -1)||
(zip.charAt(2)!="-")||
(DECIMAL_DIGITS.indexOf(zip.charAt(3)) == -1)||
(DECIMAL_DIGITS.indexOf(zip.charAt(4)) == -1)||
(DECIMAL_DIGITS.indexOf(zip.charAt(5)) == -1)
)
{
results.push(new ValidationResult(
true, baseField, "wrongFormatError",
validator.invalidFormatError));
return results;
}
}
else
{
results.push(new ValidationResult(
true, baseField, "wrongLength",
validator.wrongLengthError));
return results;
}
return results;
}
public function KodPocztowyValidator()
{
super();
bundleChanged();
}
//--------------------------------------------------------------------------
//
// Properties: Errors
//
//--------------------------------------------------------------------------
[Inspectable(category="Errors", defaultValue="Nieprawidłowe znaku w kodzie pocztowym")]
public var invalidCharError:String;
[Inspectable(category="Errors", defaultValue="Kod pocztowy musi być 6 znakowy w formacie 99-999")]
public var invalidFormatError:String;
[Inspectable(category="Errors", defaultValue="Zbyt duża ilość znaków w kodzie pocztowy")]
public var wrongLengthError:String;
//--------------------------------------------------------------------------
//
// Overridden methods
//
//--------------------------------------------------------------------------
override protected function doValidation(value:Object):Array
{
var results:Array = super.doValidation(value);
// Return if there are errors
// or if the required property is set to false and length is 0.
var val:String = value ? String(value) : "";
if (results.length > 0 || ((val.length == 0) && !required))
return results;
else
return KodPocztowyValidator.validateKodPocztowy(this, value, null);
}
//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------
/**
* @private
* Populates localizable properties from the loaded bundle for this class.
*/
private function bundleChanged():void
{
invalidCharError = resourceInvalidCharError;
wrongLengthError = resourceWrongLengthError;
invalidFormatError = resourceWrongFormatError;
}
}
}
Programowanie c++/c#/delphi/javas/php/installscript/nativescript
Przykłady - przydatne funkcje
wtorek, 27 kwietnia 2010
Flex - Walidator kodu pocztowego z pola tekstowego
Klasa Walidatora oparty na standardowym walidatorze - wykorzystująca lokalne źródła komunikatów
Etykiety:
Flex-walidatory
Komponent TextInput - kod pocztowy
Komponent TextInputKod - służy do wprowadzania polskiego kodu pocztowego, oparty o standardowy komponent TextInput. Walidacja wprowadzonego kodu odbywa się przez odrębny walidator KodPocztowyValidator - dostępny w innym artykule
package com.komponenty
{
import mx.controls.TextInput;
import mx.events.ValidationResultEvent;
import com.komponenty.KodPocztowyValidator;
import flash.events.Event;
import mx.validators.ValidationResult;
public class TextInputKod extends TextInput
{
private var kodPocztowyValidator:KodPocztowyValidator = new KodPocztowyValidator();
private var validator:ValidationResultEvent;
public function TextInputKod()
{
super();
this.maxChars=6;
this.restrict="0-9\\-";
this.kodPocztowyValidator.source = this;
this.kodPocztowyValidator.property = "text";
this.addEventListener("enter", this.validate);
}
private function validate(event:Event):void
{
validator = kodPocztowyValidator.validate();
if (validator.type == ValidationResultEvent.VALID)
{
this.errorString = "";
} else {
this.errorString = validator.message;
}
}
}
}
Etykiety:
Flex-komponenty
Prosty komponent TextInputEmail
Komponent do wprowadzania adresu email z walidacją stworzony na podstawie standardowego komponentu TextInput z przypisaniem polskich komunikatów.
package - paczka z komponentem
package - paczka z komponentem
package com.komponenty
{
import mx.controls.TextInput;
import flash.events.Event;
import mx.validators.EmailValidator;
import mx.validators.ValidationResult;
import mx.events.ValidationResultEvent;
public class TextInputEmail extends TextInput
{
private var emailValidator:EmailValidator = new EmailValidator();
private var validator:ValidationResultEvent;
public function TextInputEmail()
{
super();
this.emailValidator.source = this;
this.emailValidator.property = "text";
this.emailValidator.requiredFieldError = "To pole jest wymagane";
this.emailValidator.invalidCharError = "Nie dozwolone znaki w adresie email";
this.emailValidator.invalidDomainError = "Nieprawidłowa nazwa domeny";
this.emailValidator.invalidIPDomainError = "Niepoprawny adres IP domeny";
this.emailValidator.invalidPeriodsInDomainError = "Niedozowolona ilość kropek w nazwie domeny";
this.emailValidator.missingPeriodInDomainError="Brak kropki w nazwie domeny";
this.emailValidator.missingUsernameError="Brak nazwy użytkownika domeny";
this.emailValidator.missingAtSignError="Brak znaku @ w adresie";
this.emailValidator.tooManyAtSignsError="Za dużo znaków @ w adresie";
this.addEventListener("enter", this.validate);
}
private function validate(event:Event):void
{
validator = emailValidator.validate();
if (validator.type == ValidationResultEvent.VALID)
{
this.errorString = "";
} else {
this.errorString = validator.message;
}
}
}
}
Etykiety:
Flex-komponenty
środa, 21 kwietnia 2010
Detekcja zainstalowanego serwera Apache
Funkcja zwraca sciężkę instalacji, nazwę pliku serwisu, nazwę serwisu, wersję Apache
function BOOL DetectApacheServer(svPath, svFile, svService, svVer, bLog)
#define UKEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
#define UKEY20 "SOFTWARE\\Apache Group\\Apache"
#define UKEY22 "SOFTWARE\\Apache Software Foundation\\Apache"
BOOL bResult, bFind1, bFind2;
string RegPath,sKey,sFolder,sValue,sData,svVersionNumber,Path;
number nType,nSize,nReturn;
LIST listSubKeys;
int i;
begin
bResult = FALSE;
bFind1 = FALSE;
bFind2 = FALSE;
//Sprawdzenie w rejestrach do wersji Apache 2.0
if (bLog) then WriteLog(0,"* Sprawdzenie zainstalowanego serwera Apache 2.x"); endif;
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
if ( (RegDBKeyExist(UKEY20)==1)||(RegDBKeyExist(UKEY22)==1) ) then //Znaleziono w rejestrach
listSubKeys = ListCreate(STRINGLIST);
bFind1 = FALSE;
if (RegDBKeyExist(UKEY20)==1) then
nReturn = RegDBQueryKey(UKEY20, REGDB_KEYS, listSubKeys );
if (nReturn=0) then
if (ListCount(listSubKeys)>0) then
ListSetIndex(listSubKeys,LISTFIRST);
for i=0 to ListCount(listSubKeys)-1
ListCurrentString ( listSubKeys, sKey );
RegPath=UKEY20+"\\"+sKey;
svVer = sKey;
if (RegDBKeyExist(RegPath)==1) then
sValue="ServerRoot";
sKey = RegPath;
if (RegDBGetKeyValueEx( sKey, sValue, nType, sData, nSize )==0) then
svPath = sData;
bFind1 = TRUE;
endif; //ServerRoot;
endif; //Klucz rejestru
ListSetIndex ( listSubKeys, LISTNEXT );
endfor;
endif;
endif;
if ((bFind1)&&(Is(PATH_EXISTS,svPath))) then
if (bLog) then
WriteLog(1,"Znaleziono zainstalowany serwer Apache w wersji:"+svVer);
WriteLog(1,"- katalog serwera:\""+svPath+"\"");
endif;
else
bFind1 = FALSE;
endif;
endif; //UKEY20;
if (RegDBKeyExist(UKEY22)==1) then
ListDestroy( listSubKeys);
listSubKeys = ListCreate(STRINGLIST);
bFind2 = FALSE;
nReturn = RegDBQueryKey(UKEY22, REGDB_KEYS, listSubKeys );
if (nReturn=0) then
if (ListCount(listSubKeys)>0) then
ListSetIndex(listSubKeys,LISTFIRST);
for i=0 to ListCount(listSubKeys)-1
ListCurrentString ( listSubKeys, sKey );
RegPath=UKEY22+"\\"+sKey;
svVer = sKey;
if (RegDBKeyExist(RegPath)==1) then
sValue="ServerRoot";
sKey = RegPath;
if (RegDBGetKeyValueEx( sKey, sValue, nType, sData, nSize )==0) then
svPath = sData;
bFind2 = TRUE;
endif; //ServerRoot;
endif; //Klucz rejestru
ListSetIndex ( listSubKeys, LISTNEXT );
endfor;
endif;
endif;
if ((bFind2)&&(Is(PATH_EXISTS,svPath))) then
if (bLog) then
WriteLog(1,"Znaleziono zainstalowany serwer Apache w wersji:"+svVer);
WriteLog(1,"- katalog serwera:\""+svPath+"\"");
endif;
else
bFind2 = FALSE;
endif;
endif; //UKEY22;
endif;
//---------- Koniec sprawadzania po rejestrach windows
//***** Sprawdzenie po katalogach
if (! (bFind1 || bFind2)) then
if (Is(FILE_EXISTS, PROGRAMFILES^"Apache Group\\Apache2\\bin\\Apache.exe")) then
svPath = PROGRAMFILES^"Apache Group\\Apache2";
VerGetFileVersion(PROGRAMFILES^"Apache Group\\Apache2\\bin\\Apache.exe",svVer);
svFile = "Apache.exe";
svService = "Apache2";
if (bLog) then
WriteLog(1,"Znaleziono zainstalowany serwer Apache w wersji:"+svVer);
WriteLog(1,"- katalog serwera:\""+svPath+"\"");
endif;
bFind1 = TRUE;
endif;
if (Is(FILE_EXISTS, PROGRAMFILES^"Apache Software Foundation\\Apache2.2\\bin\\httpd.exe")) then
svPath = PROGRAMFILES^"Apache Software Foundation\\Apache2.2";
VerGetFileVersion(PROGRAMFILES^"Apache Software Foundation\\Apache2.2\\bin\\httpd.exe",svVer);
svFile = "httpd.exe";
svService = "Apache2.2";
if (bLog) then
WriteLog(1,"Znaleziono zainstalowany serwer Apache w wersji:"+svVer);
WriteLog(1,"- katalog serwera:\""+svPath+"\"");
endif;
bFind2 = TRUE;
endif;
if (Is(FILE_EXISTS, PROGRAMFILES^"Apache Software Foundation\\Apache2\\bin\\httpd.exe")) then
svPath = PROGRAMFILES^"Apache Software Foundation\\Apache2";
VerGetFileVersion(PROGRAMFILES^"Apache Software Foundation\\Apache2\\bin\\httpd.exe",svVer);
svFile = "httpd.exe";
svService = "Apache2";
if (bLog) then
WriteLog(1,"Znaleziono zainstalowany serwer Apache w wersji:"+svVer);
WriteLog(1,"- katalog serwera:\""+svPath+"\"");
endif;
bFind2 = TRUE;
endif;
endif;
if (bFind1)||(bFind2) then
bResult = TRUE;
else
if (bLog) then WriteLog(1," - brak zainstalowanego serwera Apache"); endif;
endif;
return bResult;
end;
Etykiety:
InstallShield - Apache Serwer
Detekcja zainstalowanego modułu PHP w systemie
Funkcja zwraca TRUE/FALSE i scieżkę instalacji modułu PHP w przypadku wykrycia
function BOOL DetectPHP(svPath, svVer, bLog)
BOOL bResult;
string RegPath,sKey,sFolder,sValue,sData,svVersionNumber,Path;
number nType, nSize;
begin
bResult = FALSE;
if (bLog) then WriteLog(0,"* Detekcja zainstalowanego PHP ..."); endif;
//Sprawdzenie w rejestrach
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
RegPath="SOFTWARE\\PHP";
if (RegDBKeyExist(RegPath)=1) then
sValue="InstallDir";
sKey = RegPath;
if (RegDBGetKeyValueEx( sKey, sValue, nType, sData, nSize )=0) then
StrRemoveLastSlash( sData );
if (Is(PATH_EXISTS, sData)) then
if (Is(FILE_EXISTS, sData ^ "php.exe")) then
svPath = sData;
if (VerGetFileVersion(svPath ^"php.exe", svVersionNumber)=0) then
svVer = svVersionNumber;
bResult = TRUE;
endif;
endif;
endif;
endif;
endif;
//Nie wykrytow w rejestrach - sprawdznie na dysku
if(!bResult) then
if (Is(PATH_EXISTS, PROGRAMFILES ^ "PHP")) then
if (Is(FILE_EXISTS, PROGRAMFILES ^ "PHP" ^ "php.exe")) then
svPath = PROGRAMFILES ^ "PHP";
if (VerGetFileVersion(svPath ^"php.exe", svVersionNumber)=0) then
svVer = svVersionNumber;
bResult = TRUE;
endif;
endif;
else
if (Is(PATH_EXISTS, "c:\\PHP")) then
if (Is(FILE_EXISTS, "c:\\PHP" ^ "php.exe")) then
svPath = "c:\\PHP";
if (VerGetFileVersion(svPath ^"php.exe", svVersionNumber)=0) then
svVer = svVersionNumber;
bResult = TRUE;
endif;
endif;
endif;
endif;
endif;
if (bResult) then
if (bLog) then
WriteLog(1,"- Zainstalowany moduł PHP w wersji "+svVersionNumber);
WriteLog(2,"w katalogu :"+svPath);
endif;
else
if (bLog) then
WriteLog(1,"- nie wykryto zainstalowanego modułu PHP");
endif;
endif;
return bResult;
end;
Etykiety:
InstallShield - funkcje
Detekcja zainstalowanego środowiska Java
Prosta funkcja działająca na rejestrach, porównująca zainstalowaną wersją z podaną w parametrze "sNumber"
function BOOL DetectJava(sNumber, bLog)
string RegPath,sVersion,sVer;
number nSize,nType,nResult;
BOOL bResult;
begin
bResult = FALSE;
if (bLog) then WriteLog(0,"* Sprawdzam zainstalowne środowsko Java"); endif;
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
RegPath="SOFTWARE\\JavaSoft\\Java Runtime Environment";
if (RegDBKeyExist(RegPath)=1) then
nType = REGDB_STRING;
nSize = 255;
if (RegDBGetKeyValueEx(RegPath,"CurrentVersion",nType,sVersion,nSize)=0) then
if (bLog) then WriteLog(1,"- znaleziono środowisko java w wersji "+sVersion); endif;
if StrCompare(sVersion,sNumber)>=0 then bResult = TRUE; endif;
else
if (bLog) then WriteLog(1,"- nieznaleziono środowisko java "); endif;
endif;
else
if (bLog) then WriteLog(1,"- nieznaleziono środowisko java "); endif;
endif;
return bResult;
end;
Etykiety:
InstallShield - funkcje
wtorek, 20 kwietnia 2010
Detekcja statusu serwisu serwera Apache
Funkcja zwraca 1,2 lub -1 w przypadku braku zainstalowanego serwisu, gdzie szService - to nazwa Serwisu, bRun - sprawdzanie czy uruchomiony czy zatrzymany. Funkcję można zastosować do innych serwisów
function INT DetectApacheService(szService, bRun, bLog)
INT nResult;
number nvState;
begin
nResult = 0;
if ServiceExistsService(szService) then
ServiceGetServiceState(szService, nvState);
if (nvState = SERVICE_RUNNING) then
if (bRun) then nResult = 1; endif;
if (bLog) then WriteLog(1,"- usługa \""+szService+"\" jest uruchomiona"); endif;
endif;
if (nvState = SERVICE_STOPPED) then
if (!bRun) then nResult = 1; endif;
if (bLog) then WriteLog(2,"- usługa \""+szService+"\" jest zatrzymana"); endif;
endif;
else //Brak serwisu
nResult = -1;
if (bLog) then WriteLog(1," - brak zainstalowanego serwisu \""+szService+"\" w systemie"); endif;
endif;
return nResult;
end;
Etykiety:
InstallShield - Apache Serwer
Detekcja monitora serwera Apache
Prosta funkcja detekcji uruchomionego Monitora serwera Apache
function BOOL DetectApacheMonitor( bLog )
BOOL bResult;
begin
bResult = FALSE;
if (ProcessRunning("ApacheMonitor.exe") || ProcessRunning("ApacheMonitor")) then
bResult = TRUE;
endif;
if (bResult) then
if (bLog) then WriteLog(1,"- Apache Service Monitor uruchomiony"); endif;
else
if (bLog) then WriteLog(1,"- Apache Service Monitor uruchomiony"); endif;
endif;
return bResult;
end;
Etykiety:
InstallShield - Apache Serwer
Funkcja detekcji przeglądarki Adobe Reader
Funkcja sprawdza czy w systemie zainstalowana jest przeglądarka plików pdf - Adobre Reader - zwraca true/false
function BOOL DetectAdobeReader(bLog)
string RegPath,sVersion,sVer;
number nSize,nType,nResult,i;
LIST nList;
BOOL bResult;
begin
bResult = FALSE;
if (bLog) then WriteLog(0,"* Sprawdzenie zainstalowanego Adobre Reader"); endif;
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
RegPath="SOFTWARE\\Adobe\\Acrobat Reader";
if (RegDBKeyExist(RegPath)=1) then
nList = ListCreate(STRINGLIST);
nResult = RegDBQueryKey ( RegPath, REGDB_KEYS, nList );
if (nResult = 0) then
if (ListCount(nList)>0) then
if (bLog) then WriteLog(1," - znaleziono wersje:"); endif;
ListSetIndex(nList,LISTFIRST);
for i=0 to ListCount(nList)-1
ListCurrentString(nList,sVer);
if (bLog) then WriteLog(2,sVer); endif;
ListSetIndex(nList,LISTNEXT);
endfor;
bResult = TRUE;
else
if (bLog) then WriteLog(1," - pobrana lista kluczy jest pusta"); endif;
endif;
else
if (bLog) then WriteLog(1," - nie udało się pobrać listy kluczy rejestru"); endif;
endif;
nType = REGDB_STRING;
nSize = 255;
ListDestroy(nList);
else
if (bLog) then WriteLog(1,"- nieznaleziono"); endif;
endif;
return bResult;
end;
Etykiety:
InstallShield - funkcje
Subskrybuj:
Komentarze (Atom)