锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
聽聽聽聽<page>1</page>
聽聽聽聽<pages>1</pages>
聽聽聽聽<perpage>100</perpage>
聽聽聽聽<total>19</total>
聽聽聽聽<photos>
聽聽聽聽聽聽聽聽<photo>
聽聽聽聽聽聽聽聽聽聽聽聽<id>ff8080810fc8ac78010fd3f158d40a52</id>
聽聽聽聽聽聽聽聽聽聽聽聽<owner>ff8080810f1a387b010f1a83d6530dfc</owner>
聽聽聽聽聽聽聽聽聽聽聽聽<title>Gmail-2</title>
聽聽聽聽聽聽聽聽聽聽聽聽<host>4</host>
聽聽聽聽聽聽聽聽聽聽聽聽<dir>20061230</dir>
聽聽聽聽聽聽聽聽聽聽聽聽<filename>231905_1463411198</filename>
聽聽聽聽聽聽聽聽</photo>
聽聽聽聽</photos>
</result>
綆鍗曠殑alias涓涓嬪氨鍙互璇誨埌鍊間簡
BufferedReader聽reader聽=聽new聽BufferedReader(new聽InputStreamReader(new聽FileInputStream(file),聽"UTF-8"));
XStream聽stream聽=聽new聽XStream();
stream.alias("result",聽YupooResult.class);
stream.alias("photo",YupooPhoto.class);
YupooResult聽result聽=聽(YupooResult)stream.fromXML(reader);
聽聽聽聽<photos>
聽聽聽聽聽聽聽聽<photo聽id="ff8080810fc8ac78010fd3f158d40a52"
聽聽聽聽聽聽聽聽聽聽聽聽owner="ff8080810f1a387b010f1a83d6530dfc"聽title="Gmail-2"聽host="4"
聽聽聽聽聽聽聽聽聽聽聽聽dir="20061230"聽filename="231905_1463411198"聽/>
聽聽聽聽</photos>
</result>Hello,
I am not sure about the subject but here is what I needed help for:
XML:
<field name="value">I am a Field.</field>
I have already tried several structures and nothing seem to work.
Is this possible for XStream? :)
How is the Java class form to support this?
Thanks!
鏈変漢鍥炵瓟鏄湅Converter鐨勬枃妗c傛灉鐒舵壘鍒扮瓟妗堜簡銆?br />鑷繁鍐欎竴涓猚onverter灝卞彲浠ヤ簡銆?br />涓嬮潰鏄垜鐨刢onverter
import聽java.util.ArrayList;
import聽java.util.List;
import聽com.jdkcn.yupoo.YupooPhoto;
import聽com.jdkcn.yupoo.YupooResult;
import聽com.thoughtworks.xstream.converters.Converter;
import聽com.thoughtworks.xstream.converters.MarshallingContext;
import聽com.thoughtworks.xstream.converters.UnmarshallingContext;
import聽com.thoughtworks.xstream.io.HierarchicalStreamReader;
import聽com.thoughtworks.xstream.io.HierarchicalStreamWriter;
/**
聽*聽@author聽<a聽href="mailto:rory.cn@gmail.com">somebody</a>
聽*聽@since聽Jan聽16,聽2007聽6:12:35聽PM
聽*聽@version聽$Id聽YupooResultConverter.java$
聽*/
public聽class聽YupooResultConverter聽implements聽Converter聽{
聽聽聽聽/*聽(non-Javadoc)
聽聽聽聽聽*聽@see聽com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object,聽com.thoughtworks.xstream.io.HierarchicalStreamWriter,聽com.thoughtworks.xstream.converters.MarshallingContext)
聽聽聽聽聽*/
聽聽聽聽public聽void聽marshal(Object聽obj,聽HierarchicalStreamWriter聽writer,聽MarshallingContext聽context)聽{
聽聽聽聽聽聽聽聽//聽FIXME聽unfinish.
聽聽聽聽}
聽聽聽聽/*聽(non-Javadoc)
聽聽聽聽聽*聽@see聽com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader,聽com.thoughtworks.xstream.converters.UnmarshallingContext)
聽聽聽聽聽*/
聽聽聽聽public聽Object聽unmarshal(HierarchicalStreamReader聽reader,聽UnmarshallingContext聽context)聽{
聽聽聽聽聽聽聽聽YupooResult聽result聽=聽new聽YupooResult();
聽聽聽聽聽聽聽聽result.setPage(new聽Integer(reader.getAttribute("page")));
聽聽聽聽聽聽聽聽result.setPages(new聽Integer(reader.getAttribute("pages")));
聽聽聽聽聽聽聽聽result.setPerpage(new聽Integer(reader.getAttribute("perpage")));
聽聽聽聽聽聽聽聽result.setTotal(new聽Integer(reader.getAttribute("total")));
聽聽聽聽聽聽聽聽reader.moveDown();
聽聽聽聽聽聽聽聽List<YupooPhoto>聽photos聽=聽new聽ArrayList<YupooPhoto>();
聽聽聽聽聽聽聽聽while(reader.hasMoreChildren())聽{
聽聽聽聽聽聽聽聽聽聽聽聽reader.moveDown();
聽聽聽聽聽聽聽聽聽聽聽聽YupooPhoto聽photo聽=聽new聽YupooPhoto();
聽聽聽聽聽聽聽聽聽聽聽聽photo.setDir(reader.getAttribute("dir"));
聽聽聽聽聽聽聽聽聽聽聽聽photo.setFilename(reader.getAttribute("filename"));
聽聽聽聽聽聽聽聽聽聽聽聽photo.setHost(reader.getAttribute("host"));
聽聽聽聽聽聽聽聽聽聽聽聽photo.setId(reader.getAttribute("id"));
聽聽聽聽聽聽聽聽聽聽聽聽photo.setOwner(reader.getAttribute("owner"));
聽聽聽聽聽聽聽聽聽聽聽聽photo.setTitle(reader.getAttribute("title"));
聽聽聽聽聽聽聽聽聽聽聽聽photos.add(photo);
聽聽聽聽聽聽聽聽聽聽聽聽reader.moveUp();
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽result.setPhotos(photos);
聽聽聽聽聽聽聽聽return聽result;
聽聽聽聽}
聽聽聽聽/*聽(non-Javadoc)
聽聽聽聽聽*聽@see聽com.thoughtworks.xstream.converters.ConverterMatcher#canConvert(java.lang.Class)
聽聽聽聽聽*/
聽聽聽聽public聽boolean聽canConvert(Class聽clazz)聽{
聽聽聽聽聽聽聽聽return聽clazz.equals(YupooResult.class);
聽聽聽聽}
}
鐒跺悗璋冪敤鐨勫湴鏂逛慨鏀逛竴涓嬪氨ok浜嗐?br />
stream.registerConverter(new聽YupooResultConverter());
stream.alias("result",聽YupooResult.class);
鍙傝?
http://xstream.codehaus.org/converter-tutorial.html
2007騫?鏈?8鏃ユ洿鏂般?br />榪欓噷鎰熻阿緗戝弸 Ivan Chen錛堣タ婊級聽鐨勬彁紺恒傚師鏉ユ柊鐗堢殑xstream鍙互綆鍗曠殑瑙e喅浜嗐傚湪1.2.1鐨刣oc閲岄潰鎵懼埌浜嗚繖涓袱涓柟娉曘?br />useAttributeFor
public void useAttributeFor(java.lang.String聽fieldName,
java.lang.Class聽type)
fieldName
- the name of the field
type
- the Class of the type to be rendered as XML attribute
XStream.InitializationException
- if no AttributeMapper
is available
useAttributeFor
public void useAttributeFor(java.lang.Class聽type)
type
- the Class of the type to be rendered as XML attribute
XStream.InitializationException
- if no AttributeMapper
is available
榪欎袱涓柟娉曢兘鏄粠1.2寮濮嬫敮鎸佺殑銆?br />涔熶笉鐢ㄨ嚜宸卞啓converter浜嗐傝繖鏍峰氨鍙互浜?br />
聽聽聽聽聽聽聽聽stream.useAttributeFor("page",聽Integer.class);
聽聽聽聽聽聽聽聽stream.useAttributeFor("pages",聽Integer.class);
聽聽聽聽聽聽聽聽stream.useAttributeFor("perpage",聽Integer.class);
聽聽聽聽聽聽聽聽stream.useAttributeFor("total",聽Integer.class);
聽聽聽聽聽聽聽聽stream.alias("photo",聽YupooPhoto.class);
聽聽聽聽聽聽聽聽stream.useAttributeFor("id",聽String.class);
聽聽聽聽聽聽聽聽stream.useAttributeFor("owner",聽String.class);
聽聽聽聽聽聽聽聽stream.useAttributeFor("title",聽String.class);
聽聽聽聽聽聽聽聽stream.useAttributeFor("host",聽String.class);
聽聽聽聽聽聽聽聽stream.useAttributeFor("dir",聽String.class);
聽聽聽聽聽聽聽聽stream.useAttributeFor("filename",聽String.class);聽聽 闄ょ粡鐗瑰埆娉ㄦ槑澶?鏈枃绔犵増鏉冨綊鑾娉℃場鎵鏈?
緗插悕,闈炲晢涓氱敤閫?淇濇寔涓鑷?聽聽聽somebody(鑾)
]]>
聽 鍏堢粡榪囬偅涓粺璁$殑filter鐒跺悗鍐嶇粡榪囩紪鐮佺殑filter銆傝繖鏍風殑璇濈紪鐮佺殑filter灝變笉璧蜂綔鐢ㄤ簡銆傚彧瑕佸惂緙栫爜鐨刦ilter鏀懼埌鏈鍓嶉潰灝辨病鏈夐棶棰樹簡銆傛敼鎴愯繖鏍峰氨濂姐?br />
浠ュ悗澶у涓瀹氳娉ㄦ剰鍟娿傞『搴忛棶棰樹篃鏄緢閲嶈鐨勩?br />聽聽 闄ょ粡鐗瑰埆娉ㄦ槑澶?鏈枃绔犵増鏉冨綊鑾娉℃場鎵鏈?
緗插悕,闈炲晢涓氱敤閫?淇濇寔涓鑷?聽聽聽somebody(鑾)
The top level element.
Attribute | Possible Value | Explanation |
---|---|---|
default-match-type (optional) | regex (default) | All rules and thier conditions will be processed using the Java Regular Expression engine (unless match-type is specified on a rule). |
wildcard | All rules and thier conditions will be processed using the Wildcard Expression engine (unless match-type is specified on a rule). | |
decode-using (optional) | utf8 (default) | When URL is decoded UTF-8 will be used. |
null | Do not decode. | |
[encoding] | Any string representing a supported character encoding eg, ISO-8859-1. See Java Charset Object for more info. | |
use-query-string (optional) | false (default) | The query string will not be appended to the url that the "from" element matches against. |
true | The query string will be appended to the url that the "from" element matches against. | |
use-context (optional) | false (default) | The context path will not be added to the url that the "from" element matches against. |
true | The context path will be added to the url that the "from" element matches against. |
聽聽 闄ょ粡鐗瑰埆娉ㄦ槑澶?鏈枃绔犵増鏉冨綊鑾娉℃場鎵鏈?
緗插悕,闈炲晢涓氱敤閫?淇濇寔涓鑷?聽聽聽somebody(鑾)
榪欐牱鐨勮瘽銆傛墍鏈夌殑scheduler灝遍兘涓嶇鐢ㄤ簡銆傛墍浠ヨ澶у瑕佹敞鎰忋?br />
聽
character-encoding | Resin 1.1 |
Specifies the default character encoding for the environment.
<web-app id='/'> <character-encoding>shift_jis</character-encoding> ... </web-app> |
聽聽聽聽 榪欎釜鏄痳esin doc閲岄潰鐨勬垜鏄湪web-app-default閲岄潰鍔犱笂浜唀ncoding鐨勯厤緗?/p>
甯屾湜瀵逛綘鐨勯」鐩湁甯姪銆?/p>
聽聽 闄ょ粡鐗瑰埆娉ㄦ槑澶?鏈枃绔犵増鏉冨綊鑾娉℃場鎵鏈?
緗插悕,闈炲晢涓氱敤閫?淇濇寔涓鑷?聽聽聽somebody(鑾)聽聽
聽聽聽聽聽聽 浣嗘槸鍙戠幇榪欐牱鍙湁鍚庨潰涓涓鐢?http://localhost:8080/passport/jsvm2)榪欎釜鏄彲浠?鍙槸(http://localhost:8080/community/jsvm2)灝變笉琛?寰堟槸閮侀椃銆傚彧瑕佸悗闈㈢殑document-directory涓嶆槸鍚屼竴涓洰褰曞氨鎴愩?br />聽聽聽聽聽聽 鍚庢潵鍦╮esin鐨刣oc閲岄潰鐪嬪埌path鐨勯厤緗?/p>
Maps url patterns to real paths. If using a server like IIS, you may need to match the server's path aliases.
Attribute | Meaning | default |
---|---|---|
A pattern matching the url: | , , or||
url-regexp | A regular expression matching the url | |
real-path | The prefix of the real path. When used with | , allows substitution variables like .
<web-app id='/'> <path-mapping url-pattern='/resin/*' real-path='e:\resin'/> <path-mapping url-regexp='/~([^/]*)' real-path='e:\home$1'/> </web-app> |
鏀規榪欐牱鐨勯厤緗氨ok浜嗐?/p>
鍚姩鏈嶅姟錛屾姳閿欎簡銆?/p>
java.lang.IllegalArgumentExcep
聽 聽 聽 聽at org.directwebremoting.impl
聽 聽 聽 聽at org.directwebremoting.annotati
聽 聽 聽 聽at org.directwebremoting.servlet
聽聽聽聽聽 鍦―WR鐨凪aillist閲岄潰鎼滅儲浜嗕竴涓嬶紝榪樻湁絳旀錛屽師鏉WR2.0 鍔犲叆浜咼DK5鐨勬敞閲?annotations).DwrServlet鍒濆鍖栫殑鏃跺欎細鍘繪鏌ユ敞閲婄殑綾伙紝鎵句笉鍒板氨鎶遍敊浜嗐傚鏋滀綘涓嶇敤annotations涔熷彲浠ュ拷鐣ユ帀榪欎釜閿欒銆備笉榪囩湅璧鋒潵鎬繪槸涓嶇埥銆傛湁浜烘彁鍑轟簡鏂規銆傝繖鏍峰氨ok浜嗐?/p>
聽聽 闄ょ粡鐗瑰埆娉ㄦ槑澶?鏈枃绔犵増鏉冨綊鑾娉℃場鎵鏈?
緗插悕,闈炲晢涓氱敤閫?淇濇寔涓鑷?聽聽聽somebody(鑾)聽聽