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

File AbstractExtendedURLResourceReferenceSerializer.java

 

Coverage histogram

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

Code metrics

0
7
1
1
81
37
3
0.43
7
1
3

Classes

Class Line # Actions
AbstractExtendedURLResourceReferenceSerializer 40 7 0% 3 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.url.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24   
25    import org.xwiki.component.manager.ComponentLookupException;
26    import org.xwiki.component.manager.ComponentManager;
27    import org.xwiki.component.util.DefaultParameterizedType;
28    import org.xwiki.resource.ResourceReference;
29    import org.xwiki.resource.ResourceReferenceSerializer;
30    import org.xwiki.resource.SerializeResourceReferenceException;
31    import org.xwiki.resource.UnsupportedResourceReferenceException;
32    import org.xwiki.url.ExtendedURL;
33   
34    /**
35    * Helper class to implement a Serializer to transform a XWiki Resource into a {@link ExtendedURL} object.
36    *
37    * @version $Id: 64a22388ced51b3be084549c682dee9b0026a692 $
38    * @since 7.2M1
39    */
 
40    public abstract class AbstractExtendedURLResourceReferenceSerializer
41    implements ResourceReferenceSerializer<ResourceReference, ExtendedURL>
42    {
43    @Inject
44    @Named("context")
45    private ComponentManager componentManager;
46   
47    /**
48    * Transforms a Resource Reference into some other representation.
49    *
50    * @param reference the Resource Reference to transform
51    * @param formatId the id of the URL format to use (e.g. "standard", "referene", etc)
52    * @return the new representation
53    * @throws SerializeResourceReferenceException if there was an error while serializing the XWiki Resource object
54    * @throws UnsupportedResourceReferenceException if the passed representation points to an unsupported Resource
55    * Reference type that we don't know how to serialize
56    */
 
57  25717 toggle public ExtendedURL serialize(ResourceReference reference, String formatId)
58    throws SerializeResourceReferenceException, UnsupportedResourceReferenceException
59    {
60    // Step 1: Try to locate a Serializer registered for the specific passed resource type and for the passed URL
61    // format id
62  25717 ResourceReferenceSerializer<ResourceReference, ExtendedURL> serializer;
63  25717 try {
64  25717 serializer = this.componentManager.getInstance(new DefaultParameterizedType(null,
65    ResourceReferenceSerializer.class, reference.getClass(), ExtendedURL.class), formatId);
66    } catch (ComponentLookupException e) {
67    // Step 2: Try to locate a Serializer registered only for the specific passed resource type and for all URL
68    // format ids
69  25714 try {
70  25715 serializer = this.componentManager.getInstance(new DefaultParameterizedType(null,
71    ResourceReferenceSerializer.class, reference.getClass(), ExtendedURL.class));
72    } catch (ComponentLookupException cle) {
73  1 throw new UnsupportedResourceReferenceException(String.format(
74    "Failed to find serializer for Resource Reference [%s] and URL format [%s]", reference, formatId),
75    cle);
76    }
77    }
78   
79  25716 return serializer.serialize(reference);
80    }
81    }