List of usage examples for org.xml.sax ContentHandler startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException;
From source file:org.apache.syncope.core.logic.report.GroupReportlet.java
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();/* w w w . j a va 2 s . c o m*/ 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"); } }
From source file:org.apache.syncope.core.logic.report.GroupReportlet.java
private void doExtract(final ContentHandler handler, final List<Group> groups) throws SAXException { AttributesImpl atts = new AttributesImpl(); for (Group group : groups) { atts.clear();/*from w w w . jav a 2 s. c om*/ 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"); } }
From source file:org.apache.syncope.core.logic.report.GroupReportlet.java
private void doExtractConf(final ContentHandler handler) throws SAXException { if (conf == null) { LOG.debug("Report configuration is not present"); }/* w ww. j ava 2 s . co m*/ AttributesImpl atts = new AttributesImpl(); handler.startElement("", "", "configurations", null); handler.startElement("", "", "groupAttributes", 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("", "", "groupAttributes"); handler.endElement("", "", "configurations"); }
From source file:org.apache.syncope.core.logic.report.ReconciliationReportlet.java
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;/*from w w w. j a v a 2s . c om*/ 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())); }
From source file:org.apache.syncope.core.logic.report.ReconciliationReportlet.java
@Override protected void doExtract(final ReportletConf conf, final ContentHandler handler) throws SAXException { if (conf instanceof ReconciliationReportletConf) { this.conf = ReconciliationReportletConf.class.cast(conf); } else {//from w w w . j ava2 s . c o m 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); doExtract(handler, userDAO.findAll()); } 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); doExtract(handler, groupDAO.findAll()); } 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"); } } }
From source file:org.apache.syncope.core.logic.report.RoleReportlet.java
private void doExtractResources(final ContentHandler handler, final AbstractSubjectTO subjectTO) throws SAXException { if (subjectTO.getResources().isEmpty()) { LOG.debug("No resources found for {}[{}]", subjectTO.getClass().getSimpleName(), subjectTO.getKey()); } else {//w w w . j av a 2 s . c om AttributesImpl atts = new AttributesImpl(); handler.startElement("", "", "resources", null); for (String resourceName : subjectTO.getResources()) { atts.clear(); atts.addAttribute("", "", ReportXMLConst.ATTR_NAME, ReportXMLConst.XSD_STRING, resourceName); handler.startElement("", "", "resource", atts); handler.endElement("", "", "resource"); } handler.endElement("", "", "resources"); } }
From source file:org.apache.syncope.core.logic.report.RoleReportlet.java
private void doExtractAttributes(final ContentHandler handler, final AbstractAttributableTO attributableTO, 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 = attributableTO.getPlainAttrMap(); handler.startElement("", "", "attributes", null); for (String attrName : attrs) { atts.clear();/* ww w. j ava 2 s . c o m*/ 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, attributableTO.getClass().getSimpleName(), attributableTO.getKey()); } handler.endElement("", "", "attribute"); } handler.endElement("", "", "attributes"); } if (!derAttrs.isEmpty()) { Map<String, AttrTO> derAttrMap = attributableTO.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, attributableTO.getClass().getSimpleName(), attributableTO.getKey()); } handler.endElement("", "", "derivedAttribute"); } handler.endElement("", "", "derivedAttributes"); } if (!virAttrs.isEmpty()) { Map<String, AttrTO> virAttrMap = attributableTO.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, attributableTO.getClass().getSimpleName(), attributableTO.getKey()); } handler.endElement("", "", "virtualAttribute"); } handler.endElement("", "", "virtualAttributes"); } }
From source file:org.apache.syncope.core.logic.report.RoleReportlet.java
private void doExtract(final ContentHandler handler, final List<Role> roles) throws SAXException, ReportException { AttributesImpl atts = new AttributesImpl(); for (Role role : roles) { atts.clear();/* ww w . j av a2 s . c o m*/ for (Feature feature : conf.getFeatures()) { String type = null; String value = null; switch (feature) { case key: type = ReportXMLConst.XSD_LONG; value = String.valueOf(role.getKey()); break; case name: type = ReportXMLConst.XSD_STRING; value = String.valueOf(role.getName()); break; case roleOwner: type = ReportXMLConst.XSD_LONG; value = String.valueOf(role.getRoleOwner()); break; case userOwner: type = ReportXMLConst.XSD_LONG; value = String.valueOf(role.getUserOwner()); break; default: } if (type != null && value != null) { atts.addAttribute("", "", feature.name(), type, value); } } handler.startElement("", "", "role", atts); // Using RoleTO for attribute values, since the conversion logic of // values to String is already encapsulated there RoleTO roleTO = roleDataBinder.getRoleTO(role); doExtractAttributes(handler, roleTO, conf.getPlainAttrs(), conf.getDerAttrs(), conf.getVirAttrs()); if (conf.getFeatures().contains(Feature.entitlements)) { handler.startElement("", "", "entitlements", null); for (String ent : roleTO.getEntitlements()) { atts.clear(); atts.addAttribute("", "", "id", ReportXMLConst.XSD_STRING, String.valueOf(ent)); handler.startElement("", "", "entitlement", atts); handler.endElement("", "", "entitlement"); } handler.endElement("", "", "entitlements"); } // to get resources associated to a role if (conf.getFeatures().contains(Feature.resources)) { doExtractResources(handler, roleTO); } //to get users asscoiated to a role is preferred RoleDAO to RoleTO if (conf.getFeatures().contains(Feature.users)) { handler.startElement("", "", "users", null); for (Membership memb : roleDAO.findMemberships(role)) { atts.clear(); atts.addAttribute("", "", "key", ReportXMLConst.XSD_LONG, String.valueOf(memb.getUser().getKey())); atts.addAttribute("", "", "username", ReportXMLConst.XSD_STRING, String.valueOf(memb.getUser().getUsername())); handler.startElement("", "", "user", atts); handler.endElement("", "", "user"); } handler.endElement("", "", "users"); } handler.endElement("", "", "role"); } }
From source file:org.apache.syncope.core.logic.report.RoleReportlet.java
private void doExtractConf(final ContentHandler handler) throws SAXException { if (conf == null) { LOG.debug("Report configuration is not present"); }/*from w w w . j a v a2 s .c o m*/ AttributesImpl atts = new AttributesImpl(); handler.startElement("", "", "configurations", null); handler.startElement("", "", "roleAttributes", 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("", "", "roleAttributes"); handler.endElement("", "", "configurations"); }
From source file:org.apache.syncope.core.logic.report.UserReportlet.java
private void doExtract(final ContentHandler handler, final List<User> users) throws SAXException { AttributesImpl atts = new AttributesImpl(); for (User user : users) { atts.clear();/*w w w. ja va 2 s . co m*/ 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"); } }