@Override protected Object readObject(ObjectInput in, List<Object> cache, byte version) throws IOException, ClassNotFoundException { XMLType xt = new XMLType(); xt.readExternal(in, (byte)1); return xt; } }
@Override protected Object readObject(ObjectInput in, List<Object> cache, byte version) throws IOException, ClassNotFoundException { XMLType xt = new XMLType(); xt.readExternal(in, (byte)1); return xt; } }
public static XMLType xmlPi(String name, String content) { int start = 0; char[] chars = content.toCharArray(); while (start < chars.length && chars[start] == ' ') { start++; } XMLType result = new XMLType(new SQLXMLImpl("<?" + name + " " + content.substring(start) + "?>")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ result.setType(Type.PI); return result; }
public static XMLType xmlPi(String name, String content) { int start = 0; char[] chars = content.toCharArray(); while (start < chars.length && chars[start] == ' ') { start++; } XMLType result = new XMLType(new SQLXMLImpl("<?" + name + " " + content.substring(start) + "?>")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ result.setType(Type.PI); return result; }
public static XMLType xmlPi(String name, String content) { int start = 0; char[] chars = content.toCharArray(); while (start < chars.length && chars[start] == ' ') { start++; } XMLType result = new XMLType(new SQLXMLImpl("<?" + name + " " + content.substring(start) + "?>")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ result.setType(Type.PI); return result; }
public static XMLType xmlComment(String comment) throws FunctionExecutionException { if (comment.contains("--") || comment.endsWith("-")) { //$NON-NLS-1$ //$NON-NLS-2$ throw new FunctionExecutionException(QueryPlugin.Event.TEIID31159, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31159, comment)); } XMLType result = new XMLType(new SQLXMLImpl("<!--" + comment + "-->")); //$NON-NLS-1$ //$NON-NLS-2$ result.setType(Type.COMMENT); return result; }
public static XMLType xmlComment(String comment) throws FunctionExecutionException { if (comment.contains("--") || comment.endsWith("-")) { //$NON-NLS-1$ //$NON-NLS-2$ throw new FunctionExecutionException(QueryPlugin.Event.TEIID31159, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31159, comment)); } XMLType result = new XMLType(new SQLXMLImpl("<!--" + comment + "-->")); //$NON-NLS-1$ //$NON-NLS-2$ result.setType(Type.COMMENT); return result; }
public static XMLType xmlComment(String comment) throws FunctionExecutionException { if (comment.contains("--") || comment.endsWith("-")) { //$NON-NLS-1$ //$NON-NLS-2$ throw new FunctionExecutionException(QueryPlugin.Event.TEIID31159, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31159, comment)); } XMLType result = new XMLType(new SQLXMLImpl("<!--" + comment + "-->")); //$NON-NLS-1$ //$NON-NLS-2$ result.setType(Type.COMMENT); return result; }
@TeiidFunction(category=FunctionCategoryConstants.XML, nullOnNull=true) public static XMLType xmlText(String val) throws XMLStreamException, FactoryConfigurationError, IOException, TransformerException { //TODO: see if there is a less involved way to escape StringWriter writer = new StringWriter(); XMLEventWriter eventWriter = getOutputFactory().createXMLEventWriter(writer); convertValue(writer, eventWriter, threadLocalEventtFactory.get(), val); XMLType result = new XMLType(new SQLXMLImpl(writer.toString())); result.setType(Type.TEXT); return result; }
@TeiidFunction(category=FunctionCategoryConstants.XML, nullOnNull=true) public static XMLType xmlText(String val) throws XMLStreamException, FactoryConfigurationError, IOException, TransformerException { //TODO: see if there is a less involved way to escape StringWriter writer = new StringWriter(); XMLEventWriter eventWriter = getOutputFactory().createXMLEventWriter(writer); convertValue(writer, eventWriter, threadLocalEventtFactory.get(), val); XMLType result = new XMLType(new SQLXMLImpl(writer.toString())); result.setType(Type.TEXT); return result; }
@TeiidFunction(category=FunctionCategoryConstants.XML, nullOnNull=true) public static XMLType xmlText(String val) throws XMLStreamException, FactoryConfigurationError, IOException, TransformerException { //TODO: see if there is a less involved way to escape StringWriter writer = new StringWriter(); XMLEventWriter eventWriter = getOutputFactory().createXMLEventWriter(writer); convertValue(writer, eventWriter, threadLocalEventtFactory.get(), val); XMLType result = new XMLType(new SQLXMLImpl(writer.toString())); result.setType(Type.TEXT); return result; }
/** * This method transforms a value of the source type into a value * of the target type. * @param value Incoming value of source type * @return Outgoing value of target type * @throws TransformationException if value is an incorrect input type or * the transformation fails */ public Object transformDirect(Object value) throws TransformationException { String xml = (String)value; Reader reader = new StringReader(xml); Type type = isXml(reader); XMLType result = new XMLType(new SQLXMLImpl(xml)); result.setType(type); return result; }
/** * This method transforms a value of the source type into a value * of the target type. * @param value Incoming value of source type * @return Outgoing value of target type * @throws TransformationException if value is an incorrect input type or * the transformation fails */ public Object transformDirect(Object value) throws TransformationException { String xml = (String)value; Reader reader = new StringReader(xml); Type type = isXml(reader); XMLType result = new XMLType(new SQLXMLImpl(xml)); result.setType(type); return result; }
@Test public void testXMLValue() throws Exception { String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$ SQLXMLImpl xml = new SQLXMLImpl(testString); XMLType xv = new XMLType(xml); assertEquals(testString, xv.getString()); }
@Test public void testLength() throws Exception { String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$ SQLXMLImpl xml = new SQLXMLImpl(testString); XMLType xv = new XMLType(xml); assertEquals(36, xv.length()); xml = new SQLXMLImpl(new InputStreamFactory() { @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream("<bar/>".getBytes(Streamable.CHARSET)); } }); xv = new XMLType(xml); try { xv.length(); fail(); } catch (SQLException e) { } } }
public XMLType close(CommandContext context) throws TeiidProcessingException { try { eventWriter.flush(); ew.close(); } catch (XMLStreamException e) { fs.remove(); throw new TeiidProcessingException(QueryPlugin.Event.TEIID30441, e); } catch (IOException e) { fs.remove(); throw new TeiidProcessingException(QueryPlugin.Event.TEIID30442, e); } XMLType result = new XMLType(createSQLXML(fsisf, ew, context)); if (type == null) { result.setType(Type.CONTENT); } else { result.setType(type); } return result; }
@Test public void testXMLInput() throws Exception { XMLType doc = new XMLType(new SQLXMLImpl("<foo/>"));//$NON-NLS-1$ String xpath = "a/b/c"; //$NON-NLS-1$ String value = XMLSystemFunctions.xpathValue(doc, xpath); assertNull(value); }
@Test public void testReferencePersistence() throws Exception { String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$ SQLXMLImpl xml = new SQLXMLImpl(testString); XMLType xv = new XMLType(xml); xv.setReferenceStreamId(null); // now force to serialize XMLType read = UnitTestUtil.helpSerialize(xv); assertEquals(testString, read.getString()); }
@Test public void testXMLValuePersistence() throws Exception { String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$ SQLXMLImpl xml = new SQLXMLImpl(testString); XMLType xv = new XMLType(xml); String key = xv.getReferenceStreamId(); // now force to serialize XMLType read = UnitTestUtil.helpSerialize(xv); // make sure we have kept the reference stream id assertEquals(key, read.getReferenceStreamId()); // and lost the original object assertNull(read.getReference()); }
@Test public void testXML() throws Exception { StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY); ResultsFuture<LobChunk> future = new ResultsFuture<LobChunk>(); future.getResultsReceiver().receiveResults(new LobChunk("<a/>".getBytes(Charset.forName("UTF-8")), true)); XMLType result = new XMLType(); Mockito.stub(statement.getDQP().requestNextLobChunk(0, 0, result.getReferenceStreamId())).toReturn(future); ResultsMessage resultsMsg = new ResultsMessage(); result.setEncoding("UTF-8"); resultsMsg.setResults(new List<?>[] {Arrays.asList(result)}); resultsMsg.setLastRow(1); resultsMsg.setFirstRow(1); resultsMsg.setFinalRow(1); resultsMsg.setColumnNames(new String[] {"x"}); //$NON-NLS-1$ resultsMsg.setDataTypes(new String[] {"xml"}); //$NON-NLS-1$ ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement); cs.next(); assertEquals("<a/>", cs.getString(1)); }