温馨提示:本文翻译自stackoverflow.com,查看原文请点击:java - Retrieve and assign jcr:mixinTypes a multi-valued property in magnolia

java - 检索并分配jcr:mixinTypes在木兰中的多值属性

发布于 2020-03-29 21:55:18

当我尝试在木兰中获取多值属性时遇到错误,因为我将其分配给String类型。如何正确读取单值和多值属性(因为两者都存在)?

javax.jcr.ValueFormatException:属性/ wcmstest / de / search / jcr:mixinTypes是多值属性,因此只能在org.apache.jackrabbit.core.PropertyImpl.internalGetValue(PropertyImpl.java :483),位于org.apache.jackrabbit.core.PropertyImpl.java:510(位于org.apache.jackrabbit.core.PropertyImpl.getString(PropertyImpl.java:520),位于info.magnolia.jcr.wrapper。在info.magnolia.jcr.wrapper.DelegatePropertyWrapper.getString(DelegatePropertyWrapper.java:162)处的DelegatePropertyWrapper.getString(DelegatePropertyWrapper.java:162)在info.magnolia.jcr.wrapper.DelegatePropertyWrapper.getString(Delgate。) .magnolia.jcr.wrapper.DelegatePropertyWrapper.getString(DelegatePropertyWrapper.java:162)位于info.magnolia.jcr.wrapper.DelegatePropertyWrapper.getString(DelegatePropertyWrapper.java:162)位于ch.uzh.module.versioning.CreateNestedMap.nestedMap(CreateNestedMap.java:32)位于ch.uzh.module.versioning.ContextLoggerCommand在info.magnolia.commands处的.execute(ContextLoggerCommand.java:78)在info.magnolia.commands.MgnlCommand.execute(MgnlCommand.java:69)处的info.magnolia.commands.MgnlCommand.executeSynchronized(MgnlCommand.java:80)。在info.magnolia.commands.DelegateCommand.execute(DelegateCommand.java:66)上的chain.ChainBase.execute(ChainBase.java:101):info.magnolia.commands.ContextLoggerCommand.execute(ContextLoggerCommand.java:78)at info.magnolia.commands.MgnlCommand.executeSynchronized(MgnlCommand.java:80)at info.magnolia.commands的info.magnolia.commands.MgnlCommand.execute(MgnlCommand.java:69) .chain.ChainBase.execute(ChainBase.java:101)位于info.magnolia.commands.DelegateCommand.execute(DelegateCommand.java:66):info.magnolia.commands.ContextLoggerCommand.execute(ContextLoggerCommand.java:78)at info.magnolia.commands.MgnlCommand.executeSynchronized(MgnlCommand.java:80)at info.magnolia.commands的info.magnolia.commands.MgnlCommand.execute(MgnlCommand.java:69) .chain.ChainBase.execute(ChainBase.java:101)位于info.magnolia.commands.DelegateCommand.execute(DelegateCommand.java:66):

这是我正在使用的代码:

 HashMap<String, Object> map = new LinkedHashMap<>();
 PropertyIterator pi;
 try {
    pi = node.getProperties();
    //Get properties for the root node
    while(pi.hasNext())
    {
        Property p = pi.nextProperty();
        String name = p.getName();
        String val = p.getString();

        map.put(name,val);

    }//end of while for properties of root node
 } catch (RepositoryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
 }

查看更多

提问者
Ana Sustic
被浏览
17
Ana Sustic 2020-01-31 18:47

感谢@reporter和一些试验和错误。这是一个working solution

           HashMap<String, Object> map = new LinkedHashMap<>();

           PropertyIterator pi;
            try {
                pi = node.getProperties();
                //Get properties for the root node
                while(pi.hasNext())
                    {
                       Property p = pi.nextProperty();
                       String name = p.getName();
                       String val;
                       //determine if property is multi-value
                       if (p.isMultiple()) {
                            //multi-value property           
                            val=p.getValues().toString();

                        } else {
                            //single-value property
                            val = p.getValue().getString();

                        }
                        map.put(name,val);

                    }//end of while for properties of root node
            } catch (RepositoryException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

发布
问题

分享
好友

手机
浏览

扫码手机浏览