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

File XHTMLMarkerResourceReferenceSerializer.java

 

Coverage histogram

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

Code metrics

2
11
1
1
82
32
2
0.18
11
1
2

Classes

Class Line # Actions
XHTMLMarkerResourceReferenceSerializer 43 11 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 57 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.rendering.internal.renderer.xhtml;
21   
22    import java.util.Map;
23   
24    import javax.inject.Named;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.rendering.internal.renderer.ParametersPrinter;
29    import org.xwiki.rendering.listener.reference.ResourceReference;
30    import org.xwiki.rendering.renderer.reference.ResourceReferenceSerializer;
31   
32    /**
33    * Serialize a Resource Reference into XHTML comments using the syntax
34    * {@code (isTyped)|-|(type)|-|(reference)|-|(parameters: key="value")}. This is used for example to save a Link or
35    * Image Reference in XHTML Comment in the Annotated XHTML Renderer.
36    *
37    * @version $Id: 9c94763fb83345aa2cfc2d0a4b024291e3fccfbb $
38    * @since 2.5RC1
39    */
40    @Component
41    @Named("xhtmlmarker")
42    @Singleton
 
43    public class XHTMLMarkerResourceReferenceSerializer implements ResourceReferenceSerializer
44    {
45    /**
46    * Character to separate Link reference and parameters in XHTML comments.
47    */
48    private static final String COMMENT_SEPARATOR = "|-|";
49   
50    /**
51    * Used to print Link Parameters in XHTML comments.
52    */
53    private static final ParametersPrinter PARAMETERS_PRINTER = new ParametersPrinter('\\');
54   
 
55  82 toggle @Override
56    public String serialize(ResourceReference reference)
57    {
58  82 StringBuilder buffer = new StringBuilder();
59   
60    // Print if the Resource Reference is typed, the Resource Reference Type and the Reference itself
61  82 buffer.append(reference.isTyped());
62  82 buffer.append(COMMENT_SEPARATOR);
63  82 buffer.append(reference.getType().getScheme());
64  82 buffer.append(COMMENT_SEPARATOR);
65  82 buffer.append(reference.getReference());
66   
67    // Print Resource Reference parameters. We need to do this so that the XHTML parser doesn't have
68    // to parse the query string to extract the parameters. Doing so could lead to false result since
69    // for example the XHTML renderer can add a parent parameter in the query string for links to non
70    // existing documents.
71    //
72    // Also note that we don't need to print Resource Reference parameters since they are added as XHTML class
73    // attributes by the XHTML Renderer and thus the XHTML parser will be able to get them again as attributes.
74  82 Map<String, String> linkReferenceParameters = reference.getParameters();
75  82 if (!linkReferenceParameters.isEmpty()) {
76  8 buffer.append(COMMENT_SEPARATOR);
77  8 buffer.append(PARAMETERS_PRINTER.print(linkReferenceParameters));
78    }
79   
80  82 return buffer.toString();
81    }
82    }