2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package org
.libreoffice
.report
.pentaho
.styles
;
20 import java
.util
.HashMap
;
23 import org
.pentaho
.reporting
.libraries
.resourceloader
.Resource
;
24 import org
.pentaho
.reporting
.libraries
.resourceloader
.ResourceException
;
25 import org
.pentaho
.reporting
.libraries
.resourceloader
.ResourceManager
;
29 * The style-mapper holds all information about the OpenOffice style mapping
30 * mechanism. OpenOffice references styles by their name and context, a style
31 * has a style-family assigned. The style family is determined by the element
32 * referencing the style, and there is no easily accessible information
35 * <p>Therefore this mapper acts as gatekeeper for this information. The style
36 * mapping information is read from an external definition file and can be
37 * maintained externally.</p>
41 public class StyleMapper
44 private final Map
<StyleMapperKey
,StyleMappingRule
> backend
;
48 this.backend
= new HashMap
<StyleMapperKey
,StyleMappingRule
>();
51 public void addMapping(final StyleMappingRule rule
)
53 backend
.put(rule
.getKey(), rule
);
56 public boolean isListOfStyles(final String elementNamespace
,
57 final String elementTagName
,
58 final String attributeNamespace
,
59 final String attributeName
)
61 final StyleMapperKey key
= new StyleMapperKey(elementNamespace
, elementTagName
, attributeNamespace
, attributeName
);
62 final StyleMappingRule rule
= backend
.get(key
);
63 return rule
!= null && rule
.isListOfValues();
66 public String
getStyleFamilyFor(final String elementNamespace
,
67 final String elementTagName
,
68 final String attributeNamespace
,
69 final String attributeName
)
71 final StyleMapperKey key
= new StyleMapperKey(elementNamespace
, elementTagName
, attributeNamespace
, attributeName
);
72 final StyleMappingRule rule
= backend
.get(key
);
77 return rule
.getFamily();
80 public static StyleMapper
loadInstance(final ResourceManager resourceManager
)
81 throws ResourceException
83 final Resource resource
= resourceManager
.createDirectly("res://org/libreoffice/report/pentaho/styles/stylemapper.xml", StyleMapper
.class);
84 return (StyleMapper
) resource
.getResource();