List of usage examples for org.xml.sax.helpers AttributesImpl clear
public void clear()
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 w w w . j a va 2s .co m*/ 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 {/* w w w . jav a2 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); 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(); for (Feature feature : conf.getFeatures()) { String type = null;/*from w w w. ja va 2 s .c o m*/ 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.syncope.core.util.ContentExporter.java
private void doExportTable(final TransformerHandler handler, final Connection conn, final String tableName, final String whereClause) throws SQLException, SAXException { LOG.debug("Export table {}", tableName); AttributesImpl attrs = new AttributesImpl(); PreparedStatement stmt = null; ResultSet rs = null;/* w ww .ja v a2s . com*/ ResultSet pkeyRS = null; try { // ------------------------------------ // retrieve primary keys to perform an ordered select final DatabaseMetaData meta = conn.getMetaData(); pkeyRS = meta.getPrimaryKeys(null, null, tableName); final StringBuilder orderBy = new StringBuilder(); while (pkeyRS.next()) { final String columnName = pkeyRS.getString("COLUMN_NAME"); if (columnName != null) { if (orderBy.length() > 0) { orderBy.append(","); } orderBy.append(columnName); } } // ------------------------------------ StringBuilder query = new StringBuilder(); query.append("SELECT * FROM ").append(tableName).append(" a"); if (StringUtils.isNotBlank(whereClause)) { query.append(" WHERE ").append(whereClause); } if (orderBy.length() > 0) { query.append(" ORDER BY ").append(orderBy); } stmt = conn.prepareStatement(query.toString()); rs = stmt.executeQuery(); while (rs.next()) { attrs.clear(); final ResultSetMetaData rsMeta = rs.getMetaData(); for (int i = 0; i < rsMeta.getColumnCount(); i++) { final String columnName = rsMeta.getColumnName(i + 1); final Integer columnType = rsMeta.getColumnType(i + 1); // Retrieve value taking care of binary values. String value = getValues(rs, columnName, columnType); if (value != null && (!COLUMNS_TO_BE_NULLIFIED.containsKey(tableName) || !COLUMNS_TO_BE_NULLIFIED.get(tableName).contains(columnName))) { attrs.addAttribute("", "", columnName, "CDATA", value); } } handler.startElement("", "", tableName, attrs); handler.endElement("", "", tableName); LOG.debug("Add record {}", attrs); } } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { LOG.error("While closing result set", e); } } if (pkeyRS != null) { try { pkeyRS.close(); } catch (SQLException e) { LOG.error("While closing result set", e); } } if (stmt != null) { try { stmt.close(); } catch (SQLException e) { LOG.error("While closing result set", e); } } } }
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); }/*from w ww . ja va2 s . 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(); } }
From source file:org.exist.cocoon.XMLDBSource.java
private void queryToSAX(ContentHandler handler, Collection collection, String resource) throws SAXException, XMLDBException { AttributesImpl attributes = new AttributesImpl(); XPathQueryService service = (XPathQueryService) collection.getService("XPathQueryService", "1.0"); ResourceSet resultSet = (resource == null) ? service.query(query) : service.queryResource(resource, query); attributes.addAttribute("", QUERY_ATTR, QUERY_ATTR, "CDATA", query); attributes.addAttribute("", RESULTS_COUNT_ATTR, RESULTS_COUNT_ATTR, "CDATA", Long.toString(resultSet.getSize())); handler.startDocument();//from ww w .ja v a2 s . co m handler.startPrefixMapping(PREFIX, URI); handler.startElement(URI, RESULTSET, QRESULTSET, attributes); IncludeXMLConsumer includeHandler = new IncludeXMLConsumer(handler); // Print search results ResourceIterator results = resultSet.getIterator(); while (results.hasMoreResources()) { XMLResource result = (XMLResource) results.nextResource(); final String id = result.getId(); final String documentId = result.getDocumentId(); attributes.clear(); if (id != null) { attributes.addAttribute("", RESULT_ID_ATTR, RESULT_ID_ATTR, CDATA, id); } if (documentId != null) { attributes.addAttribute("", RESULT_DOCID_ATTR, RESULT_DOCID_ATTR, CDATA, documentId); } handler.startElement(URI, RESULT, QRESULT, attributes); try { result.getContentAsSAX(includeHandler); } catch (XMLDBException xde) { // That may be a text-only result Object content = result.getContent(); if (content instanceof String) { String text = (String) content; handler.characters(text.toCharArray(), 0, text.length()); } else { // Cannot do better throw xde; } } handler.endElement(URI, RESULT, QRESULT); } handler.endElement(URI, RESULTSET, QRESULTSET); handler.endPrefixMapping(PREFIX); handler.endDocument(); }
From source file:org.freecine.filmscan.ScanStrip.java
public void writeXml(TransformerHandler hd) throws SAXException { if (perforations == null) { findPerforations();//w w w .j a v a 2 s. co m } AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "orientation", "CDATA", "0"); atts.addAttribute("", "", "gamma", "CDATA", "1.0"); hd.startElement("", "", "scan", atts); atts.clear(); hd.startElement("", "", "perforations", atts); for (Perforation p : perforations) { atts.addAttribute("", "", "x", "CDATA", Integer.toString(p.x)); atts.addAttribute("", "", "y", "CDATA", Integer.toString(p.y)); hd.startElement("", "", "perforation", atts); hd.endElement("", "", "perforation"); } hd.endElement("", "", "perforations"); hd.endElement("", "", "scan"); hd.endDocument(); }
From source file:org.lilyproject.runtime.tools.plugin.genclassloader.ClassloaderMojo.java
/** * Create a project file containing the dependencies. * * @throws IOException// www . j ava 2 s . c o m * @throws SAXException */ private void createDependencyListing(File classloaderTemplate) throws IOException, SAXException { if (classloaderTemplate != null && classloaderTemplate.exists()) { getLog().info("Found classloader template, trying to parse it..."); parseClassloaderTemplate(classloaderTemplate); } final boolean hasEntries = entryMap.size() > 0; // fill in file with all dependencies FileOutputStream fos = new FileOutputStream(projectDescriptorFile); TransformerHandler ch = null; TransformerFactory factory = TransformerFactory.newInstance(); if (factory.getFeature(SAXTransformerFactory.FEATURE)) { try { ch = ((SAXTransformerFactory) factory).newTransformerHandler(); // set properties Transformer serializer = ch.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); // set result Result result = new StreamResult(fos); ch.setResult(result); // start file generation ch.startDocument(); AttributesImpl atts = new AttributesImpl(); if (this.shareSelf != null) { atts.addAttribute("", "share-self", "share-self", "CDATA", this.shareSelf); } ch.startElement("", "classloader", "classloader", atts); atts.clear(); ch.startElement("", "classpath", "classpath", atts); SortedSet<Artifact> sortedArtifacts = new TreeSet<Artifact>(dependenciesToList); Entry entry; String entryShare; String entryVersion; for (Artifact artifact : sortedArtifacts) { atts.addAttribute("", "groupId", "groupId", "CDATA", artifact.getGroupId()); atts.addAttribute("", "artifactId", "artifactId", "CDATA", artifact.getArtifactId()); if (artifact.getClassifier() != null) { atts.addAttribute("", "classifier", "classifier", "CDATA", artifact.getClassifier()); } if (!artifact.getGroupId().equals("org.lilyproject")) { atts.addAttribute("", "version", "version", "CDATA", artifact.getBaseVersion()); } entry = new Entry(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier()); if (hasEntries && entryMap.containsKey(entry)) { entryVersion = extractAttVal(entryMap.get(entry).getAttributes(), "version"); entryShare = extractAttVal(entryMap.get(entry).getAttributes(), "share"); entryMap.remove(entry); if (entryVersion != null && !entryVersion.equals("") && !entryVersion.equals(artifact.getBaseVersion())) { getLog().warn( "version conflict between entry in template and artifact on classpath for " + entry); } if (entryShare != null) { atts.addAttribute("", "", "share", "CDATA", entryShare); } } else { // atts.addAttribute("", "", "share", "CDATA", SHARE_DEFAULT); } ch.startElement("", "artifact", "artifact", atts); ch.endElement("", "artifact", "artifact"); atts.clear(); } ch.endElement("", "classpath", "classpath"); ch.endElement("", "classloader", "classloader"); ch.endDocument(); fos.close(); if (entryMap.size() > 0) { getLog().warn("Classloader template contains entries that could not be resolved."); } } catch (TransformerConfigurationException ex) { ex.printStackTrace(); throw new SAXException("Unable to get a TransformerHandler."); } } else { throw new RuntimeException("Could not load SAXTransformerFactory."); } }
From source file:org.programmatori.domotica.own.plugin.map.Map.java
private void createStatusFile(String fileName) { StreamResult streamResult = new StreamResult(new File(fileName)); SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler hd = null; try {/* w w w . j a v a 2s.co m*/ hd = tf.newTransformerHandler(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } Transformer serializer = hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); //serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "users.dtd"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); //serializer.setOutputProperty( XalanOutputKeys.OUTPUT_PROP_INDENT_AMOUNT, "2" ); hd.setResult(streamResult); try { hd.startDocument(); AttributesImpl attrs = new AttributesImpl(); hd.startElement("", "", "home", attrs); hd.startElement("", "", "version", attrs); hd.characters("2.0".toCharArray(), 0, 3); hd.endElement("", "", "version"); attrs.clear(); attrs.addAttribute("", "", "unit", "CDATA", "min"); hd.startElement("", "", "statusSave", attrs); hd.characters("10".toCharArray(), 0, 2); hd.endElement("", "", "statusSave"); // ----------------------------------------- Area for (Iterator<Integer> iterAree = localBus.keySet().iterator(); iterAree.hasNext();) { Integer area = (Integer) iterAree.next(); attrs.clear(); attrs.addAttribute("", "", "id", "CDATA", area.toString()); attrs.addAttribute("", "", "name", "CDATA", Config.getInstance().getRoomName(area)); hd.startElement("", "", "area", attrs); // ----------------------------------------- Component Set<SCSComponent> rooms = localBus.get(area); for (Iterator<SCSComponent> iterRoom = rooms.iterator(); iterRoom.hasNext();) { SCSComponent c = (SCSComponent) iterRoom.next(); log.info("PL: " + c.getStatus().getWhere().getPL() + "(" + Config.getInstance().getWhoDescription(c.getStatus().getWho().getMain()) + ")"); attrs.clear(); attrs.addAttribute("", "", "type", "CDATA", Config.getInstance().getWhoDescription(c.getStatus().getWho().getMain())); attrs.addAttribute("", "", "pl", "CDATA", "" + c.getStatus().getWhere().getPL()); hd.startElement("", "", "component", attrs); hd.characters("0".toCharArray(), 0, 1); hd.endElement("", "", "component"); } // ----------------------------------------- Component hd.endElement("", "", "area"); } // ----------------------------------------- End Area // ----------------------------------------- Scheduler attrs.clear(); hd.startElement("", "", "scheduler", attrs); attrs.clear(); attrs.addAttribute("", "", "time", "CDATA", "-1"); hd.startElement("", "", "command2", attrs); hd.characters("*1*1*11##".toCharArray(), 0, 9); hd.endElement("", "", "command2"); hd.endElement("", "", "scheduler"); // ----------------------------------------- End Scheduler hd.endElement("", "", "home"); hd.endDocument(); } catch (SAXException e) { e.printStackTrace(); } // for (Iterator<Integer> iterAree = localBus.keySet().iterator(); iterAree.hasNext();) { // Integer area = (Integer) iterAree.next(); // // log.info("Room: " + area + " - " + Config.getInstance().getRoomName(area)); // Set<SCSComponent> rooms = localBus.get(area); // for (Iterator<SCSComponent> iterRoom = rooms.iterator(); iterRoom.hasNext();) { // SCSComponent c = (SCSComponent) iterRoom.next(); // log.info("PL: " + c.getStatus().getWhere().getPL() + "(" + Config.getInstance().getWhoDescription(c.getStatus().getWho().getMain()) + ")"); // } // } }