@Test public void testXmlSerialize2() throws Exception { XMLSerialize f = new XMLSerialize(); f.setExpression(new ElementSymbol("x")); f.setTypeString("BLOB"); f.setDeclaration(Boolean.TRUE); f.setVersion("1.0"); f.setEncoding("UTF-8"); helpTestExpression("xmlserialize(x as BLOB encoding \"UTF-8\" version '1.0' INCLUDING xmldeclaration)", "XMLSERIALIZE(x AS BLOB ENCODING \"UTF-8\" VERSION '1.0' INCLUDING XMLDECLARATION)", f); }
private InputStream handleResult(String charSet, Object result) throws SQLException { if (result == null) { return null; //or should this be an empty result? } if (result instanceof SQLXML) { if (charSet != null) { XMLSerialize serialize = new XMLSerialize(); serialize.setTypeString("blob"); //$NON-NLS-1$ serialize.setDeclaration(true); serialize.setEncoding(charSet); serialize.setDocument(true); try { return ((BlobType)XMLSystemFunctions.serialize(serialize, new XMLType((SQLXML)result))).getBinaryStream(); } catch (TransformationException e) { throw new SQLException(e); } } return ((SQLXML)result).getBinaryStream(); } else if (result instanceof Blob) { return ((Blob)result).getBinaryStream(); } else if (result instanceof Clob) { return new ReaderInputStream(((Clob)result).getCharacterStream(), charSet==null?Charset.defaultCharset():Charset.forName(charSet)); } return new ByteArrayInputStream(result.toString().getBytes(charSet==null?Charset.defaultCharset():Charset.forName(charSet))); }
@Override public void visit(XMLSerialize obj) { if (obj.getEncoding() != null ) { try { Charset.forName(obj.getEncoding()); } catch (IllegalArgumentException e) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.invalid_encoding", obj.getEncoding()), obj); //$NON-NLS-1$ } if ((obj.getType() != DataTypeManager.DefaultDataClasses.BLOB && obj.getType() != DataTypeManager.DefaultDataClasses.VARBINARY)) { handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.encoding_for_binary"), obj); //$NON-NLS-1$ } } }
@Override public void visit(XMLSerialize obj) { obj.setExpression(replaceExpression(obj.getExpression())); }
rewriteExpressions(expression); XMLSerialize serialize = (XMLSerialize)expression; if (isNull(serialize.getExpression())) { return new Constant(null, serialize.getType()); if (serialize.getDeclaration() == null && serialize.isDocument()) { if ((serialize.getVersion() != null && !serialize.getVersion().equals("1.0"))) { //$NON-NLS-1$ serialize.setDeclaration(true); } else if (serialize.getEncoding() != null) { Charset encoding = Charset.forName(serialize.getEncoding()); if (!encoding.equals(Charset.forName("UTF-8")) && !encoding.equals(Charset.forName("UTF-16"))) { //$NON-NLS-1$ //$NON-NLS-2$ serialize.setDeclaration(true);
@Test public void testXmlSerialize() throws Exception { XMLSerialize f = new XMLSerialize(); f.setDocument(true); f.setExpression(new ElementSymbol("x")); f.setTypeString("CLOB"); helpTestExpression("xmlserialize(document x as CLOB)", "XMLSERIALIZE(DOCUMENT x AS CLOB)", f); }
append(XMLSERIALIZE); append(Tokens.LPAREN); if (obj.getDocument() != null) { if (obj.getDocument()) { append(NonReserved.DOCUMENT); } else { visitNode(obj.getExpression()); if (obj.getTypeString() != null) { append(SPACE); append(AS); append(SPACE); append(obj.getTypeString()); if (obj.getEncoding() != null) { append(SPACE); append(NonReserved.ENCODING); append(SPACE); append(escapeSinglePart(obj.getEncoding())); if (obj.getVersion() != null) { append(SPACE); append(NonReserved.VERSION); append(SPACE); append(new Constant(obj.getVersion())); if (obj.getDeclaration() != null) { append(SPACE); if (obj.getDeclaration()) {
@Test public void testXmlSerialize1() throws Exception { XMLSerialize f = new XMLSerialize(); f.setExpression(new ElementSymbol("x")); f.setTypeString("CLOB"); helpTestExpression("xmlserialize(x as CLOB)", "XMLSERIALIZE(x AS CLOB)", f); }
public static Object serialize(XMLSerialize xs, XMLType value) throws TransformationException { Type type = value.getType(); final Charset encoding; if (xs.getEncoding() != null) { encoding = Charset.forName(xs.getEncoding()); } else { encoding = UTF_8; if (Boolean.TRUE.equals(xs.getDeclaration())) { xmlEventFactory.setLocation(dummyLocation); XMLEvent start = null; if (xs.getVersion() != null) { start = xmlEventFactory.createStartDocument(encoding.name(), xs.getVersion()); } else { } else if (type == Type.DOCUMENT && Boolean.FALSE.equals(xs.getDeclaration())){ final XMLType v = value; StAXSourceProvider sourceProvider = new StAXSourceProvider() { if (xs.getType() == DataTypeManager.DefaultDataClasses.STRING) { return DataTypeManager.transformValue(value, xs.getType()); if (xs.getType() == DataTypeManager.DefaultDataClasses.CLOB) { InputStreamFactory isf = Evaluator.getInputStreamFactory(value); return new ClobType(new ClobImpl(isf, -1)); if (xs.getType() == DataTypeManager.DefaultDataClasses.VARBINARY) { try { InputStream is = null;
@Override public XMLSerialize clone() { XMLSerialize clone = new XMLSerialize(); clone.document = this.document; clone.expression = (Expression)this.expression.clone(); clone.typeString = this.typeString; clone.type = this.type; clone.declaration = this.declaration; clone.version = this.version; clone.encoding = this.encoding; return clone; }
@Override public int hashCode() { return HashCodeUtil.hashCode(expression.hashCode(), getType()); }
rewriteExpressions(expression); XMLSerialize serialize = (XMLSerialize)expression; if (isNull(serialize.getExpression())) { return new Constant(null, serialize.getType()); if (serialize.getDeclaration() == null && serialize.isDocument()) { if ((serialize.getVersion() != null && !serialize.getVersion().equals("1.0"))) { //$NON-NLS-1$ serialize.setDeclaration(true); } else if (serialize.getEncoding() != null) { Charset encoding = Charset.forName(serialize.getEncoding()); if (!encoding.equals(Charset.forName("UTF-8")) && !encoding.equals(Charset.forName("UTF-16"))) { //$NON-NLS-1$ //$NON-NLS-2$ serialize.setDeclaration(true);
append(XMLSERIALIZE); append(Tokens.LPAREN); if (obj.getDocument() != null) { if (obj.getDocument()) { append(NonReserved.DOCUMENT); } else { visitNode(obj.getExpression()); if (obj.getTypeString() != null) { append(SPACE); append(AS); append(SPACE); append(obj.getTypeString()); if (obj.getEncoding() != null) { append(SPACE); append(NonReserved.ENCODING); append(SPACE); append(escapeSinglePart(obj.getEncoding())); if (obj.getVersion() != null) { append(SPACE); append(NonReserved.VERSION); append(SPACE); append(new Constant(obj.getVersion())); if (obj.getDeclaration() != null) { append(SPACE); if (obj.getDeclaration()) {
public static Object serialize(XMLSerialize xs, XMLType value) throws TransformationException { Type type = value.getType(); final Charset encoding; if (xs.getEncoding() != null) { encoding = Charset.forName(xs.getEncoding()); } else { encoding = UTF_8; if (Boolean.TRUE.equals(xs.getDeclaration())) { xmlEventFactory.setLocation(dummyLocation); XMLEvent start = null; if (xs.getVersion() != null) { start = xmlEventFactory.createStartDocument(encoding.name(), xs.getVersion()); } else if (xs.getEncoding() != null) { start = xmlEventFactory.createStartDocument(encoding.name()); } else { } else if (type == Type.DOCUMENT && Boolean.FALSE.equals(xs.getDeclaration())){ final XMLType v = value; StAXSourceProvider sourceProvider = new StAXSourceProvider() { if (xs.getType() == DataTypeManager.DefaultDataClasses.STRING) { return DataTypeManager.transformValue(value, xs.getType()); if (xs.getType() == DataTypeManager.DefaultDataClasses.CLOB) { InputStreamFactory isf = Evaluator.getInputStreamFactory(value); return new ClobType(new ClobImpl(isf, -1)); if (xs.getType() == DataTypeManager.DefaultDataClasses.VARBINARY) {
@Override public void visit(XMLSerialize obj) { obj.setExpression(replaceExpression(obj.getExpression())); }
@Override public XMLSerialize clone() { XMLSerialize clone = new XMLSerialize(); clone.document = this.document; clone.expression = (Expression)this.expression.clone(); clone.typeString = this.typeString; clone.type = this.type; clone.declaration = this.declaration; clone.version = this.version; clone.encoding = this.encoding; return clone; }
@Override public int hashCode() { return HashCodeUtil.hashCode(expression.hashCode(), getType()); }
XMLSerialize result = new XMLSerialize(); result.setEncoding(enc); result.setVersion(ver); result.setDeclaration(declr); result.setExpression(expr); if (doc != null) { result.setDocument(doc); result.setTypeString(t.image);
private InputStream handleResult(String charSet, Object result) throws SQLException { if (result == null) { return null; //or should this be an empty result? } if (result instanceof SQLXML) { if (charSet != null) { XMLSerialize serialize = new XMLSerialize(); serialize.setTypeString("blob"); //$NON-NLS-1$ serialize.setDeclaration(true); serialize.setEncoding(charSet); serialize.setDocument(true); try { return ((BlobType)XMLSystemFunctions.serialize(serialize, new XMLType((SQLXML)result))).getBinaryStream(); } catch (TransformationException e) { throw new SQLException(e); } } return ((SQLXML)result).getBinaryStream(); } else if (result instanceof Blob) { return ((Blob)result).getBinaryStream(); } else if (result instanceof Clob) { return new ReaderInputStream(((Clob)result).getCharacterStream(), charSet==null?Charset.defaultCharset():Charset.forName(charSet)); } return new ByteArrayInputStream(result.toString().getBytes(charSet==null?Charset.defaultCharset():Charset.forName(charSet))); }
rewriteExpressions(expression); XMLSerialize serialize = (XMLSerialize)expression; if (isNull(serialize.getExpression())) { return new Constant(null, serialize.getType()); if (serialize.getDeclaration() == null && serialize.isDocument()) { if ((serialize.getVersion() != null && !serialize.getVersion().equals("1.0"))) { //$NON-NLS-1$ serialize.setDeclaration(true); } else if (serialize.getEncoding() != null) { Charset encoding = Charset.forName(serialize.getEncoding()); if (!encoding.equals(Charset.forName("UTF-8")) && !encoding.equals(Charset.forName("UTF-16"))) { //$NON-NLS-1$ //$NON-NLS-2$ serialize.setDeclaration(true);