You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by fxbird <fx...@gmail.com> on 2011/03/30 11:49:30 UTC
[digester]How to use SimpleRegexMatcher?
Hi all:
I want to match some unknow elements nested some parent element where some newly defined element might be added sometime.
The sample xml is as below:
<Class name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl" method="entry">
<Parameter name="comment" index="0" type="insert" table="MOCO_CODICMT">
<Main>
<DeviceType constant="true">pc</DeviceType>
<CheckStatus constant="true">N</CheckStatus>
<ValidCheck constant="true">Yes</ValidCheck>
<CheckDesc></CheckDesc>
<UserId>userid</UserId>
<PrimaryKey1>cmtno</PrimaryKey1>
</Main>
<SubText>
<!--<Type constant="true/false"></Type>-->
<!--<Title>title</Title>-->
<Content>contents</Content>
<WriterId>writeid</WriterId>
<WriterUserName>userid</WriterUserName>
</SubText>
</Parameter>
</Class>
The elements under <Main> and <SubText> are all variable someday, both name and amounts. So I define a ParaItem pojo to wrap sub elements of the two element. That means I want to create a Paraitem for every sub element ,whatever its name is, then add the object to paraent object Parameter's list property saving all the related Paraitem.
The Paraitem source code is following:
public class ParaItem {
private String elemName;
private String argPropNameOrValue;
private boolean isConstant;
public ParaItem() {
}
public ParaItem(String elemName, String argPropNameOrValue, boolean constant) {
this.elemName = elemName;
this.argPropNameOrValue = argPropNameOrValue;
isConstant = constant;
}
public ParaItem(String elemName, String argPropNameOrValue) {
this.elemName = elemName;
this.argPropNameOrValue = argPropNameOrValue;
}
public String getElemName() {
return elemName;
}
public String getArgPropNameOrValue() {
return argPropNameOrValue;
}
public boolean isConstant() {
return isConstant;
}
}
The Parameter source code is below:
public class Parameter {
private String index;
private String operType;
private String dataType;
private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
private List<ParaItem> listSubField =new ArrayList<ParaItem>();
public Parameter(String operType) {
this.operType = operType;
}
public List<ParaItem> getListMainFiled() {
return listMainFiled;
}
public void setListMainFiled(List<ParaItem> listMainFiled) {
this.listMainFiled = listMainFiled;
}
public List<ParaItem> getListSubField() {
return listSubField;
}
public void setListSubField(List<ParaItem> listSubField) {
this.listSubField = listSubField;
}
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
public String getOperType() {
return operType;
}
public void setOperType(String operType) {
this.operType = operType;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public void addMainParaItem(ParaItem pi){
getListMainFiled().add(pi);
}
public void addSubParaItem(ParaItem pi){
getListSubField().add(pi);
}
}
I suppose regex rule is the best way to make it , but googling and the javadoc doesn't tell me how to set a regex expression for a pattern. No way out, who knows the solotion , thanks.
Kurt
Re:Re: [digester]How to use SimpleRegexMatcher?
Posted by 飞翔鸟 <fx...@163.com>.
Hello Simone:
I tried your code but receive a NullPointerException:
[WARN] Digester - Empty stack (returning null)
[ERROR] Digester - End event threw exception <java.lang.NullPointerException>java.lang.NullPointerException
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:274)
at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:220)
at org.apache.commons.digester.Rule.end(Rule.java:257)
at org.apache.commons.digester.Digester.endElement(Digester.java:1345)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1774)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2930)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.apache.commons.digester.Digester.parse(Digester.java:1990)
at com.mytest.siamon.config.ConfigManager.parseProject2(ConfigManager.java:117)
at com.mytest.siamon.config.ConfigManager.init(ConfigManager.java:147)
at com.mytest.siamon.config.ConfigManager.<init>(ConfigManager.java:40)
at com.mytest.siamon.config.ConfigManager.<init>(ConfigManager.java:45)
at com.mytest.siamon.config.ConfigManager.main(ConfigManager.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
Exception in thread "main" java.lang.NullPointerException
at org.apache.commons.digester.Digester.createSAXException(Digester.java:3363)
at org.apache.commons.digester.Digester.createSAXException(Digester.java:3389)
at org.apache.commons.digester.Digester.endElement(Digester.java:1348)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1774)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2930)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.apache.commons.digester.Digester.parse(Digester.java:1990)
at com.mytest.siamon.config.ConfigManager.parseProject2(ConfigManager.java:117)
at com.mytest.siamon.config.ConfigManager.init(ConfigManager.java:147)
at com.mytest.siamon.config.ConfigManager.<init>(ConfigManager.java:40)
at com.mytest.siamon.config.ConfigManager.<init>(ConfigManager.java:45)
at com.mytest.siamon.config.ConfigManager.main(ConfigManager.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
I go into BeanUtils source code and the place where exception generates is :
Method method = getMatchingAccessibleMethod(
object.getClass(),
methodName,
parameterTypes);
and I discovered the parameter object is null which yields the result.
any ideas?
thanks.
Kurt
At 2011-03-30 22:01:18,"Simone Tripodi" <si...@apache.org> wrote:
>Hi Kurt,
>I suggest you first creating a digester rule that helps you handling a
>generic ParaItem element:
>
>public final class ParaItemRule extends org.apache.commons.digester.Rule {
>
> @Override
> public void body(String namespace, String name, String text)
>throws Exception {
> digester.push(new ParaItem(name, text));
> }
>
>}
>
>then plug the digester rules in the following way:
>
> Digester digester = new Digester();
>
> /* take a look at
>http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>*/
> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>
> digester.addRule("Class/Parameter/Main/*", new ParaItemRule());
> digester.addSetNext("Class/Parameter/Main/*", "addMainParaItem");
>
> digester.addRule("Class/Parameter/SubText/*", new ParaItemRule());
> digester.addSetNext("Class/Parameter/SubText/*", "addSubParaItem");
>
>THT, let me know! ;)
>Simo
>
>http://people.apache.org/~simonetripodi/
>http://www.99soft.org/
>
>
>
>On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
>> Hi all:
>>
>> I want to match some unknow elements nested some parent element where some newly defined element might be added sometime.
>>
>> The sample xml is as below:
>>
>> <Class name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl" method="entry">
>> <Parameter name="comment" index="0" type="insert" table="MOCO_CODICMT">
>> <Main>
>> <DeviceType constant="true">pc</DeviceType>
>> <CheckStatus constant="true">N</CheckStatus>
>> <ValidCheck constant="true">Yes</ValidCheck>
>> <CheckDesc></CheckDesc>
>> <UserId>userid</UserId>
>> <PrimaryKey1>cmtno</PrimaryKey1>
>> </Main>
>> <SubText>
>> <!--<Type constant="true/false"></Type>-->
>> <!--<Title>title</Title>-->
>> <Content>contents</Content>
>> <WriterId>writeid</WriterId>
>> <WriterUserName>userid</WriterUserName>
>> </SubText>
>> </Parameter>
>> </Class>
>>
>>
>> The elements under <Main> and <SubText> are all variable someday, both name and amounts. So I define a ParaItem pojo to wrap sub elements of the two element. That means I want to create a Paraitem for every sub element ,whatever its name is, then add the object to paraent object Parameter's list property saving all the related Paraitem.
>>
>> The Paraitem source code is following:
>>
>> public class ParaItem {
>> private String elemName;
>> private String argPropNameOrValue;
>> private boolean isConstant;
>> public ParaItem() {
>> }
>> public ParaItem(String elemName, String argPropNameOrValue, boolean constant) {
>> this.elemName = elemName;
>> this.argPropNameOrValue = argPropNameOrValue;
>> isConstant = constant;
>> }
>> public ParaItem(String elemName, String argPropNameOrValue) {
>> this.elemName = elemName;
>> this.argPropNameOrValue = argPropNameOrValue;
>> }
>> public String getElemName() {
>> return elemName;
>> }
>> public String getArgPropNameOrValue() {
>> return argPropNameOrValue;
>> }
>> public boolean isConstant() {
>> return isConstant;
>> }
>> }
>>
>>
>>
>> The Parameter source code is below:
>> public class Parameter {
>> private String index;
>> private String operType;
>> private String dataType;
>> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>> public Parameter(String operType) {
>> this.operType = operType;
>> }
>> public List<ParaItem> getListMainFiled() {
>> return listMainFiled;
>> }
>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>> this.listMainFiled = listMainFiled;
>> }
>> public List<ParaItem> getListSubField() {
>> return listSubField;
>> }
>> public void setListSubField(List<ParaItem> listSubField) {
>> this.listSubField = listSubField;
>> }
>> public String getIndex() {
>> return index;
>> }
>> public void setIndex(String index) {
>> this.index = index;
>> }
>> public String getOperType() {
>> return operType;
>> }
>> public void setOperType(String operType) {
>> this.operType = operType;
>> }
>> public String getDataType() {
>> return dataType;
>> }
>> public void setDataType(String dataType) {
>> this.dataType = dataType;
>> }
>> public void addMainParaItem(ParaItem pi){
>> getListMainFiled().add(pi);
>> }
>> public void addSubParaItem(ParaItem pi){
>> getListSubField().add(pi);
>> }
>> }
>>
>> I suppose regex rule is the best way to make it , but googling and the javadoc doesn't tell me how to set a regex expression for a pattern. No way out, who knows the solotion , thanks.
>>
>>
>> Kurt
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>For additional commands, e-mail: user-help@commons.apache.org
>
Re: Re: Re: [digester]How to use SimpleRegexMatcher?
Posted by Simone Tripodi <si...@apache.org>.
Hi Kurt,
OK now I got it :D The Digester instance supports only 1 Rules
instance at time, you can't use 2 or more Rules instance at the same
time.
BTW all Rules implementations should support the basic matching
pattern, so the Regexp one I suggested you would work as well for your
case.
Even if I joined the team on 2010, yes, I'm one of Digester
committers; there's a new version of Digester in Sandbox[1] I
developed, I would really appreciate if you users can provide
feedbacks, contains then same features but quite different APIs,
thanks in advance :)
Have a nice day,
Simo
[1] http://commons.apache.org/sandbox/digester3/
http://people.apache.org/~simonetripodi/
http://www.99soft.org/
On Fri, Apr 1, 2011 at 1:08 PM, Kurt Xu <fx...@163.com> wrote:
> Ok, let me change the asking way. How to set RulesA and RulesB at the same
> time?
>
> btw:r u the digester developer? :)
>
> Thanks.
>
>
>
> On Fri, 01 Apr 2011 18:48:09 +0800, Simone Tripodi
> <si...@apache.org> wrote:
>
>> Sorry, I lost you, didn't understand :( Please provide me a more
>> concrete sample, please
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Fri, Apr 1, 2011 at 9:37 AM, Kurt Xu <fx...@163.com> wrote:
>>>
>>> Hi Simone:
>>> Maybe you got me wrong. Two RulesX needs calling setRules twice ,right?
>>> How
>>> could be just set once.
>>>
>>> Thanks
>>>
>>> Kurt
>>>
>>>
>>> On Fri, 01 Apr 2011 15:27:09 +0800, Simone Tripodi
>>> <si...@apache.org> wrote:
>>>
>>>> Hi Kurt
>>>> Ok now I get it: exactly, calling Digetser.setRules() you loose all
>>>> the already set Rules instance, so it would be better if you call it
>>>> first.
>>>> HTH,
>>>> Simo
>>>>
>>>> http://people.apache.org/~simonetripodi/
>>>> http://www.99soft.org/
>>>>
>>>>
>>>>
>>>> On Fri, Apr 1, 2011 at 9:14 AM, Kurt Xu <fx...@163.com> wrote:
>>>>>
>>>>> Hi Simone:
>>>>> I mean if I implement rules ,say RulesA, RulesB , then setRules(new
>>>>> RulesA()),setRules(new RulesB()).
>>>>> the second calling setRules would reset the first call, right?
>>>>>
>>>>>
>>>>> Thanks.
>>>>>
>>>>> Kurt
>>>>>
>>>>>
>>>>>
>>>>>> Hi Kurt,
>>>>>> glad you fixed your issue, but honestly I didn't understand your last
>>>>>> question, apologizes :( Can you provide more details/some sample?
>>>>>> Thanks!
>>>>>> Simo
>>>>>>
>>>>>> PS nope, I'm from Italy :P
>>>>>>
>>>>>> http://people.apache.org/~simonetripodi/
>>>>>> http://www.99soft.org/
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Fri, Apr 1, 2011 at 3:21 AM, Kurt Xu <fx...@163.com> wrote:
>>>>>>>
>>>>>>> Hi Simone:
>>>>>>>
>>>>>>> I tried by myself after emailing and resovled it . the method is the
>>>>>>> same
>>>>>>> as your reply. I have a question still though. What if I want do set
>>>>>>> two
>>>>>>> customized rule . The second setRules can reset or override the first
>>>>>>> calling, can't it?
>>>>>>>
>>>>>>> btw: why u say ni hao, r u from China?
>>>>>>>
>>>>>>> Many thanks.
>>>>>>>
>>>>>>>
>>>>>>> Kurt
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Thu, 31 Mar 2011 14:39:59 +0800, Simone Tripodi
>>>>>>> <si...@apache.org> wrote:
>>>>>>>
>>>>>>>> Ni hao again Kurt,
>>>>>>>> just realized that the ParaItemRule implementation is incomplete,
>>>>>>>> use
>>>>>>>> the one below.
>>>>>>>> Simo
>>>>>>>>
>>>>>>>> public final class ParaItemRule extends
>>>>>>>> org.apache.commons.digester.Rule
>>>>>>>> {
>>>>>>>>
>>>>>>>> @Override
>>>>>>>> public void body(String namespace, String name, String text)
>>>>>>>> throws Exception {
>>>>>>>> digester.push(new ParaItem(name, text));
>>>>>>>> }
>>>>>>>>
>>>>>>>> @Override
>>>>>>>> public void end() throws Exception {
>>>>>>>> digester.pop();
>>>>>>>> }
>>>>>>>>
>>>>>>>> http://people.apache.org/~simonetripodi/
>>>>>>>> http://www.99soft.org/
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, Mar 31, 2011 at 8:36 AM, Simone Tripodi
>>>>>>>> <si...@apache.org> wrote:
>>>>>>>>>
>>>>>>>>> Hi Kurt,
>>>>>>>>> calling the setRules() method in the way you did, makes the Rules
>>>>>>>>> instance is reset, so you loose the already set patterns.
>>>>>>>>> modify the code in order that the setRules() method is invoked
>>>>>>>>> before
>>>>>>>>> setting patterns/rules.
>>>>>>>>> HTH,
>>>>>>>>> Simo
>>>>>>>>>
>>>>>>>>> private void parseProject2(URL url) throws IOException,
>>>>>>>>> SAXException
>>>>>>>>> {
>>>>>>>>> Digester d = new Digester();
>>>>>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>>>
>>>>>>>>> String pathFunc = "Project/Functionality";
>>>>>>>>> String pathClass = pathFunc + "/Class";
>>>>>>>>> String pathPara = pathClass + "/Parameter";
>>>>>>>>>
>>>>>>>>> d.addObjectCreate("Project", Project.class);
>>>>>>>>> d.addSetProperties("Project");
>>>>>>>>>
>>>>>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>>>>>> d.addSetProperties(pathFunc);
>>>>>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>>>>>
>>>>>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>>>>>> d.addSetProperties(pathClass);
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>>>>>
>>>>>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>>>>>
>>>>>>>>> d.parse(url);
>>>>>>>>> Project project = (Project) d.getRoot();
>>>>>>>>>
>>>>>>>>> System.out.println();
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> http://people.apache.org/~simonetripodi/
>>>>>>>>> http://www.99soft.org/
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Thu, Mar 31, 2011 at 5:44 AM, Kurt Xu <fx...@163.com>
>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Sorry Simone:
>>>>>>>>>>
>>>>>>>>>> I need to paste the full xml and java file to help u locate the
>>>>>>>>>> error,:)
>>>>>>>>>>
>>>>>>>>>> xml:
>>>>>>>>>>
>>>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>>
>>>>>>>>>> <Project name="project1">
>>>>>>>>>> <Functionality description="add comment"
>>>>>>>>>> url="http://dev.mygame.co.jp/user/register.do"
>>>>>>>>>> actionName="com.mygame.action.UserAction"
>>>>>>>>>> actionMethod="register">
>>>>>>>>>>
>>>>>>>>>> <Class name="com.mygame.bo.UserBOImpl" method="register">
>>>>>>>>>> <Parameter name="user" index="0" type="insert">
>>>>>>>>>> <Main>
>>>>>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>>>>>> <CheckDesc>first check desc</CheckDesc>
>>>>>>>>>> <UserId>userid</UserId>
>>>>>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>>>>>> </Main>
>>>>>>>>>> <SubText>
>>>>>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>>>>>> <!--<Title>title</Title>-->
>>>>>>>>>> <Content>contents</Content>
>>>>>>>>>> <WriterId>writeid</WriterId>
>>>>>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>>>>>> </SubText>
>>>>>>>>>> </Parameter>
>>>>>>>>>> <Parameter name="postVO" index="1" type="update"
>>>>>>>>>> table="MOCO_CODICMT">
>>>>>>>>>> .....
>>>>>>>>>> </Parameter>
>>>>>>>>>> </Class>
>>>>>>>>>> </Functionality>
>>>>>>>>>> </Project>
>>>>>>>>>>
>>>>>>>>>> java code:
>>>>>>>>>>
>>>>>>>>>> parser method:
>>>>>>>>>> private void parseProject2(URL url) throws IOException,
>>>>>>>>>> SAXException
>>>>>>>>>> {
>>>>>>>>>> Digester d = new Digester();
>>>>>>>>>>
>>>>>>>>>> String pathFunc = "Project/Functionality";
>>>>>>>>>> String pathClass = pathFunc + "/Class";
>>>>>>>>>> String pathPara = pathClass + "/Parameter";
>>>>>>>>>>
>>>>>>>>>> d.addObjectCreate("Project", Project.class);
>>>>>>>>>> d.addSetProperties("Project");
>>>>>>>>>>
>>>>>>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>>>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>>>>>>> d.addSetProperties(pathFunc);
>>>>>>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>>>>>>
>>>>>>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>>>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>>>>>>> d.addSetProperties(pathClass);
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>>>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>>>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>>>>>>
>>>>>>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>>>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>>>>>>
>>>>>>>>>> d.parse(url);
>>>>>>>>>> Project project = (Project) d.getRoot();
>>>>>>>>>>
>>>>>>>>>> System.out.println();
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> ClassItem.java ---a pojo for saving all its Parameters
>>>>>>>>>>
>>>>>>>>>> public class ClassItem {
>>>>>>>>>>
>>>>>>>>>> private String method;
>>>>>>>>>> private String name;
>>>>>>>>>> private String handler="";
>>>>>>>>>> private List<Parameter> parameters;
>>>>>>>>>>
>>>>>>>>>> public ClassItem(String name, String method, List<Parameter>
>>>>>>>>>> parameters)
>>>>>>>>>> {
>>>>>>>>>> this.name = name;
>>>>>>>>>> this.method = method;
>>>>>>>>>> this.parameters = parameters;
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> public ClassItem() {
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> public String getMethod() {
>>>>>>>>>> return method;
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> public void setMethod(String method) {
>>>>>>>>>> this.method = method;
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> public String getName() {
>>>>>>>>>> return name;
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> public void setName(String name) {
>>>>>>>>>> this.name = name;
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> public void addParameter(Parameter parameter){
>>>>>>>>>> System.out.println("add parameter");
>>>>>>>>>> if (parameters==null){
>>>>>>>>>> parameters=new ArrayList<Parameter>();
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> parameters.add(parameter);
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> public List<Parameter> getParameters() {
>>>>>>>>>> return parameters;
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> public String getHandler() {
>>>>>>>>>> return handler;
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> public void setHandler(String handler) {
>>>>>>>>>> this.handler = handler;
>>>>>>>>>> }
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> thanks.
>>>>>>>>>>
>>>>>>>>>> Kurt
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>> Hi Kurt,
>>>>>>>>>>> I suggest you first creating a digester rule that helps you
>>>>>>>>>>> handling
>>>>>>>>>>> a
>>>>>>>>>>> generic ParaItem element:
>>>>>>>>>>>
>>>>>>>>>>> public final class ParaItemRule extends
>>>>>>>>>>> org.apache.commons.digester.Rule {
>>>>>>>>>>>
>>>>>>>>>>> @Override
>>>>>>>>>>> public void body(String namespace, String name, String text)
>>>>>>>>>>> throws Exception {
>>>>>>>>>>> digester.push(new ParaItem(name, text));
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> then plug the digester rules in the following way:
>>>>>>>>>>>
>>>>>>>>>>> Digester digester = new Digester();
>>>>>>>>>>>
>>>>>>>>>>> /* take a look at
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>>>>>>>>>>> */
>>>>>>>>>>> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>>>>>
>>>>>>>>>>> digester.addRule("Class/Parameter/Main/*", new
>>>>>>>>>>> ParaItemRule());
>>>>>>>>>>> digester.addSetNext("Class/Parameter/Main/*",
>>>>>>>>>>> "addMainParaItem");
>>>>>>>>>>>
>>>>>>>>>>> digester.addRule("Class/Parameter/SubText/*", new
>>>>>>>>>>> ParaItemRule());
>>>>>>>>>>> digester.addSetNext("Class/Parameter/SubText/*",
>>>>>>>>>>> "addSubParaItem");
>>>>>>>>>>>
>>>>>>>>>>> THT, let me know! ;)
>>>>>>>>>>> Simo
>>>>>>>>>>>
>>>>>>>>>>> http://people.apache.org/~simonetripodi/
>>>>>>>>>>> http://www.99soft.org/
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com>
>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Hi all:
>>>>>>>>>>>>
>>>>>>>>>>>> I want to match some unknow elements nested some parent element
>>>>>>>>>>>> where
>>>>>>>>>>>> some newly defined element might be added sometime.
>>>>>>>>>>>>
>>>>>>>>>>>> The sample xml is as below:
>>>>>>>>>>>>
>>>>>>>>>>>> <Class
>>>>>>>>>>>>
>>>>>>>>>>>> name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>>>>>>>>>>>> method="entry">
>>>>>>>>>>>> <Parameter name="comment" index="0" type="insert"
>>>>>>>>>>>> table="MOCO_CODICMT">
>>>>>>>>>>>> <Main>
>>>>>>>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>>>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>>>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>>>>>>>> <CheckDesc></CheckDesc>
>>>>>>>>>>>> <UserId>userid</UserId>
>>>>>>>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>>>>>>>> </Main>
>>>>>>>>>>>> <SubText>
>>>>>>>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>>>>>>>> <!--<Title>title</Title>-->
>>>>>>>>>>>> <Content>contents</Content>
>>>>>>>>>>>> <WriterId>writeid</WriterId>
>>>>>>>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>>>>>>>> </SubText>
>>>>>>>>>>>> </Parameter>
>>>>>>>>>>>> </Class>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> The elements under <Main> and <SubText> are all variable
>>>>>>>>>>>> someday,
>>>>>>>>>>>> both
>>>>>>>>>>>> name and amounts. So I define a ParaItem pojo to wrap sub
>>>>>>>>>>>> elements
>>>>>>>>>>>> of
>>>>>>>>>>>> the
>>>>>>>>>>>> two element. That means I want to create a Paraitem for every
>>>>>>>>>>>> sub
>>>>>>>>>>>> element
>>>>>>>>>>>> ,whatever its name is, then add the object to paraent object
>>>>>>>>>>>> Parameter's
>>>>>>>>>>>> list property saving all the related Paraitem.
>>>>>>>>>>>>
>>>>>>>>>>>> The Paraitem source code is following:
>>>>>>>>>>>>
>>>>>>>>>>>> public class ParaItem {
>>>>>>>>>>>> private String elemName;
>>>>>>>>>>>> private String argPropNameOrValue;
>>>>>>>>>>>> private boolean isConstant;
>>>>>>>>>>>> public ParaItem() {
>>>>>>>>>>>> }
>>>>>>>>>>>> public ParaItem(String elemName, String argPropNameOrValue,
>>>>>>>>>>>> boolean
>>>>>>>>>>>> constant) {
>>>>>>>>>>>> this.elemName = elemName;
>>>>>>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>>>>>>> isConstant = constant;
>>>>>>>>>>>> }
>>>>>>>>>>>> public ParaItem(String elemName, String argPropNameOrValue) {
>>>>>>>>>>>> this.elemName = elemName;
>>>>>>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>>>>>>> }
>>>>>>>>>>>> public String getElemName() {
>>>>>>>>>>>> return elemName;
>>>>>>>>>>>> }
>>>>>>>>>>>> public String getArgPropNameOrValue() {
>>>>>>>>>>>> return argPropNameOrValue;
>>>>>>>>>>>> }
>>>>>>>>>>>> public boolean isConstant() {
>>>>>>>>>>>> return isConstant;
>>>>>>>>>>>> }
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> The Parameter source code is below:
>>>>>>>>>>>> public class Parameter {
>>>>>>>>>>>> private String index;
>>>>>>>>>>>> private String operType;
>>>>>>>>>>>> private String dataType;
>>>>>>>>>>>> private List<ParaItem> listMainFiled =new
>>>>>>>>>>>> ArrayList<ParaItem>();
>>>>>>>>>>>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>>>>>>>>>>>> public Parameter(String operType) {
>>>>>>>>>>>> this.operType = operType;
>>>>>>>>>>>> }
>>>>>>>>>>>> public List<ParaItem> getListMainFiled() {
>>>>>>>>>>>> return listMainFiled;
>>>>>>>>>>>> }
>>>>>>>>>>>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>>>>>>>>>>>> this.listMainFiled = listMainFiled;
>>>>>>>>>>>> }
>>>>>>>>>>>> public List<ParaItem> getListSubField() {
>>>>>>>>>>>> return listSubField;
>>>>>>>>>>>> }
>>>>>>>>>>>> public void setListSubField(List<ParaItem> listSubField) {
>>>>>>>>>>>> this.listSubField = listSubField;
>>>>>>>>>>>> }
>>>>>>>>>>>> public String getIndex() {
>>>>>>>>>>>> return index;
>>>>>>>>>>>> }
>>>>>>>>>>>> public void setIndex(String index) {
>>>>>>>>>>>> this.index = index;
>>>>>>>>>>>> }
>>>>>>>>>>>> public String getOperType() {
>>>>>>>>>>>> return operType;
>>>>>>>>>>>> }
>>>>>>>>>>>> public void setOperType(String operType) {
>>>>>>>>>>>> this.operType = operType;
>>>>>>>>>>>> }
>>>>>>>>>>>> public String getDataType() {
>>>>>>>>>>>> return dataType;
>>>>>>>>>>>> }
>>>>>>>>>>>> public void setDataType(String dataType) {
>>>>>>>>>>>> this.dataType = dataType;
>>>>>>>>>>>> }
>>>>>>>>>>>> public void addMainParaItem(ParaItem pi){
>>>>>>>>>>>> getListMainFiled().add(pi);
>>>>>>>>>>>> }
>>>>>>>>>>>> public void addSubParaItem(ParaItem pi){
>>>>>>>>>>>> getListSubField().add(pi);
>>>>>>>>>>>> }
>>>>>>>>>>>> }
>>>>>>>>>>>>
>>>>>>>>>>>> I suppose regex rule is the best way to make it , but googling
>>>>>>>>>>>> and
>>>>>>>>>>>> the
>>>>>>>>>>>> javadoc doesn't tell me how to set a regex expression for a
>>>>>>>>>>>> pattern.
>>>>>>>>>>>> No way
>>>>>>>>>>>> out, who knows the solotion , thanks.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Kurt
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> Using Opera's revolutionary email client:
>>>>>>>>>> http://www.opera.com/mail/
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>
>>>
>>> --
>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> --
> Using Opera's revolutionary email client: http://www.opera.com/mail/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: Re: Re: [digester]How to use SimpleRegexMatcher?
Posted by Kurt Xu <fx...@163.com>.
Ok, let me change the asking way. How to set RulesA and RulesB at the same
time?
btw:r u the digester developer? :)
Thanks.
On Fri, 01 Apr 2011 18:48:09 +0800, Simone Tripodi
<si...@apache.org> wrote:
> Sorry, I lost you, didn't understand :( Please provide me a more
> concrete sample, please
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Fri, Apr 1, 2011 at 9:37 AM, Kurt Xu <fx...@163.com> wrote:
>> Hi Simone:
>> Maybe you got me wrong. Two RulesX needs calling setRules twice
>> ,right? How
>> could be just set once.
>>
>> Thanks
>>
>> Kurt
>>
>>
>> On Fri, 01 Apr 2011 15:27:09 +0800, Simone Tripodi
>> <si...@apache.org> wrote:
>>
>>> Hi Kurt
>>> Ok now I get it: exactly, calling Digetser.setRules() you loose all
>>> the already set Rules instance, so it would be better if you call it
>>> first.
>>> HTH,
>>> Simo
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Fri, Apr 1, 2011 at 9:14 AM, Kurt Xu <fx...@163.com> wrote:
>>>>
>>>> Hi Simone:
>>>> I mean if I implement rules ,say RulesA, RulesB , then setRules(new
>>>> RulesA()),setRules(new RulesB()).
>>>> the second calling setRules would reset the first call, right?
>>>>
>>>>
>>>> Thanks.
>>>>
>>>> Kurt
>>>>
>>>>
>>>>
>>>>> Hi Kurt,
>>>>> glad you fixed your issue, but honestly I didn't understand your last
>>>>> question, apologizes :( Can you provide more details/some sample?
>>>>> Thanks!
>>>>> Simo
>>>>>
>>>>> PS nope, I'm from Italy :P
>>>>>
>>>>> http://people.apache.org/~simonetripodi/
>>>>> http://www.99soft.org/
>>>>>
>>>>>
>>>>>
>>>>> On Fri, Apr 1, 2011 at 3:21 AM, Kurt Xu <fx...@163.com> wrote:
>>>>>>
>>>>>> Hi Simone:
>>>>>>
>>>>>> I tried by myself after emailing and resovled it . the method is
>>>>>> the
>>>>>> same
>>>>>> as your reply. I have a question still though. What if I want do
>>>>>> set
>>>>>> two
>>>>>> customized rule . The second setRules can reset or override the
>>>>>> first
>>>>>> calling, can't it?
>>>>>>
>>>>>> btw: why u say ni hao, r u from China?
>>>>>>
>>>>>> Many thanks.
>>>>>>
>>>>>>
>>>>>> Kurt
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Thu, 31 Mar 2011 14:39:59 +0800, Simone Tripodi
>>>>>> <si...@apache.org> wrote:
>>>>>>
>>>>>>> Ni hao again Kurt,
>>>>>>> just realized that the ParaItemRule implementation is incomplete,
>>>>>>> use
>>>>>>> the one below.
>>>>>>> Simo
>>>>>>>
>>>>>>> public final class ParaItemRule extends
>>>>>>> org.apache.commons.digester.Rule
>>>>>>> {
>>>>>>>
>>>>>>> @Override
>>>>>>> public void body(String namespace, String name, String text)
>>>>>>> throws Exception {
>>>>>>> digester.push(new ParaItem(name, text));
>>>>>>> }
>>>>>>>
>>>>>>> @Override
>>>>>>> public void end() throws Exception {
>>>>>>> digester.pop();
>>>>>>> }
>>>>>>>
>>>>>>> http://people.apache.org/~simonetripodi/
>>>>>>> http://www.99soft.org/
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Thu, Mar 31, 2011 at 8:36 AM, Simone Tripodi
>>>>>>> <si...@apache.org> wrote:
>>>>>>>>
>>>>>>>> Hi Kurt,
>>>>>>>> calling the setRules() method in the way you did, makes the Rules
>>>>>>>> instance is reset, so you loose the already set patterns.
>>>>>>>> modify the code in order that the setRules() method is invoked
>>>>>>>> before
>>>>>>>> setting patterns/rules.
>>>>>>>> HTH,
>>>>>>>> Simo
>>>>>>>>
>>>>>>>> private void parseProject2(URL url) throws IOException,
>>>>>>>> SAXException
>>>>>>>> {
>>>>>>>> Digester d = new Digester();
>>>>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>>
>>>>>>>> String pathFunc = "Project/Functionality";
>>>>>>>> String pathClass = pathFunc + "/Class";
>>>>>>>> String pathPara = pathClass + "/Parameter";
>>>>>>>>
>>>>>>>> d.addObjectCreate("Project", Project.class);
>>>>>>>> d.addSetProperties("Project");
>>>>>>>>
>>>>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>>>>> d.addSetProperties(pathFunc);
>>>>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>>>>
>>>>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>>>>> d.addSetProperties(pathClass);
>>>>>>>>
>>>>>>>>
>>>>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>>>>
>>>>>>>>
>>>>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>>>>
>>>>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>>>>
>>>>>>>> d.parse(url);
>>>>>>>> Project project = (Project) d.getRoot();
>>>>>>>>
>>>>>>>> System.out.println();
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>> http://people.apache.org/~simonetripodi/
>>>>>>>> http://www.99soft.org/
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, Mar 31, 2011 at 5:44 AM, Kurt Xu <fx...@163.com>
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Sorry Simone:
>>>>>>>>>
>>>>>>>>> I need to paste the full xml and java file to help u locate the
>>>>>>>>> error,:)
>>>>>>>>>
>>>>>>>>> xml:
>>>>>>>>>
>>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>>
>>>>>>>>> <Project name="project1">
>>>>>>>>> <Functionality description="add comment"
>>>>>>>>> url="http://dev.mygame.co.jp/user/register.do"
>>>>>>>>> actionName="com.mygame.action.UserAction"
>>>>>>>>> actionMethod="register">
>>>>>>>>>
>>>>>>>>> <Class name="com.mygame.bo.UserBOImpl" method="register">
>>>>>>>>> <Parameter name="user" index="0" type="insert">
>>>>>>>>> <Main>
>>>>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>>>>> <CheckDesc>first check desc</CheckDesc>
>>>>>>>>> <UserId>userid</UserId>
>>>>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>>>>> </Main>
>>>>>>>>> <SubText>
>>>>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>>>>> <!--<Title>title</Title>-->
>>>>>>>>> <Content>contents</Content>
>>>>>>>>> <WriterId>writeid</WriterId>
>>>>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>>>>> </SubText>
>>>>>>>>> </Parameter>
>>>>>>>>> <Parameter name="postVO" index="1" type="update"
>>>>>>>>> table="MOCO_CODICMT">
>>>>>>>>> .....
>>>>>>>>> </Parameter>
>>>>>>>>> </Class>
>>>>>>>>> </Functionality>
>>>>>>>>> </Project>
>>>>>>>>>
>>>>>>>>> java code:
>>>>>>>>>
>>>>>>>>> parser method:
>>>>>>>>> private void parseProject2(URL url) throws IOException,
>>>>>>>>> SAXException
>>>>>>>>> {
>>>>>>>>> Digester d = new Digester();
>>>>>>>>>
>>>>>>>>> String pathFunc = "Project/Functionality";
>>>>>>>>> String pathClass = pathFunc + "/Class";
>>>>>>>>> String pathPara = pathClass + "/Parameter";
>>>>>>>>>
>>>>>>>>> d.addObjectCreate("Project", Project.class);
>>>>>>>>> d.addSetProperties("Project");
>>>>>>>>>
>>>>>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>>>>>> d.addSetProperties(pathFunc);
>>>>>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>>>>>
>>>>>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>>>>>> d.addSetProperties(pathClass);
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>>>>>
>>>>>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>>>>>
>>>>>>>>> d.parse(url);
>>>>>>>>> Project project = (Project) d.getRoot();
>>>>>>>>>
>>>>>>>>> System.out.println();
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> ClassItem.java ---a pojo for saving all its Parameters
>>>>>>>>>
>>>>>>>>> public class ClassItem {
>>>>>>>>>
>>>>>>>>> private String method;
>>>>>>>>> private String name;
>>>>>>>>> private String handler="";
>>>>>>>>> private List<Parameter> parameters;
>>>>>>>>>
>>>>>>>>> public ClassItem(String name, String method, List<Parameter>
>>>>>>>>> parameters)
>>>>>>>>> {
>>>>>>>>> this.name = name;
>>>>>>>>> this.method = method;
>>>>>>>>> this.parameters = parameters;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public ClassItem() {
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public String getMethod() {
>>>>>>>>> return method;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public void setMethod(String method) {
>>>>>>>>> this.method = method;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public String getName() {
>>>>>>>>> return name;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public void setName(String name) {
>>>>>>>>> this.name = name;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public void addParameter(Parameter parameter){
>>>>>>>>> System.out.println("add parameter");
>>>>>>>>> if (parameters==null){
>>>>>>>>> parameters=new ArrayList<Parameter>();
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> parameters.add(parameter);
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public List<Parameter> getParameters() {
>>>>>>>>> return parameters;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public String getHandler() {
>>>>>>>>> return handler;
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> public void setHandler(String handler) {
>>>>>>>>> this.handler = handler;
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> thanks.
>>>>>>>>>
>>>>>>>>> Kurt
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> Hi Kurt,
>>>>>>>>>> I suggest you first creating a digester rule that helps you
>>>>>>>>>> handling
>>>>>>>>>> a
>>>>>>>>>> generic ParaItem element:
>>>>>>>>>>
>>>>>>>>>> public final class ParaItemRule extends
>>>>>>>>>> org.apache.commons.digester.Rule {
>>>>>>>>>>
>>>>>>>>>> @Override
>>>>>>>>>> public void body(String namespace, String name, String text)
>>>>>>>>>> throws Exception {
>>>>>>>>>> digester.push(new ParaItem(name, text));
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> then plug the digester rules in the following way:
>>>>>>>>>>
>>>>>>>>>> Digester digester = new Digester();
>>>>>>>>>>
>>>>>>>>>> /* take a look at
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>>>>>>>>>> */
>>>>>>>>>> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>>>>
>>>>>>>>>> digester.addRule("Class/Parameter/Main/*", new
>>>>>>>>>> ParaItemRule());
>>>>>>>>>> digester.addSetNext("Class/Parameter/Main/*",
>>>>>>>>>> "addMainParaItem");
>>>>>>>>>>
>>>>>>>>>> digester.addRule("Class/Parameter/SubText/*", new
>>>>>>>>>> ParaItemRule());
>>>>>>>>>> digester.addSetNext("Class/Parameter/SubText/*",
>>>>>>>>>> "addSubParaItem");
>>>>>>>>>>
>>>>>>>>>> THT, let me know! ;)
>>>>>>>>>> Simo
>>>>>>>>>>
>>>>>>>>>> http://people.apache.org/~simonetripodi/
>>>>>>>>>> http://www.99soft.org/
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com>
>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hi all:
>>>>>>>>>>>
>>>>>>>>>>> I want to match some unknow elements nested some parent element
>>>>>>>>>>> where
>>>>>>>>>>> some newly defined element might be added sometime.
>>>>>>>>>>>
>>>>>>>>>>> The sample xml is as below:
>>>>>>>>>>>
>>>>>>>>>>> <Class
>>>>>>>>>>> name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>>>>>>>>>>> method="entry">
>>>>>>>>>>> <Parameter name="comment" index="0" type="insert"
>>>>>>>>>>> table="MOCO_CODICMT">
>>>>>>>>>>> <Main>
>>>>>>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>>>>>>> <CheckDesc></CheckDesc>
>>>>>>>>>>> <UserId>userid</UserId>
>>>>>>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>>>>>>> </Main>
>>>>>>>>>>> <SubText>
>>>>>>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>>>>>>> <!--<Title>title</Title>-->
>>>>>>>>>>> <Content>contents</Content>
>>>>>>>>>>> <WriterId>writeid</WriterId>
>>>>>>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>>>>>>> </SubText>
>>>>>>>>>>> </Parameter>
>>>>>>>>>>> </Class>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> The elements under <Main> and <SubText> are all variable
>>>>>>>>>>> someday,
>>>>>>>>>>> both
>>>>>>>>>>> name and amounts. So I define a ParaItem pojo to wrap sub
>>>>>>>>>>> elements
>>>>>>>>>>> of
>>>>>>>>>>> the
>>>>>>>>>>> two element. That means I want to create a Paraitem for every
>>>>>>>>>>> sub
>>>>>>>>>>> element
>>>>>>>>>>> ,whatever its name is, then add the object to paraent object
>>>>>>>>>>> Parameter's
>>>>>>>>>>> list property saving all the related Paraitem.
>>>>>>>>>>>
>>>>>>>>>>> The Paraitem source code is following:
>>>>>>>>>>>
>>>>>>>>>>> public class ParaItem {
>>>>>>>>>>> private String elemName;
>>>>>>>>>>> private String argPropNameOrValue;
>>>>>>>>>>> private boolean isConstant;
>>>>>>>>>>> public ParaItem() {
>>>>>>>>>>> }
>>>>>>>>>>> public ParaItem(String elemName, String argPropNameOrValue,
>>>>>>>>>>> boolean
>>>>>>>>>>> constant) {
>>>>>>>>>>> this.elemName = elemName;
>>>>>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>>>>>> isConstant = constant;
>>>>>>>>>>> }
>>>>>>>>>>> public ParaItem(String elemName, String argPropNameOrValue) {
>>>>>>>>>>> this.elemName = elemName;
>>>>>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>>>>>> }
>>>>>>>>>>> public String getElemName() {
>>>>>>>>>>> return elemName;
>>>>>>>>>>> }
>>>>>>>>>>> public String getArgPropNameOrValue() {
>>>>>>>>>>> return argPropNameOrValue;
>>>>>>>>>>> }
>>>>>>>>>>> public boolean isConstant() {
>>>>>>>>>>> return isConstant;
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> The Parameter source code is below:
>>>>>>>>>>> public class Parameter {
>>>>>>>>>>> private String index;
>>>>>>>>>>> private String operType;
>>>>>>>>>>> private String dataType;
>>>>>>>>>>> private List<ParaItem> listMainFiled =new
>>>>>>>>>>> ArrayList<ParaItem>();
>>>>>>>>>>> private List<ParaItem> listSubField =new
>>>>>>>>>>> ArrayList<ParaItem>();
>>>>>>>>>>> public Parameter(String operType) {
>>>>>>>>>>> this.operType = operType;
>>>>>>>>>>> }
>>>>>>>>>>> public List<ParaItem> getListMainFiled() {
>>>>>>>>>>> return listMainFiled;
>>>>>>>>>>> }
>>>>>>>>>>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>>>>>>>>>>> this.listMainFiled = listMainFiled;
>>>>>>>>>>> }
>>>>>>>>>>> public List<ParaItem> getListSubField() {
>>>>>>>>>>> return listSubField;
>>>>>>>>>>> }
>>>>>>>>>>> public void setListSubField(List<ParaItem> listSubField) {
>>>>>>>>>>> this.listSubField = listSubField;
>>>>>>>>>>> }
>>>>>>>>>>> public String getIndex() {
>>>>>>>>>>> return index;
>>>>>>>>>>> }
>>>>>>>>>>> public void setIndex(String index) {
>>>>>>>>>>> this.index = index;
>>>>>>>>>>> }
>>>>>>>>>>> public String getOperType() {
>>>>>>>>>>> return operType;
>>>>>>>>>>> }
>>>>>>>>>>> public void setOperType(String operType) {
>>>>>>>>>>> this.operType = operType;
>>>>>>>>>>> }
>>>>>>>>>>> public String getDataType() {
>>>>>>>>>>> return dataType;
>>>>>>>>>>> }
>>>>>>>>>>> public void setDataType(String dataType) {
>>>>>>>>>>> this.dataType = dataType;
>>>>>>>>>>> }
>>>>>>>>>>> public void addMainParaItem(ParaItem pi){
>>>>>>>>>>> getListMainFiled().add(pi);
>>>>>>>>>>> }
>>>>>>>>>>> public void addSubParaItem(ParaItem pi){
>>>>>>>>>>> getListSubField().add(pi);
>>>>>>>>>>> }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>> I suppose regex rule is the best way to make it , but googling
>>>>>>>>>>> and
>>>>>>>>>>> the
>>>>>>>>>>> javadoc doesn't tell me how to set a regex expression for a
>>>>>>>>>>> pattern.
>>>>>>>>>>> No way
>>>>>>>>>>> out, who knows the solotion , thanks.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Kurt
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Using Opera's revolutionary email client:
>>>>>>>>> http://www.opera.com/mail/
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>
>>>>
>>>>
>>>> --
>>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>
>>
>> --
>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: Re: Re: [digester]How to use SimpleRegexMatcher?
Posted by Simone Tripodi <si...@apache.org>.
Sorry, I lost you, didn't understand :( Please provide me a more
concrete sample, please
Simo
http://people.apache.org/~simonetripodi/
http://www.99soft.org/
On Fri, Apr 1, 2011 at 9:37 AM, Kurt Xu <fx...@163.com> wrote:
> Hi Simone:
> Maybe you got me wrong. Two RulesX needs calling setRules twice ,right? How
> could be just set once.
>
> Thanks
>
> Kurt
>
>
> On Fri, 01 Apr 2011 15:27:09 +0800, Simone Tripodi
> <si...@apache.org> wrote:
>
>> Hi Kurt
>> Ok now I get it: exactly, calling Digetser.setRules() you loose all
>> the already set Rules instance, so it would be better if you call it
>> first.
>> HTH,
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Fri, Apr 1, 2011 at 9:14 AM, Kurt Xu <fx...@163.com> wrote:
>>>
>>> Hi Simone:
>>> I mean if I implement rules ,say RulesA, RulesB , then setRules(new
>>> RulesA()),setRules(new RulesB()).
>>> the second calling setRules would reset the first call, right?
>>>
>>>
>>> Thanks.
>>>
>>> Kurt
>>>
>>>
>>>
>>>> Hi Kurt,
>>>> glad you fixed your issue, but honestly I didn't understand your last
>>>> question, apologizes :( Can you provide more details/some sample?
>>>> Thanks!
>>>> Simo
>>>>
>>>> PS nope, I'm from Italy :P
>>>>
>>>> http://people.apache.org/~simonetripodi/
>>>> http://www.99soft.org/
>>>>
>>>>
>>>>
>>>> On Fri, Apr 1, 2011 at 3:21 AM, Kurt Xu <fx...@163.com> wrote:
>>>>>
>>>>> Hi Simone:
>>>>>
>>>>> I tried by myself after emailing and resovled it . the method is the
>>>>> same
>>>>> as your reply. I have a question still though. What if I want do set
>>>>> two
>>>>> customized rule . The second setRules can reset or override the first
>>>>> calling, can't it?
>>>>>
>>>>> btw: why u say ni hao, r u from China?
>>>>>
>>>>> Many thanks.
>>>>>
>>>>>
>>>>> Kurt
>>>>>
>>>>>
>>>>>
>>>>> On Thu, 31 Mar 2011 14:39:59 +0800, Simone Tripodi
>>>>> <si...@apache.org> wrote:
>>>>>
>>>>>> Ni hao again Kurt,
>>>>>> just realized that the ParaItemRule implementation is incomplete, use
>>>>>> the one below.
>>>>>> Simo
>>>>>>
>>>>>> public final class ParaItemRule extends
>>>>>> org.apache.commons.digester.Rule
>>>>>> {
>>>>>>
>>>>>> @Override
>>>>>> public void body(String namespace, String name, String text)
>>>>>> throws Exception {
>>>>>> digester.push(new ParaItem(name, text));
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>> public void end() throws Exception {
>>>>>> digester.pop();
>>>>>> }
>>>>>>
>>>>>> http://people.apache.org/~simonetripodi/
>>>>>> http://www.99soft.org/
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Thu, Mar 31, 2011 at 8:36 AM, Simone Tripodi
>>>>>> <si...@apache.org> wrote:
>>>>>>>
>>>>>>> Hi Kurt,
>>>>>>> calling the setRules() method in the way you did, makes the Rules
>>>>>>> instance is reset, so you loose the already set patterns.
>>>>>>> modify the code in order that the setRules() method is invoked before
>>>>>>> setting patterns/rules.
>>>>>>> HTH,
>>>>>>> Simo
>>>>>>>
>>>>>>> private void parseProject2(URL url) throws IOException, SAXException
>>>>>>> {
>>>>>>> Digester d = new Digester();
>>>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>
>>>>>>> String pathFunc = "Project/Functionality";
>>>>>>> String pathClass = pathFunc + "/Class";
>>>>>>> String pathPara = pathClass + "/Parameter";
>>>>>>>
>>>>>>> d.addObjectCreate("Project", Project.class);
>>>>>>> d.addSetProperties("Project");
>>>>>>>
>>>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>>>> d.addSetProperties(pathFunc);
>>>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>>>
>>>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>>>> d.addSetProperties(pathClass);
>>>>>>>
>>>>>>>
>>>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>>>
>>>>>>>
>>>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>>>
>>>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>>>
>>>>>>> d.parse(url);
>>>>>>> Project project = (Project) d.getRoot();
>>>>>>>
>>>>>>> System.out.println();
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> http://people.apache.org/~simonetripodi/
>>>>>>> http://www.99soft.org/
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Thu, Mar 31, 2011 at 5:44 AM, Kurt Xu <fx...@163.com> wrote:
>>>>>>>>
>>>>>>>> Sorry Simone:
>>>>>>>>
>>>>>>>> I need to paste the full xml and java file to help u locate the
>>>>>>>> error,:)
>>>>>>>>
>>>>>>>> xml:
>>>>>>>>
>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>
>>>>>>>> <Project name="project1">
>>>>>>>> <Functionality description="add comment"
>>>>>>>> url="http://dev.mygame.co.jp/user/register.do"
>>>>>>>> actionName="com.mygame.action.UserAction"
>>>>>>>> actionMethod="register">
>>>>>>>>
>>>>>>>> <Class name="com.mygame.bo.UserBOImpl" method="register">
>>>>>>>> <Parameter name="user" index="0" type="insert">
>>>>>>>> <Main>
>>>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>>>> <CheckDesc>first check desc</CheckDesc>
>>>>>>>> <UserId>userid</UserId>
>>>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>>>> </Main>
>>>>>>>> <SubText>
>>>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>>>> <!--<Title>title</Title>-->
>>>>>>>> <Content>contents</Content>
>>>>>>>> <WriterId>writeid</WriterId>
>>>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>>>> </SubText>
>>>>>>>> </Parameter>
>>>>>>>> <Parameter name="postVO" index="1" type="update"
>>>>>>>> table="MOCO_CODICMT">
>>>>>>>> .....
>>>>>>>> </Parameter>
>>>>>>>> </Class>
>>>>>>>> </Functionality>
>>>>>>>> </Project>
>>>>>>>>
>>>>>>>> java code:
>>>>>>>>
>>>>>>>> parser method:
>>>>>>>> private void parseProject2(URL url) throws IOException, SAXException
>>>>>>>> {
>>>>>>>> Digester d = new Digester();
>>>>>>>>
>>>>>>>> String pathFunc = "Project/Functionality";
>>>>>>>> String pathClass = pathFunc + "/Class";
>>>>>>>> String pathPara = pathClass + "/Parameter";
>>>>>>>>
>>>>>>>> d.addObjectCreate("Project", Project.class);
>>>>>>>> d.addSetProperties("Project");
>>>>>>>>
>>>>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>>>>> d.addSetProperties(pathFunc);
>>>>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>>>>
>>>>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>>>>> d.addSetProperties(pathClass);
>>>>>>>>
>>>>>>>>
>>>>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>>>>
>>>>>>>>
>>>>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>>
>>>>>>>>
>>>>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>>>>
>>>>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>>>>
>>>>>>>> d.parse(url);
>>>>>>>> Project project = (Project) d.getRoot();
>>>>>>>>
>>>>>>>> System.out.println();
>>>>>>>> }
>>>>>>>>
>>>>>>>> ClassItem.java ---a pojo for saving all its Parameters
>>>>>>>>
>>>>>>>> public class ClassItem {
>>>>>>>>
>>>>>>>> private String method;
>>>>>>>> private String name;
>>>>>>>> private String handler="";
>>>>>>>> private List<Parameter> parameters;
>>>>>>>>
>>>>>>>> public ClassItem(String name, String method, List<Parameter>
>>>>>>>> parameters)
>>>>>>>> {
>>>>>>>> this.name = name;
>>>>>>>> this.method = method;
>>>>>>>> this.parameters = parameters;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public ClassItem() {
>>>>>>>> }
>>>>>>>>
>>>>>>>> public String getMethod() {
>>>>>>>> return method;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public void setMethod(String method) {
>>>>>>>> this.method = method;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public String getName() {
>>>>>>>> return name;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public void setName(String name) {
>>>>>>>> this.name = name;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public void addParameter(Parameter parameter){
>>>>>>>> System.out.println("add parameter");
>>>>>>>> if (parameters==null){
>>>>>>>> parameters=new ArrayList<Parameter>();
>>>>>>>> }
>>>>>>>>
>>>>>>>> parameters.add(parameter);
>>>>>>>> }
>>>>>>>>
>>>>>>>> public List<Parameter> getParameters() {
>>>>>>>> return parameters;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public String getHandler() {
>>>>>>>> return handler;
>>>>>>>> }
>>>>>>>>
>>>>>>>> public void setHandler(String handler) {
>>>>>>>> this.handler = handler;
>>>>>>>> }
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> thanks.
>>>>>>>>
>>>>>>>> Kurt
>>>>>>>>
>>>>>>>>
>>>>>>>>> Hi Kurt,
>>>>>>>>> I suggest you first creating a digester rule that helps you
>>>>>>>>> handling
>>>>>>>>> a
>>>>>>>>> generic ParaItem element:
>>>>>>>>>
>>>>>>>>> public final class ParaItemRule extends
>>>>>>>>> org.apache.commons.digester.Rule {
>>>>>>>>>
>>>>>>>>> @Override
>>>>>>>>> public void body(String namespace, String name, String text)
>>>>>>>>> throws Exception {
>>>>>>>>> digester.push(new ParaItem(name, text));
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> then plug the digester rules in the following way:
>>>>>>>>>
>>>>>>>>> Digester digester = new Digester();
>>>>>>>>>
>>>>>>>>> /* take a look at
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>>>>>>>>> */
>>>>>>>>> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>>>
>>>>>>>>> digester.addRule("Class/Parameter/Main/*", new ParaItemRule());
>>>>>>>>> digester.addSetNext("Class/Parameter/Main/*",
>>>>>>>>> "addMainParaItem");
>>>>>>>>>
>>>>>>>>> digester.addRule("Class/Parameter/SubText/*", new
>>>>>>>>> ParaItemRule());
>>>>>>>>> digester.addSetNext("Class/Parameter/SubText/*",
>>>>>>>>> "addSubParaItem");
>>>>>>>>>
>>>>>>>>> THT, let me know! ;)
>>>>>>>>> Simo
>>>>>>>>>
>>>>>>>>> http://people.apache.org/~simonetripodi/
>>>>>>>>> http://www.99soft.org/
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>> Hi all:
>>>>>>>>>>
>>>>>>>>>> I want to match some unknow elements nested some parent element
>>>>>>>>>> where
>>>>>>>>>> some newly defined element might be added sometime.
>>>>>>>>>>
>>>>>>>>>> The sample xml is as below:
>>>>>>>>>>
>>>>>>>>>> <Class
>>>>>>>>>> name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>>>>>>>>>> method="entry">
>>>>>>>>>> <Parameter name="comment" index="0" type="insert"
>>>>>>>>>> table="MOCO_CODICMT">
>>>>>>>>>> <Main>
>>>>>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>>>>>> <CheckDesc></CheckDesc>
>>>>>>>>>> <UserId>userid</UserId>
>>>>>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>>>>>> </Main>
>>>>>>>>>> <SubText>
>>>>>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>>>>>> <!--<Title>title</Title>-->
>>>>>>>>>> <Content>contents</Content>
>>>>>>>>>> <WriterId>writeid</WriterId>
>>>>>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>>>>>> </SubText>
>>>>>>>>>> </Parameter>
>>>>>>>>>> </Class>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> The elements under <Main> and <SubText> are all variable someday,
>>>>>>>>>> both
>>>>>>>>>> name and amounts. So I define a ParaItem pojo to wrap sub elements
>>>>>>>>>> of
>>>>>>>>>> the
>>>>>>>>>> two element. That means I want to create a Paraitem for every sub
>>>>>>>>>> element
>>>>>>>>>> ,whatever its name is, then add the object to paraent object
>>>>>>>>>> Parameter's
>>>>>>>>>> list property saving all the related Paraitem.
>>>>>>>>>>
>>>>>>>>>> The Paraitem source code is following:
>>>>>>>>>>
>>>>>>>>>> public class ParaItem {
>>>>>>>>>> private String elemName;
>>>>>>>>>> private String argPropNameOrValue;
>>>>>>>>>> private boolean isConstant;
>>>>>>>>>> public ParaItem() {
>>>>>>>>>> }
>>>>>>>>>> public ParaItem(String elemName, String argPropNameOrValue,
>>>>>>>>>> boolean
>>>>>>>>>> constant) {
>>>>>>>>>> this.elemName = elemName;
>>>>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>>>>> isConstant = constant;
>>>>>>>>>> }
>>>>>>>>>> public ParaItem(String elemName, String argPropNameOrValue) {
>>>>>>>>>> this.elemName = elemName;
>>>>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>>>>> }
>>>>>>>>>> public String getElemName() {
>>>>>>>>>> return elemName;
>>>>>>>>>> }
>>>>>>>>>> public String getArgPropNameOrValue() {
>>>>>>>>>> return argPropNameOrValue;
>>>>>>>>>> }
>>>>>>>>>> public boolean isConstant() {
>>>>>>>>>> return isConstant;
>>>>>>>>>> }
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> The Parameter source code is below:
>>>>>>>>>> public class Parameter {
>>>>>>>>>> private String index;
>>>>>>>>>> private String operType;
>>>>>>>>>> private String dataType;
>>>>>>>>>> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
>>>>>>>>>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>>>>>>>>>> public Parameter(String operType) {
>>>>>>>>>> this.operType = operType;
>>>>>>>>>> }
>>>>>>>>>> public List<ParaItem> getListMainFiled() {
>>>>>>>>>> return listMainFiled;
>>>>>>>>>> }
>>>>>>>>>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>>>>>>>>>> this.listMainFiled = listMainFiled;
>>>>>>>>>> }
>>>>>>>>>> public List<ParaItem> getListSubField() {
>>>>>>>>>> return listSubField;
>>>>>>>>>> }
>>>>>>>>>> public void setListSubField(List<ParaItem> listSubField) {
>>>>>>>>>> this.listSubField = listSubField;
>>>>>>>>>> }
>>>>>>>>>> public String getIndex() {
>>>>>>>>>> return index;
>>>>>>>>>> }
>>>>>>>>>> public void setIndex(String index) {
>>>>>>>>>> this.index = index;
>>>>>>>>>> }
>>>>>>>>>> public String getOperType() {
>>>>>>>>>> return operType;
>>>>>>>>>> }
>>>>>>>>>> public void setOperType(String operType) {
>>>>>>>>>> this.operType = operType;
>>>>>>>>>> }
>>>>>>>>>> public String getDataType() {
>>>>>>>>>> return dataType;
>>>>>>>>>> }
>>>>>>>>>> public void setDataType(String dataType) {
>>>>>>>>>> this.dataType = dataType;
>>>>>>>>>> }
>>>>>>>>>> public void addMainParaItem(ParaItem pi){
>>>>>>>>>> getListMainFiled().add(pi);
>>>>>>>>>> }
>>>>>>>>>> public void addSubParaItem(ParaItem pi){
>>>>>>>>>> getListSubField().add(pi);
>>>>>>>>>> }
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> I suppose regex rule is the best way to make it , but googling
>>>>>>>>>> and
>>>>>>>>>> the
>>>>>>>>>> javadoc doesn't tell me how to set a regex expression for a
>>>>>>>>>> pattern.
>>>>>>>>>> No way
>>>>>>>>>> out, who knows the solotion , thanks.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Kurt
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ---------------------------------------------------------------------
>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>
>>>
>>> --
>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> --
> Using Opera's revolutionary email client: http://www.opera.com/mail/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: Re: Re: [digester]How to use SimpleRegexMatcher?
Posted by Kurt Xu <fx...@163.com>.
Hi Simone:
Maybe you got me wrong. Two RulesX needs calling setRules twice ,right?
How could be just set once.
Thanks
Kurt
On Fri, 01 Apr 2011 15:27:09 +0800, Simone Tripodi
<si...@apache.org> wrote:
> Hi Kurt
> Ok now I get it: exactly, calling Digetser.setRules() you loose all
> the already set Rules instance, so it would be better if you call it
> first.
> HTH,
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Fri, Apr 1, 2011 at 9:14 AM, Kurt Xu <fx...@163.com> wrote:
>> Hi Simone:
>> I mean if I implement rules ,say RulesA, RulesB , then setRules(new
>> RulesA()),setRules(new RulesB()).
>> the second calling setRules would reset the first call, right?
>>
>>
>> Thanks.
>>
>> Kurt
>>
>>
>>
>>> Hi Kurt,
>>> glad you fixed your issue, but honestly I didn't understand your last
>>> question, apologizes :( Can you provide more details/some sample?
>>> Thanks!
>>> Simo
>>>
>>> PS nope, I'm from Italy :P
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Fri, Apr 1, 2011 at 3:21 AM, Kurt Xu <fx...@163.com> wrote:
>>>>
>>>> Hi Simone:
>>>>
>>>> I tried by myself after emailing and resovled it . the method is the
>>>> same
>>>> as your reply. I have a question still though. What if I want do set
>>>> two
>>>> customized rule . The second setRules can reset or override the first
>>>> calling, can't it?
>>>>
>>>> btw: why u say ni hao, r u from China?
>>>>
>>>> Many thanks.
>>>>
>>>>
>>>> Kurt
>>>>
>>>>
>>>>
>>>> On Thu, 31 Mar 2011 14:39:59 +0800, Simone Tripodi
>>>> <si...@apache.org> wrote:
>>>>
>>>>> Ni hao again Kurt,
>>>>> just realized that the ParaItemRule implementation is incomplete, use
>>>>> the one below.
>>>>> Simo
>>>>>
>>>>> public final class ParaItemRule extends
>>>>> org.apache.commons.digester.Rule
>>>>> {
>>>>>
>>>>> @Override
>>>>> public void body(String namespace, String name, String text)
>>>>> throws Exception {
>>>>> digester.push(new ParaItem(name, text));
>>>>> }
>>>>>
>>>>> @Override
>>>>> public void end() throws Exception {
>>>>> digester.pop();
>>>>> }
>>>>>
>>>>> http://people.apache.org/~simonetripodi/
>>>>> http://www.99soft.org/
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Mar 31, 2011 at 8:36 AM, Simone Tripodi
>>>>> <si...@apache.org> wrote:
>>>>>>
>>>>>> Hi Kurt,
>>>>>> calling the setRules() method in the way you did, makes the Rules
>>>>>> instance is reset, so you loose the already set patterns.
>>>>>> modify the code in order that the setRules() method is invoked
>>>>>> before
>>>>>> setting patterns/rules.
>>>>>> HTH,
>>>>>> Simo
>>>>>>
>>>>>> private void parseProject2(URL url) throws IOException,
>>>>>> SAXException {
>>>>>> Digester d = new Digester();
>>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>
>>>>>> String pathFunc = "Project/Functionality";
>>>>>> String pathClass = pathFunc + "/Class";
>>>>>> String pathPara = pathClass + "/Parameter";
>>>>>>
>>>>>> d.addObjectCreate("Project", Project.class);
>>>>>> d.addSetProperties("Project");
>>>>>>
>>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>>> d.addSetProperties(pathFunc);
>>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>>
>>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>>> d.addSetProperties(pathClass);
>>>>>>
>>>>>>
>>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>>
>>>>>>
>>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>>
>>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>>
>>>>>> d.parse(url);
>>>>>> Project project = (Project) d.getRoot();
>>>>>>
>>>>>> System.out.println();
>>>>>> }
>>>>>>
>>>>>>
>>>>>> http://people.apache.org/~simonetripodi/
>>>>>> http://www.99soft.org/
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Thu, Mar 31, 2011 at 5:44 AM, Kurt Xu <fx...@163.com> wrote:
>>>>>>>
>>>>>>> Sorry Simone:
>>>>>>>
>>>>>>> I need to paste the full xml and java file to help u locate the
>>>>>>> error,:)
>>>>>>>
>>>>>>> xml:
>>>>>>>
>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>
>>>>>>> <Project name="project1">
>>>>>>> <Functionality description="add comment"
>>>>>>> url="http://dev.mygame.co.jp/user/register.do"
>>>>>>> actionName="com.mygame.action.UserAction"
>>>>>>> actionMethod="register">
>>>>>>>
>>>>>>> <Class name="com.mygame.bo.UserBOImpl" method="register">
>>>>>>> <Parameter name="user" index="0" type="insert">
>>>>>>> <Main>
>>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>>> <CheckDesc>first check desc</CheckDesc>
>>>>>>> <UserId>userid</UserId>
>>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>>> </Main>
>>>>>>> <SubText>
>>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>>> <!--<Title>title</Title>-->
>>>>>>> <Content>contents</Content>
>>>>>>> <WriterId>writeid</WriterId>
>>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>>> </SubText>
>>>>>>> </Parameter>
>>>>>>> <Parameter name="postVO" index="1" type="update"
>>>>>>> table="MOCO_CODICMT">
>>>>>>> .....
>>>>>>> </Parameter>
>>>>>>> </Class>
>>>>>>> </Functionality>
>>>>>>> </Project>
>>>>>>>
>>>>>>> java code:
>>>>>>>
>>>>>>> parser method:
>>>>>>> private void parseProject2(URL url) throws IOException,
>>>>>>> SAXException {
>>>>>>> Digester d = new Digester();
>>>>>>>
>>>>>>> String pathFunc = "Project/Functionality";
>>>>>>> String pathClass = pathFunc + "/Class";
>>>>>>> String pathPara = pathClass + "/Parameter";
>>>>>>>
>>>>>>> d.addObjectCreate("Project", Project.class);
>>>>>>> d.addSetProperties("Project");
>>>>>>>
>>>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>>>> d.addSetProperties(pathFunc);
>>>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>>>
>>>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>>>> d.addSetProperties(pathClass);
>>>>>>>
>>>>>>>
>>>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>>>
>>>>>>>
>>>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>
>>>>>>>
>>>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>>>
>>>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>>>
>>>>>>> d.parse(url);
>>>>>>> Project project = (Project) d.getRoot();
>>>>>>>
>>>>>>> System.out.println();
>>>>>>> }
>>>>>>>
>>>>>>> ClassItem.java ---a pojo for saving all its Parameters
>>>>>>>
>>>>>>> public class ClassItem {
>>>>>>>
>>>>>>> private String method;
>>>>>>> private String name;
>>>>>>> private String handler="";
>>>>>>> private List<Parameter> parameters;
>>>>>>>
>>>>>>> public ClassItem(String name, String method, List<Parameter>
>>>>>>> parameters)
>>>>>>> {
>>>>>>> this.name = name;
>>>>>>> this.method = method;
>>>>>>> this.parameters = parameters;
>>>>>>> }
>>>>>>>
>>>>>>> public ClassItem() {
>>>>>>> }
>>>>>>>
>>>>>>> public String getMethod() {
>>>>>>> return method;
>>>>>>> }
>>>>>>>
>>>>>>> public void setMethod(String method) {
>>>>>>> this.method = method;
>>>>>>> }
>>>>>>>
>>>>>>> public String getName() {
>>>>>>> return name;
>>>>>>> }
>>>>>>>
>>>>>>> public void setName(String name) {
>>>>>>> this.name = name;
>>>>>>> }
>>>>>>>
>>>>>>> public void addParameter(Parameter parameter){
>>>>>>> System.out.println("add parameter");
>>>>>>> if (parameters==null){
>>>>>>> parameters=new ArrayList<Parameter>();
>>>>>>> }
>>>>>>>
>>>>>>> parameters.add(parameter);
>>>>>>> }
>>>>>>>
>>>>>>> public List<Parameter> getParameters() {
>>>>>>> return parameters;
>>>>>>> }
>>>>>>>
>>>>>>> public String getHandler() {
>>>>>>> return handler;
>>>>>>> }
>>>>>>>
>>>>>>> public void setHandler(String handler) {
>>>>>>> this.handler = handler;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> thanks.
>>>>>>>
>>>>>>> Kurt
>>>>>>>
>>>>>>>
>>>>>>>> Hi Kurt,
>>>>>>>> I suggest you first creating a digester rule that helps you
>>>>>>>> handling
>>>>>>>> a
>>>>>>>> generic ParaItem element:
>>>>>>>>
>>>>>>>> public final class ParaItemRule extends
>>>>>>>> org.apache.commons.digester.Rule {
>>>>>>>>
>>>>>>>> @Override
>>>>>>>> public void body(String namespace, String name, String text)
>>>>>>>> throws Exception {
>>>>>>>> digester.push(new ParaItem(name, text));
>>>>>>>> }
>>>>>>>>
>>>>>>>> }
>>>>>>>>
>>>>>>>> then plug the digester rules in the following way:
>>>>>>>>
>>>>>>>> Digester digester = new Digester();
>>>>>>>>
>>>>>>>> /* take a look at
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>>>>>>>> */
>>>>>>>> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>>
>>>>>>>> digester.addRule("Class/Parameter/Main/*", new
>>>>>>>> ParaItemRule());
>>>>>>>> digester.addSetNext("Class/Parameter/Main/*",
>>>>>>>> "addMainParaItem");
>>>>>>>>
>>>>>>>> digester.addRule("Class/Parameter/SubText/*", new
>>>>>>>> ParaItemRule());
>>>>>>>> digester.addSetNext("Class/Parameter/SubText/*",
>>>>>>>> "addSubParaItem");
>>>>>>>>
>>>>>>>> THT, let me know! ;)
>>>>>>>> Simo
>>>>>>>>
>>>>>>>> http://people.apache.org/~simonetripodi/
>>>>>>>> http://www.99soft.org/
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>> Hi all:
>>>>>>>>>
>>>>>>>>> I want to match some unknow elements nested some parent element
>>>>>>>>> where
>>>>>>>>> some newly defined element might be added sometime.
>>>>>>>>>
>>>>>>>>> The sample xml is as below:
>>>>>>>>>
>>>>>>>>> <Class
>>>>>>>>> name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>>>>>>>>> method="entry">
>>>>>>>>> <Parameter name="comment" index="0" type="insert"
>>>>>>>>> table="MOCO_CODICMT">
>>>>>>>>> <Main>
>>>>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>>>>> <CheckDesc></CheckDesc>
>>>>>>>>> <UserId>userid</UserId>
>>>>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>>>>> </Main>
>>>>>>>>> <SubText>
>>>>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>>>>> <!--<Title>title</Title>-->
>>>>>>>>> <Content>contents</Content>
>>>>>>>>> <WriterId>writeid</WriterId>
>>>>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>>>>> </SubText>
>>>>>>>>> </Parameter>
>>>>>>>>> </Class>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> The elements under <Main> and <SubText> are all variable
>>>>>>>>> someday,
>>>>>>>>> both
>>>>>>>>> name and amounts. So I define a ParaItem pojo to wrap sub
>>>>>>>>> elements
>>>>>>>>> of
>>>>>>>>> the
>>>>>>>>> two element. That means I want to create a Paraitem for every
>>>>>>>>> sub
>>>>>>>>> element
>>>>>>>>> ,whatever its name is, then add the object to paraent object
>>>>>>>>> Parameter's
>>>>>>>>> list property saving all the related Paraitem.
>>>>>>>>>
>>>>>>>>> The Paraitem source code is following:
>>>>>>>>>
>>>>>>>>> public class ParaItem {
>>>>>>>>> private String elemName;
>>>>>>>>> private String argPropNameOrValue;
>>>>>>>>> private boolean isConstant;
>>>>>>>>> public ParaItem() {
>>>>>>>>> }
>>>>>>>>> public ParaItem(String elemName, String argPropNameOrValue,
>>>>>>>>> boolean
>>>>>>>>> constant) {
>>>>>>>>> this.elemName = elemName;
>>>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>>>> isConstant = constant;
>>>>>>>>> }
>>>>>>>>> public ParaItem(String elemName, String argPropNameOrValue) {
>>>>>>>>> this.elemName = elemName;
>>>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>>>> }
>>>>>>>>> public String getElemName() {
>>>>>>>>> return elemName;
>>>>>>>>> }
>>>>>>>>> public String getArgPropNameOrValue() {
>>>>>>>>> return argPropNameOrValue;
>>>>>>>>> }
>>>>>>>>> public boolean isConstant() {
>>>>>>>>> return isConstant;
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> The Parameter source code is below:
>>>>>>>>> public class Parameter {
>>>>>>>>> private String index;
>>>>>>>>> private String operType;
>>>>>>>>> private String dataType;
>>>>>>>>> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
>>>>>>>>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>>>>>>>>> public Parameter(String operType) {
>>>>>>>>> this.operType = operType;
>>>>>>>>> }
>>>>>>>>> public List<ParaItem> getListMainFiled() {
>>>>>>>>> return listMainFiled;
>>>>>>>>> }
>>>>>>>>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>>>>>>>>> this.listMainFiled = listMainFiled;
>>>>>>>>> }
>>>>>>>>> public List<ParaItem> getListSubField() {
>>>>>>>>> return listSubField;
>>>>>>>>> }
>>>>>>>>> public void setListSubField(List<ParaItem> listSubField) {
>>>>>>>>> this.listSubField = listSubField;
>>>>>>>>> }
>>>>>>>>> public String getIndex() {
>>>>>>>>> return index;
>>>>>>>>> }
>>>>>>>>> public void setIndex(String index) {
>>>>>>>>> this.index = index;
>>>>>>>>> }
>>>>>>>>> public String getOperType() {
>>>>>>>>> return operType;
>>>>>>>>> }
>>>>>>>>> public void setOperType(String operType) {
>>>>>>>>> this.operType = operType;
>>>>>>>>> }
>>>>>>>>> public String getDataType() {
>>>>>>>>> return dataType;
>>>>>>>>> }
>>>>>>>>> public void setDataType(String dataType) {
>>>>>>>>> this.dataType = dataType;
>>>>>>>>> }
>>>>>>>>> public void addMainParaItem(ParaItem pi){
>>>>>>>>> getListMainFiled().add(pi);
>>>>>>>>> }
>>>>>>>>> public void addSubParaItem(ParaItem pi){
>>>>>>>>> getListSubField().add(pi);
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> I suppose regex rule is the best way to make it , but googling
>>>>>>>>> and
>>>>>>>>> the
>>>>>>>>> javadoc doesn't tell me how to set a regex expression for a
>>>>>>>>> pattern.
>>>>>>>>> No way
>>>>>>>>> out, who knows the solotion , thanks.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Kurt
>>>>>>>>>
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Using Opera's revolutionary email client:
>>>>>>> http://www.opera.com/mail/
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>
>>>>
>>>>
>>>> --
>>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>
>>
>> --
>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: Re: Re: [digester]How to use SimpleRegexMatcher?
Posted by Simone Tripodi <si...@apache.org>.
Hi Kurt
Ok now I get it: exactly, calling Digetser.setRules() you loose all
the already set Rules instance, so it would be better if you call it
first.
HTH,
Simo
http://people.apache.org/~simonetripodi/
http://www.99soft.org/
On Fri, Apr 1, 2011 at 9:14 AM, Kurt Xu <fx...@163.com> wrote:
> Hi Simone:
> I mean if I implement rules ,say RulesA, RulesB , then setRules(new
> RulesA()),setRules(new RulesB()).
> the second calling setRules would reset the first call, right?
>
>
> Thanks.
>
> Kurt
>
>
>
>> Hi Kurt,
>> glad you fixed your issue, but honestly I didn't understand your last
>> question, apologizes :( Can you provide more details/some sample?
>> Thanks!
>> Simo
>>
>> PS nope, I'm from Italy :P
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Fri, Apr 1, 2011 at 3:21 AM, Kurt Xu <fx...@163.com> wrote:
>>>
>>> Hi Simone:
>>>
>>> I tried by myself after emailing and resovled it . the method is the
>>> same
>>> as your reply. I have a question still though. What if I want do set two
>>> customized rule . The second setRules can reset or override the first
>>> calling, can't it?
>>>
>>> btw: why u say ni hao, r u from China?
>>>
>>> Many thanks.
>>>
>>>
>>> Kurt
>>>
>>>
>>>
>>> On Thu, 31 Mar 2011 14:39:59 +0800, Simone Tripodi
>>> <si...@apache.org> wrote:
>>>
>>>> Ni hao again Kurt,
>>>> just realized that the ParaItemRule implementation is incomplete, use
>>>> the one below.
>>>> Simo
>>>>
>>>> public final class ParaItemRule extends org.apache.commons.digester.Rule
>>>> {
>>>>
>>>> @Override
>>>> public void body(String namespace, String name, String text)
>>>> throws Exception {
>>>> digester.push(new ParaItem(name, text));
>>>> }
>>>>
>>>> @Override
>>>> public void end() throws Exception {
>>>> digester.pop();
>>>> }
>>>>
>>>> http://people.apache.org/~simonetripodi/
>>>> http://www.99soft.org/
>>>>
>>>>
>>>>
>>>> On Thu, Mar 31, 2011 at 8:36 AM, Simone Tripodi
>>>> <si...@apache.org> wrote:
>>>>>
>>>>> Hi Kurt,
>>>>> calling the setRules() method in the way you did, makes the Rules
>>>>> instance is reset, so you loose the already set patterns.
>>>>> modify the code in order that the setRules() method is invoked before
>>>>> setting patterns/rules.
>>>>> HTH,
>>>>> Simo
>>>>>
>>>>> private void parseProject2(URL url) throws IOException, SAXException {
>>>>> Digester d = new Digester();
>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>
>>>>> String pathFunc = "Project/Functionality";
>>>>> String pathClass = pathFunc + "/Class";
>>>>> String pathPara = pathClass + "/Parameter";
>>>>>
>>>>> d.addObjectCreate("Project", Project.class);
>>>>> d.addSetProperties("Project");
>>>>>
>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>> d.addSetProperties(pathFunc);
>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>
>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>> d.addSetProperties(pathClass);
>>>>>
>>>>>
>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>
>>>>>
>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>
>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>
>>>>> d.parse(url);
>>>>> Project project = (Project) d.getRoot();
>>>>>
>>>>> System.out.println();
>>>>> }
>>>>>
>>>>>
>>>>> http://people.apache.org/~simonetripodi/
>>>>> http://www.99soft.org/
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Mar 31, 2011 at 5:44 AM, Kurt Xu <fx...@163.com> wrote:
>>>>>>
>>>>>> Sorry Simone:
>>>>>>
>>>>>> I need to paste the full xml and java file to help u locate the
>>>>>> error,:)
>>>>>>
>>>>>> xml:
>>>>>>
>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>
>>>>>> <Project name="project1">
>>>>>> <Functionality description="add comment"
>>>>>> url="http://dev.mygame.co.jp/user/register.do"
>>>>>> actionName="com.mygame.action.UserAction"
>>>>>> actionMethod="register">
>>>>>>
>>>>>> <Class name="com.mygame.bo.UserBOImpl" method="register">
>>>>>> <Parameter name="user" index="0" type="insert">
>>>>>> <Main>
>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>> <CheckDesc>first check desc</CheckDesc>
>>>>>> <UserId>userid</UserId>
>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>> </Main>
>>>>>> <SubText>
>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>> <!--<Title>title</Title>-->
>>>>>> <Content>contents</Content>
>>>>>> <WriterId>writeid</WriterId>
>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>> </SubText>
>>>>>> </Parameter>
>>>>>> <Parameter name="postVO" index="1" type="update"
>>>>>> table="MOCO_CODICMT">
>>>>>> .....
>>>>>> </Parameter>
>>>>>> </Class>
>>>>>> </Functionality>
>>>>>> </Project>
>>>>>>
>>>>>> java code:
>>>>>>
>>>>>> parser method:
>>>>>> private void parseProject2(URL url) throws IOException, SAXException {
>>>>>> Digester d = new Digester();
>>>>>>
>>>>>> String pathFunc = "Project/Functionality";
>>>>>> String pathClass = pathFunc + "/Class";
>>>>>> String pathPara = pathClass + "/Parameter";
>>>>>>
>>>>>> d.addObjectCreate("Project", Project.class);
>>>>>> d.addSetProperties("Project");
>>>>>>
>>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>>> d.addSetProperties(pathFunc);
>>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>>
>>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>>> d.addSetProperties(pathClass);
>>>>>>
>>>>>>
>>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>>
>>>>>>
>>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>
>>>>>>
>>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>>
>>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>>
>>>>>> d.parse(url);
>>>>>> Project project = (Project) d.getRoot();
>>>>>>
>>>>>> System.out.println();
>>>>>> }
>>>>>>
>>>>>> ClassItem.java ---a pojo for saving all its Parameters
>>>>>>
>>>>>> public class ClassItem {
>>>>>>
>>>>>> private String method;
>>>>>> private String name;
>>>>>> private String handler="";
>>>>>> private List<Parameter> parameters;
>>>>>>
>>>>>> public ClassItem(String name, String method, List<Parameter>
>>>>>> parameters)
>>>>>> {
>>>>>> this.name = name;
>>>>>> this.method = method;
>>>>>> this.parameters = parameters;
>>>>>> }
>>>>>>
>>>>>> public ClassItem() {
>>>>>> }
>>>>>>
>>>>>> public String getMethod() {
>>>>>> return method;
>>>>>> }
>>>>>>
>>>>>> public void setMethod(String method) {
>>>>>> this.method = method;
>>>>>> }
>>>>>>
>>>>>> public String getName() {
>>>>>> return name;
>>>>>> }
>>>>>>
>>>>>> public void setName(String name) {
>>>>>> this.name = name;
>>>>>> }
>>>>>>
>>>>>> public void addParameter(Parameter parameter){
>>>>>> System.out.println("add parameter");
>>>>>> if (parameters==null){
>>>>>> parameters=new ArrayList<Parameter>();
>>>>>> }
>>>>>>
>>>>>> parameters.add(parameter);
>>>>>> }
>>>>>>
>>>>>> public List<Parameter> getParameters() {
>>>>>> return parameters;
>>>>>> }
>>>>>>
>>>>>> public String getHandler() {
>>>>>> return handler;
>>>>>> }
>>>>>>
>>>>>> public void setHandler(String handler) {
>>>>>> this.handler = handler;
>>>>>> }
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> thanks.
>>>>>>
>>>>>> Kurt
>>>>>>
>>>>>>
>>>>>>> Hi Kurt,
>>>>>>> I suggest you first creating a digester rule that helps you handling
>>>>>>> a
>>>>>>> generic ParaItem element:
>>>>>>>
>>>>>>> public final class ParaItemRule extends
>>>>>>> org.apache.commons.digester.Rule {
>>>>>>>
>>>>>>> @Override
>>>>>>> public void body(String namespace, String name, String text)
>>>>>>> throws Exception {
>>>>>>> digester.push(new ParaItem(name, text));
>>>>>>> }
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>> then plug the digester rules in the following way:
>>>>>>>
>>>>>>> Digester digester = new Digester();
>>>>>>>
>>>>>>> /* take a look at
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>>>>>>> */
>>>>>>> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>>
>>>>>>> digester.addRule("Class/Parameter/Main/*", new ParaItemRule());
>>>>>>> digester.addSetNext("Class/Parameter/Main/*",
>>>>>>> "addMainParaItem");
>>>>>>>
>>>>>>> digester.addRule("Class/Parameter/SubText/*", new
>>>>>>> ParaItemRule());
>>>>>>> digester.addSetNext("Class/Parameter/SubText/*",
>>>>>>> "addSubParaItem");
>>>>>>>
>>>>>>> THT, let me know! ;)
>>>>>>> Simo
>>>>>>>
>>>>>>> http://people.apache.org/~simonetripodi/
>>>>>>> http://www.99soft.org/
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
>>>>>>>>
>>>>>>>> Hi all:
>>>>>>>>
>>>>>>>> I want to match some unknow elements nested some parent element
>>>>>>>> where
>>>>>>>> some newly defined element might be added sometime.
>>>>>>>>
>>>>>>>> The sample xml is as below:
>>>>>>>>
>>>>>>>> <Class
>>>>>>>> name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>>>>>>>> method="entry">
>>>>>>>> <Parameter name="comment" index="0" type="insert"
>>>>>>>> table="MOCO_CODICMT">
>>>>>>>> <Main>
>>>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>>>> <CheckDesc></CheckDesc>
>>>>>>>> <UserId>userid</UserId>
>>>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>>>> </Main>
>>>>>>>> <SubText>
>>>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>>>> <!--<Title>title</Title>-->
>>>>>>>> <Content>contents</Content>
>>>>>>>> <WriterId>writeid</WriterId>
>>>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>>>> </SubText>
>>>>>>>> </Parameter>
>>>>>>>> </Class>
>>>>>>>>
>>>>>>>>
>>>>>>>> The elements under <Main> and <SubText> are all variable someday,
>>>>>>>> both
>>>>>>>> name and amounts. So I define a ParaItem pojo to wrap sub elements
>>>>>>>> of
>>>>>>>> the
>>>>>>>> two element. That means I want to create a Paraitem for every sub
>>>>>>>> element
>>>>>>>> ,whatever its name is, then add the object to paraent object
>>>>>>>> Parameter's
>>>>>>>> list property saving all the related Paraitem.
>>>>>>>>
>>>>>>>> The Paraitem source code is following:
>>>>>>>>
>>>>>>>> public class ParaItem {
>>>>>>>> private String elemName;
>>>>>>>> private String argPropNameOrValue;
>>>>>>>> private boolean isConstant;
>>>>>>>> public ParaItem() {
>>>>>>>> }
>>>>>>>> public ParaItem(String elemName, String argPropNameOrValue,
>>>>>>>> boolean
>>>>>>>> constant) {
>>>>>>>> this.elemName = elemName;
>>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>>> isConstant = constant;
>>>>>>>> }
>>>>>>>> public ParaItem(String elemName, String argPropNameOrValue) {
>>>>>>>> this.elemName = elemName;
>>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>>> }
>>>>>>>> public String getElemName() {
>>>>>>>> return elemName;
>>>>>>>> }
>>>>>>>> public String getArgPropNameOrValue() {
>>>>>>>> return argPropNameOrValue;
>>>>>>>> }
>>>>>>>> public boolean isConstant() {
>>>>>>>> return isConstant;
>>>>>>>> }
>>>>>>>> }
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> The Parameter source code is below:
>>>>>>>> public class Parameter {
>>>>>>>> private String index;
>>>>>>>> private String operType;
>>>>>>>> private String dataType;
>>>>>>>> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
>>>>>>>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>>>>>>>> public Parameter(String operType) {
>>>>>>>> this.operType = operType;
>>>>>>>> }
>>>>>>>> public List<ParaItem> getListMainFiled() {
>>>>>>>> return listMainFiled;
>>>>>>>> }
>>>>>>>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>>>>>>>> this.listMainFiled = listMainFiled;
>>>>>>>> }
>>>>>>>> public List<ParaItem> getListSubField() {
>>>>>>>> return listSubField;
>>>>>>>> }
>>>>>>>> public void setListSubField(List<ParaItem> listSubField) {
>>>>>>>> this.listSubField = listSubField;
>>>>>>>> }
>>>>>>>> public String getIndex() {
>>>>>>>> return index;
>>>>>>>> }
>>>>>>>> public void setIndex(String index) {
>>>>>>>> this.index = index;
>>>>>>>> }
>>>>>>>> public String getOperType() {
>>>>>>>> return operType;
>>>>>>>> }
>>>>>>>> public void setOperType(String operType) {
>>>>>>>> this.operType = operType;
>>>>>>>> }
>>>>>>>> public String getDataType() {
>>>>>>>> return dataType;
>>>>>>>> }
>>>>>>>> public void setDataType(String dataType) {
>>>>>>>> this.dataType = dataType;
>>>>>>>> }
>>>>>>>> public void addMainParaItem(ParaItem pi){
>>>>>>>> getListMainFiled().add(pi);
>>>>>>>> }
>>>>>>>> public void addSubParaItem(ParaItem pi){
>>>>>>>> getListSubField().add(pi);
>>>>>>>> }
>>>>>>>> }
>>>>>>>>
>>>>>>>> I suppose regex rule is the best way to make it , but googling and
>>>>>>>> the
>>>>>>>> javadoc doesn't tell me how to set a regex expression for a pattern.
>>>>>>>> No way
>>>>>>>> out, who knows the solotion , thanks.
>>>>>>>>
>>>>>>>>
>>>>>>>> Kurt
>>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>
>>>
>>> --
>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> --
> Using Opera's revolutionary email client: http://www.opera.com/mail/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re:Re: Re: [digester]How to use SimpleRegexMatcher?
Posted by Kurt Xu <fx...@163.com>.
Hi Simone:
I mean if I implement rules ,say RulesA, RulesB , then setRules(new
RulesA()),setRules(new RulesB()).
the second calling setRules would reset the first call, right?
Thanks.
Kurt
> Hi Kurt,
> glad you fixed your issue, but honestly I didn't understand your last
> question, apologizes :( Can you provide more details/some sample?
> Thanks!
> Simo
>
> PS nope, I'm from Italy :P
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Fri, Apr 1, 2011 at 3:21 AM, Kurt Xu <fx...@163.com> wrote:
>> Hi Simone:
>>
>> I tried by myself after emailing and resovled it . the method is the
>> same
>> as your reply. I have a question still though. What if I want do set
>> two
>> customized rule . The second setRules can reset or override the first
>> calling, can't it?
>>
>> btw: why u say ni hao, r u from China?
>>
>> Many thanks.
>>
>>
>> Kurt
>>
>>
>>
>> On Thu, 31 Mar 2011 14:39:59 +0800, Simone Tripodi
>> <si...@apache.org> wrote:
>>
>>> Ni hao again Kurt,
>>> just realized that the ParaItemRule implementation is incomplete, use
>>> the one below.
>>> Simo
>>>
>>> public final class ParaItemRule extends
>>> org.apache.commons.digester.Rule {
>>>
>>> @Override
>>> public void body(String namespace, String name, String text)
>>> throws Exception {
>>> digester.push(new ParaItem(name, text));
>>> }
>>>
>>> @Override
>>> public void end() throws Exception {
>>> digester.pop();
>>> }
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Thu, Mar 31, 2011 at 8:36 AM, Simone Tripodi
>>> <si...@apache.org> wrote:
>>>>
>>>> Hi Kurt,
>>>> calling the setRules() method in the way you did, makes the Rules
>>>> instance is reset, so you loose the already set patterns.
>>>> modify the code in order that the setRules() method is invoked before
>>>> setting patterns/rules.
>>>> HTH,
>>>> Simo
>>>>
>>>> private void parseProject2(URL url) throws IOException, SAXException {
>>>> Digester d = new Digester();
>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>
>>>> String pathFunc = "Project/Functionality";
>>>> String pathClass = pathFunc + "/Class";
>>>> String pathPara = pathClass + "/Parameter";
>>>>
>>>> d.addObjectCreate("Project", Project.class);
>>>> d.addSetProperties("Project");
>>>>
>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>> d.addSetProperties(pathFunc);
>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>
>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>> d.addSetNext(pathClass, "addClassItem");
>>>> d.addSetProperties(pathClass);
>>>>
>>>>
>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>> d.addSetNext(pathPara, "addParameter");
>>>>
>>>>
>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>
>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>
>>>> d.parse(url);
>>>> Project project = (Project) d.getRoot();
>>>>
>>>> System.out.println();
>>>> }
>>>>
>>>>
>>>> http://people.apache.org/~simonetripodi/
>>>> http://www.99soft.org/
>>>>
>>>>
>>>>
>>>> On Thu, Mar 31, 2011 at 5:44 AM, Kurt Xu <fx...@163.com> wrote:
>>>>>
>>>>> Sorry Simone:
>>>>>
>>>>> I need to paste the full xml and java file to help u locate the
>>>>> error,:)
>>>>>
>>>>> xml:
>>>>>
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>
>>>>> <Project name="project1">
>>>>> <Functionality description="add comment"
>>>>> url="http://dev.mygame.co.jp/user/register.do"
>>>>> actionName="com.mygame.action.UserAction"
>>>>> actionMethod="register">
>>>>>
>>>>> <Class name="com.mygame.bo.UserBOImpl" method="register">
>>>>> <Parameter name="user" index="0" type="insert">
>>>>> <Main>
>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>> <CheckDesc>first check desc</CheckDesc>
>>>>> <UserId>userid</UserId>
>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>> </Main>
>>>>> <SubText>
>>>>> <!--<Type constant="true/false"></Type>-->
>>>>> <!--<Title>title</Title>-->
>>>>> <Content>contents</Content>
>>>>> <WriterId>writeid</WriterId>
>>>>> <WriterUserName>userid</WriterUserName>
>>>>> </SubText>
>>>>> </Parameter>
>>>>> <Parameter name="postVO" index="1" type="update"
>>>>> table="MOCO_CODICMT">
>>>>> .....
>>>>> </Parameter>
>>>>> </Class>
>>>>> </Functionality>
>>>>> </Project>
>>>>>
>>>>> java code:
>>>>>
>>>>> parser method:
>>>>> private void parseProject2(URL url) throws IOException, SAXException
>>>>> {
>>>>> Digester d = new Digester();
>>>>>
>>>>> String pathFunc = "Project/Functionality";
>>>>> String pathClass = pathFunc + "/Class";
>>>>> String pathPara = pathClass + "/Parameter";
>>>>>
>>>>> d.addObjectCreate("Project", Project.class);
>>>>> d.addSetProperties("Project");
>>>>>
>>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>>> d.addSetProperties(pathFunc);
>>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>>
>>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>>> d.addSetNext(pathClass, "addClassItem");
>>>>> d.addSetProperties(pathClass);
>>>>>
>>>>>
>>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>>> d.addSetNext(pathPara, "addParameter");
>>>>>
>>>>>
>>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>
>>>>>
>>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>>
>>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>>
>>>>> d.parse(url);
>>>>> Project project = (Project) d.getRoot();
>>>>>
>>>>> System.out.println();
>>>>> }
>>>>>
>>>>> ClassItem.java ---a pojo for saving all its Parameters
>>>>>
>>>>> public class ClassItem {
>>>>>
>>>>> private String method;
>>>>> private String name;
>>>>> private String handler="";
>>>>> private List<Parameter> parameters;
>>>>>
>>>>> public ClassItem(String name, String method, List<Parameter>
>>>>> parameters)
>>>>> {
>>>>> this.name = name;
>>>>> this.method = method;
>>>>> this.parameters = parameters;
>>>>> }
>>>>>
>>>>> public ClassItem() {
>>>>> }
>>>>>
>>>>> public String getMethod() {
>>>>> return method;
>>>>> }
>>>>>
>>>>> public void setMethod(String method) {
>>>>> this.method = method;
>>>>> }
>>>>>
>>>>> public String getName() {
>>>>> return name;
>>>>> }
>>>>>
>>>>> public void setName(String name) {
>>>>> this.name = name;
>>>>> }
>>>>>
>>>>> public void addParameter(Parameter parameter){
>>>>> System.out.println("add parameter");
>>>>> if (parameters==null){
>>>>> parameters=new ArrayList<Parameter>();
>>>>> }
>>>>>
>>>>> parameters.add(parameter);
>>>>> }
>>>>>
>>>>> public List<Parameter> getParameters() {
>>>>> return parameters;
>>>>> }
>>>>>
>>>>> public String getHandler() {
>>>>> return handler;
>>>>> }
>>>>>
>>>>> public void setHandler(String handler) {
>>>>> this.handler = handler;
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> thanks.
>>>>>
>>>>> Kurt
>>>>>
>>>>>
>>>>>> Hi Kurt,
>>>>>> I suggest you first creating a digester rule that helps you
>>>>>> handling a
>>>>>> generic ParaItem element:
>>>>>>
>>>>>> public final class ParaItemRule extends
>>>>>> org.apache.commons.digester.Rule {
>>>>>>
>>>>>> @Override
>>>>>> public void body(String namespace, String name, String text)
>>>>>> throws Exception {
>>>>>> digester.push(new ParaItem(name, text));
>>>>>> }
>>>>>>
>>>>>> }
>>>>>>
>>>>>> then plug the digester rules in the following way:
>>>>>>
>>>>>> Digester digester = new Digester();
>>>>>>
>>>>>> /* take a look at
>>>>>>
>>>>>>
>>>>>> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>>>>>> */
>>>>>> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>>
>>>>>> digester.addRule("Class/Parameter/Main/*", new
>>>>>> ParaItemRule());
>>>>>> digester.addSetNext("Class/Parameter/Main/*",
>>>>>> "addMainParaItem");
>>>>>>
>>>>>> digester.addRule("Class/Parameter/SubText/*", new
>>>>>> ParaItemRule());
>>>>>> digester.addSetNext("Class/Parameter/SubText/*",
>>>>>> "addSubParaItem");
>>>>>>
>>>>>> THT, let me know! ;)
>>>>>> Simo
>>>>>>
>>>>>> http://people.apache.org/~simonetripodi/
>>>>>> http://www.99soft.org/
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
>>>>>>>
>>>>>>> Hi all:
>>>>>>>
>>>>>>> I want to match some unknow elements nested some parent element
>>>>>>> where
>>>>>>> some newly defined element might be added sometime.
>>>>>>>
>>>>>>> The sample xml is as below:
>>>>>>>
>>>>>>> <Class
>>>>>>> name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>>>>>>> method="entry">
>>>>>>> <Parameter name="comment" index="0" type="insert"
>>>>>>> table="MOCO_CODICMT">
>>>>>>> <Main>
>>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>>> <CheckDesc></CheckDesc>
>>>>>>> <UserId>userid</UserId>
>>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>>> </Main>
>>>>>>> <SubText>
>>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>>> <!--<Title>title</Title>-->
>>>>>>> <Content>contents</Content>
>>>>>>> <WriterId>writeid</WriterId>
>>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>>> </SubText>
>>>>>>> </Parameter>
>>>>>>> </Class>
>>>>>>>
>>>>>>>
>>>>>>> The elements under <Main> and <SubText> are all variable someday,
>>>>>>> both
>>>>>>> name and amounts. So I define a ParaItem pojo to wrap sub elements
>>>>>>> of
>>>>>>> the
>>>>>>> two element. That means I want to create a Paraitem for every sub
>>>>>>> element
>>>>>>> ,whatever its name is, then add the object to paraent object
>>>>>>> Parameter's
>>>>>>> list property saving all the related Paraitem.
>>>>>>>
>>>>>>> The Paraitem source code is following:
>>>>>>>
>>>>>>> public class ParaItem {
>>>>>>> private String elemName;
>>>>>>> private String argPropNameOrValue;
>>>>>>> private boolean isConstant;
>>>>>>> public ParaItem() {
>>>>>>> }
>>>>>>> public ParaItem(String elemName, String argPropNameOrValue,
>>>>>>> boolean
>>>>>>> constant) {
>>>>>>> this.elemName = elemName;
>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>> isConstant = constant;
>>>>>>> }
>>>>>>> public ParaItem(String elemName, String argPropNameOrValue) {
>>>>>>> this.elemName = elemName;
>>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>>> }
>>>>>>> public String getElemName() {
>>>>>>> return elemName;
>>>>>>> }
>>>>>>> public String getArgPropNameOrValue() {
>>>>>>> return argPropNameOrValue;
>>>>>>> }
>>>>>>> public boolean isConstant() {
>>>>>>> return isConstant;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> The Parameter source code is below:
>>>>>>> public class Parameter {
>>>>>>> private String index;
>>>>>>> private String operType;
>>>>>>> private String dataType;
>>>>>>> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
>>>>>>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>>>>>>> public Parameter(String operType) {
>>>>>>> this.operType = operType;
>>>>>>> }
>>>>>>> public List<ParaItem> getListMainFiled() {
>>>>>>> return listMainFiled;
>>>>>>> }
>>>>>>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>>>>>>> this.listMainFiled = listMainFiled;
>>>>>>> }
>>>>>>> public List<ParaItem> getListSubField() {
>>>>>>> return listSubField;
>>>>>>> }
>>>>>>> public void setListSubField(List<ParaItem> listSubField) {
>>>>>>> this.listSubField = listSubField;
>>>>>>> }
>>>>>>> public String getIndex() {
>>>>>>> return index;
>>>>>>> }
>>>>>>> public void setIndex(String index) {
>>>>>>> this.index = index;
>>>>>>> }
>>>>>>> public String getOperType() {
>>>>>>> return operType;
>>>>>>> }
>>>>>>> public void setOperType(String operType) {
>>>>>>> this.operType = operType;
>>>>>>> }
>>>>>>> public String getDataType() {
>>>>>>> return dataType;
>>>>>>> }
>>>>>>> public void setDataType(String dataType) {
>>>>>>> this.dataType = dataType;
>>>>>>> }
>>>>>>> public void addMainParaItem(ParaItem pi){
>>>>>>> getListMainFiled().add(pi);
>>>>>>> }
>>>>>>> public void addSubParaItem(ParaItem pi){
>>>>>>> getListSubField().add(pi);
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> I suppose regex rule is the best way to make it , but googling and
>>>>>>> the
>>>>>>> javadoc doesn't tell me how to set a regex expression for a
>>>>>>> pattern.
>>>>>>> No way
>>>>>>> out, who knows the solotion , thanks.
>>>>>>>
>>>>>>>
>>>>>>> Kurt
>>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>
>>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>
>>
>> --
>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: Re: [digester]How to use SimpleRegexMatcher?
Posted by Simone Tripodi <si...@apache.org>.
Hi Kurt,
glad you fixed your issue, but honestly I didn't understand your last
question, apologizes :( Can you provide more details/some sample?
Thanks!
Simo
PS nope, I'm from Italy :P
http://people.apache.org/~simonetripodi/
http://www.99soft.org/
On Fri, Apr 1, 2011 at 3:21 AM, Kurt Xu <fx...@163.com> wrote:
> Hi Simone:
>
> I tried by myself after emailing and resovled it . the method is the same
> as your reply. I have a question still though. What if I want do set two
> customized rule . The second setRules can reset or override the first
> calling, can't it?
>
> btw: why u say ni hao, r u from China?
>
> Many thanks.
>
>
> Kurt
>
>
>
> On Thu, 31 Mar 2011 14:39:59 +0800, Simone Tripodi
> <si...@apache.org> wrote:
>
>> Ni hao again Kurt,
>> just realized that the ParaItemRule implementation is incomplete, use
>> the one below.
>> Simo
>>
>> public final class ParaItemRule extends org.apache.commons.digester.Rule {
>>
>> @Override
>> public void body(String namespace, String name, String text)
>> throws Exception {
>> digester.push(new ParaItem(name, text));
>> }
>>
>> @Override
>> public void end() throws Exception {
>> digester.pop();
>> }
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Thu, Mar 31, 2011 at 8:36 AM, Simone Tripodi
>> <si...@apache.org> wrote:
>>>
>>> Hi Kurt,
>>> calling the setRules() method in the way you did, makes the Rules
>>> instance is reset, so you loose the already set patterns.
>>> modify the code in order that the setRules() method is invoked before
>>> setting patterns/rules.
>>> HTH,
>>> Simo
>>>
>>> private void parseProject2(URL url) throws IOException, SAXException {
>>> Digester d = new Digester();
>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>
>>> String pathFunc = "Project/Functionality";
>>> String pathClass = pathFunc + "/Class";
>>> String pathPara = pathClass + "/Parameter";
>>>
>>> d.addObjectCreate("Project", Project.class);
>>> d.addSetProperties("Project");
>>>
>>> d.addObjectCreate(pathFunc, Functionality.class);
>>> d.addSetNext(pathFunc, "addFunctionality");
>>> d.addSetProperties(pathFunc);
>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>
>>> d.addObjectCreate(pathClass, ClassItem.class);
>>> d.addSetNext(pathClass, "addClassItem");
>>> d.addSetProperties(pathClass);
>>>
>>>
>>> d.addObjectCreate(pathPara, Parameter.class);
>>> d.addSetNext(pathPara, "addParameter");
>>>
>>>
>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>
>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>
>>> d.parse(url);
>>> Project project = (Project) d.getRoot();
>>>
>>> System.out.println();
>>> }
>>>
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Thu, Mar 31, 2011 at 5:44 AM, Kurt Xu <fx...@163.com> wrote:
>>>>
>>>> Sorry Simone:
>>>>
>>>> I need to paste the full xml and java file to help u locate the
>>>> error,:)
>>>>
>>>> xml:
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>
>>>> <Project name="project1">
>>>> <Functionality description="add comment"
>>>> url="http://dev.mygame.co.jp/user/register.do"
>>>> actionName="com.mygame.action.UserAction"
>>>> actionMethod="register">
>>>>
>>>> <Class name="com.mygame.bo.UserBOImpl" method="register">
>>>> <Parameter name="user" index="0" type="insert">
>>>> <Main>
>>>> <DeviceType constant="true">pc</DeviceType>
>>>> <CheckStatus constant="true">N</CheckStatus>
>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>> <CheckDesc>first check desc</CheckDesc>
>>>> <UserId>userid</UserId>
>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>> </Main>
>>>> <SubText>
>>>> <!--<Type constant="true/false"></Type>-->
>>>> <!--<Title>title</Title>-->
>>>> <Content>contents</Content>
>>>> <WriterId>writeid</WriterId>
>>>> <WriterUserName>userid</WriterUserName>
>>>> </SubText>
>>>> </Parameter>
>>>> <Parameter name="postVO" index="1" type="update"
>>>> table="MOCO_CODICMT">
>>>> .....
>>>> </Parameter>
>>>> </Class>
>>>> </Functionality>
>>>> </Project>
>>>>
>>>> java code:
>>>>
>>>> parser method:
>>>> private void parseProject2(URL url) throws IOException, SAXException {
>>>> Digester d = new Digester();
>>>>
>>>> String pathFunc = "Project/Functionality";
>>>> String pathClass = pathFunc + "/Class";
>>>> String pathPara = pathClass + "/Parameter";
>>>>
>>>> d.addObjectCreate("Project", Project.class);
>>>> d.addSetProperties("Project");
>>>>
>>>> d.addObjectCreate(pathFunc, Functionality.class);
>>>> d.addSetNext(pathFunc, "addFunctionality");
>>>> d.addSetProperties(pathFunc);
>>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>>
>>>> d.addObjectCreate(pathClass, ClassItem.class);
>>>> d.addSetNext(pathClass, "addClassItem");
>>>> d.addSetProperties(pathClass);
>>>>
>>>>
>>>> d.addObjectCreate(pathPara, Parameter.class);
>>>> d.addSetNext(pathPara, "addParameter");
>>>>
>>>>
>>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>
>>>>
>>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>>
>>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>>
>>>> d.parse(url);
>>>> Project project = (Project) d.getRoot();
>>>>
>>>> System.out.println();
>>>> }
>>>>
>>>> ClassItem.java ---a pojo for saving all its Parameters
>>>>
>>>> public class ClassItem {
>>>>
>>>> private String method;
>>>> private String name;
>>>> private String handler="";
>>>> private List<Parameter> parameters;
>>>>
>>>> public ClassItem(String name, String method, List<Parameter>
>>>> parameters)
>>>> {
>>>> this.name = name;
>>>> this.method = method;
>>>> this.parameters = parameters;
>>>> }
>>>>
>>>> public ClassItem() {
>>>> }
>>>>
>>>> public String getMethod() {
>>>> return method;
>>>> }
>>>>
>>>> public void setMethod(String method) {
>>>> this.method = method;
>>>> }
>>>>
>>>> public String getName() {
>>>> return name;
>>>> }
>>>>
>>>> public void setName(String name) {
>>>> this.name = name;
>>>> }
>>>>
>>>> public void addParameter(Parameter parameter){
>>>> System.out.println("add parameter");
>>>> if (parameters==null){
>>>> parameters=new ArrayList<Parameter>();
>>>> }
>>>>
>>>> parameters.add(parameter);
>>>> }
>>>>
>>>> public List<Parameter> getParameters() {
>>>> return parameters;
>>>> }
>>>>
>>>> public String getHandler() {
>>>> return handler;
>>>> }
>>>>
>>>> public void setHandler(String handler) {
>>>> this.handler = handler;
>>>> }
>>>> }
>>>>
>>>>
>>>>
>>>> thanks.
>>>>
>>>> Kurt
>>>>
>>>>
>>>>> Hi Kurt,
>>>>> I suggest you first creating a digester rule that helps you handling a
>>>>> generic ParaItem element:
>>>>>
>>>>> public final class ParaItemRule extends
>>>>> org.apache.commons.digester.Rule {
>>>>>
>>>>> @Override
>>>>> public void body(String namespace, String name, String text)
>>>>> throws Exception {
>>>>> digester.push(new ParaItem(name, text));
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>> then plug the digester rules in the following way:
>>>>>
>>>>> Digester digester = new Digester();
>>>>>
>>>>> /* take a look at
>>>>>
>>>>>
>>>>> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>>>>> */
>>>>> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>>
>>>>> digester.addRule("Class/Parameter/Main/*", new ParaItemRule());
>>>>> digester.addSetNext("Class/Parameter/Main/*", "addMainParaItem");
>>>>>
>>>>> digester.addRule("Class/Parameter/SubText/*", new
>>>>> ParaItemRule());
>>>>> digester.addSetNext("Class/Parameter/SubText/*",
>>>>> "addSubParaItem");
>>>>>
>>>>> THT, let me know! ;)
>>>>> Simo
>>>>>
>>>>> http://people.apache.org/~simonetripodi/
>>>>> http://www.99soft.org/
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
>>>>>>
>>>>>> Hi all:
>>>>>>
>>>>>> I want to match some unknow elements nested some parent element where
>>>>>> some newly defined element might be added sometime.
>>>>>>
>>>>>> The sample xml is as below:
>>>>>>
>>>>>> <Class
>>>>>> name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>>>>>> method="entry">
>>>>>> <Parameter name="comment" index="0" type="insert"
>>>>>> table="MOCO_CODICMT">
>>>>>> <Main>
>>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>>> <CheckDesc></CheckDesc>
>>>>>> <UserId>userid</UserId>
>>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>>> </Main>
>>>>>> <SubText>
>>>>>> <!--<Type constant="true/false"></Type>-->
>>>>>> <!--<Title>title</Title>-->
>>>>>> <Content>contents</Content>
>>>>>> <WriterId>writeid</WriterId>
>>>>>> <WriterUserName>userid</WriterUserName>
>>>>>> </SubText>
>>>>>> </Parameter>
>>>>>> </Class>
>>>>>>
>>>>>>
>>>>>> The elements under <Main> and <SubText> are all variable someday,
>>>>>> both
>>>>>> name and amounts. So I define a ParaItem pojo to wrap sub elements of
>>>>>> the
>>>>>> two element. That means I want to create a Paraitem for every sub
>>>>>> element
>>>>>> ,whatever its name is, then add the object to paraent object
>>>>>> Parameter's
>>>>>> list property saving all the related Paraitem.
>>>>>>
>>>>>> The Paraitem source code is following:
>>>>>>
>>>>>> public class ParaItem {
>>>>>> private String elemName;
>>>>>> private String argPropNameOrValue;
>>>>>> private boolean isConstant;
>>>>>> public ParaItem() {
>>>>>> }
>>>>>> public ParaItem(String elemName, String argPropNameOrValue, boolean
>>>>>> constant) {
>>>>>> this.elemName = elemName;
>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>> isConstant = constant;
>>>>>> }
>>>>>> public ParaItem(String elemName, String argPropNameOrValue) {
>>>>>> this.elemName = elemName;
>>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>>> }
>>>>>> public String getElemName() {
>>>>>> return elemName;
>>>>>> }
>>>>>> public String getArgPropNameOrValue() {
>>>>>> return argPropNameOrValue;
>>>>>> }
>>>>>> public boolean isConstant() {
>>>>>> return isConstant;
>>>>>> }
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> The Parameter source code is below:
>>>>>> public class Parameter {
>>>>>> private String index;
>>>>>> private String operType;
>>>>>> private String dataType;
>>>>>> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
>>>>>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>>>>>> public Parameter(String operType) {
>>>>>> this.operType = operType;
>>>>>> }
>>>>>> public List<ParaItem> getListMainFiled() {
>>>>>> return listMainFiled;
>>>>>> }
>>>>>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>>>>>> this.listMainFiled = listMainFiled;
>>>>>> }
>>>>>> public List<ParaItem> getListSubField() {
>>>>>> return listSubField;
>>>>>> }
>>>>>> public void setListSubField(List<ParaItem> listSubField) {
>>>>>> this.listSubField = listSubField;
>>>>>> }
>>>>>> public String getIndex() {
>>>>>> return index;
>>>>>> }
>>>>>> public void setIndex(String index) {
>>>>>> this.index = index;
>>>>>> }
>>>>>> public String getOperType() {
>>>>>> return operType;
>>>>>> }
>>>>>> public void setOperType(String operType) {
>>>>>> this.operType = operType;
>>>>>> }
>>>>>> public String getDataType() {
>>>>>> return dataType;
>>>>>> }
>>>>>> public void setDataType(String dataType) {
>>>>>> this.dataType = dataType;
>>>>>> }
>>>>>> public void addMainParaItem(ParaItem pi){
>>>>>> getListMainFiled().add(pi);
>>>>>> }
>>>>>> public void addSubParaItem(ParaItem pi){
>>>>>> getListSubField().add(pi);
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> I suppose regex rule is the best way to make it , but googling and
>>>>>> the
>>>>>> javadoc doesn't tell me how to set a regex expression for a pattern.
>>>>>> No way
>>>>>> out, who knows the solotion , thanks.
>>>>>>
>>>>>>
>>>>>> Kurt
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>>
>>>>
>>>>
>>>> --
>>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> --
> Using Opera's revolutionary email client: http://www.opera.com/mail/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: Re: [digester]How to use SimpleRegexMatcher?
Posted by Kurt Xu <fx...@163.com>.
Hi Simone:
I tried by myself after emailing and resovled it . the method is the
same as your reply. I have a question still though. What if I want do set
two customized rule . The second setRules can reset or override the first
calling, can't it?
btw: why u say ni hao, r u from China?
Many thanks.
Kurt
On Thu, 31 Mar 2011 14:39:59 +0800, Simone Tripodi
<si...@apache.org> wrote:
> Ni hao again Kurt,
> just realized that the ParaItemRule implementation is incomplete, use
> the one below.
> Simo
>
> public final class ParaItemRule extends org.apache.commons.digester.Rule
> {
>
> @Override
> public void body(String namespace, String name, String text)
> throws Exception {
> digester.push(new ParaItem(name, text));
> }
>
> @Override
> public void end() throws Exception {
> digester.pop();
> }
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Thu, Mar 31, 2011 at 8:36 AM, Simone Tripodi
> <si...@apache.org> wrote:
>> Hi Kurt,
>> calling the setRules() method in the way you did, makes the Rules
>> instance is reset, so you loose the already set patterns.
>> modify the code in order that the setRules() method is invoked before
>> setting patterns/rules.
>> HTH,
>> Simo
>>
>> private void parseProject2(URL url) throws IOException, SAXException {
>> Digester d = new Digester();
>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>
>> String pathFunc = "Project/Functionality";
>> String pathClass = pathFunc + "/Class";
>> String pathPara = pathClass + "/Parameter";
>>
>> d.addObjectCreate("Project", Project.class);
>> d.addSetProperties("Project");
>>
>> d.addObjectCreate(pathFunc, Functionality.class);
>> d.addSetNext(pathFunc, "addFunctionality");
>> d.addSetProperties(pathFunc);
>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>
>> d.addObjectCreate(pathClass, ClassItem.class);
>> d.addSetNext(pathClass, "addClassItem");
>> d.addSetProperties(pathClass);
>>
>>
>> d.addObjectCreate(pathPara, Parameter.class);
>> d.addSetNext(pathPara, "addParameter");
>>
>>
>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>
>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>
>> d.parse(url);
>> Project project = (Project) d.getRoot();
>>
>> System.out.println();
>> }
>>
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Thu, Mar 31, 2011 at 5:44 AM, Kurt Xu <fx...@163.com> wrote:
>>>
>>> Sorry Simone:
>>>
>>> I need to paste the full xml and java file to help u locate the
>>> error,:)
>>>
>>> xml:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>>
>>> <Project name="project1">
>>> <Functionality description="add comment"
>>> url="http://dev.mygame.co.jp/user/register.do"
>>> actionName="com.mygame.action.UserAction"
>>> actionMethod="register">
>>>
>>> <Class name="com.mygame.bo.UserBOImpl" method="register">
>>> <Parameter name="user" index="0" type="insert">
>>> <Main>
>>> <DeviceType constant="true">pc</DeviceType>
>>> <CheckStatus constant="true">N</CheckStatus>
>>> <ValidCheck constant="true">Yes</ValidCheck>
>>> <CheckDesc>first check desc</CheckDesc>
>>> <UserId>userid</UserId>
>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>> </Main>
>>> <SubText>
>>> <!--<Type constant="true/false"></Type>-->
>>> <!--<Title>title</Title>-->
>>> <Content>contents</Content>
>>> <WriterId>writeid</WriterId>
>>> <WriterUserName>userid</WriterUserName>
>>> </SubText>
>>> </Parameter>
>>> <Parameter name="postVO" index="1" type="update"
>>> table="MOCO_CODICMT">
>>> .....
>>> </Parameter>
>>> </Class>
>>> </Functionality>
>>> </Project>
>>>
>>> java code:
>>>
>>> parser method:
>>> private void parseProject2(URL url) throws IOException, SAXException {
>>> Digester d = new Digester();
>>>
>>> String pathFunc = "Project/Functionality";
>>> String pathClass = pathFunc + "/Class";
>>> String pathPara = pathClass + "/Parameter";
>>>
>>> d.addObjectCreate("Project", Project.class);
>>> d.addSetProperties("Project");
>>>
>>> d.addObjectCreate(pathFunc, Functionality.class);
>>> d.addSetNext(pathFunc, "addFunctionality");
>>> d.addSetProperties(pathFunc);
>>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>>
>>> d.addObjectCreate(pathClass, ClassItem.class);
>>> d.addSetNext(pathClass, "addClassItem");
>>> d.addSetProperties(pathClass);
>>>
>>>
>>> d.addObjectCreate(pathPara, Parameter.class);
>>> d.addSetNext(pathPara, "addParameter");
>>>
>>>
>>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>
>>>
>>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>>
>>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>>
>>> d.parse(url);
>>> Project project = (Project) d.getRoot();
>>>
>>> System.out.println();
>>> }
>>>
>>> ClassItem.java ---a pojo for saving all its Parameters
>>>
>>> public class ClassItem {
>>>
>>> private String method;
>>> private String name;
>>> private String handler="";
>>> private List<Parameter> parameters;
>>>
>>> public ClassItem(String name, String method, List<Parameter>
>>> parameters)
>>> {
>>> this.name = name;
>>> this.method = method;
>>> this.parameters = parameters;
>>> }
>>>
>>> public ClassItem() {
>>> }
>>>
>>> public String getMethod() {
>>> return method;
>>> }
>>>
>>> public void setMethod(String method) {
>>> this.method = method;
>>> }
>>>
>>> public String getName() {
>>> return name;
>>> }
>>>
>>> public void setName(String name) {
>>> this.name = name;
>>> }
>>>
>>> public void addParameter(Parameter parameter){
>>> System.out.println("add parameter");
>>> if (parameters==null){
>>> parameters=new ArrayList<Parameter>();
>>> }
>>>
>>> parameters.add(parameter);
>>> }
>>>
>>> public List<Parameter> getParameters() {
>>> return parameters;
>>> }
>>>
>>> public String getHandler() {
>>> return handler;
>>> }
>>>
>>> public void setHandler(String handler) {
>>> this.handler = handler;
>>> }
>>> }
>>>
>>>
>>>
>>> thanks.
>>>
>>> Kurt
>>>
>>>
>>>> Hi Kurt,
>>>> I suggest you first creating a digester rule that helps you handling a
>>>> generic ParaItem element:
>>>>
>>>> public final class ParaItemRule extends
>>>> org.apache.commons.digester.Rule {
>>>>
>>>> @Override
>>>> public void body(String namespace, String name, String text)
>>>> throws Exception {
>>>> digester.push(new ParaItem(name, text));
>>>> }
>>>>
>>>> }
>>>>
>>>> then plug the digester rules in the following way:
>>>>
>>>> Digester digester = new Digester();
>>>>
>>>> /* take a look at
>>>>
>>>> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>>>> */
>>>> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>>
>>>> digester.addRule("Class/Parameter/Main/*", new ParaItemRule());
>>>> digester.addSetNext("Class/Parameter/Main/*",
>>>> "addMainParaItem");
>>>>
>>>> digester.addRule("Class/Parameter/SubText/*", new
>>>> ParaItemRule());
>>>> digester.addSetNext("Class/Parameter/SubText/*",
>>>> "addSubParaItem");
>>>>
>>>> THT, let me know! ;)
>>>> Simo
>>>>
>>>> http://people.apache.org/~simonetripodi/
>>>> http://www.99soft.org/
>>>>
>>>>
>>>>
>>>> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
>>>>>
>>>>> Hi all:
>>>>>
>>>>> I want to match some unknow elements nested some parent element where
>>>>> some newly defined element might be added sometime.
>>>>>
>>>>> The sample xml is as below:
>>>>>
>>>>> <Class
>>>>> name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>>>>> method="entry">
>>>>> <Parameter name="comment" index="0" type="insert"
>>>>> table="MOCO_CODICMT">
>>>>> <Main>
>>>>> <DeviceType constant="true">pc</DeviceType>
>>>>> <CheckStatus constant="true">N</CheckStatus>
>>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>>> <CheckDesc></CheckDesc>
>>>>> <UserId>userid</UserId>
>>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>>> </Main>
>>>>> <SubText>
>>>>> <!--<Type constant="true/false"></Type>-->
>>>>> <!--<Title>title</Title>-->
>>>>> <Content>contents</Content>
>>>>> <WriterId>writeid</WriterId>
>>>>> <WriterUserName>userid</WriterUserName>
>>>>> </SubText>
>>>>> </Parameter>
>>>>> </Class>
>>>>>
>>>>>
>>>>> The elements under <Main> and <SubText> are all variable someday,
>>>>> both
>>>>> name and amounts. So I define a ParaItem pojo to wrap sub elements
>>>>> of the
>>>>> two element. That means I want to create a Paraitem for every sub
>>>>> element
>>>>> ,whatever its name is, then add the object to paraent object
>>>>> Parameter's
>>>>> list property saving all the related Paraitem.
>>>>>
>>>>> The Paraitem source code is following:
>>>>>
>>>>> public class ParaItem {
>>>>> private String elemName;
>>>>> private String argPropNameOrValue;
>>>>> private boolean isConstant;
>>>>> public ParaItem() {
>>>>> }
>>>>> public ParaItem(String elemName, String argPropNameOrValue,
>>>>> boolean
>>>>> constant) {
>>>>> this.elemName = elemName;
>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>> isConstant = constant;
>>>>> }
>>>>> public ParaItem(String elemName, String argPropNameOrValue) {
>>>>> this.elemName = elemName;
>>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>>> }
>>>>> public String getElemName() {
>>>>> return elemName;
>>>>> }
>>>>> public String getArgPropNameOrValue() {
>>>>> return argPropNameOrValue;
>>>>> }
>>>>> public boolean isConstant() {
>>>>> return isConstant;
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> The Parameter source code is below:
>>>>> public class Parameter {
>>>>> private String index;
>>>>> private String operType;
>>>>> private String dataType;
>>>>> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
>>>>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>>>>> public Parameter(String operType) {
>>>>> this.operType = operType;
>>>>> }
>>>>> public List<ParaItem> getListMainFiled() {
>>>>> return listMainFiled;
>>>>> }
>>>>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>>>>> this.listMainFiled = listMainFiled;
>>>>> }
>>>>> public List<ParaItem> getListSubField() {
>>>>> return listSubField;
>>>>> }
>>>>> public void setListSubField(List<ParaItem> listSubField) {
>>>>> this.listSubField = listSubField;
>>>>> }
>>>>> public String getIndex() {
>>>>> return index;
>>>>> }
>>>>> public void setIndex(String index) {
>>>>> this.index = index;
>>>>> }
>>>>> public String getOperType() {
>>>>> return operType;
>>>>> }
>>>>> public void setOperType(String operType) {
>>>>> this.operType = operType;
>>>>> }
>>>>> public String getDataType() {
>>>>> return dataType;
>>>>> }
>>>>> public void setDataType(String dataType) {
>>>>> this.dataType = dataType;
>>>>> }
>>>>> public void addMainParaItem(ParaItem pi){
>>>>> getListMainFiled().add(pi);
>>>>> }
>>>>> public void addSubParaItem(ParaItem pi){
>>>>> getListSubField().add(pi);
>>>>> }
>>>>> }
>>>>>
>>>>> I suppose regex rule is the best way to make it , but googling and
>>>>> the
>>>>> javadoc doesn't tell me how to set a regex expression for a pattern.
>>>>> No way
>>>>> out, who knows the solotion , thanks.
>>>>>
>>>>>
>>>>> Kurt
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: user-help@commons.apache.org
>>>>
>>>
>>>
>>> --
>>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: Re: [digester]How to use SimpleRegexMatcher?
Posted by Simone Tripodi <si...@apache.org>.
Ni hao again Kurt,
just realized that the ParaItemRule implementation is incomplete, use
the one below.
Simo
public final class ParaItemRule extends org.apache.commons.digester.Rule {
@Override
public void body(String namespace, String name, String text)
throws Exception {
digester.push(new ParaItem(name, text));
}
@Override
public void end() throws Exception {
digester.pop();
}
http://people.apache.org/~simonetripodi/
http://www.99soft.org/
On Thu, Mar 31, 2011 at 8:36 AM, Simone Tripodi
<si...@apache.org> wrote:
> Hi Kurt,
> calling the setRules() method in the way you did, makes the Rules
> instance is reset, so you loose the already set patterns.
> modify the code in order that the setRules() method is invoked before
> setting patterns/rules.
> HTH,
> Simo
>
> private void parseProject2(URL url) throws IOException, SAXException {
> Digester d = new Digester();
> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>
> String pathFunc = "Project/Functionality";
> String pathClass = pathFunc + "/Class";
> String pathPara = pathClass + "/Parameter";
>
> d.addObjectCreate("Project", Project.class);
> d.addSetProperties("Project");
>
> d.addObjectCreate(pathFunc, Functionality.class);
> d.addSetNext(pathFunc, "addFunctionality");
> d.addSetProperties(pathFunc);
> // d.addSetProperties(pathFunc + "/BasicInfo");
>
> d.addObjectCreate(pathClass, ClassItem.class);
> d.addSetNext(pathClass, "addClassItem");
> d.addSetProperties(pathClass);
>
>
> d.addObjectCreate(pathPara, Parameter.class);
> d.addSetNext(pathPara, "addParameter");
>
>
> d.addRule(pathPara+"/Main/*", new ParaItemRule());
> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>
> d.addRule(pathPara +"SubText/*", new ParaItemRule());
> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>
> d.parse(url);
> Project project = (Project) d.getRoot();
>
> System.out.println();
> }
>
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Thu, Mar 31, 2011 at 5:44 AM, Kurt Xu <fx...@163.com> wrote:
>>
>> Sorry Simone:
>>
>> I need to paste the full xml and java file to help u locate the error,:)
>>
>> xml:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>>
>> <Project name="project1">
>> <Functionality description="add comment"
>> url="http://dev.mygame.co.jp/user/register.do"
>> actionName="com.mygame.action.UserAction"
>> actionMethod="register">
>>
>> <Class name="com.mygame.bo.UserBOImpl" method="register">
>> <Parameter name="user" index="0" type="insert">
>> <Main>
>> <DeviceType constant="true">pc</DeviceType>
>> <CheckStatus constant="true">N</CheckStatus>
>> <ValidCheck constant="true">Yes</ValidCheck>
>> <CheckDesc>first check desc</CheckDesc>
>> <UserId>userid</UserId>
>> <PrimaryKey1>cmtno</PrimaryKey1>
>> </Main>
>> <SubText>
>> <!--<Type constant="true/false"></Type>-->
>> <!--<Title>title</Title>-->
>> <Content>contents</Content>
>> <WriterId>writeid</WriterId>
>> <WriterUserName>userid</WriterUserName>
>> </SubText>
>> </Parameter>
>> <Parameter name="postVO" index="1" type="update"
>> table="MOCO_CODICMT">
>> .....
>> </Parameter>
>> </Class>
>> </Functionality>
>> </Project>
>>
>> java code:
>>
>> parser method:
>> private void parseProject2(URL url) throws IOException, SAXException {
>> Digester d = new Digester();
>>
>> String pathFunc = "Project/Functionality";
>> String pathClass = pathFunc + "/Class";
>> String pathPara = pathClass + "/Parameter";
>>
>> d.addObjectCreate("Project", Project.class);
>> d.addSetProperties("Project");
>>
>> d.addObjectCreate(pathFunc, Functionality.class);
>> d.addSetNext(pathFunc, "addFunctionality");
>> d.addSetProperties(pathFunc);
>> // d.addSetProperties(pathFunc + "/BasicInfo");
>>
>> d.addObjectCreate(pathClass, ClassItem.class);
>> d.addSetNext(pathClass, "addClassItem");
>> d.addSetProperties(pathClass);
>>
>>
>> d.addObjectCreate(pathPara, Parameter.class);
>> d.addSetNext(pathPara, "addParameter");
>>
>>
>> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>>
>>
>> d.addRule(pathPara+"/Main/*", new ParaItemRule());
>> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>>
>> d.addRule(pathPara +"SubText/*", new ParaItemRule());
>> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>>
>> d.parse(url);
>> Project project = (Project) d.getRoot();
>>
>> System.out.println();
>> }
>>
>> ClassItem.java ---a pojo for saving all its Parameters
>>
>> public class ClassItem {
>>
>> private String method;
>> private String name;
>> private String handler="";
>> private List<Parameter> parameters;
>>
>> public ClassItem(String name, String method, List<Parameter> parameters)
>> {
>> this.name = name;
>> this.method = method;
>> this.parameters = parameters;
>> }
>>
>> public ClassItem() {
>> }
>>
>> public String getMethod() {
>> return method;
>> }
>>
>> public void setMethod(String method) {
>> this.method = method;
>> }
>>
>> public String getName() {
>> return name;
>> }
>>
>> public void setName(String name) {
>> this.name = name;
>> }
>>
>> public void addParameter(Parameter parameter){
>> System.out.println("add parameter");
>> if (parameters==null){
>> parameters=new ArrayList<Parameter>();
>> }
>>
>> parameters.add(parameter);
>> }
>>
>> public List<Parameter> getParameters() {
>> return parameters;
>> }
>>
>> public String getHandler() {
>> return handler;
>> }
>>
>> public void setHandler(String handler) {
>> this.handler = handler;
>> }
>> }
>>
>>
>>
>> thanks.
>>
>> Kurt
>>
>>
>>> Hi Kurt,
>>> I suggest you first creating a digester rule that helps you handling a
>>> generic ParaItem element:
>>>
>>> public final class ParaItemRule extends org.apache.commons.digester.Rule {
>>>
>>> @Override
>>> public void body(String namespace, String name, String text)
>>> throws Exception {
>>> digester.push(new ParaItem(name, text));
>>> }
>>>
>>> }
>>>
>>> then plug the digester rules in the following way:
>>>
>>> Digester digester = new Digester();
>>>
>>> /* take a look at
>>>
>>> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>>> */
>>> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>>>
>>> digester.addRule("Class/Parameter/Main/*", new ParaItemRule());
>>> digester.addSetNext("Class/Parameter/Main/*", "addMainParaItem");
>>>
>>> digester.addRule("Class/Parameter/SubText/*", new ParaItemRule());
>>> digester.addSetNext("Class/Parameter/SubText/*", "addSubParaItem");
>>>
>>> THT, let me know! ;)
>>> Simo
>>>
>>> http://people.apache.org/~simonetripodi/
>>> http://www.99soft.org/
>>>
>>>
>>>
>>> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
>>>>
>>>> Hi all:
>>>>
>>>> I want to match some unknow elements nested some parent element where
>>>> some newly defined element might be added sometime.
>>>>
>>>> The sample xml is as below:
>>>>
>>>> <Class name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>>>> method="entry">
>>>> <Parameter name="comment" index="0" type="insert"
>>>> table="MOCO_CODICMT">
>>>> <Main>
>>>> <DeviceType constant="true">pc</DeviceType>
>>>> <CheckStatus constant="true">N</CheckStatus>
>>>> <ValidCheck constant="true">Yes</ValidCheck>
>>>> <CheckDesc></CheckDesc>
>>>> <UserId>userid</UserId>
>>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>>> </Main>
>>>> <SubText>
>>>> <!--<Type constant="true/false"></Type>-->
>>>> <!--<Title>title</Title>-->
>>>> <Content>contents</Content>
>>>> <WriterId>writeid</WriterId>
>>>> <WriterUserName>userid</WriterUserName>
>>>> </SubText>
>>>> </Parameter>
>>>> </Class>
>>>>
>>>>
>>>> The elements under <Main> and <SubText> are all variable someday, both
>>>> name and amounts. So I define a ParaItem pojo to wrap sub elements of the
>>>> two element. That means I want to create a Paraitem for every sub element
>>>> ,whatever its name is, then add the object to paraent object Parameter's
>>>> list property saving all the related Paraitem.
>>>>
>>>> The Paraitem source code is following:
>>>>
>>>> public class ParaItem {
>>>> private String elemName;
>>>> private String argPropNameOrValue;
>>>> private boolean isConstant;
>>>> public ParaItem() {
>>>> }
>>>> public ParaItem(String elemName, String argPropNameOrValue, boolean
>>>> constant) {
>>>> this.elemName = elemName;
>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>> isConstant = constant;
>>>> }
>>>> public ParaItem(String elemName, String argPropNameOrValue) {
>>>> this.elemName = elemName;
>>>> this.argPropNameOrValue = argPropNameOrValue;
>>>> }
>>>> public String getElemName() {
>>>> return elemName;
>>>> }
>>>> public String getArgPropNameOrValue() {
>>>> return argPropNameOrValue;
>>>> }
>>>> public boolean isConstant() {
>>>> return isConstant;
>>>> }
>>>> }
>>>>
>>>>
>>>>
>>>> The Parameter source code is below:
>>>> public class Parameter {
>>>> private String index;
>>>> private String operType;
>>>> private String dataType;
>>>> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
>>>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>>>> public Parameter(String operType) {
>>>> this.operType = operType;
>>>> }
>>>> public List<ParaItem> getListMainFiled() {
>>>> return listMainFiled;
>>>> }
>>>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>>>> this.listMainFiled = listMainFiled;
>>>> }
>>>> public List<ParaItem> getListSubField() {
>>>> return listSubField;
>>>> }
>>>> public void setListSubField(List<ParaItem> listSubField) {
>>>> this.listSubField = listSubField;
>>>> }
>>>> public String getIndex() {
>>>> return index;
>>>> }
>>>> public void setIndex(String index) {
>>>> this.index = index;
>>>> }
>>>> public String getOperType() {
>>>> return operType;
>>>> }
>>>> public void setOperType(String operType) {
>>>> this.operType = operType;
>>>> }
>>>> public String getDataType() {
>>>> return dataType;
>>>> }
>>>> public void setDataType(String dataType) {
>>>> this.dataType = dataType;
>>>> }
>>>> public void addMainParaItem(ParaItem pi){
>>>> getListMainFiled().add(pi);
>>>> }
>>>> public void addSubParaItem(ParaItem pi){
>>>> getListSubField().add(pi);
>>>> }
>>>> }
>>>>
>>>> I suppose regex rule is the best way to make it , but googling and the
>>>> javadoc doesn't tell me how to set a regex expression for a pattern. No way
>>>> out, who knows the solotion , thanks.
>>>>
>>>>
>>>> Kurt
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>
>>
>> --
>> Using Opera's revolutionary email client: http://www.opera.com/mail/
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: Re: [digester]How to use SimpleRegexMatcher?
Posted by Simone Tripodi <si...@apache.org>.
Hi Kurt,
calling the setRules() method in the way you did, makes the Rules
instance is reset, so you loose the already set patterns.
modify the code in order that the setRules() method is invoked before
setting patterns/rules.
HTH,
Simo
private void parseProject2(URL url) throws IOException, SAXException {
Digester d = new Digester();
d.setRules(new RegexRules(new SimpleRegexMatcher()));
String pathFunc = "Project/Functionality";
String pathClass = pathFunc + "/Class";
String pathPara = pathClass + "/Parameter";
d.addObjectCreate("Project", Project.class);
d.addSetProperties("Project");
d.addObjectCreate(pathFunc, Functionality.class);
d.addSetNext(pathFunc, "addFunctionality");
d.addSetProperties(pathFunc);
// d.addSetProperties(pathFunc + "/BasicInfo");
d.addObjectCreate(pathClass, ClassItem.class);
d.addSetNext(pathClass, "addClassItem");
d.addSetProperties(pathClass);
d.addObjectCreate(pathPara, Parameter.class);
d.addSetNext(pathPara, "addParameter");
d.addRule(pathPara+"/Main/*", new ParaItemRule());
d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
d.addRule(pathPara +"SubText/*", new ParaItemRule());
d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
d.parse(url);
Project project = (Project) d.getRoot();
System.out.println();
}
http://people.apache.org/~simonetripodi/
http://www.99soft.org/
On Thu, Mar 31, 2011 at 5:44 AM, Kurt Xu <fx...@163.com> wrote:
>
> Sorry Simone:
>
> I need to paste the full xml and java file to help u locate the error,:)
>
> xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <Project name="project1">
> <Functionality description="add comment"
> url="http://dev.mygame.co.jp/user/register.do"
> actionName="com.mygame.action.UserAction"
> actionMethod="register">
>
> <Class name="com.mygame.bo.UserBOImpl" method="register">
> <Parameter name="user" index="0" type="insert">
> <Main>
> <DeviceType constant="true">pc</DeviceType>
> <CheckStatus constant="true">N</CheckStatus>
> <ValidCheck constant="true">Yes</ValidCheck>
> <CheckDesc>first check desc</CheckDesc>
> <UserId>userid</UserId>
> <PrimaryKey1>cmtno</PrimaryKey1>
> </Main>
> <SubText>
> <!--<Type constant="true/false"></Type>-->
> <!--<Title>title</Title>-->
> <Content>contents</Content>
> <WriterId>writeid</WriterId>
> <WriterUserName>userid</WriterUserName>
> </SubText>
> </Parameter>
> <Parameter name="postVO" index="1" type="update"
> table="MOCO_CODICMT">
> .....
> </Parameter>
> </Class>
> </Functionality>
> </Project>
>
> java code:
>
> parser method:
> private void parseProject2(URL url) throws IOException, SAXException {
> Digester d = new Digester();
>
> String pathFunc = "Project/Functionality";
> String pathClass = pathFunc + "/Class";
> String pathPara = pathClass + "/Parameter";
>
> d.addObjectCreate("Project", Project.class);
> d.addSetProperties("Project");
>
> d.addObjectCreate(pathFunc, Functionality.class);
> d.addSetNext(pathFunc, "addFunctionality");
> d.addSetProperties(pathFunc);
> // d.addSetProperties(pathFunc + "/BasicInfo");
>
> d.addObjectCreate(pathClass, ClassItem.class);
> d.addSetNext(pathClass, "addClassItem");
> d.addSetProperties(pathClass);
>
>
> d.addObjectCreate(pathPara, Parameter.class);
> d.addSetNext(pathPara, "addParameter");
>
>
> d.setRules(new RegexRules(new SimpleRegexMatcher()));
>
>
> d.addRule(pathPara+"/Main/*", new ParaItemRule());
> d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
>
> d.addRule(pathPara +"SubText/*", new ParaItemRule());
> d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
>
> d.parse(url);
> Project project = (Project) d.getRoot();
>
> System.out.println();
> }
>
> ClassItem.java ---a pojo for saving all its Parameters
>
> public class ClassItem {
>
> private String method;
> private String name;
> private String handler="";
> private List<Parameter> parameters;
>
> public ClassItem(String name, String method, List<Parameter> parameters)
> {
> this.name = name;
> this.method = method;
> this.parameters = parameters;
> }
>
> public ClassItem() {
> }
>
> public String getMethod() {
> return method;
> }
>
> public void setMethod(String method) {
> this.method = method;
> }
>
> public String getName() {
> return name;
> }
>
> public void setName(String name) {
> this.name = name;
> }
>
> public void addParameter(Parameter parameter){
> System.out.println("add parameter");
> if (parameters==null){
> parameters=new ArrayList<Parameter>();
> }
>
> parameters.add(parameter);
> }
>
> public List<Parameter> getParameters() {
> return parameters;
> }
>
> public String getHandler() {
> return handler;
> }
>
> public void setHandler(String handler) {
> this.handler = handler;
> }
> }
>
>
>
> thanks.
>
> Kurt
>
>
>> Hi Kurt,
>> I suggest you first creating a digester rule that helps you handling a
>> generic ParaItem element:
>>
>> public final class ParaItemRule extends org.apache.commons.digester.Rule {
>>
>> @Override
>> public void body(String namespace, String name, String text)
>> throws Exception {
>> digester.push(new ParaItem(name, text));
>> }
>>
>> }
>>
>> then plug the digester rules in the following way:
>>
>> Digester digester = new Digester();
>>
>> /* take a look at
>>
>> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
>> */
>> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>>
>> digester.addRule("Class/Parameter/Main/*", new ParaItemRule());
>> digester.addSetNext("Class/Parameter/Main/*", "addMainParaItem");
>>
>> digester.addRule("Class/Parameter/SubText/*", new ParaItemRule());
>> digester.addSetNext("Class/Parameter/SubText/*", "addSubParaItem");
>>
>> THT, let me know! ;)
>> Simo
>>
>> http://people.apache.org/~simonetripodi/
>> http://www.99soft.org/
>>
>>
>>
>> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
>>>
>>> Hi all:
>>>
>>> I want to match some unknow elements nested some parent element where
>>> some newly defined element might be added sometime.
>>>
>>> The sample xml is as below:
>>>
>>> <Class name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>>> method="entry">
>>> <Parameter name="comment" index="0" type="insert"
>>> table="MOCO_CODICMT">
>>> <Main>
>>> <DeviceType constant="true">pc</DeviceType>
>>> <CheckStatus constant="true">N</CheckStatus>
>>> <ValidCheck constant="true">Yes</ValidCheck>
>>> <CheckDesc></CheckDesc>
>>> <UserId>userid</UserId>
>>> <PrimaryKey1>cmtno</PrimaryKey1>
>>> </Main>
>>> <SubText>
>>> <!--<Type constant="true/false"></Type>-->
>>> <!--<Title>title</Title>-->
>>> <Content>contents</Content>
>>> <WriterId>writeid</WriterId>
>>> <WriterUserName>userid</WriterUserName>
>>> </SubText>
>>> </Parameter>
>>> </Class>
>>>
>>>
>>> The elements under <Main> and <SubText> are all variable someday, both
>>> name and amounts. So I define a ParaItem pojo to wrap sub elements of the
>>> two element. That means I want to create a Paraitem for every sub element
>>> ,whatever its name is, then add the object to paraent object Parameter's
>>> list property saving all the related Paraitem.
>>>
>>> The Paraitem source code is following:
>>>
>>> public class ParaItem {
>>> private String elemName;
>>> private String argPropNameOrValue;
>>> private boolean isConstant;
>>> public ParaItem() {
>>> }
>>> public ParaItem(String elemName, String argPropNameOrValue, boolean
>>> constant) {
>>> this.elemName = elemName;
>>> this.argPropNameOrValue = argPropNameOrValue;
>>> isConstant = constant;
>>> }
>>> public ParaItem(String elemName, String argPropNameOrValue) {
>>> this.elemName = elemName;
>>> this.argPropNameOrValue = argPropNameOrValue;
>>> }
>>> public String getElemName() {
>>> return elemName;
>>> }
>>> public String getArgPropNameOrValue() {
>>> return argPropNameOrValue;
>>> }
>>> public boolean isConstant() {
>>> return isConstant;
>>> }
>>> }
>>>
>>>
>>>
>>> The Parameter source code is below:
>>> public class Parameter {
>>> private String index;
>>> private String operType;
>>> private String dataType;
>>> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
>>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>>> public Parameter(String operType) {
>>> this.operType = operType;
>>> }
>>> public List<ParaItem> getListMainFiled() {
>>> return listMainFiled;
>>> }
>>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>>> this.listMainFiled = listMainFiled;
>>> }
>>> public List<ParaItem> getListSubField() {
>>> return listSubField;
>>> }
>>> public void setListSubField(List<ParaItem> listSubField) {
>>> this.listSubField = listSubField;
>>> }
>>> public String getIndex() {
>>> return index;
>>> }
>>> public void setIndex(String index) {
>>> this.index = index;
>>> }
>>> public String getOperType() {
>>> return operType;
>>> }
>>> public void setOperType(String operType) {
>>> this.operType = operType;
>>> }
>>> public String getDataType() {
>>> return dataType;
>>> }
>>> public void setDataType(String dataType) {
>>> this.dataType = dataType;
>>> }
>>> public void addMainParaItem(ParaItem pi){
>>> getListMainFiled().add(pi);
>>> }
>>> public void addSubParaItem(ParaItem pi){
>>> getListSubField().add(pi);
>>> }
>>> }
>>>
>>> I suppose regex rule is the best way to make it , but googling and the
>>> javadoc doesn't tell me how to set a regex expression for a pattern. No way
>>> out, who knows the solotion , thanks.
>>>
>>>
>>> Kurt
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>
>
> --
> Using Opera's revolutionary email client: http://www.opera.com/mail/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re:Re: [digester]How to use SimpleRegexMatcher?
Posted by Kurt Xu <fx...@163.com>.
Sorry Simone:
I need to paste the full xml and java file to help u locate the error,:)
xml:
<?xml version="1.0" encoding="UTF-8"?>
<Project name="project1">
<Functionality description="add comment"
url="http://dev.mygame.co.jp/user/register.do"
actionName="com.mygame.action.UserAction"
actionMethod="register">
<Class name="com.mygame.bo.UserBOImpl" method="register">
<Parameter name="user" index="0" type="insert">
<Main>
<DeviceType constant="true">pc</DeviceType>
<CheckStatus constant="true">N</CheckStatus>
<ValidCheck constant="true">Yes</ValidCheck>
<CheckDesc>first check desc</CheckDesc>
<UserId>userid</UserId>
<PrimaryKey1>cmtno</PrimaryKey1>
</Main>
<SubText>
<!--<Type constant="true/false"></Type>-->
<!--<Title>title</Title>-->
<Content>contents</Content>
<WriterId>writeid</WriterId>
<WriterUserName>userid</WriterUserName>
</SubText>
</Parameter>
<Parameter name="postVO" index="1" type="update"
table="MOCO_CODICMT">
.....
</Parameter>
</Class>
</Functionality>
</Project>
java code:
parser method:
private void parseProject2(URL url) throws IOException, SAXException {
Digester d = new Digester();
String pathFunc = "Project/Functionality";
String pathClass = pathFunc + "/Class";
String pathPara = pathClass + "/Parameter";
d.addObjectCreate("Project", Project.class);
d.addSetProperties("Project");
d.addObjectCreate(pathFunc, Functionality.class);
d.addSetNext(pathFunc, "addFunctionality");
d.addSetProperties(pathFunc);
// d.addSetProperties(pathFunc + "/BasicInfo");
d.addObjectCreate(pathClass, ClassItem.class);
d.addSetNext(pathClass, "addClassItem");
d.addSetProperties(pathClass);
d.addObjectCreate(pathPara, Parameter.class);
d.addSetNext(pathPara, "addParameter");
d.setRules(new RegexRules(new SimpleRegexMatcher()));
d.addRule(pathPara+"/Main/*", new ParaItemRule());
d.addSetNext(pathPara+"/Main/*", "addMainParaItem");
d.addRule(pathPara +"SubText/*", new ParaItemRule());
d.addSetNext(pathPara +"SubText/*", "addSubParaItem");
d.parse(url);
Project project = (Project) d.getRoot();
System.out.println();
}
ClassItem.java ---a pojo for saving all its Parameters
public class ClassItem {
private String method;
private String name;
private String handler="";
private List<Parameter> parameters;
public ClassItem(String name, String method, List<Parameter>
parameters) {
this.name = name;
this.method = method;
this.parameters = parameters;
}
public ClassItem() {
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void addParameter(Parameter parameter){
System.out.println("add parameter");
if (parameters==null){
parameters=new ArrayList<Parameter>();
}
parameters.add(parameter);
}
public List<Parameter> getParameters() {
return parameters;
}
public String getHandler() {
return handler;
}
public void setHandler(String handler) {
this.handler = handler;
}
}
thanks.
Kurt
> Hi Kurt,
> I suggest you first creating a digester rule that helps you handling a
> generic ParaItem element:
>
> public final class ParaItemRule extends org.apache.commons.digester.Rule
> {
>
> @Override
> public void body(String namespace, String name, String text)
> throws Exception {
> digester.push(new ParaItem(name, text));
> }
>
> }
>
> then plug the digester rules in the following way:
>
> Digester digester = new Digester();
>
> /* take a look at
> http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
> */
> digester.setRules(new RegexRules(new SimpleRegexMatcher()));
>
> digester.addRule("Class/Parameter/Main/*", new ParaItemRule());
> digester.addSetNext("Class/Parameter/Main/*", "addMainParaItem");
>
> digester.addRule("Class/Parameter/SubText/*", new
> ParaItemRule());
> digester.addSetNext("Class/Parameter/SubText/*",
> "addSubParaItem");
>
> THT, let me know! ;)
> Simo
>
> http://people.apache.org/~simonetripodi/
> http://www.99soft.org/
>
>
>
> On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
>> Hi all:
>>
>> I want to match some unknow elements nested some parent element where
>> some newly defined element might be added sometime.
>>
>> The sample xml is as below:
>>
>> <Class
>> name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl"
>> method="entry">
>> <Parameter name="comment" index="0" type="insert"
>> table="MOCO_CODICMT">
>> <Main>
>> <DeviceType constant="true">pc</DeviceType>
>> <CheckStatus constant="true">N</CheckStatus>
>> <ValidCheck constant="true">Yes</ValidCheck>
>> <CheckDesc></CheckDesc>
>> <UserId>userid</UserId>
>> <PrimaryKey1>cmtno</PrimaryKey1>
>> </Main>
>> <SubText>
>> <!--<Type constant="true/false"></Type>-->
>> <!--<Title>title</Title>-->
>> <Content>contents</Content>
>> <WriterId>writeid</WriterId>
>> <WriterUserName>userid</WriterUserName>
>> </SubText>
>> </Parameter>
>> </Class>
>>
>>
>> The elements under <Main> and <SubText> are all variable someday,
>> both name and amounts. So I define a ParaItem pojo to wrap sub elements
>> of the two element. That means I want to create a Paraitem for every
>> sub element ,whatever its name is, then add the object to paraent
>> object Parameter's list property saving all the related Paraitem.
>>
>> The Paraitem source code is following:
>>
>> public class ParaItem {
>> private String elemName;
>> private String argPropNameOrValue;
>> private boolean isConstant;
>> public ParaItem() {
>> }
>> public ParaItem(String elemName, String argPropNameOrValue, boolean
>> constant) {
>> this.elemName = elemName;
>> this.argPropNameOrValue = argPropNameOrValue;
>> isConstant = constant;
>> }
>> public ParaItem(String elemName, String argPropNameOrValue) {
>> this.elemName = elemName;
>> this.argPropNameOrValue = argPropNameOrValue;
>> }
>> public String getElemName() {
>> return elemName;
>> }
>> public String getArgPropNameOrValue() {
>> return argPropNameOrValue;
>> }
>> public boolean isConstant() {
>> return isConstant;
>> }
>> }
>>
>>
>>
>> The Parameter source code is below:
>> public class Parameter {
>> private String index;
>> private String operType;
>> private String dataType;
>> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
>> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
>> public Parameter(String operType) {
>> this.operType = operType;
>> }
>> public List<ParaItem> getListMainFiled() {
>> return listMainFiled;
>> }
>> public void setListMainFiled(List<ParaItem> listMainFiled) {
>> this.listMainFiled = listMainFiled;
>> }
>> public List<ParaItem> getListSubField() {
>> return listSubField;
>> }
>> public void setListSubField(List<ParaItem> listSubField) {
>> this.listSubField = listSubField;
>> }
>> public String getIndex() {
>> return index;
>> }
>> public void setIndex(String index) {
>> this.index = index;
>> }
>> public String getOperType() {
>> return operType;
>> }
>> public void setOperType(String operType) {
>> this.operType = operType;
>> }
>> public String getDataType() {
>> return dataType;
>> }
>> public void setDataType(String dataType) {
>> this.dataType = dataType;
>> }
>> public void addMainParaItem(ParaItem pi){
>> getListMainFiled().add(pi);
>> }
>> public void addSubParaItem(ParaItem pi){
>> getListSubField().add(pi);
>> }
>> }
>>
>> I suppose regex rule is the best way to make it , but googling and
>> the javadoc doesn't tell me how to set a regex expression for a
>> pattern. No way out, who knows the solotion , thanks.
>>
>>
>> Kurt
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [digester]How to use SimpleRegexMatcher?
Posted by Simone Tripodi <si...@apache.org>.
Hi Kurt,
I suggest you first creating a digester rule that helps you handling a
generic ParaItem element:
public final class ParaItemRule extends org.apache.commons.digester.Rule {
@Override
public void body(String namespace, String name, String text)
throws Exception {
digester.push(new ParaItem(name, text));
}
}
then plug the digester rules in the following way:
Digester digester = new Digester();
/* take a look at
http://commons.apache.org/digester/apidocs/org/apache/commons/digester/SimpleRegexMatcher.html
*/
digester.setRules(new RegexRules(new SimpleRegexMatcher()));
digester.addRule("Class/Parameter/Main/*", new ParaItemRule());
digester.addSetNext("Class/Parameter/Main/*", "addMainParaItem");
digester.addRule("Class/Parameter/SubText/*", new ParaItemRule());
digester.addSetNext("Class/Parameter/SubText/*", "addSubParaItem");
THT, let me know! ;)
Simo
http://people.apache.org/~simonetripodi/
http://www.99soft.org/
On Wed, Mar 30, 2011 at 11:49 AM, fxbird <fx...@gmail.com> wrote:
> Hi all:
>
> I want to match some unknow elements nested some parent element where some newly defined element might be added sometime.
>
> The sample xml is as below:
>
> <Class name="jp.hangame.motecoorde.coordinate.bo.CoordinateCommentBoImpl" method="entry">
> <Parameter name="comment" index="0" type="insert" table="MOCO_CODICMT">
> <Main>
> <DeviceType constant="true">pc</DeviceType>
> <CheckStatus constant="true">N</CheckStatus>
> <ValidCheck constant="true">Yes</ValidCheck>
> <CheckDesc></CheckDesc>
> <UserId>userid</UserId>
> <PrimaryKey1>cmtno</PrimaryKey1>
> </Main>
> <SubText>
> <!--<Type constant="true/false"></Type>-->
> <!--<Title>title</Title>-->
> <Content>contents</Content>
> <WriterId>writeid</WriterId>
> <WriterUserName>userid</WriterUserName>
> </SubText>
> </Parameter>
> </Class>
>
>
> The elements under <Main> and <SubText> are all variable someday, both name and amounts. So I define a ParaItem pojo to wrap sub elements of the two element. That means I want to create a Paraitem for every sub element ,whatever its name is, then add the object to paraent object Parameter's list property saving all the related Paraitem.
>
> The Paraitem source code is following:
>
> public class ParaItem {
> private String elemName;
> private String argPropNameOrValue;
> private boolean isConstant;
> public ParaItem() {
> }
> public ParaItem(String elemName, String argPropNameOrValue, boolean constant) {
> this.elemName = elemName;
> this.argPropNameOrValue = argPropNameOrValue;
> isConstant = constant;
> }
> public ParaItem(String elemName, String argPropNameOrValue) {
> this.elemName = elemName;
> this.argPropNameOrValue = argPropNameOrValue;
> }
> public String getElemName() {
> return elemName;
> }
> public String getArgPropNameOrValue() {
> return argPropNameOrValue;
> }
> public boolean isConstant() {
> return isConstant;
> }
> }
>
>
>
> The Parameter source code is below:
> public class Parameter {
> private String index;
> private String operType;
> private String dataType;
> private List<ParaItem> listMainFiled =new ArrayList<ParaItem>();
> private List<ParaItem> listSubField =new ArrayList<ParaItem>();
> public Parameter(String operType) {
> this.operType = operType;
> }
> public List<ParaItem> getListMainFiled() {
> return listMainFiled;
> }
> public void setListMainFiled(List<ParaItem> listMainFiled) {
> this.listMainFiled = listMainFiled;
> }
> public List<ParaItem> getListSubField() {
> return listSubField;
> }
> public void setListSubField(List<ParaItem> listSubField) {
> this.listSubField = listSubField;
> }
> public String getIndex() {
> return index;
> }
> public void setIndex(String index) {
> this.index = index;
> }
> public String getOperType() {
> return operType;
> }
> public void setOperType(String operType) {
> this.operType = operType;
> }
> public String getDataType() {
> return dataType;
> }
> public void setDataType(String dataType) {
> this.dataType = dataType;
> }
> public void addMainParaItem(ParaItem pi){
> getListMainFiled().add(pi);
> }
> public void addSubParaItem(ParaItem pi){
> getListSubField().add(pi);
> }
> }
>
> I suppose regex rule is the best way to make it , but googling and the javadoc doesn't tell me how to set a regex expression for a pattern. No way out, who knows the solotion , thanks.
>
>
> Kurt
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org