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

File DocumentInstanceInputEventGenerator.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

0
25
3
1
123
80
7
0.28
8.33
3
2.33

Classes

Class Line # Actions
DocumentInstanceInputEventGenerator 50 25 0% 7 7
0.7575%
 

Contributing tests

This file is covered by 1 test. .

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.util.List;
23    import java.util.Locale;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.annotation.InstantiationStrategy;
31    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
32    import org.xwiki.filter.FilterEventParameters;
33    import org.xwiki.filter.FilterException;
34    import org.xwiki.filter.descriptor.FilterStreamDescriptor;
35    import org.xwiki.filter.event.model.WikiDocumentFilter;
36    import org.xwiki.filter.instance.input.AbstractInstanceInputEventGenerator;
37    import org.xwiki.filter.instance.input.EntityEventGenerator;
38    import org.xwiki.model.reference.DocumentReference;
39    import org.xwiki.model.reference.SpaceReference;
40    import org.xwiki.properties.BeanManager;
41   
42    import com.xpn.xwiki.XWikiContext;
43    import com.xpn.xwiki.XWikiException;
44    import com.xpn.xwiki.doc.XWikiDocument;
45    import com.xpn.xwiki.internal.filter.XWikiDocumentFilter;
46   
47    @Component
48    @Named("documents")
49    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
50    public class DocumentInstanceInputEventGenerator extends AbstractInstanceInputEventGenerator<XWikiDocumentFilter>
51    {
52    /**
53    * The {@link BeanManager} component.
54    */
55    @Inject
56    protected BeanManager beanManager;
57   
58    @Inject
59    private EntityEventGenerator<XWikiDocument> documentLocaleParser;
60   
61    @Inject
62    private Provider<XWikiContext> xcontextProvider;
63   
 
64  2 toggle @Override
65    public FilterStreamDescriptor getDescriptor()
66    {
67  2 return this.documentLocaleParser.getDescriptor();
68    }
69   
 
70  3 toggle @Override
71    public void setWikiDocumentParameters(String name, FilterEventParameters documentParameters) throws FilterException
72    {
73  3 DocumentReference reference = new DocumentReference(name, new SpaceReference(this.currentReference));
74   
75  3 XWikiContext xcontext = this.xcontextProvider.get();
76   
77  3 XWikiDocument defaultDocument;
78  3 try {
79  3 defaultDocument = xcontext.getWiki().getDocument(reference, xcontext);
80    } catch (XWikiException e) {
81  0 throw new FilterException("Failed to get document [" + reference + "]", e);
82    }
83   
84  3 documentParameters.put(WikiDocumentFilter.PARAMETER_LOCALE, defaultDocument.getDefaultLocale());
85    }
86   
 
87  3 toggle @Override
88    public void beginWikiDocument(String name, FilterEventParameters parameters) throws FilterException
89    {
90  3 super.beginWikiDocument(name, parameters);
91   
92  3 DocumentReference reference = new DocumentReference(this.currentReference);
93   
94  3 XWikiContext xcontext = this.xcontextProvider.get();
95   
96  3 XWikiDocument defaultDocument;
97  3 try {
98  3 defaultDocument = xcontext.getWiki().getDocument(reference, xcontext);
99    } catch (XWikiException e) {
100  0 throw new FilterException("Failed to get document [" + reference + "]", e);
101    }
102   
103    // Default document locale
104  3 this.documentLocaleParser.write(defaultDocument, this.filter, this.properties);
105   
106  3 List<Locale> locales;
107  3 try {
108  3 locales = defaultDocument.getTranslationLocales(xcontext);
109    } catch (XWikiException e) {
110  0 throw new FilterException("Failed to get translations of document [" + reference + "]", e);
111    }
112   
113    // Translations
114  3 for (Locale locale : locales) {
115  0 try {
116  0 XWikiDocument translationDocument = defaultDocument.getTranslatedDocument(locale, xcontext);
117  0 this.documentLocaleParser.write(translationDocument, this.filter, this.properties);
118    } catch (XWikiException e) {
119  0 throw new FilterException("Failed to get document [" + reference + "] for locale [" + locale + "]", e);
120    }
121    }
122    }
123    }