use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class GetUploadedFileName method eval.
@Override
public Sequence eval(final Sequence[] args, @Nonnull final RequestWrapper request) throws XPathException {
final String uploadParamName = args[0].getStringValue();
final List<String> fnames = request.getUploadedFileName(uploadParamName);
if (fnames == null || fnames.isEmpty()) {
return Sequence.EMPTY_SEQUENCE;
}
final ValueSequence result = new ValueSequence();
for (final String name : fnames) {
result.add(new StringValue(name));
}
return result;
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class GetParameterNames method eval.
@Override
public Sequence eval(final Sequence[] args, @Nonnull final RequestWrapper request) throws XPathException {
final Enumeration<String> parameterNames = request.getParameterNames();
if (!parameterNames.hasMoreElements()) {
return Sequence.EMPTY_SEQUENCE;
}
final ValueSequence result = new ValueSequence();
while (parameterNames.hasMoreElements()) {
final String parameterName = parameterNames.nextElement();
result.add(new StringValue(parameterName));
}
return result;
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class GMLHSQLIndexWorker method getGeometricPropertyForNode.
@Override
protected AtomicValue getGeometricPropertyForNode(XQueryContext context, NodeProxy p, Connection conn, String propertyName) throws SQLException, XPathException {
PreparedStatement ps = conn.prepareStatement("SELECT " + propertyName + " FROM " + GMLHSQLIndex.TABLE_NAME + " WHERE DOCUMENT_URI = ? AND NODE_ID_UNITS = ? AND NODE_ID = ?");
ps.setString(1, p.getOwnerDocument().getURI().toString());
ps.setInt(2, p.getNodeId().units());
byte[] bytes = new byte[p.getNodeId().size()];
p.getNodeId().serialize(bytes, 0);
ps.setBytes(3, bytes);
ResultSet rs = null;
try {
rs = ps.executeQuery();
if (!rs.next())
// Nothing returned
return AtomicValue.EMPTY_VALUE;
AtomicValue result = null;
if (rs.getMetaData().getColumnClassName(1).equals(Boolean.class.getName())) {
result = new BooleanValue(rs.getBoolean(1));
} else if (rs.getMetaData().getColumnClassName(1).equals(Double.class.getName())) {
result = new DoubleValue(rs.getDouble(1));
} else if (rs.getMetaData().getColumnClassName(1).equals(String.class.getName())) {
result = new StringValue(rs.getString(1));
} else if (rs.getMetaData().getColumnType(1) == java.sql.Types.BINARY) {
result = BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), new UnsynchronizedByteArrayInputStream(rs.getBytes(1)));
} else
throw new SQLException("Unable to make an atomic value from '" + rs.getMetaData().getColumnClassName(1) + "'");
if (rs.next()) {
// Should be impossible
throw new SQLException("More than one geometry for node " + p);
}
return result;
} finally {
if (rs != null)
rs.close();
ps.close();
}
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class GMLHSQLIndexWorker method getGeometricPropertyForNodes.
@Override
protected ValueSequence getGeometricPropertyForNodes(XQueryContext context, NodeSet contextSet, Connection conn, String propertyName) throws SQLException, XPathException {
// TODO : generate it in AbstractGMLJDBCIndexWorker
String docConstraint = "";
boolean refine_query_on_doc = false;
if (contextSet != null) {
if (contextSet.getDocumentSet().getDocumentCount() <= index.getMaxDocsInContextToRefineQuery()) {
DocumentImpl doc;
Iterator<DocumentImpl> it = contextSet.getDocumentSet().getDocumentIterator();
doc = it.next();
docConstraint = "(DOCUMENT_URI = '" + doc.getURI().toString() + "')";
while (it.hasNext()) {
doc = it.next();
docConstraint = docConstraint + " OR (DOCUMENT_URI = '" + doc.getURI().toString() + "')";
}
if (LOG.isDebugEnabled()) {
LOG.debug("Refine query on documents is enabled.");
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Refine query on documents is disabled.");
}
}
}
PreparedStatement ps = conn.prepareStatement("SELECT " + propertyName + ", DOCUMENT_URI, NODE_ID_UNITS, NODE_ID" + " FROM " + GMLHSQLIndex.TABLE_NAME + (refine_query_on_doc ? " WHERE " + docConstraint : ""));
ResultSet rs = null;
try {
rs = ps.executeQuery();
ValueSequence result;
if (contextSet == null)
result = new ValueSequence();
else
result = new ValueSequence(contextSet.getLength());
while (rs.next()) {
DocumentImpl doc = null;
try {
doc = (DocumentImpl) broker.getXMLResource(XmldbURI.create(rs.getString("DOCUMENT_URI")));
} catch (PermissionDeniedException e) {
LOG.debug(e);
// Untested, but that is roughly what should be returned.
if (rs.getMetaData().getColumnClassName(1).equals(Boolean.class.getName())) {
result.add(AtomicValue.EMPTY_VALUE);
} else if (rs.getMetaData().getColumnClassName(1).equals(Double.class.getName())) {
result.add(AtomicValue.EMPTY_VALUE);
} else if (rs.getMetaData().getColumnClassName(1).equals(String.class.getName())) {
result.add(AtomicValue.EMPTY_VALUE);
} else if (rs.getMetaData().getColumnType(1) == java.sql.Types.BINARY) {
result.add(AtomicValue.EMPTY_VALUE);
} else
throw new SQLException("Unable to make an atomic value from '" + rs.getMetaData().getColumnClassName(1) + "'");
// Ignore since the broker has no right on the document
continue;
}
if (contextSet.getDocumentSet().contains(doc.getDocId())) {
NodeId nodeId = new DLN(rs.getInt("NODE_ID_UNITS"), rs.getBytes("NODE_ID"), 0);
NodeProxy p = new NodeProxy(doc, nodeId);
// VirtualNodeSet when on the DESCENDANT_OR_SELF axis
if (contextSet.get(p) != null) {
if (rs.getMetaData().getColumnClassName(1).equals(Boolean.class.getName())) {
result.add(new BooleanValue(rs.getBoolean(1)));
} else if (rs.getMetaData().getColumnClassName(1).equals(Double.class.getName())) {
result.add(new DoubleValue(rs.getDouble(1)));
} else if (rs.getMetaData().getColumnClassName(1).equals(String.class.getName())) {
result.add(new StringValue(rs.getString(1)));
} else if (rs.getMetaData().getColumnType(1) == java.sql.Types.BINARY) {
result.add(BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), new UnsynchronizedByteArrayInputStream(rs.getBytes(1))));
} else
throw new SQLException("Unable to make an atomic value from '" + rs.getMetaData().getColumnClassName(1) + "'");
}
}
}
return result;
} finally {
if (rs != null)
rs.close();
if (ps != null)
ps.close();
}
}
use of org.exist.xquery.value.StringValue in project exist by eXist-db.
the class FunGeometricProperties method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
Sequence result = null;
Sequence nodes = args[0];
if (nodes.isEmpty()) {
result = Sequence.EMPTY_SEQUENCE;
} else {
try {
Geometry geometry = null;
String sourceCRS = null;
AbstractGMLJDBCIndexWorker indexWorker = (AbstractGMLJDBCIndexWorker) context.getBroker().getIndexController().getWorkerByIndexId(AbstractGMLJDBCIndex.ID);
if (indexWorker == null) {
logger.error("Unable to find a spatial index worker");
throw new XPathException(this, "Unable to find a spatial index worker");
}
String propertyName = null;
if (isCalledAs("getWKT")) {
propertyName = "WKT";
} else if (isCalledAs("getWKB")) {
propertyName = "WKB";
} else if (isCalledAs("getMinX")) {
propertyName = "MINX";
} else if (isCalledAs("getMaxX")) {
propertyName = "MAXX";
} else if (isCalledAs("getMinY")) {
propertyName = "MINY";
} else if (isCalledAs("getMaxY")) {
propertyName = "MAXY";
} else if (isCalledAs("getCentroidX")) {
propertyName = "CENTROID_X";
} else if (isCalledAs("getCentroidY")) {
propertyName = "CENTROID_Y";
} else if (isCalledAs("getArea")) {
propertyName = "AREA";
} else if (isCalledAs("getEPSG4326WKT")) {
propertyName = "EPSG4326_WKT";
} else if (isCalledAs("getEPSG4326WKB")) {
propertyName = "EPSG4326_WKB";
} else if (isCalledAs("getEPSG4326MinX")) {
propertyName = "EPSG4326_MINX";
} else if (isCalledAs("getEPSG4326MaxX")) {
propertyName = "EPSG4326_MAXX";
} else if (isCalledAs("getEPSG4326MinY")) {
propertyName = "EPSG4326_MINY";
} else if (isCalledAs("getEPSG4326MaxY")) {
propertyName = "EPSG4326_MAXY";
} else if (isCalledAs("getEPSG4326CentroidX")) {
propertyName = "EPSG4326_CENTROID_X";
} else if (isCalledAs("getEPSG4326CentroidY")) {
propertyName = "EPSG4326_CENTROID_Y";
} else if (isCalledAs("getEPSG4326Area")) {
propertyName = "EPSG4326_AREA";
} else if (isCalledAs("getSRS")) {
propertyName = "SRS_NAME";
} else if (isCalledAs("getGeometryType")) {
propertyName = "GEOMETRY_TYPE";
} else if (isCalledAs("isClosed")) {
propertyName = "IS_CLOSED";
} else if (isCalledAs("isSimple")) {
propertyName = "IS_SIMPLE";
} else if (isCalledAs("isValid")) {
propertyName = "IS_VALID";
} else {
logger.error("Unknown spatial property: {}", getName().getLocalPart());
throw new XPathException("Unknown spatial property: " + getName().getLocalPart());
}
NodeValue geometryNode = (NodeValue) nodes.itemAt(0);
if (geometryNode.getImplementationType() == NodeValue.PERSISTENT_NODE) {
// The node should be indexed : get its property
result = indexWorker.getGeometricPropertyForNode(context, (NodeProxy) geometryNode, propertyName);
hasUsedIndex = true;
} else {
// builds the geometry
sourceCRS = ((Element) geometryNode.getNode()).getAttribute("srsName").trim();
geometry = indexWorker.streamNodeToGeometry(context, geometryNode);
if (geometry == null) {
logger.error("Unable to get a geometry from the node");
throw new XPathException("Unable to get a geometry from the node");
}
// Transform the geometry to EPSG:4326 if relevant
if (propertyName.contains("EPSG4326")) {
geometry = indexWorker.transformGeometry(geometry, sourceCRS, "EPSG:4326");
if (isCalledAs("getEPSG4326WKT")) {
result = new StringValue(wktWriter.write(geometry));
} else if (isCalledAs("getEPSG4326WKB")) {
byte[] data = wkbWriter.write(geometry);
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), new UnsynchronizedByteArrayInputStream(data));
} else if (isCalledAs("getEPSG4326MinX")) {
result = new DoubleValue(geometry.getEnvelopeInternal().getMinX());
} else if (isCalledAs("getEPSG4326MaxX")) {
result = new DoubleValue(geometry.getEnvelopeInternal().getMaxX());
} else if (isCalledAs("getEPSG4326MinY")) {
result = new DoubleValue(geometry.getEnvelopeInternal().getMinY());
} else if (isCalledAs("getEPSG4326MaxY")) {
result = new DoubleValue(geometry.getEnvelopeInternal().getMaxY());
} else if (isCalledAs("getEPSG4326CentroidX")) {
result = new DoubleValue(geometry.getCentroid().getX());
} else if (isCalledAs("getEPSG4326CentroidY")) {
result = new DoubleValue(geometry.getCentroid().getY());
} else if (isCalledAs("getEPSG4326Area")) {
result = new DoubleValue(geometry.getArea());
}
} else if (isCalledAs("getWKT")) {
result = new StringValue(wktWriter.write(geometry));
} else if (isCalledAs("getWKB")) {
byte[] data = wkbWriter.write(geometry);
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), new UnsynchronizedByteArrayInputStream(data));
} else if (isCalledAs("getMinX")) {
result = new DoubleValue(geometry.getEnvelopeInternal().getMinX());
} else if (isCalledAs("getMaxX")) {
result = new DoubleValue(geometry.getEnvelopeInternal().getMaxX());
} else if (isCalledAs("getMinY")) {
result = new DoubleValue(geometry.getEnvelopeInternal().getMinY());
} else if (isCalledAs("getMaxY")) {
result = new DoubleValue(geometry.getEnvelopeInternal().getMaxY());
} else if (isCalledAs("getCentroidX")) {
result = new DoubleValue(geometry.getCentroid().getX());
} else if (isCalledAs("getCentroidY")) {
result = new DoubleValue(geometry.getCentroid().getY());
} else if (isCalledAs("getArea")) {
result = new DoubleValue(geometry.getArea());
} else if (isCalledAs("getSRS")) {
result = new StringValue(((Element) geometryNode).getAttribute("srsName"));
} else if (isCalledAs("getGeometryType")) {
result = new StringValue(geometry.getGeometryType());
} else if (isCalledAs("isClosed")) {
result = new BooleanValue(!geometry.isEmpty());
} else if (isCalledAs("isSimple")) {
result = new BooleanValue(geometry.isSimple());
} else if (isCalledAs("isValid")) {
result = new BooleanValue(geometry.isValid());
} else {
logger.error("Unknown spatial property: {}", getName().getLocalPart());
throw new XPathException("Unknown spatial property: " + getName().getLocalPart());
}
}
} catch (SpatialIndexException e) {
logger.error(e.getMessage());
throw new XPathException(e);
}
}
return result;
}
Aggregations