1 /*
2 * Copyright (c) 2002-2018, Mairie de Paris
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice
10 * and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice
13 * and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
32 * License 1.0
33 */
34 package fr.paris.lutece.plugins.directory.modules.multiview.web.record.column.display.impl;
35
36 import java.util.Locale;
37
38 import org.apache.commons.lang3.StringUtils;
39
40 import fr.paris.lutece.plugins.directory.modules.multiview.business.record.column.IRecordColumn;
41 import fr.paris.lutece.plugins.directory.modules.multiview.business.record.column.RecordColumnCell;
42 import fr.paris.lutece.plugins.directory.modules.multiview.web.record.column.display.IRecordColumnDisplay;
43
44 /**
45 * Abstract class for the implementation of IRecordColumnDisplay
46 */
47 public abstract class AbstractRecordColumnDisplay implements IRecordColumnDisplay
48 {
49 // Constants
50 private static final String COLUMN_POSITION_SORT_ATTRIBUTE = "&column_position=%s";
51
52 // Variables
53 private String _strRecordColumnHeaderTemplate;
54 private int _nPosition;
55 private IRecordColumn _recordColumn;
56
57 /**
58 * {@inheritDoc}
59 */
60 @Override
61 public String getRecordColumnHeaderTemplate( )
62 {
63 return _strRecordColumnHeaderTemplate;
64 }
65
66 /**
67 * Set the record column header template to the record column
68 *
69 * @param strRecordColumnHeaderTemplate
70 * The record column header template to set to the record column
71 */
72 protected void setRecordColumnHeaderTemplate( String strRecordColumnHeaderTemplate )
73 {
74 _strRecordColumnHeaderTemplate = strRecordColumnHeaderTemplate;
75 }
76
77 /**
78 * {@inheritDoc}
79 */
80 @Override
81 public IRecordColumn getRecordColumn( )
82 {
83 return _recordColumn;
84 }
85
86 /**
87 * {@inheritDoc}
88 */
89 @Override
90 public void setRecordColumn( IRecordColumn recordColumn )
91 {
92 _recordColumn = recordColumn;
93 }
94
95 /**
96 * {@inheritDoc}
97 */
98 @Override
99 public int getPosition( )
100 {
101 return _nPosition;
102 }
103
104 /**
105 * {@inheritDoc}
106 */
107 @Override
108 public void setPosition( int nPosition )
109 {
110 _nPosition = nPosition;
111 }
112
113 /**
114 * {@inheritDoc}
115 */
116 @Override
117 public abstract String buildRecordColumnHeaderTemplate( String strSortUrl, Locale locale );
118
119 /**
120 * {@inheritDoc}
121 */
122 @Override
123 public abstract String buildRecordColumnCellTemplate( RecordColumnCell recordColumnCell, Locale locale );
124
125 /**
126 * Return the title of the RecordColumn or StringUtils.EMPTY if not found
127 *
128 * @return the title of the RecordColumn or StringUtils.EMPTY if not found
129 */
130 protected String getRecordColumnTitle( )
131 {
132 String strDirectoryColumnTitle = StringUtils.EMPTY;
133
134 IRecordColumn recordColumn = getRecordColumn( );
135 if ( recordColumn != null )
136 {
137 strDirectoryColumnTitle = recordColumn.getRecordColumnTitle( );
138 }
139
140 return strDirectoryColumnTitle;
141 }
142
143 /**
144 * Build the complete sort url for the column
145 *
146 * @param strSortUrl
147 * The base url for the sort of the column values
148 * @return the complete url for the sort of the column values
149 */
150 protected String buildCompleteSortUrl( String strSortUrl )
151 {
152 StringBuilder stringBuilderSortUrl = new StringBuilder( );
153
154 if ( StringUtils.isNotBlank( strSortUrl ) )
155 {
156 stringBuilderSortUrl.append( strSortUrl );
157
158 String strColumnPositionAttribute = String.format( COLUMN_POSITION_SORT_ATTRIBUTE, getPosition( ) );
159 stringBuilderSortUrl.append( strColumnPositionAttribute );
160 }
161
162 return stringBuilderSortUrl.toString( );
163 }
164 }