use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class BufferedStringValue method getInternalValue.
public InternalValue getInternalValue(int type) throws ValueFormatException, RepositoryException {
try {
if (type == PropertyType.BINARY) {
// decode using Reader
if (length() < 0x10000) {
// < 65kb: deserialize BINARY type in memory
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Base64.decode(retrieve(), baos);
//baos.close();
return InternalValue.create(baos.toByteArray());
} else {
// >= 65kb: deserialize BINARY type
// using Reader and temporary file
Base64ReaderInputStream in = new Base64ReaderInputStream(reader());
return InternalValue.createTemporary(in);
}
} else {
// current namespace context of xml document
return InternalValue.create(ValueHelper.convert(retrieveString(), type, valueFactory), nsContext);
}
} catch (IOException e) {
throw new RepositoryException("Error accessing property value", e);
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class ClonedInputSource method read.
private static char[] read(Reader reader) throws RepositoryException {
if (reader != null) {
try {
final int bufferSize = 4096;
CharArrayWriter w = new CharArrayWriter(bufferSize);
char[] buffer = new char[bufferSize];
while (true) {
int numRead = reader.read(buffer);
if (numRead > 0) {
w.write(buffer, 0, numRead);
}
if (numRead != bufferSize) {
break;
}
}
return w.toCharArray();
} catch (IOException e) {
throw new RepositoryException(e);
} finally {
try {
reader.close();
} catch (IOException ignore) {
}
}
} else {
return null;
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class DocViewImportHandler method startElement.
//-------------------------------------------------------< ContentHandler >
/**
* {@inheritDoc}
* <p>
* See also {@link org.apache.jackrabbit.commons.xml.Exporter#exportProperties(Node)}
* regarding special handling of multi-valued properties on export.
*/
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
// process buffered character data
processCharacters();
try {
Name nodeName = NameFactoryImpl.getInstance().create(namespaceURI, localName);
// process node name
nodeName = processName(nodeName);
// properties
NodeId id = null;
Name nodeTypeName = null;
Name[] mixinTypes = null;
List<PropInfo> props = new ArrayList<PropInfo>(atts.getLength());
for (int i = 0; i < atts.getLength(); i++) {
if (atts.getURI(i).equals(Name.NS_XMLNS_URI)) {
// see http://issues.apache.org/jira/browse/JCR-620#action_12448164
continue;
}
Name propName = NameFactoryImpl.getInstance().create(atts.getURI(i), atts.getLocalName(i));
// process property name
propName = processName(propName);
// value(s)
String attrValue = atts.getValue(i);
TextValue[] propValues;
// always assume single-valued property for the time being
// until a way of properly serializing/detecting multi-valued
// properties on re-import is found (see JCR-325);
// see also DocViewSAXEventGenerator#leavingProperties(Node, int)
// todo proper multi-value serialization support
propValues = new TextValue[1];
propValues[0] = new StringValue(attrValue, resolver, valueFactory);
if (propName.equals(NameConstants.JCR_PRIMARYTYPE)) {
// jcr:primaryType
if (attrValue.length() > 0) {
try {
nodeTypeName = resolver.getQName(attrValue);
} catch (NameException ne) {
throw new SAXException("illegal jcr:primaryType value: " + attrValue, ne);
}
}
} else if (propName.equals(NameConstants.JCR_MIXINTYPES)) {
// jcr:mixinTypes
mixinTypes = parseNames(attrValue);
} else if (propName.equals(NameConstants.JCR_UUID)) {
// jcr:uuid
if (attrValue.length() > 0) {
id = NodeId.valueOf(attrValue);
}
} else {
props.add(new PropInfo(propName, PropertyType.UNDEFINED, propValues));
}
}
NodeInfo node = new NodeInfo(nodeName, nodeTypeName, mixinTypes, id);
// all information has been collected, now delegate to importer
importer.startNode(node, props);
// push current node data onto stack
stack.push(node);
} catch (RepositoryException re) {
throw new SAXException(re);
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class DocViewImportHandler method processCharacters.
/**
* Translates character data reported by the
* <code>{@link #characters(char[], int, int)}</code> &
* <code>{@link #ignorableWhitespace(char[], int, int)}</code> SAX events
* into a <code>jcr:xmltext</code> child node with one
* <code>jcr:xmlcharacters</code> property.
*
* @throws SAXException if an error occurs
* @see #appendCharacters(char[], int, int)
*/
private void processCharacters() throws SAXException {
try {
if (textHandler != null && textHandler.length() > 0) {
// there is character data that needs to be added to
// the current node
// check for pure whitespace character data
Reader reader = textHandler.reader();
try {
int ch;
while ((ch = reader.read()) != -1) {
if (ch > 0x20) {
break;
}
}
if (ch == -1) {
// the character data consists of pure whitespace, ignore
log.debug("ignoring pure whitespace character data...");
// reset handler
textHandler.dispose();
textHandler = null;
return;
}
} finally {
reader.close();
}
NodeInfo node = new NodeInfo(NameConstants.JCR_XMLTEXT, null, null, null);
TextValue[] values = new TextValue[] { textHandler };
ArrayList<PropInfo> props = new ArrayList<PropInfo>();
props.add(new PropInfo(NameConstants.JCR_XMLCHARACTERS, PropertyType.STRING, values));
// call Importer
importer.startNode(node, props);
importer.endNode(node);
// reset handler
textHandler.dispose();
textHandler = null;
}
} catch (IOException ioe) {
String msg = "internal error while processing internal buffer data";
log.error(msg, ioe);
throw new SAXException(msg, ioe);
} catch (RepositoryException re) {
throw new SAXException(re);
}
}
use of javax.jcr.RepositoryException in project jackrabbit by apache.
the class WorkspaceInitTest method testIdleTime.
public void testIdleTime() throws Exception {
// simply access the workspace, which will cause
// initialization of SlowQueryHandler.
List threads = new ArrayList();
for (int i = 0; i < 10; i++) {
Thread t = new Thread(new Runnable() {
public void run() {
try {
getHelper().getSuperuserSession("wsp-init-test").logout();
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
});
t.start();
threads.add(t);
}
for (Iterator it = threads.iterator(); it.hasNext(); ) {
((Thread) it.next()).join();
}
}
Aggregations