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.UserReportlet.java
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();/*from w w w . j a va 2 s.co m*/ 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"); }
From source file:org.apache.syncope.core.provisioning.java.job.report.AuditReportlet.java
private void doExtractConf(final ContentHandler handler) throws SAXException { JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource); jdbcTemplate.setMaxRows(conf.getSize()); List<Map<String, Object>> rows = jdbcTemplate .queryForList("SELECT * FROM SYNCOPEAUDIT ORDER BY EVENT_DATE DESC"); handler.startElement("", "", "events", null); AttributesImpl atts = new AttributesImpl(); for (Map<String, Object> row : rows) { AuditEntry auditEntry = POJOHelper.deserialize(row.get("MESSAGE").toString(), AuditEntry.class); atts.clear();/*from w w w . j a va2s. com*/ if (StringUtils.isNotBlank(auditEntry.getWho())) { atts.addAttribute("", "", "who", ReportXMLConst.XSD_STRING, auditEntry.getWho()); } handler.startElement("", "", "event", atts); atts.clear(); if (StringUtils.isNotBlank(auditEntry.getLogger().getCategory())) { atts.addAttribute("", "", "category", ReportXMLConst.XSD_STRING, auditEntry.getLogger().getCategory()); } if (StringUtils.isNotBlank(auditEntry.getLogger().getSubcategory())) { atts.addAttribute("", "", "subcategory", ReportXMLConst.XSD_STRING, auditEntry.getLogger().getSubcategory()); } if (StringUtils.isNotBlank(auditEntry.getLogger().getEvent())) { atts.addAttribute("", "", "event", ReportXMLConst.XSD_STRING, auditEntry.getLogger().getEvent()); } if (auditEntry.getLogger().getResult() != null) { atts.addAttribute("", "", "result", ReportXMLConst.XSD_STRING, auditEntry.getLogger().getResult().name()); } handler.startElement("", "", "logger", atts); handler.endElement("", "", "logger"); if (auditEntry.getBefore() != null) { char[] before = ToStringBuilder.reflectionToString(auditEntry.getBefore(), ToStringStyle.JSON_STYLE) .toCharArray(); handler.startElement("", "", "before", null); handler.characters(before, 0, before.length); handler.endElement("", "", "before"); } if (auditEntry.getInput() != null) { handler.startElement("", "", "inputs", null); for (Object inputObj : auditEntry.getInput()) { char[] input = ToStringBuilder.reflectionToString(inputObj, ToStringStyle.JSON_STYLE) .toCharArray(); handler.startElement("", "", "input", null); handler.characters(input, 0, input.length); handler.endElement("", "", "input"); } handler.endElement("", "", "inputs"); } if (auditEntry.getOutput() != null) { char[] output = ToStringBuilder.reflectionToString(auditEntry.getOutput(), ToStringStyle.JSON_STYLE) .toCharArray(); handler.startElement("", "", "output", null); handler.characters(output, 0, output.length); handler.endElement("", "", "output"); } handler.startElement("", "", "throwable", null); char[] throwable = row.get("THROWABLE").toString().toCharArray(); handler.characters(throwable, 0, throwable.length); handler.endElement("", "", "throwable"); handler.endElement("", "", "event"); } handler.endElement("", "", "events"); }
From source file:org.apache.syncope.core.provisioning.java.job.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 = EntityTOUtils.buildAttrMap(anyTO.getPlainAttrs()); handler.startElement("", "", "attributes", null); for (String attrName : attrs) { atts.clear();//from w ww. j av a2 s . com 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 = EntityTOUtils.buildAttrMap(anyTO.getDerAttrs()); 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 = EntityTOUtils.buildAttrMap(anyTO.getVirAttrs()); 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.provisioning.java.job.report.GroupReportlet.java
private void doExtractConf(final ContentHandler handler) throws SAXException { if (conf == null) { LOG.debug("Report configuration is not present"); }/*from www . j a v a 2 s .com*/ 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"); }
From source file:org.apache.syncope.core.provisioning.java.job.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 ww . j a va 2s .c om*/ 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"); } } }
From source file:org.apache.syncope.core.provisioning.java.job.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();/*from w w w . jav a 2 s. c o 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.getOtherEndKey()); handler.startElement("", "", "relationship", atts); if (conf.getFeatures().contains(Feature.resources)) { for (URelationship actualRel : user.getRelationships(rel.getOtherEndKey())) { 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.getGroupKey()); atts.addAttribute("", "", "groupName", ReportXMLConst.XSD_STRING, memb.getGroupName()); handler.startElement("", "", "membership", atts); if (conf.getFeatures().contains(Feature.resources)) { UMembership actualMemb = user.getMembership(memb.getGroupKey()).orElse(null); if (actualMemb == null) { LOG.warn("Unexpected: cannot find membership for group {} for user {}", memb.getGroupKey(), 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"); } }
From source file:org.apache.tika.parser.jdbc.JDBCTableReader.java
public boolean nextRow(ContentHandler handler, ParseContext context) throws IOException, SAXException { //lazy initialization if (results == null) { reset();/*www. j av a 2 s.c om*/ } try { if (!results.next()) { return false; } } catch (SQLException e) { throw new IOExceptionWithCause(e); } try { ResultSetMetaData meta = results.getMetaData(); handler.startElement(XHTMLContentHandler.XHTML, "tr", "tr", EMPTY_ATTRIBUTES); for (int i = 1; i <= meta.getColumnCount(); i++) { handler.startElement(XHTMLContentHandler.XHTML, "td", "td", EMPTY_ATTRIBUTES); handleCell(meta, i, handler, context); handler.endElement(XHTMLContentHandler.XHTML, "td", "td"); } handler.endElement(XHTMLContentHandler.XHTML, "tr", "tr"); } catch (SQLException e) { throw new IOExceptionWithCause(e); } rows++; return true; }
From source file:org.apache.tika.parser.jdbc.JDBCTableReader.java
protected void handleBlob(String tableName, String columnName, int rowNum, ResultSet resultSet, int columnIndex, ContentHandler handler, ParseContext context) throws SQLException, IOException, SAXException { Metadata m = new Metadata(); m.set(Database.TABLE_NAME, tableName); m.set(Database.COLUMN_NAME, columnName); m.set(Database.PREFIX + "ROW_NUM", Integer.toString(rowNum)); m.set(Database.PREFIX + "IS_BLOB", "true"); Blob blob = null;//from ww w . ja v a2s. c o m TikaInputStream is = null; try { blob = getBlob(resultSet, columnIndex, m); if (blob == null) { return; } is = TikaInputStream.get(blob, m); Attributes attrs = new AttributesImpl(); ((AttributesImpl) attrs).addAttribute("", "type", "type", "CDATA", "blob"); ((AttributesImpl) attrs).addAttribute("", "column_name", "column_name", "CDATA", columnName); ((AttributesImpl) attrs).addAttribute("", "row_number", "row_number", "CDATA", Integer.toString(rowNum)); handler.startElement("", "span", "span", attrs); String extension = embeddedDocumentUtil.getExtension(is, m); m.set(TikaMetadataKeys.RESOURCE_NAME_KEY, //just in case something screwy is going on with the column name FilenameUtils.normalize(FilenameUtils.getName(columnName + "_" + rowNum + extension))); if (embeddedDocumentUtil.shouldParseEmbedded(m)) { embeddedDocumentUtil.parseEmbedded(is, handler, m, true); } } finally { if (blob != null) { try { blob.free(); } catch (SQLException | UnsupportedOperationException e) { //swallow } } IOUtils.closeQuietly(is); } handler.endElement("", "span", "span"); }
From source file:org.apache.tika.parser.microsoft.ooxml.SXSLFPowerPointExtractorDecorator.java
/** * This should handle the comments, master, notes, etc * * @param contentType// ww w.ja v a2s . com * @param xhtmlClassLabel * @param parentPart * @param contentHandler */ private void handleBasicRelatedParts(String contentType, String xhtmlClassLabel, PackagePart parentPart, ContentHandler contentHandler) throws SAXException { PackageRelationshipCollection relatedPartPRC = null; try { relatedPartPRC = parentPart.getRelationshipsByType(contentType); } catch (InvalidFormatException e) { metadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING, ExceptionUtils.getStackTrace(e)); } if (relatedPartPRC != null && relatedPartPRC.size() > 0) { AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute("", "class", "class", "CDATA", xhtmlClassLabel); contentHandler.startElement("", "div", "div", attributes); for (int i = 0; i < relatedPartPRC.size(); i++) { PackageRelationship relatedPartPackageRelationship = relatedPartPRC.getRelationship(i); try { PackagePart relatedPartPart = parentPart.getRelatedPart(relatedPartPackageRelationship); try (InputStream stream = relatedPartPart.getInputStream()) { context.getSAXParser().parse(stream, new OfflineContentHandler(new EmbeddedContentHandler(contentHandler))); } catch (IOException | TikaException e) { metadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING, ExceptionUtils.getStackTrace(e)); } } catch (InvalidFormatException e) { metadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING, ExceptionUtils.getStackTrace(e)); } } contentHandler.endElement("", "div", "div"); } }
From source file:org.exist.cocoon.XMLDBSource.java
private void collectionToSAX(ContentHandler handler) throws SAXException, XMLDBException { AttributesImpl attributes = new AttributesImpl(); if (query != null) { // Query collection if (getLogger().isDebugEnabled()) { getLogger().debug("Querying collection " + url + "; query= " + this.query); }// w ww . j a v a 2s .c o m queryToSAX(handler, collection, null); } else { // List collection if (getLogger().isDebugEnabled()) { getLogger().debug("Listing collection " + url); } final String nresources = Integer.toString(collection.getResourceCount()); attributes.addAttribute("", RESOURCE_COUNT_ATTR, RESOURCE_COUNT_ATTR, "CDATA", nresources); final String ncollections = Integer.toString(collection.getChildCollectionCount()); attributes.addAttribute("", COLLECTION_COUNT_ATTR, COLLECTION_COUNT_ATTR, "CDATA", ncollections); attributes.addAttribute("", COLLECTION_BASE_ATTR, COLLECTION_BASE_ATTR, "CDATA", url); handler.startDocument(); handler.startPrefixMapping(PREFIX, URI); handler.startElement(URI, COLLECTIONS, QCOLLECTIONS, attributes); // Print child collections String[] collections = collection.listChildCollections(); for (int i = 0; i < collections.length; i++) { attributes.clear(); attributes.addAttribute("", NAME_ATTR, NAME_ATTR, CDATA, collections[i]); handler.startElement(URI, COLLECTION, QCOLLECTION, attributes); handler.endElement(URI, COLLECTION, QCOLLECTION); } // Print child resources String[] resources = collection.listResources(); for (int i = 0; i < resources.length; i++) { attributes.clear(); attributes.addAttribute("", NAME_ATTR, NAME_ATTR, CDATA, resources[i]); handler.startElement(URI, RESOURCE, QRESOURCE, attributes); handler.endElement(URI, RESOURCE, QRESOURCE); } handler.endElement(URI, COLLECTIONS, QCOLLECTIONS); handler.endPrefixMapping(PREFIX); handler.endDocument(); } }