ContentWriter contentWriter = contentService.getWriter(nodeCurrentLogFile, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype("text/plain");
FileChannel fileChannel = contentWriter.getFileChannel(false);
ByteBuffer bf = ByteBuffer.wrap(logLine.getBytes());
fileChannel.position(contentWriter.getSize());
fileChannel.write(bf);
fileChannel.force(false);
fileChannel.close();
星期三, 6月 27, 2012
[Alfresco ] How to update content with ContentWriter class
此問題欲解決要利用ContentWriter變更Node的內容,
不是指新增版本的方式,目前尚未用到,待驗證 :)
星期一, 6月 25, 2012
[Alfresco] Java Foundation API
記錄一下Alfresco low level的java API學習資源 :)
Search Service
http://wiki.alfresco.com/wiki/Search#Search_Parameters
https://wiki.alfresco.com/wiki/Search_Documentation#Lucene_Language
How to exceed Lucene Limit Search?
Content repository services
Content repository services are the fundamental services for working with content in Alfresco. Content repository services are written in Java.
Content repository services are built on the storage and query engines. As with the engines, the same infrastructure is shared. The concept of users and groups is introduced into these services, such as recording the author of content, who has content locked or access to content. Implementation of the standards-defined services is packaged into the Alfresco content repository.- File Folders service
The File Folders service manages nodes for modeling files and folders in the repository. The service provides methods to create and update nodes and define the relationships between them. - Versioning service
The Versioning service manages versions of individual content nodes. To enable versioning behavior, you must apply the versionable aspect to the node. - Check Out / Check In service
Check Out and Check In services control updates to document and prevent unwanted overwrites. - Audit service
The Audit service provides a configurable record of actions and events. It collects information and stores it in a simple database form. - Authority service
The Authority service supports the creation and updating of users and groups. - Permission service
The Permission service supports methods relating to various permissions. - Person service
The Person service supports various methods relating to users. - Dictionary service
The Dictionary service supports methods to access and view content models and their definitions. - Search service
The Search service provides methods for querying the repository and returning a filtered collection of nodes based on a user’s permission.
Search Service
http://wiki.alfresco.com/wiki/Search#Search_Parameters
https://wiki.alfresco.com/wiki/Search_Documentation#Lucene_Language
How to exceed Lucene Limit Search?
[Java] Jersey Client
本文記錄如何使用Jersey client API
Reference:
https://blogs.oracle.com/enterprisetechtips/entry/consuming_restful_web_services_with
Reference:
https://blogs.oracle.com/enterprisetechtips/entry/consuming_restful_web_services_with
星期六, 6月 23, 2012
星期二, 6月 19, 2012
[Alfresco] How to create Java backed web script in alfresco (3)
這個範例在Google都找的到,沒做多大的修改。
重點是記錄Spring Bean XML的差異性。
Spring Bean XML
重點在於property標籤設定,如果你參考了foundation的api請記得把他加進來!!,
所以這個範例要使用了Repository,請設定rel=repositoryHelper。
Java backed controller
透過xml的設定, 就可以透過 public void setRepository(Repository repository) {}直接呼叫alfresco的核心api了。
重點是記錄Spring Bean XML的差異性。
Spring Bean XML
重點在於property標籤設定,如果你參考了foundation的api請記得把他加進來!!,
所以這個範例要使用了Repository,請設定rel=repositoryHelper。
<bean
id="webscript.org.example.simplejavadir.get"
class="org.example.SimpleJavaDir"
parent="webscript">
<property name="repository" ref="repositoryHelper"/>
</bean>
Java backed controller
透過xml的設定, 就可以透過 public void setRepository(Repository repository) {}直接呼叫alfresco的核心api了。
package org.example;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.repo.model.Repository;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
public class SimpleJavaDir extends DeclarativeWebScript {
private Repository repository;
private static Log s_logger = LogFactory.getLog(SimpleJavaDir.class);
public void setRepository(Repository repository) {
this.repository = repository;
}
@Override
protected Map<string, object> executeImpl(WebScriptRequest req,
Status status, Cache cache) {
s_logger.debug("SimpleJavaDir entry");
// extract folder listing arguments from URI
String verboseArg = req.getParameter("verbose");
Boolean verbose = Boolean.parseBoolean(verboseArg);
Map<string, string> templateArgs = req.getServiceMatch().getTemplateVars();
String folderPath = templateArgs.get("folderpath");
String nodePath = "workspace/SpacesStore/" + folderPath;
// @param1 one of "node", "path", or "avmpath"
NodeRef folder = repository.findNodeRef("path", nodePath.split("/"));
// validate that folder has been found
if (folder == null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Folder "
+ folderPath + " not found");
//you will see the followning messages in your server
// ERROR [extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 05190001 Folder Company Homes not found
}
// construct model for response template to render
Map<string, object> model = new HashMap<string, object>();
model.put("verbose", verbose);
model.put("folder", folder);
model.put("nodePath", nodePath);
return model;
}
}
星期日, 6月 10, 2012
[phpmyadmin] stored procedure and trigger
查看目前已建立的stored procedure
show procedure status
查看目前已建立的stored procedure
查看指定資料庫內已有的stored procedure
新建stored procedure
Reference:
如何使用MySQL的Stored Procedure與Trigger
Using phpMyAdmin to Create Stored Procedures
show procedure status
查看目前已建立的stored procedure
select * from information_schema.routines where routine_type = 'procedure'
查看指定資料庫內已有的stored procedure
select * from information_schema.routines where routine_type = 'procedure' and routine_schema = 'your_db'
新建stored procedure
- Open phpMyadmin.
- Select a database to work with.
- Open the SQL tab.
- Select all of the SQL statements between the DELIMITER statements in your stored procedure script. Do not include the DELIMITER statements! Here’s what my example script should look like:
DROP PROCEDURE IF EXISTS spFoo $$ CREATE PROCEDURE spFoo () BEGIN SELECT 'Foo' FROM DUAL; END $$
- In the delimiter field, just below the SQL editor’s text area, enter $$ as your delimiter.
Reference:
如何使用MySQL的Stored Procedure與Trigger
Using phpMyAdmin to Create Stored Procedures
星期日, 6月 03, 2012
[Java] Jersey Session
Session控制
@Path("/helloworld")
public class HelloWorld {
@GET
@Produces("text/plain")
public String hello(@Context HttpServletRequest req) {
HttpSession session= req.getSession(true);
Object foo = session.getAttribute("foo");
if (foo!=null) {
System.out.println(foo.toString());
} else {
foo = "bar";
session.setAttribute("foo", "bar");
}
return foo.toString();
}
}
[Java] java.lang.UnsupportedClassVersionError: example/Hello : Unsupported major.minor version 51.0 (unable to load class example.Hello)
今天在local編譯完java後,丟到機器後就爆炸了。
是JDK版本不一樣導致XD,記錄一下這個痛!!
java.lang.UnsupportedClassVersionError: example/Hello : Unsupported major.minor version 51.0 (unable to load class example.Hello)
JDK 1.1 = 45
JDK 1.2 = 46
JDK 1.3 = 47
JDK 1.4 = 48
JDK 1.5 = 49
JDK 1.6 = 50
是JDK版本不一樣導致XD,記錄一下這個痛!!
java.lang.UnsupportedClassVersionError: example/Hello : Unsupported major.minor version 51.0 (unable to load class example.Hello)
Major Class Versions of Various JDK
Following are the major version of class file format in standard JDK environment.
JDK 1.1 = 45JDK 1.2 = 46
JDK 1.3 = 47
JDK 1.4 = 48
JDK 1.5 = 49
JDK 1.6 = 50
[Java] org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
案例:
本地端(mac)的JRE使用1.7的64bit版本,build出來的程式在機器上都爆炸XD
目前先把elicpse的環境設回1.6的版本就可以在server正常跑了。
有遇到一樣情形的朋友一定要先確定Java的版本到底有沒有一致
專案按右鍵選擇Properties設定
JAVA BUILD PATH 設定
JAVA COMPILER 設定
星期五, 6月 01, 2012
[Mysql] Host ‘yourhost’ is not allowed to connect to this MySQL server錯誤
連線MySQL時,出現標題上的錯誤訊息,
這個問題是此IP位址未授權給MYSQL
解決方法:直接在下SQL語法設定即可這個問題是此IP位址未授權給MYSQL
補充:
進入設定檔 改bind-address
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0
1.登入mysql
shell>mysql -u root -p
mysql>use mysql
2.設定資料庫的使用權限
允許所有連線
mysql>GRANT ALL PRIVILEGES ON *.* TO ‘MySQL帳號’@'%’ IDENTIFIED BY ‘MySQL密碼’ WITH GRANT OPTION;
Tip:% 代表不限client的連線ip
設定特地連結的ip
mysql>GRANT ALL PRIVILEGES ON *.* TO ‘MySQL帳號’@'你要連線IP‘ IDENTIFIED BY ‘MySQL密碼’ WITH GRANT OPTION;
3.最後一定要更新權限
mysql>FLUSH PRIVILEGES;
Reference:
[MySQL]解決ERROR 1130: Host ‘yourhost’ is not allowed to connect to this MySQL server錯誤無法遠端連接MySQL:message from server: "Host xxx is not allowed to connect to this MySQL server"
MySQL的重要語法
[Java] DBCP Sample
簡單的DBCP範例,主要記錄Reference物件的用法
Setting up initial context for DBCP connection pool.
Setting up initial context for DBCP connection pool.
[Java] OpenID4Java
今天在處理OpenID的議題時,發現在local測試跑很正常。
但BUILD到伺服器的時候,會產生類別找不到的問題。
發現在tomcat/lib放了二個版本的openid4java的函式庫,
把舊的砍掉就執行正常了
但BUILD到伺服器的時候,會產生類別找不到的問題。
發現在tomcat/lib放了二個版本的openid4java的函式庫,
把舊的砍掉就執行正常了
星期四, 5月 31, 2012
[Java] Cannot create JDBC driver of class '' for connect URL 'null'
想要透過local的專案直接連mysql所遇到的
Cannot create JDBC driver of class '' for connect URL 'null'錯誤訊息的方法,
Google到的資訊實在太多做法了,把試成功的經驗記錄一下。
step1:在專案內的WEB-INF/加入context.xml檔
Tip:DBCP已經設全域設定了,所以這個不用加
step2:在專案的web.xml加入
<resource-ref>
<description>DB Connectiondescription>
<res-ref-name>jdbc/資料表連接名稱res-ref-name>
<res-type>javax.sql.DataSourceres-type>
resource-ref>
Cannot create JDBC driver of class '' for connect URL 'null'錯誤訊息的方法,
Google到的資訊實在太多做法了,把試成功的經驗記錄一下。
step1:在專案內的WEB-INF/加入context.xml檔
<xml version="1.0" encoding="UTF-8"?>
<Context >
<Resource
name="jdbc/資料表連接名稱"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="root"
password="密碼"
driverClassName="com.mysql.jdbc.Driver"
autoReconnect="true"
removeAbandoned="true"
removeAbandonedTimeout="300"
logAbandoned="false"
url="jdbc:mysql://遠端IP:3306/資料庫名稱"/>
Context>
Tip:DBCP已經設全域設定了,所以這個不用加
非常重要!!記得要重新開Tomcat!!
星期三, 5月 30, 2012
Mac lion Eclipse 設定 JDK7
在lion安裝完JDK7後,它的路徑已經先之前安裝的路徑不一樣了。
目前預設的安裝目錄是在
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
之後打開Eclipse後,透過偏好設定的JAVA中的Installed JREs,指定新的JDK就可以了。
找到的參考資料
目前預設的安裝目錄是在
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
之後打開Eclipse後,透過偏好設定的JAVA中的Installed JREs,指定新的JDK就可以了。
If you are a Java developer who wants to do Java development on Mac OS X 10.7, here are a few not-so-tricky steps to follow to get going:
- Go to http://connect.apple.com and sign in with your Apple ID (developer account may be required – it’s free).
- From the list titled “Downloads for Apple Developers”, select the item labeled “Java for Mac OS X 10.7 Update 1 Developer Package” (release date Nov 8, 2011) then download and install the package.
- The JDK will be installed into a different location then previous. This will result in IDEs (such as Eclipse) being unable to locate source code and java docs.
- At the time of writing the JDK ended up here:
/Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home - Open up Eclipse preferences and go to Java > Installed JREs page
- Rather than use the “JVM Contents (MacOS X Default) we will need to use the JDK location
- At the time of writing Search is not aware of the new JDK location; we we will need to click on the Add button
- From the Add JRE wizard choose “MacOS X VM” for the JRE Type
- For the JRE Definition Page we need to fill in the following:
JRE Home: /Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home - The other fields will now auto fill, with the default JRE name being “Home”. You can quickly correct this to something more meaningful such as:
JRE name: System JDK - Finish the wizard and return to the Installed JREs page
- Choose “System JDK” from the list
- You can now develop normally with:
[Java] Filter 變更 jsp輸出內容
今天為了讓jsp上面的js檔案能使用SVN的版號做版本控制,
又為了讓同事能不用變更之前放在jsp裡面的script path,
所以想到了可以透過filter來將jsp輸出前把script path加上SVN的版號,
這樣就可以模擬出使用者每次都能讀到最新變更的Javascript
以下是簡單置換內容的Filter Sample
又為了讓同事能不用變更之前放在jsp裡面的script path,
所以想到了可以透過filter來將jsp輸出前把script path加上SVN的版號,
這樣就可以模擬出使用者每次都能讀到最新變更的Javascript
以下是簡單置換內容的Filter Sample
星期二, 5月 29, 2012
[Eclipse] UTF-8 環境設定
Eclipse UTF-8環境設定
1.Windows->Preferences
2.偏好視窗:General->Workspace
Text file encoding 把 default(MS950)改Other的UTF-8
3.偏好視窗:Web->JSP Files
把Encoding改為UTF-8
Reference:
http://wiki.cheyingwu.tw/Eclipse/UTF8-Setting
1.Windows->Preferences
2.偏好視窗:General->Workspace
Text file encoding 把 default(MS950)改Other的UTF-8
3.偏好視窗:Web->JSP Files
把Encoding改為UTF-8
Reference:
http://wiki.cheyingwu.tw/Eclipse/UTF8-Setting
JSP Cache Filter
The right way to do it is to create a subclass of
http://onjava.com/pub/a/onjava/2003/11/19/filters.html?page=3
http://www.codeproject.com/Articles/203288/Automatic-JS-CSS-versioning-to-update-browser-cach
https://github.com/h5bp/html5-boilerplate/wiki
http://livingtao.blogspot.com/2012/01/servlet-filter-to-set-response-headers.html
HttpServletRequestWrapper, override its getRequestURI()and other methods to return the new URL, and wrap the request with it. So you don't have to change the other filter mappings.
http://onjava.com/pub/a/onjava/2003/11/19/filters.html?page=3
http://www.codeproject.com/Articles/203288/Automatic-JS-CSS-versioning-to-update-browser-cach
https://github.com/h5bp/html5-boilerplate/wiki
http://livingtao.blogspot.com/2012/01/servlet-filter-to-set-response-headers.html
星期一, 5月 28, 2012
[Alfresco] Alfresco Namespace
Note: This list will expand / change between now and the next release.
| Namespace | Common Prefix | Description |
|---|---|---|
| http://www.alfresco.org | alf | General Alfresco Namespace |
| http://www.alfresco.org/model/dictionary/1.0 | d | Data Dictionary model |
| http://www.alfresco.org/model/system/1.0 | sys | Repository system model |
| http://www.alfresco.org/model/content/1.0 | cm | Content Domain model |
| http://www.alfresco.org/model/application/1.0 | app | Application model |
| http://www.alfresco.org/model/bpm/1.0 | bpm | Business Process Model |
| http://www.alfresco.org/model/site/1.0 | st | Site Model |
| http://www.alfresco.org/model/forum/1.0 | fm | Forum Model |
| http://www.alfresco.org/model/user/1.0 | usr | User model (in repository.jar) |
| http://www.alfresco.org/view/repository/1.0 | view | Alfresco Import / Export View |
| http://www.alfresco.org/model/action/1.0 | act | Action service model |
| http://www.alfresco.org/model/rule/1.0 | rule | Rule service model |
| http://www.alfresco.org/ws/service/authentication/1.0 | auth | Authentication Web Service |
| http://www.alfresco.org/ws/service/repository/1.0 | rep | Repository Web Service |
| http://www.alfresco.org/ws/service/content/1.0 | content | Content Web Service |
| http://www.alfresco.org/ws/service/authoring/1.0 | author | Authoring Web Service |
| http://www.alfresco.org/ws/service/classification/1.0 | cls | Classification Web Service |
| http://www.alfresco.org/ws/cml/1.0 | cml | Content Manipulation Language |
| http://www.alfresco.org/ws/model/content/1.0 | cm | Web Service Content Domain Model |
| http://www.alfresco.org/ws/headers/1.0 | hdr | SOAP Headers |
| http://www.alfresco.org/model/workflow/1.0 | wf | Workflow Model(link is to Alfresco simple workflow model, not generally extended) |
訂閱:
意見 (Atom)


