use of com.servoy.j2db.AbstractActiveSolutionHandler 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.AbstractActiveSolutionHandler in project servoy-client by Servoy.
the class FormElementHelper method getSharedFlattenedSolution.
private FlattenedSolution getSharedFlattenedSolution(FlattenedSolution fs) {
FlattenedSolution flattenedSolution = globalFlattendSolutions.get(fs.getMainSolutionMetaData().getName());
if (flattenedSolution == null) {
try {
flattenedSolution = new FlattenedSolution(true);
flattenedSolution.setSolution(fs.getMainSolutionMetaData(), false, true, new AbstractActiveSolutionHandler(ApplicationServerRegistry.getService(IApplicationServer.class)) {
@Override
public IRepository getRepository() {
return ApplicationServerRegistry.get().getLocalRepository();
}
});
FlattenedSolution alreadyCreated = globalFlattendSolutions.putIfAbsent(flattenedSolution.getName(), flattenedSolution);
if (alreadyCreated != null) {
flattenedSolution.close(null);
flattenedSolution = alreadyCreated;
}
} catch (Exception e) {
throw new RuntimeException("Can't create FlattenedSolution for: " + fs, e);
}
}
return flattenedSolution;
}
use of com.servoy.j2db.AbstractActiveSolutionHandler 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.AbstractActiveSolutionHandler 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.AbstractActiveSolutionHandler in project servoy-client by Servoy.
the class AngularIndexPageWriter method getFlattenedSolution.
private static Pair<FlattenedSolution, Boolean> getFlattenedSolution(String solutionName, String clientnr, HttpServletRequest request, HttpServletResponse response) {
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 (applicationServerUnavailable(response, as)) {
return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
}
SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(solutionName, SOLUTIONS);
if (solutionMissing(response, solutionName, solutionMetaData)) {
return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
}
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);
}
}
return new Pair<FlattenedSolution, Boolean>(fs, Boolean.valueOf(closeFS));
}
Aggregations