Changeset 4669


Ignore:
Timestamp:
03/11/14 16:39:52 (10 years ago)
Author:
Twan Goosen
Message:

Added CMDI view (obtained through XSLT transform) to record page

Location:
vlo/branches/vlo-3.0/vlo-web-app
Files:
3 added
6 edited
2 copied

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/pom.xml

    r4651 r4669  
    137137            <artifactId>guava</artifactId>
    138138            <version>16.0.1</version>
     139        </dependency>
     140        <dependency>
     141            <groupId>net.sf.saxon</groupId>
     142            <artifactId>Saxon-HE</artifactId>
     143            <version>9.5.1-4</version>
     144            <type>jar</type>
    139145        </dependency>
    140146    </dependencies>
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/VloWicketApplication.java

    r4661 r4669  
    11package eu.clarin.cmdi.vlo;
    22
     3import eu.clarin.cmdi.vlo.service.XmlTransformationService;
    34import eu.clarin.cmdi.vlo.service.solr.SolrDocumentService;
    45import eu.clarin.cmdi.vlo.wicket.pages.FacetedSearchPage;
     
    2425    @Autowired
    2526    private SolrDocumentService documentService;
     27    @Autowired
     28    private XmlTransformationService cmdiTransformationService;
    2629
    2730    private ApplicationContext applicationContext;
     
    7477    }
    7578
     79    /**
     80     *
     81     * @return a service that retrieves SolrDocuments from the attached index
     82     */
    7683    public SolrDocumentService getDocumentService() {
    7784        return documentService;
    7885    }
    7986
     87    /**
     88     *
     89     * @return a service that transforms CMDI documents to HTML representations
     90     */
     91    public XmlTransformationService getCmdiTransformationService() {
     92        return cmdiTransformationService;
     93    }
     94
    8095}
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/config/VloSpringConfig.java

    r4661 r4669  
    2727import eu.clarin.cmdi.vlo.service.ResourceStringConverter;
    2828import eu.clarin.cmdi.vlo.service.ResourceTypeCountingService;
     29import eu.clarin.cmdi.vlo.service.XmlTransformationService;
    2930import eu.clarin.cmdi.vlo.service.solr.SearchResultsDao;
    3031import eu.clarin.cmdi.vlo.service.solr.SolrDocumentService;
     
    3334import eu.clarin.cmdi.vlo.service.impl.ResourceStringConverterImpl;
    3435import eu.clarin.cmdi.vlo.service.impl.ResourceTypeCountingServiceImpl;
     36import eu.clarin.cmdi.vlo.service.impl.XmlTransformationServiceImpl;
    3537import eu.clarin.cmdi.vlo.service.solr.impl.SearchResultsDaoImpl;
    3638import eu.clarin.cmdi.vlo.service.solr.impl.SolrDocumentQueryFactoryImpl;
     
    3941import eu.clarin.cmdi.vlo.service.solr.impl.SolrFacetQueryFactoryImpl;
    4042import java.io.IOException;
     43import java.util.Properties;
     44import javax.xml.transform.OutputKeys;
     45import javax.xml.transform.Source;
     46import javax.xml.transform.TransformerConfigurationException;
     47import javax.xml.transform.stream.StreamSource;
    4148import org.apache.solr.client.solrj.SolrServer;
    4249import org.apache.solr.client.solrj.impl.HttpSolrServer;
     
    125132    }
    126133
     134    @Bean
     135    public XmlTransformationService cmdiTransformationService() throws TransformerConfigurationException {
     136        final Source xsltSource = new StreamSource(getClass().getResourceAsStream("/cmdi2xhtml.xsl"));
     137        //TODO: Read properties from file??
     138        final Properties transformationProperties = new Properties();
     139        transformationProperties.setProperty(OutputKeys.METHOD, "html");
     140        transformationProperties.setProperty(OutputKeys.INDENT, "yes");
     141        transformationProperties.setProperty(OutputKeys.ENCODING, "UTF-8");
     142        return new XmlTransformationServiceImpl(xsltSource, transformationProperties);
     143    }
     144
    127145    @Bean(name = "basicPropertiesFilter")
    128146    public FieldFilter basicPropertiesFieldFilter() {
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/XsltModel.java

    r4660 r4669  
    11/*
    2  * To change this license header, choose License Headers in Project Properties.
    3  * To change this template file, choose Tools | Templates
    4  * and open the template in the editor.
     2 * Copyright (C) 2014 CLARIN
     3 *
     4 * This program is free software: you can redistribute it and/or modify
     5 * it under the terms of the GNU General Public License as published by
     6 * the Free Software Foundation, either version 3 of the License, or
     7 * (at your option) any later version.
     8 *
     9 * This program is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    516 */
    6 package eu.clarin.cmdi.vlo.pages;
     17package eu.clarin.cmdi.vlo.wicket.model;
    718
     19import eu.clarin.cmdi.vlo.VloWicketApplication;
    820import java.io.IOException;
    921import java.io.InputStreamReader;
    1022import java.io.StringWriter;
    1123import java.net.URL;
     24import javax.xml.transform.TransformerException;
    1225import javax.xml.transform.stream.StreamSource;
    1326import net.sf.saxon.s9api.Processor;
     
    1831import net.sf.saxon.s9api.XsltExecutable;
    1932import net.sf.saxon.s9api.XsltTransformer;
     33import org.apache.wicket.model.IModel;
    2034import org.apache.wicket.model.LoadableDetachableModel;
    2135import org.slf4j.Logger;
     
    2943 * @author twagoo
    3044 */
    31 public class CmdiXsltModel extends LoadableDetachableModel<String> {
     45public class XsltModel extends LoadableDetachableModel<String> {
    3246
    33     private final static Logger LOG = LoggerFactory.getLogger(CmdiXsltModel.class);
    34 
    35     private final URL xslFile = getClass().getResource("/eu/clarin/cmdi/vlo/pages/cmdi2xhtml.xsl");
    36     private final URL metadataUrl;
     47    private final static Logger logger = LoggerFactory.getLogger(XsltModel.class);
     48    private final IModel<URL> metadataUrl;
    3749
    3850    /**
     
    4052     * @param metadataUrl URL of the metadata file to be presented
    4153     */
    42     public CmdiXsltModel(URL metadataUrl) {
     54    public XsltModel(IModel<URL> metadataUrl) {
    4355        this.metadataUrl = metadataUrl;
    4456    }
     
    5163    @Override
    5264    protected String load() {
    53         final Processor proc = new Processor(false);
    54         final XsltCompiler comp = proc.newXsltCompiler();
    55 
    56         final StringWriter strWriter = new StringWriter();
     65        final URL object = metadataUrl.getObject();
     66        if (object == null) {
     67            return "";
     68        }
    5769        try {
    58             final XsltExecutable exp = comp.compile(new StreamSource(xslFile.getFile()));
    59             final XdmNode source = proc.newDocumentBuilder().build(
    60                     new StreamSource(new InputStreamReader(metadataUrl.openStream())));
    61             final Serializer out = new Serializer();
    62             out.setOutputProperty(Serializer.Property.METHOD, "html");
    63             out.setOutputProperty(Serializer.Property.INDENT, "yes");
    64             out.setOutputProperty(Serializer.Property.ENCODING, "UTF-8");
    65             out.setOutputWriter(strWriter);
    66             final XsltTransformer trans = exp.load();
    67 
    68             trans.setInitialContextNode(source);
    69             trans.setDestination(out);
    70             trans.transform();
    71             return (strWriter.toString());
    72         } catch (SaxonApiException e) {
    73             LOG.error("Couldn't transform CMDI metadata at {}: ", metadataUrl, e);
    74             return ("<b>Could not load complete CMDI metadata</b>");
    75         } catch (IOException e) {
    76             LOG.error("Couldn't read CMDI metadata at {}: ", metadataUrl, e);
     70            return VloWicketApplication.get().getCmdiTransformationService().transformXml(object);
     71        } catch (TransformerException ex) {
     72            logger.error("Could not transform {}", object, ex);
    7773            return ("<b>Could not load complete CMDI metadata</b>");
    7874        }
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/RecordPage.html

    r4653 r4669  
    7171                    <a href="#" id="hiderecordcmdi" class="recordhidelink">Hide all metadata fields</a>
    7272                </p>
    73                 <div id="recordcmdi">
    74                     <h2>CMDI Metadata</h2>
    75                     <!--<p><a href="#" id="recordcmditoggle">View/Hide CMDI metadata</a></p>-->
    76                     <article xmlns:cmd="http://www.clarin.eu/cmd/" xmlns:fn="http://www.w3.org/2005/xpath-functions" style="background-color:#EEEEEE">
    77                         <div class="endgame">
    78                             <p>
    79                                 <h1>Resources</h1>
    80                                 <table>
    81                                     <caption>Resources</caption>
    82                                     <thead>
    83                                         <tr>
    84                                             <th class="attribute">Reference to resource</th>
    85                                             <th class="attribute">Resource description</th>
    86                                             <th class="attribute">Resource MIME type</th>
    87                                             <th class="attribute">Resource Proxy ID</th>
    88                                         </tr>
    89                                     </thead>
    90                                     <tbody class="attributesTbody">
    91                                         <tr>
    92                                             <td class="attributeValue"><a href="http://dspace.library.uu.nl/handle/1874/205294">http://dspace.library.uu.nl/handle/1874/205294</a></td>
    93                                             <td class="attributeValue">LandingPage</td>
    94                                             <td class="attributeValue">text/html</td>
    95                                             <td class="attributeValue">h.1874.205294</td>
    96                                         </tr>
    97                                         <tr>
    98                                             <td class="attributeValue"><a href="http://dspace.library.uu.nl/bitstream/1874/205294/1/Masterthesis+Carolyn+van+de+Wall.docx">http://dspace.library.uu.nl/bitstream/1874/205294/1/Masterthesis+Carolyn+van+de+Wall.docx</a></td>
    99                                             <td class="attributeValue">Resource</td>
    100                                             <td class="attributeValue">application/octet-stream</td>
    101                                             <td class="attributeValue">h.1874.205294.1</td>
    102                                         </tr>
    103                                     </tbody>
    104                                 </table>
    105                             </p>
    106                         </div>
    107                         <p>
    108                             <h1>Metadata content</h1>
    109                             <ul>
    110                                 <li><code class="node">mods
    111                                         <div class="attributes">version="3.2"
    112 
    113                                         </div></code><ul>
    114                                         <ul>
    115                                             <li><code class="node">edboOverlap </code><div class="Component_tree_node_content"><code class="leaf">no</code></div>
    116                                             </li>
    117                                             <li><code class="node">machineReadable </code><div class="Component_tree_node_content"><code class="leaf">unknown</code></div>
    118                                             </li>
    119                                             <li><code class="node">typeOfResource </code><div class="Component_tree_node_content"><code class="leaf">text</code></div>
    120                                             </li>
    121                                             <li><code class="node">genre </code><div class="Component_tree_node_content"><code class="leaf">info:eu-repo/semantics/masterThesis</code></div>
    122                                             </li>
    123                                             <li><code class="node">titleInfo </code><ul>
    124                                                     <ul>
    125                                                         <li><code class="node">title </code><div class="Component_tree_node_content"><code class="leaf">" De professionaliteit van medisch specialisten onder de loep"</code></div>
    126                                                         </li>
    127                                                     </ul>
    128                                                 </ul>
    129                                             </li>
    130                                             <li><code class="node">name
    131                                                     <div class="attributes">ID="n205294_aut_1"
    132                                                         type="personal"
    133 
    134                                                     </div></code><ul>
    135                                                     <ul>
    136                                                         <li><code class="node">namePart
    137                                                                 <div class="attributes">type="family"
    138 
    139                                                                 </div></code><div class="Component_tree_node_content"><code class="leaf">Wall</code></div>
    140                                                         </li>
    141                                                         <li><code class="node">namePart
    142                                                                 <div class="attributes">type="given"
    143 
    144                                                                 </div></code><div class="Component_tree_node_content"><code class="leaf"> C.J. van de</code></div>
    145                                                         </li>
    146                                                         <li><code class="node">role </code><ul>
    147                                                                 <ul>
    148                                                                     <li><code class="node">roleTerm
    149                                                                             <div class="attributes">authority="marcrelator"
    150                                                                                 type="code"
    151 
    152                                                                             </div></code><div class="Component_tree_node_content"><code class="leaf">aut</code></div>
    153                                                                     </li>
    154                                                                 </ul>
    155                                                             </ul>
    156                                                         </li>
    157                                                     </ul>
    158                                                 </ul>
    159                                             </li>
    160                                             <li><code class="node">name
    161                                                     <div class="attributes">ID="n205294_ths_1"
    162                                                         type="personal"
    163 
    164                                                     </div></code><ul>
    165                                                     <ul>
    166                                                         <li><code class="node">namePart
    167                                                                 <div class="attributes">type="family"
    168 
    169                                                                 </div></code><div class="Component_tree_node_content"><code class="leaf">Knies</code></div>
    170                                                         </li>
    171                                                         <li><code class="node">namePart
    172                                                                 <div class="attributes">type="given"
    173 
    174                                                                 </div></code><div class="Component_tree_node_content"><code class="leaf"> E.</code></div>
    175                                                         </li>
    176                                                         <li><code class="node">role </code><ul>
    177                                                                 <ul>
    178                                                                     <li><code class="node">roleTerm
    179                                                                             <div class="attributes">authority="marcrelator"
    180                                                                                 type="code"
    181 
    182                                                                             </div></code><div class="Component_tree_node_content"><code class="leaf">ths</code></div>
    183                                                                     </li>
    184                                                                 </ul>
    185                                                             </ul>
    186                                                         </li>
    187                                                     </ul>
    188                                                 </ul>
    189                                             </li>
    190                                             <li><code class="node">originInfo </code><ul>
    191                                                     <ul>
    192                                                         <li><code class="node">dateCreated
    193                                                                 <div class="attributes">encoding="iso8601"
    194 
    195                                                                 </div></code><div class="Component_tree_node_content"><code class="leaf">2011-03-31</code></div>
    196                                                         </li>
    197                                                         <li><code class="node">dateCreated
    198                                                                 <div class="attributes">encoding="iso8601"
    199 
    200                                                                 </div></code><div class="Component_tree_node_content"><code class="leaf">2011-05-31</code></div>
    201                                                         </li>
    202                                                     </ul>
    203                                                 </ul>
    204                                             </li>
    205                                             <li><code class="node">language </code><ul>
    206                                                     <ul>
    207                                                         <li><code class="node">languageTerm
    208                                                                 <div class="attributes">authority="rfc3066"
    209                                                                     type="code"
    210 
    211                                                                 </div></code><div class="Component_tree_node_content"><code class="leaf">nl</code></div>
    212                                                         </li>
    213                                                     </ul>
    214                                                 </ul>
    215                                             </li>
    216                                             <li><code class="node">subject </code><ul>
    217                                                     <ul>
    218                                                         <li><code class="node">topic </code><div class="Component_tree_node_content"><code class="leaf">professionaliteit, ziekenhuis, medisch specialisten, management, Klink, loondienst,
    219                                                                     maatschappen, autonomie, kwaliteit zorg, motivatie, ondersteunend personeel</code></div>
    220                                                         </li>
    221                                                     </ul>
    222                                                 </ul>
    223                                             </li>
    224                                         </ul>
    225                                     </ul>
    226                                 </li>
    227                             </ul>
    228                         </p>
    229                     </article>
    230                 </div> <!-- recordcmdi -->
     73                <div wicket:id="cmdi" id="recordcmdi">[CMDI metadata]</div>
    23174
    23275                <p id="recordtechnicaldetailstoggle" class="recordtogglelinks">
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/RecordPage.java

    r4661 r4669  
    2727import eu.clarin.cmdi.vlo.wicket.model.SolrFieldModel;
    2828import eu.clarin.cmdi.vlo.wicket.model.SolrFieldStringModel;
     29import eu.clarin.cmdi.vlo.wicket.model.UrlFromStringModel;
     30import eu.clarin.cmdi.vlo.wicket.model.XsltModel;
    2931import eu.clarin.cmdi.vlo.wicket.provider.DocumentFieldsProvider;
    3032import org.apache.solr.common.SolrDocument;
     33import org.apache.wicket.markup.html.basic.Label;
    3134import org.apache.wicket.markup.html.link.ExternalLink;
    3235import org.apache.wicket.model.IModel;
     
    5255    public RecordPage(PageParameters params) {
    5356        super(params);
    54        
     57
    5558        final SolrDocumentModel documentModel = new SolrDocumentModel(params.get("docId").toString());
    5659        setModel(documentModel);
    57        
     60
    5861        final QueryFacetsSelection selection = selectionParametersConverter.fromParameters(params);
    5962        this.contextModel = Model.of(selection);
    60        
    61         addComponents(documentModel);
     63
     64        addComponents();
    6265    }
    6366
     
    6568        super(documentModel);
    6669        this.contextModel = contextModel;
    67         addComponents(documentModel);
     70        addComponents();
    6871    }
    6972
    70     private void addComponents(IModel<SolrDocument> documentModel) {
    71         add(new SolrFieldLabel("name", documentModel, FacetConstants.FIELD_NAME, "Unnamed record"));
    72         add(createLandingPageLink("landingPageLink", documentModel));
    73         add(new FieldsTablePanel("documentProperties", new DocumentFieldsProvider(documentModel, basicPropertiesFilter)));
    74         add(new ResourceLinksPanel("resources", new SolrFieldModel<String>(documentModel, FacetConstants.FIELD_RESOURCE)));
    75         add(new FieldsTablePanel("technicalProperties", new DocumentFieldsProvider(documentModel, technicalPropertiesFilter)));
     73    private void addComponents() {
     74        // General information section
     75        add(new SolrFieldLabel("name", getModel(), FacetConstants.FIELD_NAME, "Unnamed record"));
     76        add(createLandingPageLink("landingPageLink"));
     77        add(new FieldsTablePanel("documentProperties", new DocumentFieldsProvider(getModel(), basicPropertiesFilter)));
     78       
     79        // Resources section
     80        add(new ResourceLinksPanel("resources", new SolrFieldModel<String>(getModel(), FacetConstants.FIELD_RESOURCE)));
     81       
     82        // Technical section
     83        add(createCmdiContent("cmdi"));
     84        add(new FieldsTablePanel("technicalProperties", new DocumentFieldsProvider(getModel(), technicalPropertiesFilter)));
    7685    }
    7786
    78     private ExternalLink createLandingPageLink(String id, IModel<SolrDocument> documentModel) {
    79         final SolrFieldStringModel landingPageHrefModel = new SolrFieldStringModel(documentModel, FacetConstants.FIELD_LANDINGPAGE);
     87    private ExternalLink createLandingPageLink(String id) {
     88        final SolrFieldStringModel landingPageHrefModel = new SolrFieldStringModel(getModel(), FacetConstants.FIELD_LANDINGPAGE);
    8089        // add landing page link
    8190        final ExternalLink landingPageLink = new ExternalLink(id, landingPageHrefModel) {
     
    91100    }
    92101
     102    private Label createCmdiContent(String id) {
     103        final IModel<String> locationModel = new SolrFieldStringModel(getModel(), FacetConstants.FIELD_FILENAME);
     104        final UrlFromStringModel locationUrlModel = new UrlFromStringModel(locationModel);
     105        final Label cmdiContentLabel = new Label(id, new XsltModel(locationUrlModel));
     106        cmdiContentLabel.setEscapeModelStrings(false);
     107        return cmdiContentLabel;
     108    }
     109
    93110    @Override
    94111    public void detachModels() {
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/provider/FacetFieldValuesProvider.java

    r4666 r4669  
    3535 * SOLR) present on a {@link FacetField}, sortable by either count or name
    3636 *
     37 * TODO: Add option to hide values with only 1 record (as in VLO 2.x)
     38 *
    3739 * @see FieldValuesOrder
    3840 * @author twagoo
Note: See TracChangeset for help on using the changeset viewer.