星期四, 九月 20, 2012

Fwd: OSWORKFLOW on JBOSS 4.22 Config.

1.download osworkflow 2.8,2006年以后已不再维护。
   http://java.net/downloads/osworkflow/

2.将osworkflow-2.8.0-example.war展开到jboss 422/server/default/deploy/osworkflow-2.8.0-example.war 目录下。

3.在MYSQL 上建立一个osworkflow的database,并运行osworkflow-2.8.0\src\etc\deployment\jdbc
 \mysql.sql,建立其需要使用的表格.
4.配置JBOSS 数据源
   在
jboss 422/server/default/deploy/mysql-ds.xml里加入数据源:
   <!-- add for osworkflow datasorce -->
  <local-tx-datasource>
    <jndi-name>osworkflow</jndi-name>
   <connection-url>jdbc:mysql://192.1.1.100:3306/osworkflow?autoReconnect=true&amp;useUnicode=TRUE&amp;characterEncoding=utf-8</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password></password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
        <min-pool-size>5</min-pool-size>
        <max-pool-size>10</max-pool-size>
        <idle-timeout-minutes>1</idle-timeout-minutes>
    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
  </local-tx-datasource>


5.进入
jboss 422/server/default/deploy/osworkflow-2.8.0-example.war/WEB-INF/classes下修改配置,加入数据源说明.
  注意Linux table name 有大小写的问题。

  osuser.xml:
<opensymphony-user>
   <provider class="com.opensymphony.user.provider.jdbc.JDBCAccessProvider">
  <property name="user.table">OS_USER</property>
  <property name="group.table">OS_GROUP</property>
  <property name="membership.table">OS_MEMBERSHIP</property>
  <property name="user.name" >username</property>
  <property name="user.password">passwordhash</property>
  <property name="group.name">groupname</property>
  <property name="membership.userName" >username</property>
  <property name="membership.groupName">groupname</property>
  <property name="datasource">java:/osworkflow</property>
</provider>

<provider class="com.opensymphony.user.provider.jdbc.JDBCCredentialsProvider">
 <property name="user.table">OS_USER</property>
  <property name="group.table">OS_GROUP</property>
  <property name="membership.table">OS_MEMBERSHIP</property>
<property name="user.name" >username</property>
  <property name="user.password">passwordhash</property>
  <property name="group.name">groupname</property>
  <property name="membership.userName" >username</property>
  <property name="membership.groupName">groupname</property>
  <property name="datasource">java:/osworkflow</property>
 </provider>

    <provider class="com.opensymphony.user.provider.jdbc.JDBCProfileProvider">
 <property name="user.table">OS_USER</property>
  <property name="group.table">OS_GROUP</property>
  <property name="membership.table">OS_MEMBERSHIP</property>
<property name="user.name" >username</property>
  <property name="user.password">passwordhash</property>
  <property name="group.name">groupname</property>
  <property name="membership.userName" >username</property>
  <property name="membership.groupName">groupname</property>
  <property name="datasource">java:/osworkflow</property>
 </provider>

 <authenticator class="com.opensymphony.user.authenticator.SmartAuthenticator" />

</opensymphony-user>

osworkflow.xml:
<osworkflow>
    <!--persistence class="com.opensymphony.workflow.spi.memory.MemoryWorkflowStore"/-->
    <persistence class="com.opensymphony.workflow.spi.jdbc.MySQLWorkflowStore">
 <property key="datasource" value="java:/osworkflow"/>
<property key="entry.sequence"
                      value="SELECT max(id)+1 FROM OS_WFENTRY"/>
 <property key="entry.table" value="OS_WFENTRY"/>
 <property key="entry.id" value="ID"/>
 <property key="entry.name" value="NAME"/>
 <property key="entry.state" value="STATE"/>
 <property key="step.sequence"  value="SELECT max(ID)+1 FROM OS_STEPIDS"/>

 <property key="step.sequence.increment"    value="INSERT INTO OS_STEPIDS (ID) values (null)"/>
 <property key="step.sequence.retrieve"   value="SELECT max(ID) FROM OS_STEPIDS"/>
 <property key="entry.sequence.increment" value="INSERT INTO OS_ENTRYIDS (ID) values (null)"/>
 <property key="entry.sequence.retrieve" value="SELECT max(ID) FROM OS_ENTRYIDS"/>

 <property key="history.table" value="OS_HISTORYSTEP"/>
 <property key="current.table" value="OS_CURRENTSTEP"/>
 <property key="historyPrev.table" value="OS_HISTORYSTEP_PREV"/>
 <property key="currentPrev.table" value="OS_CURRENTSTEP_PREV"/>
 <property key="step.id" value="ID"/>
 <property key="step.entryId" value="ENTRY_ID"/>
 <property key="step.stepId" value="STEP_ID"/>
 <property key="step.actionId" value="ACTION_ID"/>
 <property key="step.owner" value="OWNER"/>
 <property key="step.caller" value="CALLER"/>
 <property key="step.startDate" value="START_DATE"/>
 <property key="step.finishDate" value="FINISH_DATE"/>
 <property key="step.dueDate" value="DUE_DATE"/>
 <property key="step.status" value="STATUS"/>
 <property key="step.previousId" value="PREVIOUS_ID"/>
</persistence>
    <factory class="com.opensymphony.workflow.loader.XMLWorkflowFactory">
        <property key="resource" value="workflows.xml" />
    </factory>
</osworkflow>

 propertyset.xml:
<propertysets>
 <propertyset name="jdbc" class="com.opensymphony.module.propertyset.database.JDBCPropertySet">
  <arg name="table.name" value="OS_PROPERTYENTRY"/>
  <arg name="col.globalKey" value="GLOBAL_KEY"/>
  <arg name="col.itemKey" value="ITEM_KEY"/>
  <arg name="col.itemType" value="ITEM_TYPE"/>
  <arg name="col.string" value="STRING_VALUE"/>
  <arg name="col.date" value="DATE_VALUE"/>
  <arg name="col.data" value="DATA_VALUE"/>
  <arg name="col.float" value="FLOAT_VALUE"/>
  <arg name="col.number" value="NUMBER_VALUE"/>
  <arg name="datasource" value="java:/osworkflow"/>
  <arg name="" value=""/>
 </propertyset>
</propertysets>


至此配置完成,启动JBOSS,从浏览器输入:
http://192.168.1.1:8080/osworkflow-2.8.0-example/

即可查看.



星期二, 九月 18, 2012

Android如何确认一个Intent是否存在呢?


 /**
     * Indicates whether the specified action can be used as an intent. This
     * method queries the package manager for installed packages that can
     * respond to an intent with the specified action. If no suitable package is
     * found, this method returns false.
     *
     * @param context The application's environment.
     * @param action The Intent action to check for availability.
     *
     * @return True if an Intent with the specified action can be sent and
     * responded to, false otherwise.
     *  Example:isIntentAvailable(getApplicationContext(),Intent.ACTION_WEB_SEARCH)
     */
    public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List<ResolveInfo> list =
    packageManager.queryIntentActivities(intent,
    PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
    }

星期四, 九月 13, 2012

Android动态改变语言并自动刷新菜单.

Locale locale=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String languageToLoad  = "zh";
         locale = new Locale(languageToLoad);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config, null);
        //getBaseContext().getResources().getDisplayMetrics()
        Log.v("log:","local is changed!");
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.activity_main);
         }

星期二, 九月 11, 2012

Andorid xml is binary format in .apk package

All of the resource XML files are compiled to a binary format by aapt at build time.
只有一个例外就是 res/raw下的文件是原始文件,没有做任何处理。

Activity的getString和Activity.getResource().getString的区别是什么呢?

activity的getString下的说明如此:
 localized string from the application's package's default string table

Resource的getString说明如下:
Returns the string value associated with a particular resource ID. It will be stripped of any styled text information

但是查看源代码,发现activity的getString如下:
    public final String getString(int resId) {
        return getResources().getString(resId);
    }

其实是一回事。真不明白为什么说明差异如此之大。

Android classpath access external resource.

Resources.getSystem().getString(android.R.string.somecommonstuff)