You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2017/06/06 13:06:35 UTC
[09/10] syncope git commit: [SYNCOPE-1103] Option to put Quartz
scheduler in standby, from provisioning.properties
http://git-wip-us.apache.org/repos/asf/syncope/blob/bd695da7/core/logic/src/main/java/org/apache/syncope/core/logic/report/GroupReportlet.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/GroupReportlet.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/GroupReportlet.java
deleted file mode 100644
index 0aeaf0a..0000000
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/report/GroupReportlet.java
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.logic.report;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.syncope.common.lib.SyncopeConstants;
-import org.apache.syncope.common.lib.report.GroupReportletConf;
-import org.apache.syncope.common.lib.report.GroupReportletConf.Feature;
-import org.apache.syncope.common.lib.report.ReportletConf;
-import org.apache.syncope.common.lib.to.AnyTO;
-import org.apache.syncope.common.lib.to.AttrTO;
-import org.apache.syncope.common.lib.to.GroupTO;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.core.persistence.api.dao.AnyDAO;
-import org.apache.syncope.core.persistence.api.dao.GroupDAO;
-import org.apache.syncope.core.persistence.api.dao.search.OrderByClause;
-import org.apache.syncope.core.persistence.api.entity.group.Group;
-import org.apache.syncope.core.persistence.api.search.SearchCondConverter;
-import org.apache.syncope.core.persistence.api.dao.AnySearchDAO;
-import org.apache.syncope.core.persistence.api.dao.ReportletConfClass;
-import org.apache.syncope.core.persistence.api.entity.user.UMembership;
-import org.apache.syncope.core.provisioning.api.data.GroupDataBinder;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-
-@ReportletConfClass(GroupReportletConf.class)
-public class GroupReportlet extends AbstractReportlet {
-
- @Autowired
- private GroupDAO groupDAO;
-
- @Autowired
- private AnySearchDAO searchDAO;
-
- @Autowired
- private GroupDataBinder groupDataBinder;
-
- private GroupReportletConf conf;
-
- private void doExtractResources(final ContentHandler handler, final AnyTO anyTO)
- throws SAXException {
-
- if (anyTO.getResources().isEmpty()) {
- LOG.debug("No resources found for {}[{}]", anyTO.getClass().getSimpleName(), anyTO.getKey());
- } else {
- AttributesImpl atts = new AttributesImpl();
- handler.startElement("", "", "resources", null);
-
- for (String resourceName : anyTO.getResources()) {
- atts.clear();
-
- atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, resourceName);
- handler.startElement("", "", "resource", atts);
- handler.endElement("", "", "resource");
- }
-
- handler.endElement("", "", "resources");
- }
- }
-
- private void doExtractAttributes(final ContentHandler handler, final AnyTO anyTO,
- final Collection<String> attrs, final Collection<String> derAttrs, final Collection<String> virAttrs)
- throws SAXException {
-
- AttributesImpl atts = new AttributesImpl();
- if (!attrs.isEmpty()) {
- Map<String, AttrTO> attrMap = anyTO.getPlainAttrMap();
-
- handler.startElement("", "", "attributes", null);
- for (String attrName : attrs) {
- atts.clear();
-
- atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
- handler.startElement("", "", "attribute", atts);
-
- if (attrMap.containsKey(attrName)) {
- for (String value : attrMap.get(attrName).getValues()) {
- handler.startElement("", "", "value", null);
- handler.characters(value.toCharArray(), 0, value.length());
- handler.endElement("", "", "value");
- }
- } else {
- LOG.debug("{} not found for {}[{}]", attrName,
- anyTO.getClass().getSimpleName(), anyTO.getKey());
- }
-
- handler.endElement("", "", "attribute");
- }
- handler.endElement("", "", "attributes");
- }
-
- if (!derAttrs.isEmpty()) {
- Map<String, AttrTO> derAttrMap = anyTO.getDerAttrMap();
-
- handler.startElement("", "", "derivedAttributes", null);
- for (String attrName : derAttrs) {
- atts.clear();
-
- atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
- handler.startElement("", "", "derivedAttribute", atts);
-
- if (derAttrMap.containsKey(attrName)) {
- for (String value : derAttrMap.get(attrName).getValues()) {
- handler.startElement("", "", "value", null);
- handler.characters(value.toCharArray(), 0, value.length());
- handler.endElement("", "", "value");
- }
- } else {
- LOG.debug("{} not found for {}[{}]", attrName,
- anyTO.getClass().getSimpleName(), anyTO.getKey());
- }
-
- handler.endElement("", "", "derivedAttribute");
- }
- handler.endElement("", "", "derivedAttributes");
- }
-
- if (!virAttrs.isEmpty()) {
- Map<String, AttrTO> virAttrMap = anyTO.getVirAttrMap();
-
- handler.startElement("", "", "virtualAttributes", null);
- for (String attrName : virAttrs) {
- atts.clear();
-
- atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
- handler.startElement("", "", "virtualAttribute", atts);
-
- if (virAttrMap.containsKey(attrName)) {
- for (String value : virAttrMap.get(attrName).getValues()) {
- handler.startElement("", "", "value", null);
- handler.characters(value.toCharArray(), 0, value.length());
- handler.endElement("", "", "value");
- }
- } else {
- LOG.debug("{} not found for {}[{}]", attrName,
- anyTO.getClass().getSimpleName(), anyTO.getKey());
- }
-
- handler.endElement("", "", "virtualAttribute");
- }
- handler.endElement("", "", "virtualAttributes");
- }
- }
-
- private void doExtract(final ContentHandler handler, final List<Group> groups) throws SAXException {
- AttributesImpl atts = new AttributesImpl();
- for (Group group : groups) {
- atts.clear();
-
- for (Feature feature : conf.getFeatures()) {
- String type = null;
- String value = null;
- switch (feature) {
- case key:
- type = ReportXMLConst.XSD_STRING;
- value = group.getKey();
- break;
-
- case name:
- type = ReportXMLConst.XSD_STRING;
- value = String.valueOf(group.getName());
- break;
-
- case groupOwner:
- type = ReportXMLConst.XSD_STRING;
- value = group.getGroupOwner().getKey();
- break;
-
- case userOwner:
- type = ReportXMLConst.XSD_STRING;
- value = group.getUserOwner().getKey();
- break;
-
- default:
- }
-
- if (type != null && value != null) {
- atts.addAttribute("", "", feature.name(), type, value);
- }
- }
-
- handler.startElement("", "", "group", atts);
-
- // Using GroupTO for attribute values, since the conversion logic of
- // values to String is already encapsulated there
- GroupTO groupTO = groupDataBinder.getGroupTO(group, true);
-
- doExtractAttributes(handler, groupTO, conf.getPlainAttrs(), conf.getDerAttrs(), conf.getVirAttrs());
-
- // to get resources associated to a group
- if (conf.getFeatures().contains(Feature.resources)) {
- doExtractResources(handler, groupTO);
- }
- //to get users asscoiated to a group is preferred GroupDAO to GroupTO
- if (conf.getFeatures().contains(Feature.users)) {
- handler.startElement("", "", "users", null);
-
- for (UMembership memb : groupDAO.findUMemberships(group)) {
- atts.clear();
-
- atts.addAttribute("", "", "key", ReportXMLConst.XSD_STRING,
- memb.getLeftEnd().getKey());
- atts.addAttribute("", "", "username", ReportXMLConst.XSD_STRING,
- String.valueOf(memb.getLeftEnd().getUsername()));
-
- handler.startElement("", "", "user", atts);
- handler.endElement("", "", "user");
- }
-
- handler.endElement("", "", "users");
- }
-
- handler.endElement("", "", "group");
- }
- }
-
- private void doExtractConf(final ContentHandler handler) throws SAXException {
- if (conf == null) {
- LOG.debug("Report configuration is not present");
- }
-
- AttributesImpl atts = new AttributesImpl();
- handler.startElement("", "", "configurations", null);
- handler.startElement("", "", "groupAttributes", atts);
-
- if (conf != null) {
- for (Feature feature : conf.getFeatures()) {
- atts.clear();
- handler.startElement("", "", "feature", atts);
- handler.characters(feature.name().toCharArray(), 0, feature.name().length());
- handler.endElement("", "", "feature");
- }
-
- for (String attr : conf.getPlainAttrs()) {
- atts.clear();
- handler.startElement("", "", "attribute", atts);
- handler.characters(attr.toCharArray(), 0, attr.length());
- handler.endElement("", "", "attribute");
- }
-
- for (String derAttr : conf.getDerAttrs()) {
- atts.clear();
- handler.startElement("", "", "derAttribute", atts);
- handler.characters(derAttr.toCharArray(), 0, derAttr.length());
- handler.endElement("", "", "derAttribute");
- }
-
- for (String virAttr : conf.getVirAttrs()) {
- atts.clear();
- handler.startElement("", "", "virAttribute", atts);
- handler.characters(virAttr.toCharArray(), 0, virAttr.length());
- handler.endElement("", "", "virAttribute");
- }
- }
-
- handler.endElement("", "", "groupAttributes");
- handler.endElement("", "", "configurations");
- }
-
- private int count() {
- return StringUtils.isBlank(conf.getMatchingCond())
- ? groupDAO.count()
- : searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS,
- SearchCondConverter.convert(conf.getMatchingCond()), AnyTypeKind.GROUP);
- }
-
- @Override
- protected void doExtract(final ReportletConf conf, final ContentHandler handler) throws SAXException {
- if (conf instanceof GroupReportletConf) {
- this.conf = GroupReportletConf.class.cast(conf);
- } else {
- throw new ReportException(new IllegalArgumentException("Invalid configuration provided"));
- }
-
- doExtractConf(handler);
-
- for (int page = 1; page <= (count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
- List<Group> groups;
- if (StringUtils.isBlank(this.conf.getMatchingCond())) {
- groups = groupDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE);
- } else {
- groups = searchDAO.search(
- SyncopeConstants.FULL_ADMIN_REALMS,
- SearchCondConverter.convert(this.conf.getMatchingCond()),
- page,
- AnyDAO.DEFAULT_PAGE_SIZE,
- Collections.<OrderByClause>emptyList(),
- AnyTypeKind.USER);
- }
-
- doExtract(handler, groups);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/bd695da7/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReconciliationReportlet.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReconciliationReportlet.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReconciliationReportlet.java
deleted file mode 100644
index 4922015..0000000
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReconciliationReportlet.java
+++ /dev/null
@@ -1,519 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.logic.report;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import org.apache.commons.collections4.Closure;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.syncope.common.lib.SyncopeConstants;
-import org.apache.syncope.common.lib.report.ReconciliationReportletConf;
-import org.apache.syncope.common.lib.report.ReconciliationReportletConf.Feature;
-import org.apache.syncope.common.lib.report.ReportletConf;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.core.persistence.api.dao.AnyDAO;
-import org.apache.syncope.core.persistence.api.search.SearchCondConverter;
-import org.apache.syncope.core.provisioning.api.utils.FormatUtils;
-import org.apache.syncope.core.persistence.api.dao.AnySearchDAO;
-import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
-import org.apache.syncope.core.persistence.api.dao.GroupDAO;
-import org.apache.syncope.core.persistence.api.dao.ReportletConfClass;
-import org.apache.syncope.core.persistence.api.dao.UserDAO;
-import org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond;
-import org.apache.syncope.core.persistence.api.dao.search.OrderByClause;
-import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
-import org.apache.syncope.core.persistence.api.entity.Any;
-import org.apache.syncope.core.persistence.api.entity.AnyType;
-import org.apache.syncope.core.persistence.api.entity.AnyUtils;
-import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
-import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
-import org.apache.syncope.core.persistence.api.entity.group.Group;
-import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
-import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
-import org.apache.syncope.core.persistence.api.entity.resource.Provision;
-import org.apache.syncope.core.persistence.api.entity.user.User;
-import org.apache.syncope.core.provisioning.api.Connector;
-import org.apache.syncope.core.provisioning.api.ConnectorFactory;
-import org.apache.syncope.core.provisioning.api.MappingManager;
-import org.apache.syncope.core.provisioning.java.utils.MappingUtils;
-import org.identityconnectors.common.Base64;
-import org.identityconnectors.framework.common.objects.Attribute;
-import org.identityconnectors.framework.common.objects.AttributeBuilder;
-import org.identityconnectors.framework.common.objects.ConnectorObject;
-import org.identityconnectors.framework.common.objects.OperationalAttributes;
-import org.identityconnectors.framework.common.objects.Uid;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-
-/**
- * Reportlet for extracting information for the current reconciliation status, e.g. the coherence between Syncope
- * information and mapped entities on external resources.
- */
-@ReportletConfClass(ReconciliationReportletConf.class)
-public class ReconciliationReportlet extends AbstractReportlet {
-
- private static final int PAGE_SIZE = 10;
-
- @Autowired
- private UserDAO userDAO;
-
- @Autowired
- private GroupDAO groupDAO;
-
- @Autowired
- private AnyTypeDAO anyTypeDAO;
-
- @Autowired
- private AnySearchDAO searchDAO;
-
- @Autowired
- private MappingManager mappingManager;
-
- @Autowired
- private ConnectorFactory connFactory;
-
- @Autowired
- private AnyUtilsFactory anyUtilsFactory;
-
- private ReconciliationReportletConf conf;
-
- private String getAnyElementName(final AnyTypeKind anyTypeKind) {
- String elementName;
-
- switch (anyTypeKind) {
- case USER:
- elementName = "user";
- break;
-
- case GROUP:
- elementName = "group";
- break;
-
- case ANY_OBJECT:
- default:
- elementName = "anyObject";
- }
-
- return elementName;
- }
-
- private void doExtract(
- final ContentHandler handler,
- final Any<?> any,
- final Set<Missing> missing,
- final Set<Misaligned> misaligned)
- throws SAXException {
-
- AttributesImpl atts = new AttributesImpl();
-
- for (Feature feature : conf.getFeatures()) {
- String type = null;
- String value = null;
- switch (feature) {
- case key:
- type = ReportXMLConst.XSD_STRING;
- value = any.getKey();
- break;
-
- case username:
- if (any instanceof User) {
- type = ReportXMLConst.XSD_STRING;
- value = User.class.cast(any).getUsername();
- }
- break;
-
- case groupName:
- if (any instanceof Group) {
- type = ReportXMLConst.XSD_STRING;
- value = Group.class.cast(any).getName();
- }
- break;
-
- case workflowId:
- type = ReportXMLConst.XSD_STRING;
- value = any.getWorkflowId();
- break;
-
- case status:
- type = ReportXMLConst.XSD_STRING;
- value = any.getStatus();
- break;
-
- case creationDate:
- type = ReportXMLConst.XSD_DATETIME;
- value = any.getCreationDate() == null
- ? StringUtils.EMPTY
- : FormatUtils.format(any.getCreationDate());
- break;
-
- case lastLoginDate:
- if (any instanceof User) {
- type = ReportXMLConst.XSD_DATETIME;
- value = User.class.cast(any).getLastLoginDate() == null
- ? StringUtils.EMPTY
- : FormatUtils.format(User.class.cast(any).getLastLoginDate());
- }
- break;
-
- case changePwdDate:
- if (any instanceof User) {
- type = ReportXMLConst.XSD_DATETIME;
- value = User.class.cast(any).getChangePwdDate() == null
- ? StringUtils.EMPTY
- : FormatUtils.format(User.class.cast(any).getChangePwdDate());
- }
- break;
-
- case passwordHistorySize:
- if (any instanceof User) {
- type = ReportXMLConst.XSD_INT;
- value = String.valueOf(User.class.cast(any).getPasswordHistory().size());
- }
- break;
-
- case failedLoginCount:
- if (any instanceof User) {
- type = ReportXMLConst.XSD_INT;
- value = String.valueOf(User.class.cast(any).getFailedLogins());
- }
- break;
-
- default:
- }
-
- if (type != null && value != null) {
- atts.addAttribute("", "", feature.name(), type, value);
- }
- }
-
- handler.startElement("", "", getAnyElementName(any.getType().getKind()), atts);
-
- for (Missing item : missing) {
- atts.clear();
- atts.addAttribute("", "", "resource", ReportXMLConst.XSD_STRING, item.getResource());
- atts.addAttribute("", "", "connObjectKeyValue", ReportXMLConst.XSD_STRING, item.getConnObjectKeyValue());
-
- handler.startElement("", "", "missing", atts);
- handler.endElement("", "", "missing");
- }
- for (Misaligned item : misaligned) {
- atts.clear();
- atts.addAttribute("", "", "resource", ReportXMLConst.XSD_STRING, item.getResource());
- atts.addAttribute("", "", "connObjectKeyValue", ReportXMLConst.XSD_STRING, item.getConnObjectKeyValue());
- atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, item.getName());
-
- handler.startElement("", "", "misaligned", atts);
-
- handler.startElement("", "", "onSyncope", null);
- if (item.getOnSyncope() != null) {
- for (Object value : item.getOnSyncope()) {
- char[] asChars = value.toString().toCharArray();
-
- handler.startElement("", "", "value", null);
- handler.characters(asChars, 0, asChars.length);
- handler.endElement("", "", "value");
- }
- }
- handler.endElement("", "", "onSyncope");
-
- handler.startElement("", "", "onResource", null);
- if (item.getOnResource() != null) {
- for (Object value : item.getOnResource()) {
- char[] asChars = value.toString().toCharArray();
-
- handler.startElement("", "", "value", null);
- handler.characters(asChars, 0, asChars.length);
- handler.endElement("", "", "value");
- }
- }
- handler.endElement("", "", "onResource");
-
- handler.endElement("", "", "misaligned");
- }
-
- handler.endElement("", "", getAnyElementName(any.getType().getKind()));
- }
-
- private Set<Object> getValues(final Attribute attr) {
- Set<Object> values;
- if (attr.getValue() == null || attr.getValue().isEmpty()) {
- values = Collections.emptySet();
- } else if (attr.getValue().get(0) instanceof byte[]) {
- values = new HashSet<>(attr.getValue().size());
- for (Object single : attr.getValue()) {
- values.add(Base64.encode((byte[]) single));
- }
- } else {
- values = new HashSet<>(attr.getValue());
- }
-
- return values;
- }
-
- private void doExtract(final ContentHandler handler, final List<? extends Any<?>> anys)
- throws SAXException, ReportException {
-
- final Set<Missing> missing = new HashSet<>();
- final Set<Misaligned> misaligned = new HashSet<>();
-
- for (Any<?> any : anys) {
- missing.clear();
- misaligned.clear();
-
- AnyUtils anyUtils = anyUtilsFactory.getInstance(any);
- for (final ExternalResource resource : anyUtils.getAllResources(any)) {
- Provision provision = resource.getProvision(any.getType());
- MappingItem connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision);
- final String connObjectKeyValue = connObjectKeyItem == null
- ? StringUtils.EMPTY
- : mappingManager.getConnObjectKeyValue(any, provision);
- if (provision != null && connObjectKeyItem != null && StringUtils.isNotBlank(connObjectKeyValue)) {
- // 1. read from the underlying connector
- Connector connector = connFactory.getConnector(resource);
- ConnectorObject connectorObject = connector.getObject(provision.getObjectClass(),
- new Uid(connObjectKeyValue),
- MappingUtils.buildOperationOptions(provision.getMapping().getItems().iterator()));
-
- if (connectorObject == null) {
- // 2. not found on resource?
- LOG.error("Object {} with class {} not found on resource {}",
- connObjectKeyValue, provision.getObjectClass(), resource);
-
- missing.add(new Missing(resource.getKey(), connObjectKeyValue));
- } else {
- // 3. found but misaligned?
- Pair<String, Set<Attribute>> preparedAttrs =
- mappingManager.prepareAttrs(any, null, false, null, provision);
- preparedAttrs.getRight().add(AttributeBuilder.build(
- Uid.NAME, preparedAttrs.getLeft()));
- preparedAttrs.getRight().add(AttributeBuilder.build(
- connObjectKeyItem.getExtAttrName(), preparedAttrs.getLeft()));
-
- final Map<String, Set<Object>> syncopeAttrs = new HashMap<>();
- for (Attribute attr : preparedAttrs.getRight()) {
- syncopeAttrs.put(attr.getName(), getValues(attr));
- }
-
- final Map<String, Set<Object>> resourceAttrs = new HashMap<>();
- for (Attribute attr : connectorObject.getAttributes()) {
- if (!OperationalAttributes.PASSWORD_NAME.equals(attr.getName())
- && !OperationalAttributes.ENABLE_NAME.equals(attr.getName())) {
-
- resourceAttrs.put(attr.getName(), getValues(attr));
- }
- }
-
- IterableUtils.forEach(CollectionUtils.subtract(syncopeAttrs.keySet(), resourceAttrs.keySet()),
- new Closure<String>() {
-
- @Override
- public void execute(final String name) {
- misaligned.add(new Misaligned(
- resource.getKey(),
- connObjectKeyValue,
- name,
- syncopeAttrs.get(name),
- Collections.emptySet()));
- }
- });
-
- for (Map.Entry<String, Set<Object>> entry : resourceAttrs.entrySet()) {
- if (syncopeAttrs.containsKey(entry.getKey())) {
- if (!Objects.equals(syncopeAttrs.get(entry.getKey()), entry.getValue())) {
- misaligned.add(new Misaligned(
- resource.getKey(),
- connObjectKeyValue,
- entry.getKey(),
- syncopeAttrs.get(entry.getKey()),
- entry.getValue()));
- }
- } else {
- misaligned.add(new Misaligned(
- resource.getKey(),
- connObjectKeyValue,
- entry.getKey(),
- Collections.emptySet(),
- entry.getValue()));
- }
- }
- }
- }
- }
-
- if (!missing.isEmpty() || !misaligned.isEmpty()) {
- doExtract(handler, any, missing, misaligned);
- }
- }
- }
-
- private void doExtract(
- final ContentHandler handler, final int count, final SearchCond cond, final AnyTypeKind anyTypeKind)
- throws SAXException {
-
- for (int page = 1; page <= (count / PAGE_SIZE) + 1; page++) {
- List<AnyObject> anys = searchDAO.search(
- SyncopeConstants.FULL_ADMIN_REALMS,
- cond,
- page,
- PAGE_SIZE,
- Collections.<OrderByClause>emptyList(),
- anyTypeKind);
-
- doExtract(handler, anys);
- }
- }
-
- @Override
- protected void doExtract(final ReportletConf conf, final ContentHandler handler) throws SAXException {
- if (conf instanceof ReconciliationReportletConf) {
- this.conf = ReconciliationReportletConf.class.cast(conf);
- } else {
- throw new ReportException(new IllegalArgumentException("Invalid configuration provided"));
- }
-
- AttributesImpl atts = new AttributesImpl();
-
- if (StringUtils.isBlank(this.conf.getUserMatchingCond())) {
- atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(userDAO.count()));
- handler.startElement("", "", getAnyElementName(AnyTypeKind.USER) + "s", atts);
-
- for (int page = 1; page <= (userDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
- doExtract(handler, userDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE));
- }
- } else {
- SearchCond cond = SearchCondConverter.convert(this.conf.getUserMatchingCond());
-
- int count = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.USER);
- atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(count));
- handler.startElement("", "", getAnyElementName(AnyTypeKind.USER) + "s", atts);
-
- doExtract(handler, count, cond, AnyTypeKind.USER);
- }
- handler.endElement("", "", getAnyElementName(AnyTypeKind.USER) + "s");
-
- atts.clear();
- if (StringUtils.isBlank(this.conf.getGroupMatchingCond())) {
- atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(groupDAO.count()));
- handler.startElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s", atts);
-
- for (int page = 1; page <= (groupDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
- doExtract(handler, groupDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE));
- }
- } else {
- SearchCond cond = SearchCondConverter.convert(this.conf.getUserMatchingCond());
-
- int count = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.GROUP);
- atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(count));
- handler.startElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s", atts);
-
- doExtract(handler, count, cond, AnyTypeKind.GROUP);
- }
- handler.endElement("", "", getAnyElementName(AnyTypeKind.GROUP) + "s");
-
- for (AnyType anyType : anyTypeDAO.findAll()) {
- if (!anyType.equals(anyTypeDAO.findUser()) && !anyType.equals(anyTypeDAO.findGroup())) {
- AnyTypeCond anyTypeCond = new AnyTypeCond();
- anyTypeCond.setAnyTypeKey(anyType.getKey());
- SearchCond cond = StringUtils.isBlank(this.conf.getAnyObjectMatchingCond())
- ? SearchCond.getLeafCond(anyTypeCond)
- : SearchCond.getAndCond(
- SearchCond.getLeafCond(anyTypeCond),
- SearchCondConverter.convert(this.conf.getAnyObjectMatchingCond()));
-
- int count = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, cond, AnyTypeKind.ANY_OBJECT);
-
- atts.clear();
- atts.addAttribute("", "", "type", ReportXMLConst.XSD_STRING, anyType.getKey());
- atts.addAttribute("", "", "total", ReportXMLConst.XSD_INT, String.valueOf(count));
- handler.startElement("", "", getAnyElementName(AnyTypeKind.ANY_OBJECT) + "s", atts);
-
- doExtract(handler, count, cond, AnyTypeKind.ANY_OBJECT);
-
- handler.endElement("", "", getAnyElementName(AnyTypeKind.ANY_OBJECT) + "s");
- }
- }
- }
-
- private static class Missing {
-
- private final String resource;
-
- private final String connObjectKeyValue;
-
- Missing(final String resource, final String connObjectKeyValue) {
- this.resource = resource;
- this.connObjectKeyValue = connObjectKeyValue;
- }
-
- public String getResource() {
- return resource;
- }
-
- public String getConnObjectKeyValue() {
- return connObjectKeyValue;
- }
-
- }
-
- private static class Misaligned extends Missing {
-
- private final String name;
-
- private final Set<Object> onSyncope;
-
- private final Set<Object> onResource;
-
- Misaligned(
- final String resource,
- final String connObjectKeyValue,
- final String name,
- final Set<Object> onSyncope,
- final Set<Object> onResource) {
-
- super(resource, connObjectKeyValue);
-
- this.name = name;
- this.onSyncope = onSyncope;
- this.onResource = onResource;
- }
-
- public String getName() {
- return name;
- }
-
- public Set<Object> getOnSyncope() {
- return onSyncope;
- }
-
- public Set<Object> getOnResource() {
- return onResource;
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/bd695da7/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportException.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportException.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportException.java
deleted file mode 100644
index f4495ad..0000000
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.logic.report;
-
-public class ReportException extends RuntimeException {
-
- private static final long serialVersionUID = 6719507778589395283L;
-
- public ReportException(final Throwable cause) {
- super(cause);
- }
-
- public ReportException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/bd695da7/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportJob.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportJob.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportJob.java
deleted file mode 100644
index 8b14024..0000000
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportJob.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.logic.report;
-
-import org.apache.syncope.core.spring.security.AuthContextUtils;
-import org.apache.syncope.core.provisioning.java.job.AbstractInterruptableJob;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.apache.syncope.core.provisioning.api.job.JobManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Quartz job for executing a given report.
- */
-public class ReportJob extends AbstractInterruptableJob {
-
- private static final Logger LOG = LoggerFactory.getLogger(ReportJob.class);
-
- /**
- * Key, set by the caller, for identifying the report to be executed.
- */
- private String reportKey;
-
- @Autowired
- private ReportJobDelegate delegate;
-
- /**
- * Report id setter.
- *
- * @param reportKey to be set
- */
- public void setReportKey(final String reportKey) {
- this.reportKey = reportKey;
- }
-
- @Override
- public void execute(final JobExecutionContext context) throws JobExecutionException {
- super.execute(context);
-
- try {
- AuthContextUtils.execWithAuthContext(context.getMergedJobDataMap().getString(JobManager.DOMAIN_KEY),
- new AuthContextUtils.Executable<Void>() {
-
- @Override
- public Void exec() {
- try {
- delegate.execute(reportKey);
- } catch (Exception e) {
- LOG.error("While executing report {}", reportKey, e);
- throw new RuntimeException(e);
- }
-
- return null;
- }
- });
- } catch (RuntimeException e) {
- LOG.error("While executing report {}", reportKey, e);
- throw new JobExecutionException("While executing report " + reportKey, e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/bd695da7/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportJobDelegate.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportJobDelegate.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportJobDelegate.java
deleted file mode 100644
index 6d41686..0000000
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportJobDelegate.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.logic.report;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.zip.Deflater;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stream.StreamResult;
-import org.apache.commons.io.IOUtils;
-import org.apache.syncope.common.lib.report.ReportletConf;
-import org.apache.syncope.common.lib.types.ReportExecStatus;
-import org.apache.syncope.core.provisioning.api.utils.ExceptionUtils2;
-import org.apache.syncope.core.spring.ApplicationContextProvider;
-import org.apache.syncope.core.persistence.api.ImplementationLookup;
-import org.apache.syncope.core.persistence.api.dao.ReportDAO;
-import org.apache.syncope.core.persistence.api.dao.ReportExecDAO;
-import org.apache.syncope.core.persistence.api.dao.Reportlet;
-import org.apache.syncope.core.persistence.api.entity.EntityFactory;
-import org.apache.syncope.core.persistence.api.entity.Report;
-import org.apache.syncope.core.persistence.api.entity.ReportExec;
-import org.quartz.JobExecutionException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-import org.xml.sax.helpers.AttributesImpl;
-
-@Component
-public class ReportJobDelegate {
-
- private static final Logger LOG = LoggerFactory.getLogger(ReportJobDelegate.class);
-
- /**
- * Report DAO.
- */
- @Autowired
- private ReportDAO reportDAO;
-
- /**
- * Report execution DAO.
- */
- @Autowired
- private ReportExecDAO reportExecDAO;
-
- @Autowired
- private EntityFactory entityFactory;
-
- @Autowired
- private ImplementationLookup implementationLookup;
-
- @Transactional
- public void execute(final String reportKey) throws JobExecutionException {
- Report report = reportDAO.find(reportKey);
- if (report == null) {
- throw new JobExecutionException("Report " + reportKey + " not found");
- }
-
- if (!report.isActive()) {
- LOG.info("Report {} not active, aborting...", reportKey);
- return;
- }
-
- // 1. create execution
- ReportExec execution = entityFactory.newEntity(ReportExec.class);
- execution.setStatus(ReportExecStatus.STARTED);
- execution.setStart(new Date());
- execution.setReport(report);
- execution = reportExecDAO.save(execution);
-
- report.add(execution);
- report = reportDAO.save(report);
-
- // 2. define a SAX handler for generating result as XML
- TransformerHandler handler;
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ZipOutputStream zos = new ZipOutputStream(baos);
- zos.setLevel(Deflater.BEST_COMPRESSION);
- try {
- SAXTransformerFactory tFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
- tFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
- handler = tFactory.newTransformerHandler();
- Transformer serializer = handler.getTransformer();
- serializer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
- serializer.setOutputProperty(OutputKeys.INDENT, "yes");
-
- // a single ZipEntry in the ZipOutputStream
- zos.putNextEntry(new ZipEntry(report.getName()));
-
- // streaming SAX handler in a compressed byte array stream
- handler.setResult(new StreamResult(zos));
- } catch (Exception e) {
- throw new JobExecutionException("While configuring for SAX generation", e, true);
- }
-
- execution.setStatus(ReportExecStatus.RUNNING);
- execution = reportExecDAO.save(execution);
-
- // 3. actual report execution
- StringBuilder reportExecutionMessage = new StringBuilder();
- try {
- // report header
- handler.startDocument();
- AttributesImpl atts = new AttributesImpl();
- atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, report.getName());
- handler.startElement("", "", ReportXMLConst.ELEMENT_REPORT, atts);
-
- // iterate over reportlet instances defined for this report
- for (ReportletConf reportletConf : report.getReportletConfs()) {
- Class<? extends Reportlet> reportletClass =
- implementationLookup.getReportletClass(reportletConf.getClass());
- if (reportletClass == null) {
- LOG.warn("Could not find matching reportlet for {}", reportletConf.getClass());
- } else {
- // fetch (or create) reportlet
- Reportlet reportlet;
- if (ApplicationContextProvider.getBeanFactory().containsSingleton(reportletClass.getName())) {
- reportlet = (Reportlet) ApplicationContextProvider.getBeanFactory().
- getSingleton(reportletClass.getName());
- } else {
- reportlet = (Reportlet) ApplicationContextProvider.getBeanFactory().
- createBean(reportletClass, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
- ApplicationContextProvider.getBeanFactory().
- registerSingleton(reportletClass.getName(), reportlet);
- }
-
- // invoke reportlet
- try {
- reportlet.extract(reportletConf, handler);
- } catch (Throwable t) {
- LOG.error("While executing reportlet {} for report {}", reportlet, reportKey, t);
-
- execution.setStatus(ReportExecStatus.FAILURE);
-
- Throwable effective = t instanceof ReportException
- ? t.getCause()
- : t;
- reportExecutionMessage.
- append(ExceptionUtils2.getFullStackTrace(effective)).
- append("\n==================\n");
- }
- }
- }
-
- // report footer
- handler.endElement("", "", ReportXMLConst.ELEMENT_REPORT);
- handler.endDocument();
-
- if (!ReportExecStatus.FAILURE.name().equals(execution.getStatus())) {
- execution.setStatus(ReportExecStatus.SUCCESS);
- }
- } catch (Exception e) {
- execution.setStatus(ReportExecStatus.FAILURE);
- reportExecutionMessage.append(ExceptionUtils2.getFullStackTrace(e));
-
- throw new JobExecutionException(e, true);
- } finally {
- try {
- zos.closeEntry();
- IOUtils.closeQuietly(zos);
- IOUtils.closeQuietly(baos);
- } catch (IOException e) {
- LOG.error("While closing StreamResult's backend", e);
- }
-
- execution.setExecResult(baos.toByteArray());
- execution.setMessage(reportExecutionMessage.toString());
- execution.setEnd(new Date());
- reportExecDAO.save(execution);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/bd695da7/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportXMLConst.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportXMLConst.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportXMLConst.java
deleted file mode 100644
index 1bbae73..0000000
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/report/ReportXMLConst.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.logic.report;
-
-public final class ReportXMLConst {
-
- public static final String XSD_STRING = "xsd:string";
-
- public static final String XSD_INT = "xsd:integer";
-
- public static final String XSD_LONG = "xsd:long";
-
- public static final String XSD_BOOLEAN = "xsd:boolean";
-
- public static final String XSD_DATETIME = "xsd:dateTime";
-
- public static final String ELEMENT_REPORT = "report";
-
- public static final String ATTR_NAME = "name";
-
- public static final String ATTR_CLASS = "class";
-
- public static final String ELEMENT_REPORTLET = "reportlet";
-
- private ReportXMLConst() {
- // empty private constructor for static utility class
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/bd695da7/core/logic/src/main/java/org/apache/syncope/core/logic/report/StaticReportlet.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/StaticReportlet.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/StaticReportlet.java
deleted file mode 100644
index 404d086..0000000
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/report/StaticReportlet.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.logic.report;
-
-import org.apache.syncope.core.persistence.api.dao.ReportletConfClass;
-import org.apache.syncope.common.lib.report.ReportletConf;
-import org.apache.syncope.common.lib.report.StaticReportletConf;
-import org.apache.syncope.core.provisioning.api.utils.FormatUtils;
-import org.springframework.util.StringUtils;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-
-@ReportletConfClass(StaticReportletConf.class)
-public class StaticReportlet extends AbstractReportlet {
-
- private StaticReportletConf conf;
-
- private void doExtractConf(final ContentHandler handler) throws SAXException {
- AttributesImpl atts = new AttributesImpl();
- handler.startElement("", "", "configurations", null);
- handler.startElement("", "", "staticAttributes", atts);
-
- handler.startElement("", "", "string", atts);
- handler.characters("string".toCharArray(), 0, "string".length());
- handler.endElement("", "", "string");
-
- handler.startElement("", "", "long", atts);
- handler.characters("long".toCharArray(), 0, "long".length());
- handler.endElement("", "", "long");
-
- handler.startElement("", "", "double", atts);
- handler.characters("double".toCharArray(), 0, "double".length());
- handler.endElement("", "", "double");
-
- handler.startElement("", "", "date", atts);
- handler.characters("date".toCharArray(), 0, "date".length());
- handler.endElement("", "", "date");
-
- handler.startElement("", "", "double", atts);
- handler.characters("double".toCharArray(), 0, "double".length());
- handler.endElement("", "", "double");
-
- handler.startElement("", "", "enum", atts);
- handler.characters("enum".toCharArray(), 0, "enum".length());
- handler.endElement("", "", "enum");
-
- handler.startElement("", "", "list", atts);
- handler.characters("list".toCharArray(), 0, "list".length());
- handler.endElement("", "", "list");
-
- handler.endElement("", "", "staticAttributes");
- handler.endElement("", "", "configurations");
- }
-
- @Override
- protected void doExtract(final ReportletConf conf, final ContentHandler handler) throws SAXException {
- if (conf instanceof StaticReportletConf) {
- this.conf = StaticReportletConf.class.cast(conf);
- } else {
- throw new ReportException(new IllegalArgumentException("Invalid configuration provided"));
- }
-
- doExtractConf(handler);
-
- if (StringUtils.hasText(this.conf.getStringField())) {
- handler.startElement("", "", "string", null);
- handler.characters(this.conf.getStringField().toCharArray(), 0, this.conf.getStringField().length());
- handler.endElement("", "", "string");
- }
-
- if (this.conf.getLongField() != null) {
- handler.startElement("", "", "long", null);
- String printed = String.valueOf(this.conf.getLongField());
- handler.characters(printed.toCharArray(), 0, printed.length());
- handler.endElement("", "", "long");
- }
-
- if (this.conf.getDoubleField() != null) {
- handler.startElement("", "", "double", null);
- String printed = String.valueOf(this.conf.getDoubleField());
- handler.characters(printed.toCharArray(), 0, printed.length());
- handler.endElement("", "", "double");
- }
-
- if (this.conf.getDateField() != null) {
- handler.startElement("", "", "date", null);
- String printed = FormatUtils.format(this.conf.getDateField());
- handler.characters(printed.toCharArray(), 0, printed.length());
- handler.endElement("", "", "date");
- }
-
- if (this.conf.getTraceLevel() != null) {
- handler.startElement("", "", "enum", null);
- String printed = this.conf.getTraceLevel().name();
- handler.characters(printed.toCharArray(), 0, printed.length());
- handler.endElement("", "", "enum");
- }
-
- if (this.conf.getListField() != null && !this.conf.getListField().isEmpty()) {
- handler.startElement("", "", "list", null);
- for (String item : this.conf.getListField()) {
- if (StringUtils.hasText(item)) {
- handler.startElement("", "", "string", null);
- handler.characters(item.toCharArray(), 0, item.length());
- handler.endElement("", "", "string");
- }
- }
- handler.endElement("", "", "list");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/bd695da7/core/logic/src/main/java/org/apache/syncope/core/logic/report/TextSerializer.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/TextSerializer.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/TextSerializer.java
deleted file mode 100644
index f1f3a9e..0000000
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/report/TextSerializer.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.logic.report;
-
-import org.apache.cocoon.sax.component.XMLSerializer;
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-
-/**
- * Converts XML into plain text. It omits all XML tags and writes only character events to the output. Input document
- * must have at least one element - root element - which should wrap all the text inside it.
- *
- */
-public class TextSerializer extends XMLSerializer {
-
- private static final String UTF_8 = "UTF-8";
-
- private static final String TXT = "text";
-
- public TextSerializer() {
- super();
- super.setOmitXmlDeclaration(true);
- }
-
- @Override
- public void setDocumentLocator(final Locator locator) {
- // nothing
- }
-
- @Override
- public void processingInstruction(final String target, final String data)
- throws SAXException {
- // nothing
- }
-
- @Override
- public void startDTD(final String name, final String publicId, final String systemId)
- throws SAXException {
- // nothing
- }
-
- @Override
- public void endDTD() throws SAXException {
- // nothing
- }
-
- @Override
- public void startElement(final String uri, final String loc, final String raw, final Attributes atts)
- throws SAXException {
- // nothing
- }
-
- @Override
- public void endElement(final String uri, final String name, final String raw)
- throws SAXException {
- // nothing
- }
-
- public static TextSerializer createPlainSerializer() {
- final TextSerializer serializer = new TextSerializer();
- serializer.setContentType("text/plain; charset=" + UTF_8);
- serializer.setEncoding(UTF_8);
- serializer.setMethod(TXT);
- return serializer;
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/bd695da7/core/logic/src/main/java/org/apache/syncope/core/logic/report/UserReportlet.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/UserReportlet.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/UserReportlet.java
deleted file mode 100644
index bb1048b..0000000
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/report/UserReportlet.java
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.logic.report;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.syncope.common.lib.SyncopeConstants;
-import org.apache.syncope.common.lib.report.ReportletConf;
-import org.apache.syncope.common.lib.report.UserReportletConf;
-import org.apache.syncope.common.lib.report.UserReportletConf.Feature;
-import org.apache.syncope.common.lib.to.AnyTO;
-import org.apache.syncope.common.lib.to.AttrTO;
-import org.apache.syncope.common.lib.to.MembershipTO;
-import org.apache.syncope.common.lib.to.RelationshipTO;
-import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.core.persistence.api.dao.AnyDAO;
-import org.apache.syncope.core.persistence.api.dao.UserDAO;
-import org.apache.syncope.core.persistence.api.dao.search.OrderByClause;
-import org.apache.syncope.core.persistence.api.entity.user.User;
-import org.apache.syncope.core.persistence.api.search.SearchCondConverter;
-import org.apache.syncope.core.provisioning.api.utils.FormatUtils;
-import org.apache.syncope.core.persistence.api.dao.AnySearchDAO;
-import org.apache.syncope.core.persistence.api.dao.ReportletConfClass;
-import org.apache.syncope.core.persistence.api.entity.user.UMembership;
-import org.apache.syncope.core.persistence.api.entity.user.URelationship;
-import org.apache.syncope.core.provisioning.api.data.AnyObjectDataBinder;
-import org.apache.syncope.core.provisioning.api.data.GroupDataBinder;
-import org.apache.syncope.core.provisioning.api.data.UserDataBinder;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
-
-@ReportletConfClass(UserReportletConf.class)
-public class UserReportlet extends AbstractReportlet {
-
- @Autowired
- private UserDAO userDAO;
-
- @Autowired
- private AnySearchDAO searchDAO;
-
- @Autowired
- private UserDataBinder userDataBinder;
-
- @Autowired
- private GroupDataBinder groupDataBinder;
-
- @Autowired
- private AnyObjectDataBinder anyObjectDataBinder;
-
- private UserReportletConf conf;
-
- private void doExtractResources(final ContentHandler handler, final AnyTO anyTO)
- throws SAXException {
-
- if (anyTO.getResources().isEmpty()) {
- LOG.debug("No resources found for {}[{}]", anyTO.getClass().getSimpleName(), anyTO.getKey());
- } else {
- AttributesImpl atts = new AttributesImpl();
- handler.startElement("", "", "resources", null);
-
- for (String resourceName : anyTO.getResources()) {
- atts.clear();
-
- atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, resourceName);
- handler.startElement("", "", "resource", atts);
- handler.endElement("", "", "resource");
- }
-
- handler.endElement("", "", "resources");
- }
- }
-
- private void doExtractAttributes(final ContentHandler handler, final AnyTO anyTO,
- final Collection<String> attrs, final Collection<String> derAttrs, final Collection<String> virAttrs)
- throws SAXException {
-
- AttributesImpl atts = new AttributesImpl();
- if (!attrs.isEmpty()) {
- Map<String, AttrTO> attrMap = anyTO.getPlainAttrMap();
-
- handler.startElement("", "", "attributes", null);
- for (String attrName : attrs) {
- atts.clear();
-
- atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
- handler.startElement("", "", "attribute", atts);
-
- if (attrMap.containsKey(attrName)) {
- for (String value : attrMap.get(attrName).getValues()) {
- handler.startElement("", "", "value", null);
- handler.characters(value.toCharArray(), 0, value.length());
- handler.endElement("", "", "value");
- }
- } else {
- LOG.debug("{} not found for {}[{}]", attrName,
- anyTO.getClass().getSimpleName(), anyTO.getKey());
- }
-
- handler.endElement("", "", "attribute");
- }
- handler.endElement("", "", "attributes");
- }
-
- if (!derAttrs.isEmpty()) {
- Map<String, AttrTO> derAttrMap = anyTO.getDerAttrMap();
-
- handler.startElement("", "", "derivedAttributes", null);
- for (String attrName : derAttrs) {
- atts.clear();
-
- atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
- handler.startElement("", "", "derivedAttribute", atts);
-
- if (derAttrMap.containsKey(attrName)) {
- for (String value : derAttrMap.get(attrName).getValues()) {
- handler.startElement("", "", "value", null);
- handler.characters(value.toCharArray(), 0, value.length());
- handler.endElement("", "", "value");
- }
- } else {
- LOG.debug("{} not found for {}[{}]", attrName,
- anyTO.getClass().getSimpleName(), anyTO.getKey());
- }
-
- handler.endElement("", "", "derivedAttribute");
- }
- handler.endElement("", "", "derivedAttributes");
- }
-
- if (!virAttrs.isEmpty()) {
- Map<String, AttrTO> virAttrMap = anyTO.getVirAttrMap();
-
- handler.startElement("", "", "virtualAttributes", null);
- for (String attrName : virAttrs) {
- atts.clear();
-
- atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, attrName);
- handler.startElement("", "", "virtualAttribute", atts);
-
- if (virAttrMap.containsKey(attrName)) {
- for (String value : virAttrMap.get(attrName).getValues()) {
- handler.startElement("", "", "value", null);
- handler.characters(value.toCharArray(), 0, value.length());
- handler.endElement("", "", "value");
- }
- } else {
- LOG.debug("{} not found for {}[{}]", attrName,
- anyTO.getClass().getSimpleName(), anyTO.getKey());
- }
-
- handler.endElement("", "", "virtualAttribute");
- }
- handler.endElement("", "", "virtualAttributes");
- }
- }
-
- private void doExtract(final ContentHandler handler, final List<User> users) throws SAXException {
- AttributesImpl atts = new AttributesImpl();
- for (User user : users) {
- atts.clear();
-
- for (Feature feature : conf.getFeatures()) {
- String type = null;
- String value = null;
- switch (feature) {
- case key:
- type = ReportXMLConst.XSD_STRING;
- value = user.getKey();
- break;
-
- case username:
- type = ReportXMLConst.XSD_STRING;
- value = user.getUsername();
- break;
-
- case workflowId:
- type = ReportXMLConst.XSD_STRING;
- value = user.getWorkflowId();
- break;
-
- case status:
- type = ReportXMLConst.XSD_STRING;
- value = user.getStatus();
- break;
-
- case creationDate:
- type = ReportXMLConst.XSD_DATETIME;
- value = user.getCreationDate() == null
- ? ""
- : FormatUtils.format(user.getCreationDate());
- break;
-
- case lastLoginDate:
- type = ReportXMLConst.XSD_DATETIME;
- value = user.getLastLoginDate() == null
- ? ""
- : FormatUtils.format(user.getLastLoginDate());
- break;
-
- case changePwdDate:
- type = ReportXMLConst.XSD_DATETIME;
- value = user.getChangePwdDate() == null
- ? ""
- : FormatUtils.format(user.getChangePwdDate());
- break;
-
- case passwordHistorySize:
- type = ReportXMLConst.XSD_INT;
- value = String.valueOf(user.getPasswordHistory().size());
- break;
-
- case failedLoginCount:
- type = ReportXMLConst.XSD_INT;
- value = String.valueOf(user.getFailedLogins());
- break;
-
- default:
- }
-
- if (type != null && value != null) {
- atts.addAttribute("", "", feature.name(), type, value);
- }
- }
-
- handler.startElement("", "", "user", atts);
-
- // Using UserTO for attribute values, since the conversion logic of
- // values to String is already encapsulated there
- UserTO userTO = userDataBinder.getUserTO(user, true);
-
- doExtractAttributes(handler, userTO, conf.getPlainAttrs(), conf.getDerAttrs(), conf.getVirAttrs());
-
- if (conf.getFeatures().contains(Feature.relationships)) {
- handler.startElement("", "", "relationships", null);
-
- for (RelationshipTO rel : userTO.getRelationships()) {
- atts.clear();
-
- atts.addAttribute("", "", "anyObjectKey",
- ReportXMLConst.XSD_STRING, rel.getRightKey());
- handler.startElement("", "", "relationship", atts);
-
- if (conf.getFeatures().contains(Feature.resources)) {
- for (URelationship actualRel : user.getRelationships(rel.getRightKey())) {
- doExtractResources(
- handler, anyObjectDataBinder.getAnyObjectTO(actualRel.getRightEnd(), true));
- }
- }
-
- handler.endElement("", "", "relationship");
- }
-
- handler.endElement("", "", "relationships");
- }
- if (conf.getFeatures().contains(Feature.memberships)) {
- handler.startElement("", "", "memberships", null);
-
- for (MembershipTO memb : userTO.getMemberships()) {
- atts.clear();
-
- atts.addAttribute("", "", "groupKey",
- ReportXMLConst.XSD_STRING, memb.getRightKey());
- atts.addAttribute("", "", "groupName", ReportXMLConst.XSD_STRING, memb.getGroupName());
- handler.startElement("", "", "membership", atts);
-
- if (conf.getFeatures().contains(Feature.resources)) {
- UMembership actualMemb = user.getMembership(memb.getRightKey());
- if (actualMemb == null) {
- LOG.warn("Unexpected: cannot find membership for group {} for user {}",
- memb.getRightKey(), user);
- } else {
- doExtractResources(handler, groupDataBinder.getGroupTO(actualMemb.getRightEnd(), true));
- }
- }
-
- handler.endElement("", "", "membership");
- }
-
- handler.endElement("", "", "memberships");
- }
-
- if (conf.getFeatures().contains(Feature.resources)) {
- doExtractResources(handler, userTO);
- }
-
- handler.endElement("", "", "user");
- }
- }
-
- private void doExtractConf(final ContentHandler handler) throws SAXException {
- AttributesImpl atts = new AttributesImpl();
- handler.startElement("", "", "configurations", null);
- handler.startElement("", "", "userAttributes", atts);
-
- for (Feature feature : conf.getFeatures()) {
- atts.clear();
- handler.startElement("", "", "feature", atts);
- handler.characters(feature.name().toCharArray(), 0, feature.name().length());
- handler.endElement("", "", "feature");
- }
-
- for (String attr : conf.getPlainAttrs()) {
- atts.clear();
- handler.startElement("", "", "attribute", atts);
- handler.characters(attr.toCharArray(), 0, attr.length());
- handler.endElement("", "", "attribute");
- }
-
- for (String derAttr : conf.getDerAttrs()) {
- atts.clear();
- handler.startElement("", "", "derAttribute", atts);
- handler.characters(derAttr.toCharArray(), 0, derAttr.length());
- handler.endElement("", "", "derAttribute");
- }
-
- for (String virAttr : conf.getVirAttrs()) {
- atts.clear();
- handler.startElement("", "", "virAttribute", atts);
- handler.characters(virAttr.toCharArray(), 0, virAttr.length());
- handler.endElement("", "", "virAttribute");
- }
-
- handler.endElement("", "", "userAttributes");
- handler.endElement("", "", "configurations");
- }
-
- private int count() {
- return StringUtils.isBlank(conf.getMatchingCond())
- ? userDAO.count()
- : searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS,
- SearchCondConverter.convert(conf.getMatchingCond()), AnyTypeKind.USER);
- }
-
- @Override
- protected void doExtract(final ReportletConf conf, final ContentHandler handler) throws SAXException {
- if (conf instanceof UserReportletConf) {
- this.conf = UserReportletConf.class.cast(conf);
- } else {
- throw new ReportException(new IllegalArgumentException("Invalid configuration provided"));
- }
-
- doExtractConf(handler);
-
- for (int page = 1; page <= (count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
- List<User> users;
- if (StringUtils.isBlank(this.conf.getMatchingCond())) {
- users = userDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE);
- } else {
- users = searchDAO.search(
- SyncopeConstants.FULL_ADMIN_REALMS,
- SearchCondConverter.convert(this.conf.getMatchingCond()),
- page,
- AnyDAO.DEFAULT_PAGE_SIZE,
- Collections.<OrderByClause>emptyList(),
- AnyTypeKind.USER);
- }
-
- doExtract(handler, users);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/bd695da7/core/logic/src/main/java/org/apache/syncope/core/logic/report/XSLTTransformer.java
----------------------------------------------------------------------
diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/report/XSLTTransformer.java b/core/logic/src/main/java/org/apache/syncope/core/logic/report/XSLTTransformer.java
deleted file mode 100644
index 3dd6d78..0000000
--- a/core/logic/src/main/java/org/apache/syncope/core/logic/report/XSLTTransformer.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.syncope.core.logic.report;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Pattern;
-import javax.xml.transform.Source;
-import javax.xml.transform.Templates;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
-import org.apache.cocoon.pipeline.SetupException;
-import org.apache.cocoon.pipeline.caching.CacheKey;
-import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
-import org.apache.cocoon.pipeline.util.StringRepresentation;
-import org.apache.cocoon.sax.AbstractSAXTransformer;
-import org.apache.cocoon.sax.SAXConsumer;
-import org.apache.cocoon.sax.util.SAXConsumerAdapter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class XSLTTransformer extends AbstractSAXTransformer implements CachingPipelineComponent {
-
- private static final Logger LOG = LoggerFactory.getLogger(XSLTTransformer.class);
-
- /**
- * A generic transformer factory to parse XSLTs.
- */
- private static final SAXTransformerFactory TRAX_FACTORY = createNewSAXTransformerFactory();
-
- /**
- * The XSLT parameters name pattern.
- */
- private static final Pattern XSLT_PARAMETER_NAME_PATTERN = Pattern.compile("[a-zA-Z_][\\w\\-\\.]*");
-
- /**
- * The XSLT parameters reference.
- */
- private Map<String, Object> parameters;
-
- /**
- * The XSLT Template reference.
- */
- private Templates templates;
-
- private Source source;
-
- public XSLTTransformer(final Source source) {
- super();
- this.load(source, null);
- }
-
- /**
- * Creates a new transformer reading the XSLT from the Source source and setting the TransformerFactory attributes.
- *
- * This constructor is useful when users want to perform XSLT transformation using <a
- * href="http://xml.apache.org/xalan-j/xsltc_usage.html">xsltc</a>.
- *
- * @param source the XSLT source
- * @param attributes the Transformer Factory attributes
- */
- public XSLTTransformer(final Source source, final Map<String, Object> attributes) {
- super();
- this.load(source, attributes);
- }
-
- /**
- * Method useful to create a new transformer reading the XSLT from the URL source and setting the Transformer
- * Factory attributes.
- *
- * This method is useful when users want to perform XSLT transformation using <a
- * href="http://xml.apache.org/xalan-j/xsltc_usage.html">xsltc</a>.
- *
- * @param source the XSLT source
- * @param attributes the Transformer Factory attributes
- */
- private void load(final Source source, final Map<String, Object> attributes) {
- if (source == null) {
- throw new IllegalArgumentException("The parameter 'source' mustn't be null.");
- }
-
- this.source = source;
-
- this.load(this.source, this.source.toString(), attributes);
- }
-
- private void load(final Source source, final String localCacheKey, final Map<String, Object> attributes) {
- LOG.debug("{} local cache miss: {}", getClass().getSimpleName(), localCacheKey);
-
- // XSLT has to be parsed
- final SAXTransformerFactory transformerFactory;
- if (attributes == null || attributes.isEmpty()) {
- transformerFactory = TRAX_FACTORY;
- } else {
- transformerFactory = createNewSAXTransformerFactory();
- for (Map.Entry<String, Object> attribute : attributes.entrySet()) {
- transformerFactory.setAttribute(attribute.getKey(), attribute.getValue());
- }
- }
-
- try {
- this.templates = transformerFactory.newTemplates(source);
- } catch (TransformerConfigurationException e) {
- throw new SetupException("Impossible to read XSLT from '" + source + "', see nested exception", e);
- }
- }
-
- /**
- * Sets the XSLT parameters to be applied to XSLT stylesheet.
- *
- * @param parameters the XSLT parameters to be applied to XSLT stylesheet
- */
- public void setParameters(final Map<String, ? extends Object> parameters) {
- if (parameters == null) {
- this.parameters = null;
- } else {
- this.parameters = new HashMap<String, Object>(parameters);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void setSAXConsumer(final SAXConsumer consumer) {
- TransformerHandler transformerHandler;
- try {
- transformerHandler = TRAX_FACTORY.newTransformerHandler(this.templates);
- } catch (Exception e) {
- throw new SetupException("Could not initialize transformer handler.", e);
- }
-
- if (this.parameters != null) {
- final Transformer transformer = transformerHandler.getTransformer();
-
- for (Map.Entry<String, Object> entry : this.parameters.entrySet()) {
- final String name = entry.getKey();
-
- // is valid XSLT parameter name
- if (XSLT_PARAMETER_NAME_PATTERN.matcher(name).matches()) {
- transformer.setParameter(name, entry.getValue());
- }
- }
- }
-
- final SAXResult result = new SAXResult();
- result.setHandler(consumer);
- // According to TrAX specs, all TransformerHandlers are LexicalHandlers
- result.setLexicalHandler(consumer);
- transformerHandler.setResult(result);
-
- final SAXConsumerAdapter saxConsumerAdapter = new SAXConsumerAdapter();
- saxConsumerAdapter.setContentHandler(transformerHandler);
- super.setSAXConsumer(saxConsumerAdapter);
- }
-
- @Override
- public CacheKey constructCacheKey() {
- return null;
- }
-
- /**
- * Utility method to create a new transformer factory.
- *
- * @return a new transformer factory
- */
- private static SAXTransformerFactory createNewSAXTransformerFactory() {
- return (SAXTransformerFactory) TransformerFactory.newInstance();
- }
-
- @Override
- public String toString() {
- return StringRepresentation.buildString(this, "src=<" + this.source + ">");
- }
-}