List of usage examples for org.xml.sax.helpers AttributesImpl AttributesImpl
public AttributesImpl()
From source file:org.syncope.core.util.ImportExport.java
public void export(final OutputStream os) throws SAXException, TransformerConfigurationException, CycleInMultiParentTreeException { StreamResult streamResult = new StreamResult(os); SAXTransformerFactory transformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler handler = transformerFactory.newTransformerHandler(); Transformer serializer = handler.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); handler.setResult(streamResult);// w w w.ja v a 2 s . com handler.startDocument(); handler.startElement("", "", ROOT_ELEMENT, new AttributesImpl()); Connection conn = DataSourceUtils.getConnection(dataSource); ResultSet rs = null; try { // first read all tables... rs = conn.getMetaData().getTables(null, null, null, new String[] { "TABLE" }); Set<String> tableNames = new HashSet<String>(); while (rs.next()) { String tableName = rs.getString("TABLE_NAME"); // these tables must be ignored if (!tableName.toUpperCase().startsWith("QRTZ_") && !tableName.toUpperCase().equals("ACT_GE_PROPERTY")) { tableNames.add(tableName); } } // then sort tables based on foreign keys and dump for (String tableName : sortByForeignKeys(conn, tableNames)) { doExportTable(handler, conn, tableName); } } catch (SQLException e) { LOG.error("While exporting database content", e); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { LOG.error("While closing tables result set", e); } } DataSourceUtils.releaseConnection(conn, dataSource); } handler.endElement("", "", ROOT_ELEMENT); handler.endDocument(); }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test public void locatorSplitingEmptyElementTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();//from ww w.j a v a 2s . c o m AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "", "name", "", "Stream attr name"); // NON-NLS attrs.addAttribute("", "", "locator", "", "|555"); // NON-NLS attrs.addAttribute("", "", "value", "", ""); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS }
From source file:org.syncope.core.report.UserReportlet.java
@Override @Transactional(readOnly = true)//from www . j av a2s . c o m public void extract(final ContentHandler handler) throws SAXException, ReportException { if (getConf() == null || !(getConf() instanceof UserReportletConf)) { throw new ReportException(new IllegalArgumentException( "Expected " + UserReportletConf.class.getName() + ", got " + getConf())); } UserReportletConf conf = (UserReportletConf) getConf(); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", ATTR_NAME, XSD_STRING, getConf().getName()); atts.addAttribute("", "", ATTR_CLASS, XSD_STRING, getClass().getName()); handler.startElement("", "", ELEMENT_REPORTLET, atts); for (int i = 1; i <= (count(conf) / PAGE_SIZE) + 1; i++) { doExtract(handler, conf, getPagedUsers(conf, i)); } handler.endElement("", "", ELEMENT_REPORTLET); }
From source file:com.adobe.acs.commons.rewriter.impl.VersionedClientlibsTransformerFactoryTest.java
@Test public void testProxiedJavaScriptClientLibrary() throws Exception { when(htmlLibraryManager.getLibrary(eq(LibraryType.JS), eq(PROXIED_PATH))).thenReturn(proxiedHtmlLibrary); final AttributesImpl in = new AttributesImpl(); in.addAttribute("", "src", "", "CDATA", PROXY_PATH + ".js"); in.addAttribute("", "type", "", "CDATA", "text/javascript"); transformer.startElement(null, "script", null, in); ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class); verify(handler, only()).startElement(isNull(String.class), eq("script"), isNull(String.class), attributesCaptor.capture()); assertEquals(PROXY_PATH + "." + PROXIED_FAKE_STREAM_CHECKSUM + ".js", attributesCaptor.getValue().getValue(0)); }
From source file:de.gbv.ole.Marc21ToOleBulk.java
/** * Start the element without attributes using <code>handler</code>. * /*from ww w .j a va 2s .c o m*/ * @param name used for localName and qName * @throws SAXException bei XML-Fehler */ private void startElement(final String name) throws SAXException { AttributesImpl atts = new AttributesImpl(); startElement(name, atts); }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test(expected = SAXParseException.class) public void processFieldLocatorTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();/* w w w . j a va 2s. c om*/ AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "", "name", "", "Stream attr name"); // NON-NLS attrs.addAttribute("", "", "datatype", "", "Timestamp"); // NON-NLS attrs.addAttribute("", "", "radix", "", "555"); // NON-NLS attrs.addAttribute("", "", "required", "", "Requered"); // NON-NLS attrs.addAttribute("", "", "units", "", null); // NON-NLS attrs.addAttribute("", "", "format", "", "YYYY-mm-dd HH:mm:ss"); // NON-NLS attrs.addAttribute("", "", "locale", "", "lt_LT"); // NON-NLS attrs.addAttribute("", "", "timezone", "", "Europe/Vilnius"); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS attrs.addAttribute("", "", "value", "", ""); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field-locator", attrs); // NON-NLS }
From source file:com.adobe.acs.commons.rewriter.impl.VersionedClientlibsTransformerFactoryTest.java
@Test public void testMinifiedJavaScriptClientLibrary() throws Exception { when(htmlLibraryManager.getLibrary(eq(LibraryType.JS), eq(PATH))).thenReturn(htmlLibrary); final AttributesImpl in = new AttributesImpl(); in.addAttribute("", "src", "", "CDATA", PATH + ".min.js"); in.addAttribute("", "type", "", "CDATA", "text/javascript"); transformer.startElement(null, "script", null, in); ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class); verify(handler, only()).startElement(isNull(String.class), eq("script"), isNull(String.class), attributesCaptor.capture()); assertEquals(PATH + ".min." + FAKE_STREAM_CHECKSUM + ".js", attributesCaptor.getValue().getValue(0)); }
From source file:com.adobe.acs.commons.rewriter.impl.VersionedClientlibsTransformerFactoryTest.java
@Test public void testCssClientLibraryWithInvalidExtension() throws Exception { when(htmlLibraryManager.getLibrary(eq(LibraryType.CSS), eq(PATH))).thenReturn(htmlLibrary); final AttributesImpl in = new AttributesImpl(); in.addAttribute("", "href", "", "CDATA", PATH + ".styles"); in.addAttribute("", "type", "", "CDATA", "text/css"); in.addAttribute("", "rel", "", "CDATA", "stylesheet"); transformer.startElement(null, "link", null, in); ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class); verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture()); assertEquals(PATH + ".styles", attributesCaptor.getValue().getValue(0)); }
From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java
@Test public void processFieldLocatorUnitsNotNullTest() throws Exception { ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS); test.startDocument();// ww w . j a v a 2s . co m AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "", "name", "", "Stream attr name"); // NON-NLS attrs.addAttribute("", "", "datatype", "", "Timestamp"); // NON-NLS attrs.addAttribute("", "", "radix", "", "555"); // NON-NLS attrs.addAttribute("", "", "required", "", "Requered"); // NON-NLS attrs.addAttribute("", "", "units", "", "Kb"); // NON-NLS attrs.addAttribute("", "", "format", "", "YYYY-mm-dd HH:mm:ss"); // NON-NLS attrs.addAttribute("", "", "locale", "", "lt_LT"); // NON-NLS attrs.addAttribute("", "", "timezone", "", "Europe/Vilnius"); // NON-NLS attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS attrs.addAttribute("", "", "value", "", "TEST_VALUE"); // NON-NLS test.startElement("TEST_URL", "TEST_LOCALNAME", "field-locator", attrs); // NON-NLS }
From source file:com.adobe.acs.commons.rewriter.impl.VersionedClientlibsTransformerFactoryTest.java
@Test public void testCssClientLibraryWithRelAttributeValueDiffersFromStylesheet() throws Exception { when(htmlLibraryManager.getLibrary(eq(LibraryType.CSS), eq(PATH))).thenReturn(htmlLibrary); final AttributesImpl in = new AttributesImpl(); in.addAttribute("", "href", "", "CDATA", PATH + ".css"); in.addAttribute("", "type", "", "CDATA", "text/css"); in.addAttribute("", "rel", "", "CDATA", "preload"); transformer.startElement(null, "link", null, in); ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class); verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class), attributesCaptor.capture()); assertEquals(PATH + "." + FAKE_STREAM_CHECKSUM + ".css", attributesCaptor.getValue().getValue(0)); }