org.exist.source.StringSourceWithMapKey Maven / Gradle / Ivy
package org.exist.source;
import java.io.*;
import java.util.Map;
import org.exist.security.PermissionDeniedException;
import org.exist.security.Subject;
import org.exist.storage.DBBroker;
/**
* A simple source object wrapping a single query string, but associating it with a specific
* map (e.g., of namespace bindings). This prevents two textually equal queries with different
* maps from getting aliased in the query pool.
*
* @author Piotr Kaminski
*/
public class StringSourceWithMapKey extends AbstractSource {
private final Map map;
/**
* Create a new source for the given content and namespace map (string to string).
* The map will be taken over and modified by the source, so make a copy first if
* you're passing a shared one.
*
* @param content the content of the query
* @param map the map of prefixes to namespace URIs
*/
public StringSourceWithMapKey(String content, Map map) {
this.map = map;
this.map.put("", content);
}
@Override
public String path() {
return type();
}
@Override
public String type() {
return "StringWithMapKey";
}
public Object getKey() {return map;}
@Override
public Validity isValid(final DBBroker broker) {
return Validity.VALID;
}
@Override
public Validity isValid(final Source other) {
return Validity.VALID;
}
public Reader getReader() throws IOException {return new StringReader(map.get(""));}
public InputStream getInputStream() throws IOException {
// not implemented
return null;
}
public String getContent() throws IOException {return map.get("");}
@Override
public void validate(Subject subject, int perm) throws PermissionDeniedException {
// TODO protected?
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy