/*******************************************************************************
* Copyright (c) 2005-2010 Dennis Wagelaar, Vrije Universiteit Brussel.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Dennis Wagelaar, Vrije Universiteit Brussel
*******************************************************************************/
java
final Properties parameters = getParameters();
setDescription(new PlatformDescription());
final PlatformDescription description = getDescription();
description.setBrowserID(req.getHeader("User-Agent"));
if (ServletFileUpload.isMultipartContent(req)) {
PlatformkitLogger.logger.info("Retrieving uploaded ontology file");
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator fileItems = upload.getItemIterator(req);
description.setData(new byte[0]);
while (fileItems.hasNext()) {
FileItemStream item = fileItems.next();
InputStream stream = item.openStream();
if (item.isFormField()) {
if ("context".equals(item.getFieldName())
&& (description.getData().length == 0)) {
description.setFromInputStream(stream);
PlatformkitLogger.logger
.info("platform description data set from context (length = "
+ description.getData().length + ")");
} else {
parameters.setProperty(item.getFieldName(), Streams
.asString(stream));
}
} else if (description.getData().length == 0) {
description.setFromInputStream(stream);
PlatformkitLogger.logger
.info("platform description data set from context file (length = "
+ description.getData().length + ")");
}
}
} else {
PlatformkitLogger.logger
.warning("No platform ontology file uploaded");
final Enumeration<?> ns = req.getParameterNames();
if (ns.hasMoreElements()) {
while (ns.hasMoreElements()) {
String name = (String) ns.nextElement();
parameters.setProperty(name, req.getParameter(name));
}
} else {
StringTokenizer query = new StringTokenizer(req
.getQueryString(), "&");
while (query.hasMoreTokens()) {
StringTokenizer par = new StringTokenizer(
query.nextToken(), "=");
parameters.setProperty(par.nextToken(), par.nextToken());
}
}
final PlatformDescription pd = getStore().getPlatformDescription(
description.getBrowserID());
if (pd != null) {
PlatformkitLogger.logger
.info("Standard platform ontology found for: \""
+ pd.getBrowserID() + "\"");
setDescription(pd);
} else {
PlatformkitLogger.logger
.info("No standard platform ontology found for: \""
+ description.getBrowserID() + "\"");
}
}
PlatformkitLogger.logger.info(parameters.toString());
setLeastSpecific(parameters.getProperty("result").equals(
"leastspecific"));
setNoValidate(parameters.getProperty("noValidate").equals("true"));
setBaseURL(parameters.getProperty("baseurl"));
java
return new ByteArrayInputStream(getData());
java
byte[] buf = new byte[1024];
ByteArrayOutputStream out = new ByteArrayOutputStream(buf.length);
for (int read = stream.read(buf); read > -1; read = stream.read(buf)) {
out.write(buf, 0, read);
}
out.flush();
setData(out.toByteArray());
java
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Matcher m = quotes.matcher(browserID);
List<?> ps = session.createQuery(
"from " + PlatformDescription.class.getCanonicalName()
+ " where browserID=" + "'"
+ m.replaceAll(escapedQuote) + "'").list();
Iterator<?> e_itr = ps.iterator();
while (e_itr.hasNext()) {
return (PlatformDescription) e_itr.next();
}
return null;
java
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
session.save(pd);
session.getTransaction().commit();