2010年12月30日木曜日

正規表現構文の要約

正規表現構文の要約

構文 マッチ対象

文字
x 文字 x
\\ バックスラッシュ文字
\0n 8 進値 0n を持つ文字 (0 <= n <= 7)
\0nn 8 進値 0nn を持つ文字 (0 <= n <= 7)
\0mnn 8 進値 0mnn を持つ文字 (0 <= m <= 3、0 <= n <= 7)
\xhh 16 進値 0xhh を持つ文字
\uhhhh 16 進値 0xhhhh を持つ文字
\t タブ文字 ('\u0009')
\n 改行文字 ('\u000A')
\r キャリッジリターン文字 ('\u000D')
\f 用紙送り文字 ('\u000C')
\a 警告 (ベル) 文字 ('\u0007')
\e エスケープ文字 ('\u001B')
\cx x に対応する制御文字

文字クラス
[abc] a、b、または c (単純クラス)
[^abc] a、b、c 以外の文字 (否定)
[a-zA-Z] a ~ z または A ~ Z (範囲)
[a-d[m-p]] a ~ d、または m ~ p: [a-dm-p] (結合)
[a-z&&[def]] d、e、f (交差)
[a-z&&[^bc]] b と c を除く a ~ z: [ad-z] (減算)
[a-z&&[^m-p]] m ~ p を除く a ~ z: [a-lq-z] (減算)

定義済みの文字クラス
. 任意の文字 (行末記号とマッチする場合もある)
\d 数字: [0-9]
\D 数字以外: [^0-9]
\s 空白文字: [ \t\n\x0B\f\r]
\S 非空白文字: [^\s]
\w 単語構成文字: [a-zA-Z_0-9]
\W 非単語文字: [^\w]

POSIX 文字クラス (US-ASCII のみ)
\p{Lower} 小文字の英字: [a-z]
\p{Upper} 大文字の英字: [A-Z]
\p{ASCII} すべての ASCII 文字: [\x00-\x7F]
\p{Alpha} 英字: [\p{Lower}\p{Upper}]
\p{Digit} 10 進数字: [0-9]
\p{Alnum} 英数字: [\p{Alpha}\p{Digit}]
\p{Punct} 句読文字: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ のいずれか
\p{Graph} 表示できる文字: [\p{Alnum}\p{Punct}]
\p{Print} プリント可能文字: [\p{Graph}\x20]
\p{Blank} 空白またはタブ: [ \t]
\p{Cntrl} 制御文字: [\x00-\x1F\x7F]
\p{XDigit} 16 進数字: [0-9a-fA-F]
\p{Space} 空白文字: [ \t\n\x0B\f\r]

java.lang.Character クラス (単純な java 文字タイプ)
\p{javaLowerCase} java.lang.Character.isLowerCase() と等価
\p{javaUpperCase} java.lang.Character.isUpperCase() と等価
\p{javaWhitespace} java.lang.Character.isWhitespace() と等価
\p{javaMirrored} java.lang.Character.isMirrored() と等価

Unicode ブロックとカテゴリのクラス
\p{InGreek} ギリシャ語ブロックの文字 (単純ブロック)
\p{Lu} 大文字 (単純カテゴリ)
\p{Sc} 通貨記号
\P{InGreek} ギリシャ語ブロック以外の文字 (否定)
[\p{L}&&[^\p{Lu}]] 大文字以外の文字 (減算)

境界正規表現エンジン
^ 行の先頭
$ 行の末尾
\b 単語境界
\B 非単語境界
\A 入力の先頭
\G 前回のマッチの末尾
\Z 最後の行末記号がある場合は、それを除く入力の末尾
\z 入力の末尾

最長一致数量子
X? X、1 または 0 回
X* X、0 回以上
X+ X、1 回以上
X{n} X、n 回
X{n,} X、n 回以上
X{n,m} X、n 回以上、m 回以下

最短一致数量子
X?? X、1 または 0 回
X*? X、0 回以上
X+? X、1 回以上
X{n}? X、n 回
X{n,}? X、n 回以上
X{n,m}? X、n 回以上、m 回以下

強欲な数量子
X?+ X、1 または 0 回
X*+ X、0 回以上
X++ X、1 回以上
X{n}+ X、n 回
X{n,}+ X、n 回以上
X{n,m}+ X、n 回以上、m 回以下

論理演算子
XY X の直後に Y
X|Y X または Y
(X) X、先方参照を行う正規表現グループ

前方参照
\n マッチした n 番目の先方参照を行う正規表現グループ

引用
\ 正規表現ではないが、次の文字をエスケープする
\Q 正規表現ではないが、\E までのすべての文字をエスケープする
\E 正規表現ではないが、\Q で開始された引用をエスケープする

特殊な構文 (先方参照を行わない)
(?:X) X、先方参照を行わない正規表現グループ
(?idmsux-idmsux) 正規表現ではないが、マッチフラグのオン/オフを切り替える
(?idmsux-idmsux:X) X、指定されたフラグをオン/オフにした先方参照を行わない正規表現グループ
(?=X) X、幅ゼロの肯定先読み
(?!X) X、幅ゼロの否定先読み
(?<=X) X、幅ゼロの肯定後読み
(?(?>X) X、独立した先方参照を行わない正規表現グループ

2010年12月20日月曜日

2010年12月19日日曜日

Constants define

static final Integer INT_CONST1 = 2000;
static final Integer INT_CONST2;
static {
INT_CONST2= 2010;
}

System-defined enums

System.StatusCode
System.XmlTag
System.ApplicationReadWriteMode
System.LoggingLevel
System.RoundingMode
System.SoapType
System.DisplayType
ApexPages.Severity
Dom.XmlNodeType

Maps SOQL Result

Map<ID, Contact> m = new Map<ID, Contact>([select id, lastname
from contact]);

SOSL Find

1)
List<List<sObject>> results = [find {4155557000}
in phone
fields
returning contact(id, phone, firstname, lastname),
lead(id, phone,
firstname, lastname), account(id, phone, name)];
sObject[] records =
((List<sObject>)results[0]);
if (!records.isEmpty()) {
for (Integer
i = 0; i < records.size(); i++) {
sObject record = records[i];
if
(record.getSObjectType() == Contact.sObjectType) {
contacts.add((Contact)
record);
} else if (record.getSObjectType() ==
Lead.sObjectType){
leads.add((Lead) record);} else if
(record.getSObjectType() == Account.sObjectType) {
accounts.add((Account)
record);
}
}
}

2)
List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS
RETURNING Account (id, name),
Contact, Opportunity, Lead];

2010年12月16日木曜日

Extension Contraller

<apex:page standardController="Account"
extensions="ExtOne,ExtTwo">
<apex:outputText value="{!foo}"
/>
</apex:page>


public class ExtOne {
private ApexPages.StandardController
sdController;
public ExtOne(ApexPages.StandardController acon) {sdController
= acon; }
public String getFoo() {
return 'foo-One';
}
}


public class ExtTwo {
private ApexPages.StandardController
sdController;
public ExtTwo(ApexPages.StandardController acon) {sdController
= acon; }
public String getFoo() {
return
'foo-Two';
}
}

2010年12月14日火曜日

Standard List Controller Action

a list controller returns 25 records on the page

<apex:page standardController="Account"
recordSetvar="accounts">
<apex:form>
<apex:dataList var="a"
value="{!accounts}">{!a.name}</apex:dataList>
<apex:panelGrid
columns="4">
<apex:commandLink
action="{!first}">First</apex:commandlink>
<apex:commandLink
action="{!previous}">Previous</apex:commandlink>
<apex:commandLink
action="{!next}">Next</apex:commandlink>
<apex:commandLink
action="{!last}">Last</apex:commandlink>
</apex:panelGrid>
</apex:form>
</apex:page>

Standard Controller Action

<apex:page standardController="Contact">
<apex:form
><apex:commandButton action="{!save}"
value="save"/>
<apex:commandButton action="{!quicksave}"
value="quicksave"/>
<apex:commandButton action="{!edit}"
value="edit"/>
<apex:commandButton action="{!delete}"
value="delete"/>
<apex:commandButton action="{!cancel}"
value="cancel"/>
<apex:commandButton action="{!list}"
value="list"/>
<apex:inputField
value="{!contact.LastName}"/>
</apex:form>
</apex:page>

return (new ApexPages.StandardController(account)).cancel();
return (new ApexPages.StandardController(account)).save();
return (new ApexPages.StandardController(account)).edit();//goto edit page
return (new ApexPages.StandardController(account)).view();//goto detail page

Output Word Excel Pdf

Output Word
<apex:page standardController="Account"
contenttype="application/msword">
<apex:pageBlock>
<apex:pageBlockTable
value="{!account.Contacts}" var="contact">
<apex:column
value="{!contact.Name}"/>
<apex:column
value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>


Output Excel
<apex:page standardController="Account"
contenttype="application/vnd.ms-excel">
<apex:pageBlock>
<apex:pageBlockTable
value="{!account.Contacts}" var="contact">
<apex:column
value="{!contact.Name}"/>
<apex:column
value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>


Output PDF
<apex:page standardController="Account"
renderAs="pdf">
<apex:pageBlock>
<apex:pageBlockTable
value="{!account.Contacts}" var="contact">
<apex:column
value="{!contact.Name}"/>
<apex:column
value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>

Style sheet

<apex:stylesheet value="{!URLFOR($Resource.myStyles, 'newStyles.css')}"
/>

• Theme1—Obsolete Salesforce.com theme
• Theme2—Salesforce.com theme used prior to Spring '10
• PortalDefault—Salesforce.com Customer Portal theme
• Webstore—Salesforce.com AppExchange theme
• Theme3—Current Salesforce.com theme, introduced during Spring '10


http://wiki.developerforce.com/index.php/Using_the_Salesforce_CSS_in_Your_Apps


<apex:page standardStylesheets="false">
<!-- page content here
-->
</apex:page>

action support

<apex:actionSupport event="onmouseover"
rerender="detail">
<apex:param name="cid"
value="{!contact.id}"/>
</apex:actionSupport>

action status

<apex:actionStatus startText="Requesting...">
<apex:facet
name="stop">
<apex:detail
subject="{!$CurrentPage.parameters.cid}"
relatedList="false"
title="false"/>
</apex:facet>
</apex:actionStatus>

New Edit Detail URL

<apex:page >
<apex:form >
<a
href="/{!$ObjectType.TestObj__c}/e">New</a><br/>
<a
href="/003A000000GOkuO/e">Edit</a><br/>
<a
href="/003A000000GOkuO">Detail</a><br/>
</apex:form>
</apex:page>

List All Objects

<apex:page standardController="Account"
recordSetvar="objs">
<apex:dataList var="o"
value="{!objs}">
{!o.name}
</apex:dataList>
</apex:page>

Radio Button

<apex:selectRadio value="{!account.name}">
<apex:selectOption
itemValue="Item1" itemLabel="Item 1"/>
<apex:selectOption
itemValue="Item2" itemLabel="Item
2"/>
</apex:selectRadio>

Input Password

<apex:inputSecret value="{!TestObj__c.password}"/>

Goto View Button

<apex:page >
<apex:form>
<apex:commandButton
action="{!URLFOR($Action.TestObj__c.List, $ObjectType.TestObj__c)}" value="Goto
View"/>
</apex:form>
</apex:page>