use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.
the class TenantServlet method register_csps.
/* Not in the constructor because errors during construction of servlets tend to get lost in a mess of startup.
* Better present it on first request.
*/
protected void register_csps(String tenantId) throws IOException, DocumentException {
if (!tenantCSPM.containsKey(tenantId)) {
tenantCSPM.put(tenantId, new CSPManagerImpl());
}
tenantCSPM.get(tenantId).register(new CoreConfig());
tenantCSPM.get(tenantId).register(new FileStorage());
tenantCSPM.get(tenantId).register(new ServicesStorageGenerator());
tenantCSPM.get(tenantId).register(new WebUI());
tenantCSPM.get(tenantId).register(new Spec());
}
use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.
the class NullResolver method serveSingle.
/**
* Return a single request from the cspace-ui servlet context
* @param tenant
* @param sub
* @param sc
* @throws UIException
* @throws IOException
*/
private void serveSingle(String tenant, CompositeWebUIRequestPart sub, ServletContext sc) throws UIException, IOException {
// Setup our request object
UI web = tenantCSPM.get(tenant).getUI("web");
WebUI webui = (WebUI) web;
UIMapping[] allmappings = webui.getAllMappings();
ConfigRoot root = tenantCSPM.get(tenant).getConfigRoot();
Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
// this doesn't seem to work yet
Boolean doMetaConfig = true;
String[] pathbits = sub.getPrincipalPath();
String pathinfo = StringUtils.join(pathbits, "/");
String path = pathinfo;
Map<String, Object> validmap = doMapping(pathinfo, allmappings, spec);
if (null != validmap) {
path = (String) validmap.get("File");
if (((UIMapping) validmap.get("map")).hasMetaConfig() && doMetaConfig) {
InputStream is = getFixedContent(sc, path, tenant);
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer, "UTF-8");
String theString = writer.toString();
/*
SAXReader reader = new SAXReader();
reader.setEntityResolver(new NullResolver());
Document xmlfile = null;
ByteArrayOutputStream dump = new ByteArrayOutputStream();
xmlfile = reader.read(new TeeInputStream(is, dump));
// log.info(dump.toString("UTF-8"));
// log.info(xmlfile.asXML());<tr></tr<.>
TODO I want this to work... it just doesn't yet as I haven\'t had time to work on it
this is all about replace items in the title etc of the universal files so they become more specific
*/
for (String metafield : ((UIMapping) validmap.get("map")).getAllMetaConfigs()) {
String rtext = ((UIMapping) validmap.get("map")).getMetaConfig(metafield).parseValue((Record) validmap.get("record"), (Instance) validmap.get("instance"));
// try as json
String regex = "\"" + metafield + "\": \"[^\"]*\"";
String replacement = "\"" + metafield + "\": \"" + rtext + "\"";
theString = theString.replaceFirst(regex, replacement);
// try as xml
String regex2 = "<" + metafield + ">[^<]*</" + metafield + ">";
String replacement2 = "<" + metafield + ">" + rtext + "</" + metafield + ">";
theString = theString.replaceFirst(regex2, replacement2);
}
InputStream is2 = new ByteArrayInputStream(theString.getBytes("UTF-8"));
serveExternalContent(sub, sc, is2, path);
is.close();
return;
}
}
if (pathbits[1].equals("bundle")) {
if (serverCreateMergedExternalContent(sub, sc, pathinfo, tenant)) {
return;
}
}
if (serverFixedExternalContent(sub, sc)) {
return;
}
}
use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.
the class NullResolver method serveSingle.
/**
* abstraction for returning a single item.
* probably could be simplified with other serveSingle function
* @param tenant
* @param servlet_request
* @param servlet_response
* @param pathinfo
* @param pathbits
* @param sc
* @throws IOException
* @throws BadRequestException
* @throws UnsupportedEncodingException
*/
private void serveSingle(String tenant, HttpServletRequest servlet_request, HttpServletResponse servlet_response, String pathinfo, String[] pathbits, ServletContext sc) throws IOException, BadRequestException, UnsupportedEncodingException {
// should we redirect this url or just do the normal stuff
// Setup our request object
UI web = tenantCSPM.get(tenant).getUI("web");
WebUI webui = (WebUI) web;
UIMapping[] allmappings = webui.getAllMappings();
ConfigRoot root = tenantCSPM.get(tenant).getConfigRoot();
Spec spec = (Spec) root.getRoot(Spec.SPEC_ROOT);
// this doesn't seem to work yet
Boolean doMetaConfig = true;
String path = pathinfo;
Map<String, Object> validmap = doMapping(pathinfo, allmappings, spec);
if (null != validmap) {
path = (String) validmap.get("File");
if (((UIMapping) validmap.get("map")).hasMetaConfig() && doMetaConfig) {
InputStream is = getFixedContent(sc, path, tenant);
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer, "UTF-8");
String theString = writer.toString();
/*
SAXReader reader = new SAXReader();
reader.setEntityResolver(new NullResolver());
Document xmlfile = null;
ByteArrayOutputStream dump = new ByteArrayOutputStream();
xmlfile = reader.read(new TeeInputStream(is, dump));
// log.info(dump.toString("UTF-8"));
// log.info(xmlfile.asXML());<tr></tr<.>
TODO I want this to work... it just doesn't yet as I haven\'t had time to work on it
this is all about replace items in the title etc of the universal files so they become more specific
*/
for (String metafield : ((UIMapping) validmap.get("map")).getAllMetaConfigs()) {
String rtext = ((UIMapping) validmap.get("map")).getMetaConfig(metafield).parseValue((Record) validmap.get("record"), (Instance) validmap.get("instance"));
// try as json
String regex = "\"" + metafield + "\": \"[^\"]*\"";
String replacement = "\"" + metafield + "\": \"" + rtext + "\"";
theString = theString.replaceFirst(regex, replacement);
// try as xml
String regex2 = "<" + metafield + ">[^<]*</" + metafield + ">";
String replacement2 = "<" + metafield + ">" + rtext + "</" + metafield + ">";
theString = theString.replaceFirst(regex2, replacement2);
}
InputStream is2 = new ByteArrayInputStream(theString.getBytes("UTF-8"));
serveContent(servlet_response, is2);
is.close();
return;
}
}
if (pathbits[1].equals("bundle")) {
if (serverCreateMergedExternalContent(servlet_request, servlet_response, sc, pathinfo, tenant)) {
return;
}
}
if (serverFixedExternalContent(servlet_request, servlet_response, sc, path, tenant)) {
return;
}
}
use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.
the class WebUI method complete_init.
@Override
public void complete_init(CSPManager cspManager, boolean forXsdGeneration) throws CSPDependencyException {
Spec spec = (Spec) ctx.getConfigRoot().getRoot(Spec.SPEC_ROOT);
if (spec == null)
throw new CSPDependencyException("Could not load spec");
configure_finish(spec);
for (WebMethod m : all_methods) m.configure(this, spec);
String name = (String) ctx.getConfigRoot().getRoot(CSPContext.XXX_SERVICE_NAME);
xxx_storage = ctx.getStorage(name);
}
use of org.collectionspace.chain.csp.schema.Spec in project application by collectionspace.
the class TestData method getDefaultUser.
public JSONObject getDefaultUser(ServletTester tester) {
Spec spec = getSpec(tester);
String username = spec.getAdminData().getAuthUser();
String pass = spec.getAdminData().getAuthPass();
String tenant = spec.getAdminData().getTenant();
JSONObject user = new JSONObject();
try {
user.put("userid", username);
user.put("password", pass);
user.put("tenant", tenant);
return user;
} catch (JSONException e) {
errored(e);
}
return user;
}
Aggregations