1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.filter.internal.job

File FilterStreamConverterJob.java

 

Coverage histogram

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

Code metrics

0
14
5
1
125
75
5
0.36
2.8
5
1

Classes

Class Line # Actions
FilterStreamConverterJob 54 14 0% 5 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

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 org.xwiki.filter.internal.job;
21   
22    import java.util.Arrays;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Provider;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.annotation.InstantiationStrategy;
30    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
31    import org.xwiki.component.manager.ComponentManager;
32    import org.xwiki.filter.input.InputFilterStream;
33    import org.xwiki.filter.input.InputFilterStreamFactory;
34    import org.xwiki.filter.job.FilterConversionFinished;
35    import org.xwiki.filter.job.FilterConversionStarted;
36    import org.xwiki.filter.job.FilterStreamConverterJobRequest;
37    import org.xwiki.filter.job.FilterStreamJobRequest;
38    import org.xwiki.filter.output.OutputFilterStream;
39    import org.xwiki.filter.output.OutputFilterStreamFactory;
40    import org.xwiki.job.AbstractJob;
41    import org.xwiki.job.DefaultJobStatus;
42    import org.xwiki.job.GroupedJob;
43    import org.xwiki.job.JobGroupPath;
44   
45    /**
46    * Perform a Filter conversion.
47    *
48    * @version $Id: 537daa29d5017e66e4b1729ccfa0bb9683d5efcd $
49    * @since 6.2M1
50    */
51    @Component
52    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
53    @Named(FilterStreamConverterJob.JOBTYPE)
 
54    public class FilterStreamConverterJob
55    extends AbstractJob<FilterStreamConverterJobRequest, DefaultJobStatus<FilterStreamConverterJobRequest>>
56    implements GroupedJob
57    {
58    /**
59    * The id of the job.
60    */
61    public static final String JOBTYPE = "filter.converter";
62   
63    /**
64    * The root group of all filter conversion jobs.
65    */
66    public static final JobGroupPath ROOT_GROUP =
67    new JobGroupPath(Arrays.asList(FilterStreamJobRequest.JOBID_PREFIX, "converter"));
68   
69    @Inject
70    @Named("context")
71    private Provider<ComponentManager> componentManagerProvider;
72   
 
73  7 toggle @Override
74    public String getType()
75    {
76  7 return JOBTYPE;
77    }
78   
 
79  1 toggle @Override
80    public JobGroupPath getGroupPath()
81    {
82  1 return ROOT_GROUP;
83    }
84   
 
85  1 toggle @Override
86    protected void runInternal() throws Exception
87    {
88  1 InputFilterStreamFactory inputFactory = this.componentManagerProvider.get()
89    .getInstance(InputFilterStreamFactory.class, getRequest().getInputType().serialize());
90   
91  1 InputFilterStream inputFilter = inputFactory.createInputFilterStream(getRequest().getInputProperties());
92   
93  1 OutputFilterStreamFactory outputFactory = this.componentManagerProvider.get()
94    .getInstance(OutputFilterStreamFactory.class, getRequest().getOutputType().serialize());
95   
96  1 OutputFilterStream outputFilter = outputFactory.createOutputFilterStream(getRequest().getOutputProperties());
97   
98    // Convert
99   
100  1 inputFilter.read(outputFilter.getFilter());
101   
102  1 inputFilter.close();
103  1 outputFilter.close();
104    }
105   
 
106  1 toggle @Override
107    protected void jobStarting()
108    {
109  1 this.observationManager.notify(new FilterConversionStarted(getRequest().getId(), getType(), this.request),
110    this);
111   
112  1 super.jobStarting();
113    }
114   
 
115  1 toggle @Override
116    protected void jobFinished(Throwable error)
117    {
118  1 try {
119  1 super.jobFinished(error);
120    } finally {
121  1 this.observationManager.notify(new FilterConversionFinished(getRequest().getId(), getType(), this.request),
122    this);
123    }
124    }
125    }