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

File ExtendedURLTemporaryResourceReferenceSerializer.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

0
9
2
1
82
48
2
0.22
4.5
2
1

Classes

Class Line # Actions
ExtendedURLTemporaryResourceReferenceSerializer 51 9 0% 2 11
0.00%
 

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.resource.temporary.internal;
21   
22    import java.util.HashMap;
23    import java.util.LinkedList;
24    import java.util.List;
25    import java.util.Map;
26   
27    import javax.inject.Inject;
28    import javax.inject.Named;
29    import javax.inject.Singleton;
30   
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.model.reference.EntityReference;
33    import org.xwiki.model.reference.EntityReferenceSerializer;
34    import org.xwiki.resource.ResourceReferenceSerializer;
35    import org.xwiki.resource.SerializeResourceReferenceException;
36    import org.xwiki.resource.UnsupportedResourceReferenceException;
37    import org.xwiki.resource.temporary.TemporaryResourceReference;
38    import org.xwiki.url.ExtendedURL;
39    import org.xwiki.url.URLNormalizer;
40   
41    /**
42    * Serializes a {@link TemporaryResourceReference} as an {@link ExtendedURL}. The following URL format is used
43    * {@code http://<server>/<context>/tmp/<module id>/<owning entity reference>/<module-dependent resource path>}.
44    *
45    * @version $Id: d05ccd7401713514f0020515491b20a3880e0394 $
46    * @since 6.1M2
47    */
48    @Component
49    @Named("standard/tmp")
50    @Singleton
 
51    public class ExtendedURLTemporaryResourceReferenceSerializer
52    implements ResourceReferenceSerializer<TemporaryResourceReference, ExtendedURL>
53    {
54    @Inject
55    @Named("contextpath")
56    private URLNormalizer<ExtendedURL> extendedURLNormalizer;
57   
58    @Inject
59    @Named("url")
60    private EntityReferenceSerializer<String> urlEntityReferenceSerializer;
61   
 
62  0 toggle @Override
63    public ExtendedURL serialize(TemporaryResourceReference reference)
64    throws SerializeResourceReferenceException, UnsupportedResourceReferenceException
65    {
66  0 List<String> segments = new LinkedList<String>();
67  0 segments.add("tmp");
68  0 segments.add(reference.getModuleId());
69  0 segments.add(serialize(reference.getOwningEntityReference()));
70  0 segments.addAll(reference.getResourcePath());
71    // A modifiable map is used here so parameters can be added to the URL later.
72  0 Map<String, List<String>> parameters = new HashMap<String, List<String>>(reference.getParameters());
73  0 ExtendedURL result = new ExtendedURL(segments, parameters);
74  0 return this.extendedURLNormalizer.normalize(result);
75    }
76   
 
77  0 toggle private String serialize(EntityReference reference)
78    {
79  0 return reference.getType().toString().toLowerCase() + ':'
80    + this.urlEntityReferenceSerializer.serialize(reference);
81    }
82    }