1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal.filter.input

File BaseObjectEventGenerator.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
16
1
1
111
59
5
0.31
16
1
5

Classes

Class Line # Actions
BaseObjectEventGenerator 51 16 0% 5 2
0.913043591.3%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.internal.filter.input;
21   
22    import java.lang.reflect.ParameterizedType;
23    import java.util.Iterator;
24    import java.util.Map;
25   
26    import javax.inject.Inject;
27    import javax.inject.Provider;
28    import javax.inject.Singleton;
29   
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.component.util.DefaultParameterizedType;
32    import org.xwiki.filter.FilterEventParameters;
33    import org.xwiki.filter.FilterException;
34    import org.xwiki.filter.event.model.WikiObjectFilter;
35    import org.xwiki.filter.instance.input.DocumentInstanceInputProperties;
36    import org.xwiki.filter.instance.input.EntityEventGenerator;
37    import org.xwiki.filter.instance.internal.input.AbstractBeanEntityEventGenerator;
38   
39    import com.xpn.xwiki.XWikiContext;
40    import com.xpn.xwiki.internal.filter.BaseObjectFilter;
41    import com.xpn.xwiki.objects.BaseObject;
42    import com.xpn.xwiki.objects.BaseProperty;
43    import com.xpn.xwiki.objects.classes.BaseClass;
44   
45    /**
46    * @version $Id: 5083cab654a84af9987f09a76d5dff25a5d85306 $
47    * @since 6.2M1
48    */
49    @Component
50    @Singleton
 
51    public class BaseObjectEventGenerator
52    extends AbstractBeanEntityEventGenerator<BaseObject, BaseObjectFilter, DocumentInstanceInputProperties>
53    {
54    /**
55    * The role of this component.
56    */
57    public static final ParameterizedType ROLE = new DefaultParameterizedType(null, EntityEventGenerator.class,
58    BaseObject.class, DocumentInstanceInputProperties.class);
59   
60    @Inject
61    private Provider<XWikiContext> xcontextProvider;
62   
63    @Inject
64    private EntityEventGenerator<BaseClass> classEventGenerator;
65   
66    @Inject
67    private EntityEventGenerator<BaseProperty> propertyEventGenerator;
68   
 
69  7667 toggle @Override
70    public void write(BaseObject xobject, Object filter, BaseObjectFilter objectFilter,
71    DocumentInstanceInputProperties properties) throws FilterException
72    {
73  7667 XWikiContext xcontext = this.xcontextProvider.get();
74   
75    // > WikiObject
76   
77  7667 FilterEventParameters objectParameters = new FilterEventParameters();
78   
79  7667 objectParameters.put(WikiObjectFilter.PARAMETER_NAME, xobject.getName());
80  7667 objectParameters.put(WikiObjectFilter.PARAMETER_CLASS_REFERENCE, xobject.getClassName());
81  7667 objectParameters.put(WikiObjectFilter.PARAMETER_GUID, xobject.getGuid());
82  7667 objectParameters.put(WikiObjectFilter.PARAMETER_NUMBER, xobject.getNumber());
83   
84  7667 objectFilter.beginWikiObject(xobject.getReference() != null ? xobject.getReference().getName() : null,
85    objectParameters);
86   
87    // Object class
88   
89  7667 BaseClass xclass = xobject.getXClass(xcontext);
90  7667 ((BaseClassEventGenerator) this.classEventGenerator).write(xclass, filter, objectFilter, properties);
91   
92    // Properties
93   
94    // Iterate over values/properties sorted by field name so that the values are
95    // exported to XML in a consistent order.
96  7667 Iterator<BaseProperty<?>> it = xobject.getSortedIterator();
97  37401 while (it.hasNext()) {
98  29734 BaseProperty<?> xproperty = it.next();
99   
100  29734 String pname = xproperty.getName();
101  29734 if (pname != null && !pname.trim().equals("")) {
102  29734 ((BasePropertyEventGenerator) this.propertyEventGenerator).write(xproperty, filter,
103    (Map<String, Object>) properties);
104    }
105    }
106   
107    // < WikiObject
108   
109  7667 objectFilter.endWikiObject(xobject.getReference().getName(), objectParameters);
110    }
111    }