List of usage examples for org.apache.wicket.util.string AppendingStringBuffer toString
@Override
public String toString()
From source file:com.doculibre.constellio.wicket.components.modal.NonAjaxModalWindow.java
License:Apache License
/** * Returns the javascript used to open the window. * /*from www.j a v a 2 s. c o m*/ * @return javascript that opens the window */ private String getWindowOpenJavascript() { AppendingStringBuffer buffer = new AppendingStringBuffer(); if (isCustomComponent() == true) { buffer.append("var element = document.getElementById(\"" + getContentMarkupId() + "\");\n"); } buffer.append("var settings = new Object();\n"); buffer.append("settings.minWidth=" + getMinimalWidth() + ";\n"); buffer.append("settings.minHeight=" + getMinimalHeight() + ";\n"); buffer.append("settings.className=\"" + getCssClassName() + "\";\n"); buffer.append("settings.width=\"" + getInitialWidth() + "\";\n"); if (isUseInitialHeight() == true || isCustomComponent() == false) buffer.append("settings.height=\"" + getInitialHeight() + "\";\n"); else buffer.append("settings.height=null;\n"); buffer.append("settings.resizable=" + Boolean.toString(isResizable()) + ";\n"); if (isResizable() == false) { buffer.append("settings.widthUnit=\"" + getWidthUnit() + "\";\n"); buffer.append("settings.heightUnit=\"" + getHeightUnit() + "\";\n"); } if (isCustomComponent() == false) { Page page = createPage(); if (page == null) { throw new WicketRuntimeException("Error creating page for modal dialog."); } RequestCycle.get().setUrlForNewWindowEncoding(); buffer.append("settings.src=\"" + RequestCycle.get().urlFor(page) + "\";\n"); if (getPageMapName() != null) { buffer.append("settings.iframeName=\"" + getPageMapName() + "\";\n"); } } else { buffer.append("settings.element = element;\n"); } if (getCookieName() != null) { buffer.append("settings.cookieId=\"" + getCookieName() + "\";\n"); } Object title = getTitle() != null ? getTitle().getObject() : null; if (title != null) { buffer.append("settings.title=\"" + escapeQuotes(title.toString()) + "\";\n"); } if (getMaskType() == MaskType.TRANSPARENT) { buffer.append("settings.mask=\"transparent\";\n"); } else if (getMaskType() == MaskType.SEMI_TRANSPARENT) { buffer.append("settings.mask=\"semi-transparent\";\n"); } // set true if we set a windowclosedcallback boolean haveCloseCallback = false; // in case user is interested in window close callback or we have a // pagemap to clean // attach notification request if ((isCustomComponent() == false && deletePageMap) || windowClosedCallback != null) { WindowClosedBehavior behavior = (WindowClosedBehavior) getBehaviors(WindowClosedBehavior.class).get(0); buffer.append("settings.onClose = function() { " + /*behavior.getCallbackScript() +*/ " };\n"); haveCloseCallback = true; } // in case we didn't set windowclosecallback, we need at least callback // on close button, // to close window property (thus cleaning the shown flag) if (closeButtonCallback != null || haveCloseCallback == false) { CloseButtonBehavior behavior = (CloseButtonBehavior) getBehaviors(CloseButtonBehavior.class).get(0); buffer.append("settings.onCloseButton = function() { " + /*behavior.getCallbackScript() +*/ "};\n"); } postProcessSettings(buffer); buffer.append("Wicket.Window.create(settings).show();\n"); return buffer.toString(); }
From source file:com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.java
License:Open Source License
public String getRowSelectionScript(List<Integer> indexToUpdate) { if (currentData == null) return null; if (!hasOnRender() && (bgColorScript != null || hasOddEvenSelected()) && indexToUpdate != null) { int firstRow = table.isPageableMode() ? table.getCurrentPage() * table.getRowsPerPage() : table.getStartIndex(); int lastRow = firstRow + table.getViewSize() - 1; int[] newSelectedIndexes = getSelectedIndexes(); AppendingStringBuffer sab = new AppendingStringBuffer(); for (int rowIdx : indexToUpdate) { ArrayList<String> bgRuntimeColorjsArray = new ArrayList<String>(); ArrayList<String> fgRuntimeColorjsArray = new ArrayList<String>(); ArrayList<String> fstyleJsAray = new ArrayList<String>(); ArrayList<String> fweightJsAray = new ArrayList<String>(); ArrayList<String> fsizeJsAray = new ArrayList<String>(); ArrayList<String> ffamilyJsAray = new ArrayList<String>(); ArrayList<String> bstyleJsAray = new ArrayList<String>(); ArrayList<String> bwidthJsAray = new ArrayList<String>(); ArrayList<String> bcolorJsAray = new ArrayList<String>(); if (rowIdx >= firstRow && rowIdx <= lastRow) { ListItem<IRecordInternal> selectedListItem = (ListItem<IRecordInternal>) table .get(Integer.toString(rowIdx)); if (selectedListItem != null) { String selectedId = selectedListItem.getMarkupId(); boolean isSelected = Arrays.binarySearch(newSelectedIndexes, rowIdx) >= 0; // IF ONLY SELCTED STYLE RULE is defined then apply runtimeComonent style properties if (bgColorScript == null && !isSelected && (getRowOddStyle().getAttributeCount() == 0) && (getRowEvenStyle().getAttributeCount() == 0)) { Iterable<? extends Component> it = Utils.iterate(selectedListItem.iterator()); Component cellContents; for (Component c : it) { if (c instanceof CellContainer) { CellContainer cell = (CellContainer) c; cellContents = cell.iterator().next(); } else { cellContents = c; }// w w w . jav a 2s. c o m if (cellContents instanceof IScriptableProvider) { IScriptable scriptableComponent = ((IScriptableProvider) cellContents) .getScriptObject(); if (scriptableComponent instanceof IRuntimeComponent) { IRuntimeComponent runtimeComponent = (IRuntimeComponent) scriptableComponent; //bgcolor bgRuntimeColorjsArray.add(runtimeComponent.getBgcolor()); //fgcolor fgRuntimeColorjsArray.add(runtimeComponent.getFgcolor()); // font style String fontStyle = runtimeComponent.getFont(); StringBuilder fstyle = new StringBuilder(""), //$NON-NLS-1$ fweight = new StringBuilder(""), fsize = new StringBuilder(""), //$NON-NLS-1$//$NON-NLS-2$ ffamily = new StringBuilder(""); //$NON-NLS-1$ splitFontStyle(fontStyle, fstyle, fweight, fsize, ffamily); fstyleJsAray.add(fstyle.toString()); fweightJsAray.add(fweight.toString()); fsizeJsAray.add(fsize.toString()); ffamilyJsAray.add(ffamily.toString()); // border style String borderStyle = runtimeComponent.getBorder(); StringBuilder bstyle = new StringBuilder(""), //$NON-NLS-1$ bwidth = new StringBuilder(""), bcolor = new StringBuilder(""); //$NON-NLS-1$ //$NON-NLS-2$ splitBorderStyle(borderStyle, bstyle, bwidth, bcolor); bstyleJsAray.add(bstyle.toString()); bwidthJsAray.add(bwidth.toString()); bcolorJsAray.add(bcolor.toString()); } } } } String selectedColor = null, selectedFgColor = null, selectedFont = null, selectedBorder = null; selectedColor = getListItemBgColor(selectedListItem, isSelected, true); if (!isListViewMode()) { selectedFgColor = getListItemFgColor(selectedListItem, isSelected, true); selectedFont = getListItemFont(selectedListItem, isSelected); selectedBorder = getListItemBorder(selectedListItem, isSelected); } selectedColor = (selectedColor == null ? "" : selectedColor.toString()); //$NON-NLS-1$ selectedFgColor = (selectedFgColor == null) ? "" : selectedFgColor.toString(); //$NON-NLS-1$ // font styles StringBuilder fstyle = new StringBuilder(""), fweight = new StringBuilder(""), //$NON-NLS-1$//$NON-NLS-2$ fsize = new StringBuilder(""), //$NON-NLS-1$ ffamily = new StringBuilder(""); //$NON-NLS-1$ splitFontStyle(selectedFont, fstyle, fweight, fsize, ffamily); //border styles StringBuilder bstyle = new StringBuilder(""), bwidth = new StringBuilder(""), //$NON-NLS-1$//$NON-NLS-2$ bcolor = new StringBuilder(""); //$NON-NLS-1$ splitBorderStyle(selectedBorder, bstyle, bwidth, bcolor); if (bgColorScript == null && !isSelected && (getRowOddStyle().getAttributeCount() == 0) && (getRowEvenStyle().getAttributeCount() == 0) && !isListViewMode()) { //backgroundcolor and color are sent as final inline string sab.append("Servoy.TableView.setRowStyle('"). //$NON-NLS-1$ append(selectedId).append("', "). //$NON-NLS-1$ append(toJsArrayString(bgRuntimeColorjsArray, "background-color:")).append(","). //$NON-NLS-1$ append(toJsArrayString(fgRuntimeColorjsArray, "color:")).append(","). //$NON-NLS-1$ append(toJsArrayString(fstyleJsAray, "")).append(", "). //$NON-NLS-1$ append(toJsArrayString(fweightJsAray, "")).append(", "). //$NON-NLS-1$ append(toJsArrayString(fsizeJsAray, "")).append(", "). //$NON-NLS-1$ append(toJsArrayString(ffamilyJsAray, "")).append(", "). //$NON-NLS-1$ append(toJsArrayString(bstyleJsAray, "")).append(", "). //$NON-NLS-1$ append(toJsArrayString(bwidthJsAray, "")).append(","). //$NON-NLS-1$ append(toJsArrayString(bcolorJsAray, "")).append(","). //$NON-NLS-1$ append(isListViewMode()).append(");\n"); //$NON-NLS-1$ } else { sab.append("Servoy.TableView.setRowStyle('"). //$NON-NLS-1$ append(selectedId).append("', '"). //$NON-NLS-1$ append(selectedColor).append("', '"). //$NON-NLS-1$ append(selectedFgColor).append("', '"). //$NON-NLS-1$ append(fstyle).append("', '"). //$NON-NLS-1$ append(fweight).append("', '"). //$NON-NLS-1$ append(fsize).append("', '"). //$NON-NLS-1$ append(ffamily).append("', '"). //$NON-NLS-1$ append(bstyle).append("', '"). //$NON-NLS-1$ append(bwidth).append("', '"). //$NON-NLS-1$ append(bcolor).append("', "). //$NON-NLS-1$ append(isListViewMode()).append(");\n"); //$NON-NLS-1$ } } } } String rowSelectionScript = sab.toString(); if (rowSelectionScript.length() > 0) return rowSelectionScript; } return null; }
From source file:com.servoy.j2db.server.headlessclient.dataui.WebDataHtmlView.java
License:Open Source License
/** * @see com.servoy.j2db.server.headlessclient.dataui.ISupportScriptCallback#getCallBackUrl(java.lang.String, boolean) *//*from w ww . j a v a2 s. c o m*/ @SuppressWarnings("nls") public CharSequence getCallBackUrl(String scriptName, boolean testDoubleClick) { boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX")); if (useAJAX) { if (inlineScriptExecutor == null) { inlineScriptExecutor = new InlineScriptExecutorBehavior(this); add(inlineScriptExecutor); } AppendingStringBuffer asb = new AppendingStringBuffer(80); if (testDoubleClick) { asb.append("if (testDoubleClickId('"); asb.append(getMarkupId()); asb.append("')) { "); } asb.append("document.getElementById('").append(getMarkupId()).append("').focus();"); asb.append("window.setTimeout(function() { wicketAjaxGet('"); asb.append(inlineScriptExecutor.getCallbackUrl()); ICrypt urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt(); asb.append("&snenc="); String escapedScriptName = Utils.stringReplace(Utils.stringReplace(scriptName, "\\\'", "\'"), """, "\""); asb.append(WicketURLEncoder.QUERY_INSTANCE.encode(urlCrypt.encryptUrlSafe(escapedScriptName))); for (String browserArgument : inlineScriptExecutor.getBrowserArguments(scriptName)) { asb.append("&").append(browserArgument).append("=' + ").append(browserArgument).append(" + '"); } asb.append("');}, 0);"); if (testDoubleClick) { asb.append("} "); } asb.append("return false;"); return asb.toString(); } else { return StripHTMLTagsConverter.getTriggerJavaScript(this, scriptName); } }
From source file:com.servoy.j2db.server.headlessclient.DivWindow.java
License:Open Source License
/** * When show was initially called from a child iframe request (thus callback scripts were generated using that * page's target), you need to call this method subsequently on a request from the root main frame, to make * behaviors work with the main page as you would expect (otherwise problems occur when you try to close it). * @param mainFrameTarget/*from ww w . j a v a 2s . com*/ * @param childFrameBatchId should never be null; it is the child frame batchId that will execute/has executed the show. */ public void reAttachBehaviorsAfterShow(AjaxRequestTarget mainFrameTarget, String childFrameBatchId) { if (childFrameBatchId == null) throw new IllegalArgumentException( "'reAttachBehaviors' is only to be called if a show happened on child frame."); AppendingStringBuffer settingsToUpdate = new AppendingStringBuffer(500); // if show was already called (as a result of a child frame request), just re-register; otherwise wait for show to be called and that will do the re-register directly settingsToUpdate.append("function (settings) {\n"); attachOnMove(settingsToUpdate); attachOnResize(settingsToUpdate); reattachOnClose(settingsToUpdate); reattachOnCloseButton(settingsToUpdate); settingsToUpdate.append("}"); mainFrameTarget.appendJavascript("Wicket.DivWindow.reAttachBehaviorsAfterShow(" + settingsToUpdate.toString() + ", \"" + getJSId() + "\", \"" + childFrameBatchId + "\");"); }
From source file:com.servoy.j2db.server.ngclient.NGClient.java
private void initLocaleAndTimeZone() { Object retValue = null;//from w w w. j av a 2s . c om try { retValue = this.getWebsocketSession().getClientService(NGClient.APPLICATION_SERVICE) .executeServiceCall("getUtcOffsetsAndLocale", null); } catch (IOException e) { Debug.warn(e); return; } if (retValue instanceof JSONObject) { String userAgent = ((JSONObject) retValue).optString("userAgent"); if (userAgent != null) { getClientInfo().addInfo("useragent:" + userAgent); } String platform = ((JSONObject) retValue).optString("platform"); if (platform != null) { getClientInfo().addInfo("platform:" + platform); } if (timeZone == null) { String utc = ((JSONObject) retValue).optString("utcOffset"); if (utc != null) { // apparently it is platform dependent on whether you get the // offset in a decimal form or not. This parses the decimal // form of the UTC offset, taking into account several // possibilities // such as getting the format in +2.5 or -1.2 int dotPos = utc.indexOf('.'); if (dotPos >= 0) { String hours = utc.substring(0, dotPos); String hourPart = utc.substring(dotPos + 1); if (hours.startsWith("+")) { hours = hours.substring(1); } int offsetHours = Integer.parseInt(hours); int offsetMins = (int) (Double.parseDouble(hourPart) * 6); // construct a GMT timezone offset string from the retrieved // offset which can be parsed by the TimeZone class. AppendingStringBuffer sb = new AppendingStringBuffer("GMT"); sb.append(offsetHours > 0 ? "+" : "-"); sb.append(Math.abs(offsetHours)); sb.append(":"); if (offsetMins < 10) { sb.append("0"); } sb.append(offsetMins); timeZone = TimeZone.getTimeZone(sb.toString()); } else { int offset = Integer.parseInt(utc); if (offset < 0) { utc = utc.substring(1); } timeZone = TimeZone.getTimeZone("GMT" + ((offset > 0) ? "+" : "-") + utc); } String dstOffset = ((JSONObject) retValue).optString("utcDstOffset"); if (timeZone != null && dstOffset != null) { TimeZone dstTimeZone = null; dotPos = dstOffset.indexOf('.'); if (dotPos >= 0) { String hours = dstOffset.substring(0, dotPos); String hourPart = dstOffset.substring(dotPos + 1); if (hours.startsWith("+")) { hours = hours.substring(1); } int offsetHours = Integer.parseInt(hours); int offsetMins = (int) (Double.parseDouble(hourPart) * 6); // construct a GMT timezone offset string from the // retrieved // offset which can be parsed by the TimeZone class. AppendingStringBuffer sb = new AppendingStringBuffer("GMT"); sb.append(offsetHours > 0 ? "+" : "-"); sb.append(Math.abs(offsetHours)); sb.append(":"); if (offsetMins < 10) { sb.append("0"); } sb.append(offsetMins); dstTimeZone = TimeZone.getTimeZone(sb.toString()); } else { int offset = Integer.parseInt(dstOffset); if (offset < 0) { dstOffset = dstOffset.substring(1); } dstTimeZone = TimeZone.getTimeZone("GMT" + ((offset > 0) ? "+" : "-") + dstOffset); } // if the dstTimezone (1 July) has a different offset then // the real time zone (1 January) try to combine the 2. if (dstTimeZone != null && dstTimeZone.getRawOffset() != timeZone.getRawOffset()) { int dstSaving = dstTimeZone.getRawOffset() - timeZone.getRawOffset(); String[] availableIDs = TimeZone.getAvailableIDs(timeZone.getRawOffset()); for (String availableID : availableIDs) { TimeZone zone = TimeZone.getTimeZone(availableID); if (zone.getDSTSavings() == dstSaving) { // this is a best guess... still the start and end of the DST should // be needed to know to be completely correct, or better yet // not just the GMT offset but the TimeZone ID should be transfered // from the browser. timeZone = zone; break; } } } // if the timezone is really just the default of the server just use that one. TimeZone dftZone = TimeZone.getDefault(); if (timeZone.getRawOffset() == dftZone.getRawOffset() && timeZone.getDSTSavings() == dftZone.getDSTSavings()) { timeZone = dftZone; } } } } if (locale == null) { String browserLocale = ((JSONObject) retValue).optString("locale"); if (browserLocale != null) { String[] languageAndCountry = browserLocale.split("-"); if (languageAndCountry.length == 1) { locale = new Locale(languageAndCountry[0]); } else if (languageAndCountry.length == 2) { locale = new Locale(languageAndCountry[0], languageAndCountry[1]); } getClientInfo().addInfo("locale:" + locale); } } } if (timeZone != null) { getClientInfo().setTimeZone(timeZone); } getClientInfo().addInfo("session uuid: " + getWebsocketSession().getUuid()); try { getClientHost().pushClientInfo(getClientInfo().getClientId(), getClientInfo()); } catch (RemoteException e) { Debug.error(e); } }
From source file:nl.knaw.dans.dccd.web.upload.CombinedUploadStatus.java
License:Apache License
private String convertToHtmlUnicodeEscapes(String s) { if (s == null) return null; int len = s.length(); final AppendingStringBuffer buffer = new AppendingStringBuffer((int) (len * 1.1)); for (int i = 0; i < len; i++) { final char c = s.charAt(i); int ci = 0xffff & c; if (ci < 160) { // nothing special only 7 Bit buffer.append(c);//from ww w. j ava 2 s . c o m } else { // Not 7 Bit use the unicode system buffer.append("&#"); buffer.append(new Integer(ci).toString()); buffer.append(';'); } } return buffer.toString(); }
From source file:org.bosik.diacomp.web.frontend.wicket.dialogs.common.CommonEditor.java
License:Open Source License
@Override public void show(final AjaxRequestTarget target) { if (!isShown()) { final AppendingStringBuffer buffer = new AppendingStringBuffer(500); buffer.append("function mwClose(ev) {\n" + "var code = ev.keyCode || ev.which;\n" + "if (code == 27) { " + getCloseJavacript() + "};" + "}"); buffer.append("jQuery(document).keyup(mwClose);\n"); target.appendJavaScript(buffer.toString()); }//w ww .ja va2s . c o m super.show(target); }
From source file:org.cast.cwm.data.models.UserPeriodNamesModel.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public String getObject() { IModel<User> mUser = ((IModel<User>) getTarget()); if (mUser == null || mUser.getObject() == null) return null; AppendingStringBuffer output = new AppendingStringBuffer(); List<Period> list = mUser.getObject().getPeriodsAsList(); Iterator<Period> listIt = list.listIterator(); while (listIt.hasNext()) { Period p = listIt.next(); output.append(p.getName());/*from ww w . ja va 2 s. c om*/ if (listIt.hasNext()) output.append(", "); } return output.toString(); }
From source file:org.sakaiproject.scorm.ui.player.pages.PlayerPage.java
License:Educational Community License
private String getCompletionUrl() { RequestCycle cycle = getRequestCycle(); IRequestCodingStrategy encoder = cycle.getProcessor().getRequestCodingStrategy(); WebRequest webRequest = (WebRequest) getRequest(); HttpServletRequest servletRequest = webRequest.getHttpServletRequest(); String toolUrl = servletRequest.getContextPath(); Class<? extends Page> pageClass = PackageListPage.class; if (lms.canLaunchNewWindow()) pageClass = CompletionPage.class; CharSequence completionUrl = encoder.encode(cycle, new BookmarkablePageRequestTarget(pageClass, new PageParameters())); AppendingStringBuffer url = new AppendingStringBuffer(); url.append(toolUrl).append("/").append(completionUrl); return url.toString(); }
From source file:org.wicketstuff.extjs.util.ExtConfigResourceLoader.java
License:Apache License
protected String getCacheKey(final String key, final Component component) { String cacheKey = key;//from w w w . java 2 s .com if (component != null) { AppendingStringBuffer buffer = new AppendingStringBuffer(200); buffer.append(key); Component cursor = component; while (cursor != null) { buffer.append("-").append(cursor.getClass().hashCode()); if (cursor instanceof Page) { break; } if (cursor.getParent() != null && !(cursor.getParent() instanceof AbstractRepeater)) { /* * only append component id if parent is not a repeater because * * (a) these ids are irrelevant when generating resource cache keys * * (b) they cause a lot of redundant keys to be generated */ buffer.append(":").append(cursor.getId()); } cursor = cursor.getParent(); } buffer.append("-").append(component.getLocale()); buffer.append("-").append(component.getStyle()); // TODO 1.4 look if we want to properly separate getstyle/getvariation // for now getvariation() is rolled up into getstyle() // buffer.append("-").append(component.getVariation()); cacheKey = buffer.toString(); } return cacheKey; }