use of com.servoy.j2db.server.shared.IApplicationServer in project servoy-client by Servoy.
the class HeadlessClientFactoryInternal method createImportHookClient.
public static ISessionClient createImportHookClient(final Solution importHookModule, final IXMLImportUserChannel channel) throws Exception {
final String[] loadException = new String[1];
// assuming no login and no method args for import hooks
SessionClient sc = new SessionClient(null, null, null, null, null, importHookModule.getName()) {
@Override
protected IActiveSolutionHandler createActiveSolutionHandler() {
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
return new LocalActiveSolutionHandler(as, this) {
@Override
protected Solution loadSolution(RootObjectMetaData solutionDef) throws RemoteException, RepositoryException {
// grab the latest version (-1) not the active one, because the hook was not yet activated.
return (Solution) ((IDeveloperRepository) getRepository()).getRootObject(solutionDef.getRootObjectId(), -1);
}
};
}
@Override
protected IExecutingEnviroment createScriptEngine() {
return new ScriptEngine(this) {
@Override
public Object executeFunction(Function f, Scriptable scope, Scriptable thisObject, Object[] args, boolean focusEvent, boolean throwException) throws Exception {
// always throw exception
return super.executeFunction(f, scope, thisObject, args, focusEvent, true);
}
};
}
@Override
public void reportError(String msg, Object detail) {
super.reportError(msg, detail);
loadException[0] = msg;
if (detail instanceof JavaScriptException && ((JavaScriptException) detail).getValue() instanceof Scriptable) {
loadException[0] += " " + Utils.getScriptableString((Scriptable) ((JavaScriptException) detail).getValue());
}
if (detail instanceof Exception) {
loadException[0] += " " + ((Exception) detail).getMessage();
}
}
};
sc.setUseLoginSolution(false);
String userName = channel.getImporterUsername();
if (userName != null) {
// let the import hook client run with credentials from the logged in user from the admin page.
sc.getClientInfo().setUserUid(ApplicationServerRegistry.get().getUserManager().getUserUID(sc.getClientID(), userName));
sc.getClientInfo().setUserName(userName);
}
sc.setOutputChannel(channel);
sc.loadSolution(importHookModule.getName());
if (loadException[0] != null) {
sc.shutDown(true);
throw new RepositoryException(loadException[0]);
}
return sc;
}
use of com.servoy.j2db.server.shared.IApplicationServer in project servoy-client by Servoy.
the class TemplateGenerator method getFormHTMLAndCSS.
public static Pair<String, String> getFormHTMLAndCSS(Solution solution, Form form, IServiceProvider sp, String formInstanceName) throws RepositoryException, RemoteException {
if (form == null)
return null;
final IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
boolean enableAnchoring = sp != null ? Utils.getAsBoolean(sp.getRuntimeProperties().get("enableAnchors")) : Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.webclient.enableAnchors", Boolean.TRUE.toString()));
String overriddenStyleName = null;
Pair<String, ArrayList<Pair<String, String>>> retval = formCache.getFormAndCssPair(form, formInstanceName, overriddenStyleName, repository);
Form f = form;
FlattenedSolution fsToClose = null;
try {
if (retval == null) {
if (f.getExtendsID() > 0) {
FlattenedSolution fs = sp == null ? null : sp.getFlattenedSolution();
if (fs == null) {
try {
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
fsToClose = fs = new FlattenedSolution(solution.getSolutionMetaData(), new AbstractActiveSolutionHandler(as) {
@Override
public IRepository getRepository() {
return repository;
}
});
} catch (RepositoryException e) {
Debug.error("Couldn't create flattened form for the template generator", e);
}
}
f = fs.getFlattenedForm(f);
if (f == null) {
Debug.log("TemplateGenerator couldn't get a FlattenedForm for " + form + ", solution closed?");
f = form;
}
}
StringBuffer html = new StringBuffer();
TextualCSS css = new TextualCSS();
IFormLayoutProvider layoutProvider = FormLayoutProviderFactory.getFormLayoutProvider(sp, solution, f, formInstanceName);
int viewType = layoutProvider.getViewType();
layoutProvider.renderOpenFormHTML(html, css);
int startY = 0;
Iterator<Part> parts = f.getParts();
while (parts.hasNext()) {
Part part = parts.next();
int endY = part.getHeight();
if (Part.rendersOnlyInPrint(part.getPartType())) {
startY = part.getHeight();
// is never shown (=printing only)
continue;
}
Color bgColor = ComponentFactory.getPartBackground(sp, part, f);
if (part.getPartType() == Part.BODY && (viewType == FormController.TABLE_VIEW || viewType == FormController.LOCKED_TABLE_VIEW || viewType == IForm.LIST_VIEW || viewType == FormController.LOCKED_LIST_VIEW)) {
layoutProvider.renderOpenTableViewHTML(html, css, part);
// tableview == bodypart
createCellBasedView(f, f, html, css, layoutProvider.needsHeaders(), startY, endY, bgColor, sp, viewType, enableAnchoring, startY, endY);
layoutProvider.renderCloseTableViewHTML(html);
} else {
layoutProvider.renderOpenPartHTML(html, css, part);
placePartElements(f, startY, endY, html, css, bgColor, enableAnchoring, sp);
layoutProvider.renderClosePartHTML(html, part);
}
startY = part.getHeight();
}
layoutProvider.renderCloseFormHTML(html);
retval = new Pair<String, ArrayList<Pair<String, String>>>(html.toString(), css.getAsSelectorValuePairs());
formCache.putFormAndCssPair(form, formInstanceName, overriddenStyleName, repository, retval);
}
Map<String, String> formIDToMarkupIDMap = null;
if (sp instanceof IApplication) {
Map runtimeProps = sp.getRuntimeProperties();
Map<WebForm, Map<String, String>> clientFormsIDToMarkupIDMap = (Map<WebForm, Map<String, String>>) runtimeProps.get("WebFormIDToMarkupIDCache");
if (clientFormsIDToMarkupIDMap == null) {
clientFormsIDToMarkupIDMap = new WeakHashMap<WebForm, Map<String, String>>();
runtimeProps.put("WebFormIDToMarkupIDCache", clientFormsIDToMarkupIDMap);
}
IForm wfc = ((IApplication) sp).getFormManager().getForm(formInstanceName);
if (wfc instanceof FormController) {
IFormUIInternal wf = ((FormController) wfc).getFormUI();
if (wf instanceof WebForm) {
if (!((WebForm) wf).isUIRecreated())
formIDToMarkupIDMap = clientFormsIDToMarkupIDMap.get(wf);
if (formIDToMarkupIDMap == null) {
ArrayList<Pair<String, String>> formCSS = retval.getRight();
ArrayList<String> selectors = new ArrayList<String>(formCSS.size());
for (Pair<String, String> formCSSEntry : formCSS) selectors.add(formCSSEntry.getLeft());
formIDToMarkupIDMap = getWebFormIDToMarkupIDMap((WebForm) wf, selectors);
clientFormsIDToMarkupIDMap.put((WebForm) wf, formIDToMarkupIDMap);
}
}
}
}
String webFormCSS = getWebFormCSS(retval.getRight(), formIDToMarkupIDMap);
// string the formcss/solutionname/ out of the url.
webFormCSS = StripHTMLTagsConverter.convertMediaReferences(webFormCSS, solution.getName(), new ResourceReference("media"), "", false).toString();
return new Pair<String, String>(retval.getLeft(), webFormCSS);
} finally {
if (fsToClose != null) {
fsToClose.close(null);
}
}
}
use of com.servoy.j2db.server.shared.IApplicationServer in project servoy-client by Servoy.
the class SharedMediaResource method getResource.
private ResourceState getResource(final String iconId, final String solutionName) {
return new ResourceState() {
private String contentType;
private int length;
byte[] array = null;
@Override
public Time lastModifiedTime() {
try {
IRootObject solution = ApplicationServerRegistry.get().getLocalRepository().getActiveRootObject(solutionName, IRepository.SOLUTIONS);
if (solution != null)
return Time.valueOf(solution.getLastModifiedTime());
} catch (Exception e) {
Debug.trace(e);
}
return time;
}
@Override
public byte[] getData() {
if (array == null) {
boolean closeFS = false;
try {
final IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
FlattenedSolution fs = null;
try {
if (Session.exists() && ((WebClientSession) Session.get()).getWebClient() != null) {
fs = ((WebClientSession) Session.get()).getWebClient().getFlattenedSolution();
}
if (fs == null) {
SolutionMetaData solutionMetaData = (SolutionMetaData) repository.getRootObjectMetaData(solutionName, IRepository.SOLUTIONS);
if (solutionMetaData == null)
return new byte[0];
closeFS = true;
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {
@Override
public IRepository getRepository() {
return repository;
}
});
}
Media m = fs.getMedia(iconId);
if (m == null) {
try {
Integer iIconID = new Integer(iconId);
m = fs.getMedia(iIconID.intValue());
} catch (NumberFormatException ex) {
Debug.error("no media found for: " + iconId);
}
}
if (m != null) {
array = m.getMediaData();
contentType = m.getMimeType();
}
} finally {
if (closeFS && fs != null) {
fs.close(null);
}
}
if (array != null) {
if (contentType == null) {
contentType = MimeTypes.getContentType(array);
}
length = array.length;
}
} catch (Exception ex) {
Debug.error(ex);
}
}
return array == null ? new byte[0] : array;
}
/**
* @see wicket.markup.html.DynamicWebResource.ResourceState#getLength()
*/
@Override
public int getLength() {
return length;
}
@Override
public String getContentType() {
return contentType;
}
};
}
use of com.servoy.j2db.server.shared.IApplicationServer in project servoy-client by Servoy.
the class FormTemplateGenerator method isSingleValueComponent.
/**
* @return false if the persist has no valuelist or at most one value in the valuelist, true otherwise
*/
public static boolean isSingleValueComponent(IFormElement persist) {
Field field = (Field) persist;
if (field.getValuelistID() > 0) {
try {
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
FlattenedSolution fs = new FlattenedSolution((SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(((Solution) persist.getRootObject()).getName(), IRepository.SOLUTIONS), new AbstractActiveSolutionHandler(as) {
@Override
public IRepository getRepository() {
return ApplicationServerRegistry.get().getLocalRepository();
}
});
ValueList valuelist = fs.getValueList(field.getValuelistID());
return isSingleValue(valuelist);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return true;
}
use of com.servoy.j2db.server.shared.IApplicationServer in project servoy-client by Servoy.
the class NGClientEntryFilter method doFilter.
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
try {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
if ("GET".equalsIgnoreCase(request.getMethod())) {
if (request.getCharacterEncoding() == null)
request.setCharacterEncoding("UTF8");
String uri = request.getRequestURI();
if (handleShortSolutionRequest(request, response)) {
return;
}
if (handleDeeplink(request, response)) {
return;
}
if (handleRecording(request, response)) {
return;
}
if (uri != null && (uri.endsWith(".html") || uri.endsWith(".js"))) {
String solutionName = getSolutionNameFromURI(uri);
if (solutionName != null) {
String clientnr = AngularIndexPageWriter.getClientNr(uri, request);
INGClientWebsocketSession wsSession = null;
HttpSession httpSession = request.getSession(false);
if (clientnr != null && httpSession != null) {
wsSession = (INGClientWebsocketSession) WebsocketSessionManager.getSession(CLIENT_ENDPOINT, httpSession, Integer.parseInt(clientnr));
}
FlattenedSolution fs = null;
boolean closeFS = false;
if (wsSession != null) {
fs = wsSession.getClient().getFlattenedSolution();
}
if (fs == null) {
try {
closeFS = true;
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
if (AngularIndexPageWriter.applicationServerUnavailable(response, as)) {
return;
}
SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(solutionName, SOLUTIONS);
if (AngularIndexPageWriter.solutionMissing(response, solutionName, solutionMetaData)) {
return;
}
fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {
@Override
public IRepository getRepository() {
return ApplicationServerRegistry.get().getLocalRepository();
}
});
} catch (Exception e) {
Debug.error("error loading solution: " + solutionName + " for clientnr: " + clientnr, e);
}
}
if (fs != null) {
try {
if (handleMainJs(request, response, fs)) {
return;
}
if (handleForm(request, response, wsSession, fs)) {
return;
}
if (AngularIndexPageWriter.handleMaintenanceMode(request, response, wsSession)) {
return;
}
// prepare for possible index.html lookup
Map<String, Object> variableSubstitution = getSubstitutions(request, solutionName, clientnr, fs);
List<String> extraMeta = new ArrayList<String>();
addManifest(fs, extraMeta);
addHeadIndexContributions(fs, extraMeta);
ContentSecurityPolicyConfig contentSecurityPolicyConfig = addcontentSecurityPolicyHeader(request, response, true);
super.doFilter(servletRequest, servletResponse, filterChain, asList(SERVOY_CSS), new ArrayList<String>(getFormScriptReferences(fs)), extraMeta, variableSubstitution, contentSecurityPolicyConfig == null ? null : contentSecurityPolicyConfig.getNonce());
return;
} finally {
if (closeFS) {
fs.close(null);
}
}
}
}
}
if (!uri.contains(ModifiablePropertiesGenerator.PUSH_TO_SERVER_BINDINGS_LIST))
Debug.log("No solution found for this request, calling the default filter: " + uri);
}
super.doFilter(servletRequest, servletResponse, filterChain, null, null, null, null, null);
} catch (RuntimeException | Error e) {
Debug.error(e);
throw e;
}
}
Aggregations