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

File ConfluenceInputFilterStream.java

 

Coverage histogram

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

Code metrics

88
234
8
1
576
443
83
0.35
29.25
8
10.38

Classes

Class Line # Actions
ConfluenceInputFilterStream 64 234 0% 83 80
0.7575757575.8%
 

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 org.xwiki.filter.confluence.xml.internal.input;
21   
22    import java.io.File;
23    import java.io.FileInputStream;
24    import java.io.FileNotFoundException;
25    import java.io.IOException;
26    import java.io.StringReader;
27    import java.text.ParseException;
28    import java.util.LinkedHashMap;
29    import java.util.List;
30    import java.util.Locale;
31    import java.util.Map;
32   
33    import javax.inject.Inject;
34    import javax.inject.Named;
35   
36    import org.apache.commons.configuration.ConfigurationException;
37    import org.apache.commons.configuration.PropertiesConfiguration;
38    import org.apache.commons.lang3.StringUtils;
39    import org.slf4j.Logger;
40    import org.xwiki.component.annotation.Component;
41    import org.xwiki.component.annotation.InstantiationStrategy;
42    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
43    import org.xwiki.filter.FilterEventParameters;
44    import org.xwiki.filter.FilterException;
45    import org.xwiki.filter.confluence.input.ConfluenceInputProperties;
46    import org.xwiki.filter.confluence.xml.internal.ConfluenceFilter;
47    import org.xwiki.filter.confluence.xml.internal.ConfluenceXMLPackage;
48    import org.xwiki.filter.event.model.WikiAttachmentFilter;
49    import org.xwiki.filter.event.model.WikiDocumentFilter;
50    import org.xwiki.filter.event.user.GroupFilter;
51    import org.xwiki.filter.event.user.UserFilter;
52    import org.xwiki.filter.input.AbstractBeanInputFilterStream;
53    import org.xwiki.rendering.listener.Listener;
54    import org.xwiki.rendering.parser.StreamParser;
55    import org.xwiki.rendering.syntax.Syntax;
56   
57    /**
58    * @version $Id: 63d214f23b3e01ec9b52d006ac7cc3116da412b2 $
59    * @since 6.2M1
60    */
61    @Component
62    @Named(ConfluenceInputFilterStreamFactory.ROLEHINT)
63    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
64    public class ConfluenceInputFilterStream
65    extends AbstractBeanInputFilterStream<ConfluenceInputProperties, ConfluenceFilter>
66    {
67    @Inject
68    private Logger logger;
69   
70    @Inject
71    @Named("confluence/1.0")
72    private StreamParser confluenceWIKIParser;
73   
74    @Inject
75    @Named("confluence+xhtml/1.0")
76    private StreamParser confluenceXHTMLParser;
77   
78    private ConfluenceXMLPackage confluencePackage;
79   
 
80  3 toggle @Override
81    public void close() throws IOException
82    {
83  3 this.properties.getSource().close();
84    }
85   
 
86  3 toggle @Override
87    protected void read(Object filter, ConfluenceFilter proxyFilter) throws FilterException
88    {
89    // Prepare package
90  3 try {
91  3 this.confluencePackage = new ConfluenceXMLPackage(this.properties.getSource());
92    } catch (Exception e) {
93  0 throw new FilterException("Failed to read package", e);
94    }
95   
96    // Generate users events
97  3 for (int userInt : this.confluencePackage.getUsers()) {
98  5 PropertiesConfiguration userProperties;
99  5 try {
100  5 userProperties = this.confluencePackage.getUserProperties(userInt);
101    } catch (ConfigurationException e) {
102  0 throw new FilterException("Failed to get user properties", e);
103    }
104   
105  5 String userId = userProperties.getString(ConfluenceXMLPackage.KEY_USER_NAME, String.valueOf(userInt));
106  5 if (this.properties.isConvertToXWiki() && userId.equals("admin")) {
107  2 userId = "Admin";
108    }
109   
110  5 FilterEventParameters userParameters = new FilterEventParameters();
111   
112  5 userParameters.put(UserFilter.PARAMETER_FIRSTNAME,
113    userProperties.getString(ConfluenceXMLPackage.KEY_USER_FIRSTNAME));
114  5 userParameters.put(UserFilter.PARAMETER_LASTNAME,
115    userProperties.getString(ConfluenceXMLPackage.KEY_USER_LASTNAME));
116  5 userParameters.put(UserFilter.PARAMETER_EMAIL,
117    userProperties.getString(ConfluenceXMLPackage.KEY_USER_EMAIL));
118  5 userParameters.put(UserFilter.PARAMETER_ACTIVE,
119    userProperties.getBoolean(ConfluenceXMLPackage.KEY_USER_ACTIVE));
120   
121  5 try {
122  5 userParameters.put(UserFilter.PARAMETER_REVISION_DATE,
123    this.confluencePackage.getDate(userProperties, ConfluenceXMLPackage.KEY_USER_REVISION_DATE));
124  5 userParameters.put(UserFilter.PARAMETER_CREATION_DATE,
125    this.confluencePackage.getDate(userProperties, ConfluenceXMLPackage.KEY_USER_CREATION_DATE));
126    } catch (ParseException e) {
127  0 if (this.properties.isVerbose()) {
128  0 this.logger.error("Failed to parse date", e);
129    }
130    }
131   
132    // TODO: no idea how to import/convert the password, probably salted with the Confluence instance id
133   
134    // > User
135  5 proxyFilter.beginUser(userId, userParameters);
136   
137    // < User
138  5 proxyFilter.endUser(userId, userParameters);
139    }
140   
141    // Generate users events
142  3 for (int groupInt : this.confluencePackage.getGroups()) {
143  11 PropertiesConfiguration groupProperties;
144  11 try {
145  11 groupProperties = this.confluencePackage.getGroupProperties(groupInt);
146    } catch (ConfigurationException e) {
147  0 throw new FilterException("Failed to get group properties", e);
148    }
149   
150  11 String groupName = groupProperties.getString(ConfluenceXMLPackage.KEY_GROUP_NAME, String.valueOf(groupInt));
151  11 if (this.properties.isConvertToXWiki()) {
152  11 if (groupName.equals("confluence-administrators")) {
153  2 groupName = "XWikiAdminGroup";
154  9 } else if (groupName.equals("confluence-users")) {
155  2 groupName = "XWikiAllGroup";
156    }
157    }
158   
159  11 FilterEventParameters groupParameters = new FilterEventParameters();
160   
161  11 try {
162  11 groupParameters.put(GroupFilter.PARAMETER_REVISION_DATE,
163    this.confluencePackage.getDate(groupProperties, ConfluenceXMLPackage.KEY_GROUP_REVISION_DATE));
164  11 groupParameters.put(GroupFilter.PARAMETER_CREATION_DATE,
165    this.confluencePackage.getDate(groupProperties, ConfluenceXMLPackage.KEY_GROUP_CREATION_DATE));
166    } catch (ParseException e) {
167  0 if (this.properties.isVerbose()) {
168  0 this.logger.error("Failed to parse date", e);
169    }
170    }
171   
172    // > Group
173  11 proxyFilter.beginGroupContainer(groupName, groupParameters);
174   
175    // Members users
176  11 if (groupProperties.containsKey(ConfluenceXMLPackage.KEY_GROUP_MEMBERUSERS)) {
177  8 List<Integer> users =
178    this.confluencePackage.getIntegertList(groupProperties, ConfluenceXMLPackage.KEY_GROUP_MEMBERUSERS);
179  8 for (Integer memberInt : users) {
180  11 FilterEventParameters memberParameters = new FilterEventParameters();
181   
182  11 try {
183  11 String memberId = this.confluencePackage.getUserProperties(memberInt)
184    .getString(ConfluenceXMLPackage.KEY_USER_NAME, String.valueOf(memberInt));
185   
186  11 if (this.properties.isConvertToXWiki() && memberId.equals("admin")) {
187  6 memberId = "Admin";
188    }
189   
190  11 proxyFilter.onGroupMemberGroup(memberId, memberParameters);
191    } catch (ConfigurationException e) {
192  0 this.logger.error("Failed to get user properties", e);
193    }
194    }
195    }
196   
197    // Members groups
198  11 if (groupProperties.containsKey(ConfluenceXMLPackage.KEY_GROUP_MEMBERGROUPS)) {
199  0 List<Integer> groups = this.confluencePackage.getIntegertList(groupProperties,
200    ConfluenceXMLPackage.KEY_GROUP_MEMBERGROUPS);
201  0 for (Integer memberInt : groups) {
202  0 FilterEventParameters memberParameters = new FilterEventParameters();
203   
204  0 try {
205  0 String memberId = this.confluencePackage.getGroupProperties(memberInt)
206    .getString(ConfluenceXMLPackage.KEY_GROUP_NAME, String.valueOf(memberInt));
207   
208  0 if (this.properties.isConvertToXWiki()) {
209  0 if (memberId.equals("confluence-administrators")) {
210  0 memberId = "XWikiAdminGroup";
211  0 } else if (memberId.equals("confluence-users")) {
212  0 memberId = "XWikiAllGroup";
213    }
214    }
215   
216  0 proxyFilter.onGroupMemberGroup(memberId, memberParameters);
217    } catch (ConfigurationException e) {
218  0 this.logger.error("Failed to get group properties", e);
219    }
220    }
221    }
222   
223    // < Group
224  11 proxyFilter.endGroupContainer(groupName, groupParameters);
225    }
226   
227    // Generate documents events
228  3 for (Map.Entry<Integer, List<Integer>> entry : this.confluencePackage.getPages().entrySet()) {
229  5 int spaceId = entry.getKey();
230   
231  5 PropertiesConfiguration spaceProperties;
232  5 try {
233  5 spaceProperties = this.confluencePackage.getSpaceProperties(spaceId);
234    } catch (ConfigurationException e) {
235  0 throw new FilterException("Failed to get space properties", e);
236    }
237   
238  5 String spaceName = spaceProperties.getString(ConfluenceXMLPackage.KEY_SPACE_NAME);
239  5 FilterEventParameters spaceParameters = new FilterEventParameters();
240   
241    // > WikiSpace
242  5 proxyFilter.beginWikiSpace(spaceName, spaceParameters);
243   
244    // Main page
245  5 Integer descriptionId = spaceProperties.getInteger(ConfluenceXMLPackage.KEY_SPACE_DESCRIPTION, null);
246  5 if (descriptionId != null) {
247  5 readPage(descriptionId, filter, proxyFilter);
248    }
249   
250    // Other pages
251  5 for (int pageId : entry.getValue()) {
252  19 readPage(pageId, filter, proxyFilter);
253    }
254   
255    // < WikiSpace
256  5 proxyFilter.endWikiSpace(spaceName, spaceParameters);
257    }
258   
259    // Cleanup
260   
261  3 try {
262  3 this.confluencePackage.close();
263    } catch (IOException e) {
264  0 throw new FilterException("Failed to close package", e);
265    }
266    }
267   
 
268  24 toggle private void readPage(int pageId, Object filter, ConfluenceFilter proxyFilter) throws FilterException
269    {
270  24 PropertiesConfiguration pageProperties = getPageProperties(pageId);
271   
272  24 String documentName;
273  24 if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_HOMEPAGE)) {
274  5 documentName = this.properties.getSpacePageName();
275    } else {
276  19 documentName = pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_TITLE);
277    }
278   
279  24 FilterEventParameters documentParameters = new FilterEventParameters();
280  24 if (this.properties.getDefaultLocale() != null) {
281  0 documentParameters.put(WikiDocumentFilter.PARAMETER_LOCALE, this.properties.getDefaultLocale());
282    }
283   
284    // > WikiDocument
285  24 proxyFilter.beginWikiDocument(documentName, documentParameters);
286   
287  24 Locale locale = Locale.ROOT;
288   
289  24 FilterEventParameters documentLocaleParameters = new FilterEventParameters();
290  24 if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_CREATION_AUTHOR)) {
291  9 documentLocaleParameters.put(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR,
292    pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_CREATION_AUTHOR));
293    }
294  24 if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_CREATION_DATE)) {
295  23 try {
296  23 documentLocaleParameters.put(WikiDocumentFilter.PARAMETER_CREATION_DATE,
297    this.confluencePackage.getDate(pageProperties, ConfluenceXMLPackage.KEY_PAGE_CREATION_DATE));
298    } catch (ParseException e) {
299  0 if (this.properties.isVerbose()) {
300  0 this.logger.error("Failed to parse date", e);
301    }
302    }
303    }
304  24 if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_REVISION)) {
305  24 documentLocaleParameters.put(WikiDocumentFilter.PARAMETER_LASTREVISION,
306    pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_REVISION));
307    }
308   
309    // > WikiDocumentLocale
310  24 proxyFilter.beginWikiDocumentLocale(locale, documentLocaleParameters);
311   
312    // Revisions
313  24 if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_REVISIONS)) {
314  3 List<Integer> revisions =
315    this.confluencePackage.getIntegertList(pageProperties, ConfluenceXMLPackage.KEY_PAGE_REVISIONS);
316  3 for (Integer revisionId : revisions) {
317  8 readPageRevision(revisionId, filter, proxyFilter);
318    }
319    }
320   
321    // Current version
322  24 readPageRevision(pageId, filter, proxyFilter);
323   
324    // < WikiDocumentLocale
325  24 proxyFilter.endWikiDocumentLocale(locale, documentLocaleParameters);
326   
327    // < WikiDocument
328  24 proxyFilter.endWikiDocument(documentName, documentParameters);
329    }
330   
 
331  56 toggle private PropertiesConfiguration getPageProperties(Integer pageId) throws FilterException
332    {
333  56 try {
334  56 return this.confluencePackage.getPageProperties(pageId);
335    } catch (ConfigurationException e) {
336  0 throw new FilterException("Failed to get page properties", e);
337    }
338    }
339   
 
340  32 toggle private void readPageRevision(Integer pageId, Object filter, ConfluenceFilter proxyFilter) throws FilterException
341    {
342  32 PropertiesConfiguration pageProperties = getPageProperties(pageId);
343   
344  32 readPageRevision(pageId, pageProperties, filter, proxyFilter);
345    }
346   
 
347  32 toggle private void readPageRevision(int pageId, PropertiesConfiguration pageProperties, Object filter,
348    ConfluenceFilter proxyFilter) throws FilterException
349    {
350  32 String revision = pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_REVISION);
351   
352  32 FilterEventParameters documentRevisionParameters = new FilterEventParameters();
353  32 if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_PARENT)) {
354  13 try {
355  13 documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_PARENT,
356    this.confluencePackage.getReferenceFromId(pageProperties, ConfluenceXMLPackage.KEY_PAGE_PARENT));
357    } catch (ConfigurationException e) {
358  0 if (this.properties.isVerbose()) {
359  0 this.logger.error("Failed to parse parent", e);
360    }
361    }
362    }
363  32 if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_REVISION_AUTHOR)) {
364  16 documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_AUTHOR,
365    pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_REVISION_AUTHOR));
366    }
367  32 if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_REVISION_DATE)) {
368  31 try {
369  31 documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_DATE,
370    this.confluencePackage.getDate(pageProperties, ConfluenceXMLPackage.KEY_PAGE_REVISION_DATE));
371    } catch (ParseException e) {
372  0 if (this.properties.isVerbose()) {
373  0 this.logger.error("Failed to parse date", e);
374    }
375    }
376    }
377  32 if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_REVISION_COMMENT)) {
378  31 documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_REVISION_COMMENT,
379    pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_REVISION_COMMENT));
380    }
381  32 documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_TITLE,
382    pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_TITLE));
383   
384  32 String bodyContent = null;
385  32 Syntax bodySyntax = null;
386  32 int bodyType = -1;
387   
388  32 if (pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_BODY)
389    && pageProperties.containsKey(ConfluenceXMLPackage.KEY_PAGE_BODY_TYPE)) {
390  31 bodyContent = pageProperties.getString(ConfluenceXMLPackage.KEY_PAGE_BODY);
391  31 bodyType = pageProperties.getInt(ConfluenceXMLPackage.KEY_PAGE_BODY_TYPE);
392   
393  31 switch (bodyType) {
394  5 case 0:
395  5 bodySyntax = Syntax.CONFLUENCE_1_0;
396  5 break;
397  26 case 2:
398  26 bodySyntax = Syntax.CONFLUENCEXHTML_1_0;
399  26 break;
400  0 default:
401  0 if (this.properties.isVerbose()) {
402  0 this.logger.error("Unknown body type [{}]", bodyType);
403    }
404  0 break;
405    }
406    }
407   
408    // If target filter does not support rendering events, pass the content as it is
409  32 if (!(filter instanceof Listener) && bodyContent != null && bodySyntax != null) {
410  0 documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_CONTENT, bodyContent);
411  0 documentRevisionParameters.put(WikiDocumentFilter.PARAMETER_SYNTAX, bodySyntax);
412    }
413   
414    // > WikiDocumentRevision
415  32 proxyFilter.beginWikiDocumentRevision(revision, documentRevisionParameters);
416   
417    // Content
418  32 if (filter instanceof Listener && bodyContent != null && bodySyntax != null) {
419  31 try {
420  31 switch (bodyType) {
421  5 case 0:
422  5 this.confluenceWIKIParser.parse(new StringReader(bodyContent), proxyFilter);
423  5 break;
424  26 case 2:
425  26 this.confluenceXHTMLParser.parse(new StringReader(bodyContent), proxyFilter);
426  26 break;
427  0 default:
428  0 break;
429    }
430    } catch (org.xwiki.rendering.parser.ParseException e) {
431  0 throw new FilterException(String.format("Failed parser content [%s]", bodyContent), e);
432    }
433    }
434   
435    // Attachments
436  32 Map<String, PropertiesConfiguration> pageAttachments = new LinkedHashMap<>();
437  32 for (int attachmentId : this.confluencePackage.getAttachments(pageId)) {
438  33 PropertiesConfiguration attachmentProperties;
439  33 try {
440  33 attachmentProperties = this.confluencePackage.getAttachmentProperties(pageId, attachmentId);
441    } catch (ConfigurationException e) {
442  0 throw new FilterException("Failed to get attachment properties", e);
443    }
444   
445  33 String attachmentName = this.confluencePackage.getAttachmentName(attachmentProperties);
446   
447  33 PropertiesConfiguration currentAttachmentProperties = pageAttachments.get(attachmentName);
448  33 if (currentAttachmentProperties != null) {
449  6 int version = this.confluencePackage.getAttachementVersion(attachmentProperties);
450  6 int currentVersion = this.confluencePackage.getAttachementVersion(currentAttachmentProperties);
451   
452  6 if (version > currentVersion) {
453  1 pageAttachments.put(attachmentName, attachmentProperties);
454    }
455    } else {
456  27 pageAttachments.put(attachmentName, attachmentProperties);
457    }
458    }
459   
460  32 for (PropertiesConfiguration attachmentProperties : pageAttachments.values()) {
461  27 readAttachment(pageId, attachmentProperties, filter, proxyFilter);
462    }
463   
464    // < WikiDocumentRevision
465  32 proxyFilter.endWikiDocumentRevision(revision, documentRevisionParameters);
466    }
467   
 
468  27 toggle private void readAttachment(int pageId, PropertiesConfiguration attachmentProperties, Object filter,
469    ConfluenceFilter proxyFilter) throws FilterException
470    {
471  27 String contentStatus = attachmentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTSTATUS, null);
472  27 if (StringUtils.equals(contentStatus, "deleted")) {
473    // The actual deleted attachment is not in the exported package so we can't really do anything with it
474  2 return;
475    }
476   
477  25 int attachmentId = attachmentProperties.getInt("id");
478   
479  25 String attachmentName = this.confluencePackage.getAttachmentName(attachmentProperties);
480   
481  25 long attachmentSize;
482  25 String mediaType = null;
483  25 if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTPROPERTIES)) {
484  20 PropertiesConfiguration attachmentContentProperties =
485    getContentProperties(attachmentProperties, ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTPROPERTIES);
486   
487  20 attachmentSize = attachmentContentProperties.getLong(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENT_FILESIZE);
488  20 if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTTYPE)) {
489  0 mediaType =
490    attachmentContentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENT_MEDIA_TYPE);
491    }
492    } else {
493  5 attachmentSize = attachmentProperties.getLong(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENT_SIZE);
494  5 if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTTYPE)) {
495  5 mediaType = attachmentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_CONTENTTYPE);
496    }
497    }
498   
499  25 Integer version = this.confluencePackage.getAttachementVersion(attachmentProperties);
500   
501  25 int originalRevisionId =
502    this.confluencePackage.getAttachmentOriginalVersionId(attachmentProperties, attachmentId);
503  25 File contentFile;
504  25 try {
505  25 contentFile = this.confluencePackage.getAttachmentFile(pageId, originalRevisionId, version);
506    } catch (FileNotFoundException e) {
507  0 throw new FilterException(
508    String.format("Filed to find file corresponding to version [%s] attachment [%s] in page [%s]", version,
509    attachmentName, pageId),
510    e);
511    }
512   
513  25 FilterEventParameters attachmentParameters = new FilterEventParameters();
514  25 if (mediaType != null) {
515  5 attachmentParameters.put(WikiAttachmentFilter.PARAMETER_CONTENT_TYPE, mediaType);
516    }
517  25 if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_CREATION_AUTHOR)) {
518  4 attachmentParameters.put(WikiAttachmentFilter.PARAMETER_CREATION_AUTHOR,
519    attachmentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_CREATION_AUTHOR));
520    }
521  25 if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_CREATION_DATE)) {
522  25 try {
523  25 attachmentParameters.put(WikiAttachmentFilter.PARAMETER_CREATION_DATE, this.confluencePackage
524    .getDate(attachmentProperties, ConfluenceXMLPackage.KEY_ATTACHMENT_CREATION_DATE));
525    } catch (ParseException e) {
526  0 if (this.properties.isVerbose()) {
527  0 this.logger.error("Failed to parse date", e);
528    }
529    }
530    }
531   
532  25 attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION, String.valueOf(version));
533  25 if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_AUTHOR)) {
534  4 attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_AUTHOR,
535    attachmentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_AUTHOR));
536    }
537  25 if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_DATE)) {
538  25 try {
539  25 attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_DATE, this.confluencePackage
540    .getDate(attachmentProperties, ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_DATE));
541    } catch (ParseException e) {
542  0 if (this.properties.isVerbose()) {
543  0 this.logger.error("Failed to parse date", e);
544    }
545    }
546    }
547  25 if (attachmentProperties.containsKey(ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_COMMENT)) {
548  5 attachmentParameters.put(WikiAttachmentFilter.PARAMETER_REVISION_COMMENT,
549    attachmentProperties.getString(ConfluenceXMLPackage.KEY_ATTACHMENT_REVISION_COMMENT));
550    }
551   
552    // WikiAttachment
553   
554  25 try {
555  25 FileInputStream fis = new FileInputStream(contentFile);
556   
557  25 try {
558  25 proxyFilter.onWikiAttachment(attachmentName, fis, attachmentSize, attachmentParameters);
559    } finally {
560  25 fis.close();
561    }
562    } catch (Exception e) {
563  0 throw new FilterException("Failed to read attachment", e);
564    }
565    }
566   
 
567  20 toggle public PropertiesConfiguration getContentProperties(PropertiesConfiguration properties, String key)
568    throws FilterException
569    {
570  20 try {
571  20 return this.confluencePackage.getContentProperties(properties, key);
572    } catch (Exception e) {
573  0 throw new FilterException("Failed to parse content properties", e);
574    }
575    }
576    }