List of usage examples for java.lang StringBuffer substring
@Override public synchronized String substring(int start)
From source file:org.zkoss.poi.ss.format.CellNumberFormatter.java
private void writeScientific(double value, StringBuffer output, Set<StringMod> mods) { StringBuffer result = new StringBuffer(); FieldPosition fractionPos = new FieldPosition(DecimalFormat.FRACTION_FIELD); decimalFmt.format(value, result, fractionPos); writeInteger(result, output, integerSpecials, mods, integerCommas, false); writeFractional(result, output);// w w w .j a v a 2 s .c o m /* * Exponent sign handling is complex. * * In DecimalFormat, you never put the sign in the format, and the sign only * comes out of the format if it is negative. * * In Excel, you always say whether to always show the sign ("e+") or only * show negative signs ("e-"). * * Also in Excel, where you put the sign in the format is NOT where it comes * out in the result. In the format, the sign goes with the "e"; in the * output it goes with the exponent value. That is, if you say "#e-|#" you * get "1e|-5", not "1e-|5". This makes sense I suppose, but it complicates * things. * * Finally, everything else in this formatting code assumes that the base of * the result is the original format, and that starting from that situation, * the indexes of the original special characters can be used to place the new * characters. As just described, this is not true for the exponent's sign. * <p/> * So here is how we handle it: * * (1) When parsing the format, remove the sign from after the 'e' and put it * before the first digit of the exponent (where it will be shown). * * (2) Determine the result's sign. * * (3) If it's missing, put the sign into the output to keep the result * lined up with the output. (In the result, "after the 'e'" and "before the * first digit" are the same because the result has no extra chars to be in * the way.) * * (4) In the output, remove the sign if it should not be shown ("e-" was used * and the sign is negative) or set it to the correct value. */ // (2) Determine the result's sign. int ePos = fractionPos.getEndIndex(); int signPos = ePos + 1; char expSignRes = result.charAt(signPos); if (expSignRes != '-') { // not a sign, so it's a digit, and therefore a positive exponent expSignRes = '+'; // (3) If it's missing, put the sign into the output to keep the result // lined up with the output. result.insert(signPos, '+'); } // Now the result lines up like it is supposed to with the specials' indexes ListIterator<Special> it = exponentSpecials.listIterator(1); Special expSign = it.next(); char expSignFmt = expSign.ch; // (4) In the output, remove the sign if it should not be shown or set it to // the correct value. if (expSignRes == '-' || expSignFmt == '+') mods.add(replaceMod(expSign, true, expSign, true, expSignRes)); else mods.add(deleteMod(expSign, true, expSign, true)); StringBuffer exponentNum = new StringBuffer(result.substring(signPos + 1)); writeInteger(exponentNum, output, exponentDigitSpecials, mods, false, false); }
From source file:LayoutExample.java
/** * Generates code for the example layout. *///from ww w. j a v a 2 s . co m StringBuffer generateLayoutCode() { StringBuffer code = new StringBuffer(); code.append("\t\tGridLayout gridLayout = new GridLayout ();\n"); if (gridLayout.numColumns != 1) { code.append("\t\tgridLayout.numColumns = " + gridLayout.numColumns + ";\n"); } if (gridLayout.makeColumnsEqualWidth) { code.append("\t\tgridLayout.makeColumnsEqualWidth = true;\n"); } if (gridLayout.marginHeight != 5) { code.append("\t\tgridLayout.marginHeight = " + gridLayout.marginHeight + ";\n"); } if (gridLayout.marginWidth != 5) { code.append("\t\tgridLayout.marginWidth = " + gridLayout.marginWidth + ";\n"); } if (gridLayout.horizontalSpacing != 5) { code.append("\t\tgridLayout.horizontalSpacing = " + gridLayout.horizontalSpacing + ";\n"); } if (gridLayout.verticalSpacing != 5) { code.append("\t\tgridLayout.verticalSpacing = " + gridLayout.verticalSpacing + ";\n"); } code.append("\t\tshell.setLayout (gridLayout);\n"); boolean first = true; for (int i = 0; i < children.length; i++) { Control control = children[i]; code.append(getChildCode(control, i)); GridData data = (GridData) control.getLayoutData(); if (data != null) { code.append("\t\t"); if (first) { code.append("GridData "); first = false; } code.append("data = new GridData ();\n"); if (data.widthHint != SWT.DEFAULT) { code.append("\t\tdata.widthHint = " + data.widthHint + ";\n"); } if (data.heightHint != SWT.DEFAULT) { code.append("\t\tdata.heightHint = " + data.heightHint + ";\n"); } if (data.horizontalAlignment != GridData.BEGINNING) { String alignment; int hAlignment = data.horizontalAlignment; if (hAlignment == GridData.CENTER) alignment = "GridData.CENTER"; else if (hAlignment == GridData.END) alignment = "GridData.END"; else alignment = "GridData.FILL"; code.append("\t\tdata.horizontalAlignment = " + alignment + ";\n"); } if (data.verticalAlignment != GridData.CENTER) { String alignment; int vAlignment = data.verticalAlignment; if (vAlignment == GridData.BEGINNING) alignment = "GridData.BEGINNING"; else if (vAlignment == GridData.END) alignment = "GridData.END"; else alignment = "GridData.FILL"; code.append("\t\tdata.verticalAlignment = " + alignment + ";\n"); } if (data.horizontalIndent != 0) { code.append("\t\tdata.horizontalIndent = " + data.horizontalIndent + ";\n"); } if (data.horizontalSpan != 1) { code.append("\t\tdata.horizontalSpan = " + data.horizontalSpan + ";\n"); } if (data.verticalSpan != 1) { code.append("\t\tdata.verticalSpan = " + data.verticalSpan + ";\n"); } if (data.grabExcessHorizontalSpace) { code.append("\t\tdata.grabExcessHorizontalSpace = true;\n"); } if (data.grabExcessVerticalSpace) { code.append("\t\tdata.grabExcessVerticalSpace = true;\n"); } if (code.substring(code.length() - 33).equals("GridData data = new GridData ();\n")) { code.delete(code.length() - 33, code.length()); first = true; } else if (code.substring(code.length() - 24).equals("data = new GridData ();\n")) { code.delete(code.length() - 24, code.length()); } else { code.append("\t\t" + names[i] + ".setLayoutData (data);\n"); } } } return code; }
From source file:org.infoglue.deliver.invokers.DecoratedComponentBasedHTMLPageInvoker.java
/** * This method adds the necessary html to a template to make it right-clickable. *//*from w ww .ja v a 2 s .c om*/ private String decorateTemplate(TemplateController templateController, String template, DeliveryContext deliveryContext, InfoGlueComponent component) { Timer timer = new Timer(); timer.setActive(false); String decoratedTemplate = template; try { String cmsBaseUrl = CmsPropertyHandler.getCmsBaseUrl(); String componentEditorUrl = CmsPropertyHandler.getComponentEditorUrl(); InfoGluePrincipal principal = templateController.getPrincipal(); String cmsUserName = (String) templateController.getHttpServletRequest().getSession() .getAttribute("cmsUserName"); if (cmsUserName != null && !CmsPropertyHandler.getAnonymousUser().equalsIgnoreCase(cmsUserName)) { InfoGluePrincipal newPrincipal = templateController.getPrincipal(cmsUserName); if (newPrincipal != null) principal = newPrincipal; } Locale locale = templateController.getLocaleAvailableInTool(principal); boolean hasAccessToAccessRights = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.ChangeSlotAccess", ""); boolean hasAccessToAddComponent = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.AddComponent", "" + component.getContentId() + "_" + component.getCleanedSlotName()); boolean hasAccessToDeleteComponent = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.DeleteComponent", "" + component.getContentId() + "_" + component.getCleanedSlotName()); boolean hasAccessToChangeComponent = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.ChangeComponent", "" + component.getContentId() + "_" + component.getCleanedSlotName()); boolean hasSaveTemplateAccess = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.SavePageTemplate", true, false, true); boolean hasSubmitToPublishAccess = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.SubmitToPublish", true, false, true); boolean hasPageStructureAccess = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.PageStructure", true, false, true); boolean hasOpenInNewWindowAccess = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.OpenInNewWindow", true, false, true); boolean hasViewSourceAccess = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.ViewSource", true, false, true); boolean showNotifyUserOfPage = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.NotifyUserOfPage", true, false, true); boolean showContentNotifications = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.ContentNotifications", true, false, true); boolean showPageNotifications = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.PageNotifications", true, false, true); boolean showW3CValidator = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.W3CValidator", true, false, true); boolean showLanguageMenu = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.ShowLanguageMenu", true, false, true); boolean showHomeButton = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.ShowHomeButton", true, false, true); boolean showMySettingsButton = AccessRightController.getController().getIsPrincipalAuthorized( templateController.getDatabase(), principal, "ComponentEditor.ShowMySettingsButton", true, false, true); String useApprovalFlow = CmsPropertyHandler.getUseApprovalFlow(); String autoShowApprovalButtons = CmsPropertyHandler.getAutoShowApprovalButtons(); String extraHeader = FileHelper.getFileAsString(new File(CmsPropertyHandler.getContextDiskPath() + (CmsPropertyHandler.getContextDiskPath().endsWith("/") ? "" : "/") + "preview/pageComponentEditorHeader.vm"), "iso-8859-1"); String extraBody = FileHelper.getFileAsString(new File(CmsPropertyHandler.getContextDiskPath() + (CmsPropertyHandler.getContextDiskPath().endsWith("/") ? "" : "/") + "preview/pageComponentEditorBody.vm"), "iso-8859-1"); boolean oldUseFullUrl = this.getTemplateController().getDeliveryContext().getUseFullUrl(); this.getTemplateController().getDeliveryContext().setUseFullUrl(true); String parameters = "repositoryId=" + templateController.getSiteNode().getRepositoryId() + "&siteNodeId=" + templateController.getSiteNodeId() + "&languageId=" + templateController.getLanguageId() + "&contentId=" + templateController.getContentId() + "&componentId=" + this.getRequest().getParameter("activatedComponentId") + "&componentContentId=" + this.getRequest().getParameter("componentContentId") + "&showSimple=false&showLegend=false&originalUrl=" + URLEncoder.encode(this.getTemplateController().getCurrentPageUrl(), "UTF-8"); String WYSIWYGEditorFile = "ckeditor/ckeditor.js"; if (!CmsPropertyHandler.getPrefferedWYSIWYG().equals("ckeditor4")) WYSIWYGEditorFile = "FCKEditor/fckeditor.js"; StringBuffer path = getPagePathAsCommaseparatedIds(templateController); extraHeader = extraHeader.replaceAll("\\$\\{focusElementId\\}", "" + this.getRequest().getParameter("focusElementId")); extraHeader = extraHeader.replaceAll("\\$\\{cmsBaseUrl\\}", cmsBaseUrl); extraHeader = extraHeader.replaceAll("\\$\\{contextName\\}", this.getRequest().getContextPath()); extraHeader = extraHeader.replaceAll("\\$\\{componentEditorUrl\\}", componentEditorUrl); if (principal.getName().equalsIgnoreCase(CmsPropertyHandler.getAnonymousUser())) extraHeader = extraHeader.replaceAll("\\$\\{limitedUserWarning\\}", "alert('Your session must have expired as you are now in decorated mode as " + principal.getName() + ". Please close browser and login again.');"); else extraHeader = extraHeader.replaceAll("\\$\\{limitedUserWarning\\}", ""); //extraHeader = extraHeader.replaceAll("\\$\\{currentUrl\\}", URLEncoder.encode(this.getTemplateController().getCurrentPageUrl(), "UTF-8")); extraHeader = extraHeader.replaceAll("\\$\\{currentUrl\\}", URLEncoder.encode(this.getTemplateController().getOriginalFullURL(), "UTF-8")); extraHeader = extraHeader.replaceAll("\\$\\{activatedComponentId\\}", "" + this.getRequest().getParameter("activatedComponentId")); extraHeader = extraHeader.replaceAll("\\$\\{parameters\\}", parameters); extraHeader = extraHeader.replaceAll("\\$\\{siteNodeId\\}", "" + templateController.getSiteNodeId()); extraHeader = extraHeader.replaceAll("\\$\\{languageId\\}", "" + templateController.getLanguageId()); extraHeader = extraHeader.replaceAll("\\$\\{contentId\\}", "" + templateController.getContentId()); extraHeader = extraHeader.replaceAll("\\$\\{metaInfoContentId\\}", "" + templateController.getMetaInformationContentId()); extraHeader = extraHeader.replaceAll("\\$\\{parentSiteNodeId\\}", "" + templateController.getSiteNode().getParentSiteNodeId()); extraHeader = extraHeader.replaceAll("\\$\\{repositoryId\\}", "" + templateController.getSiteNode().getRepositoryId()); extraHeader = extraHeader.replaceAll("\\$\\{path\\}", "" + path.substring(1)); extraHeader = extraHeader.replaceAll("\\$\\{userPrefferredLanguageCode\\}", "" + CmsPropertyHandler.getPreferredLanguageCode(principal.getName())); extraHeader = extraHeader.replaceAll("\\$\\{userPrefferredWYSIWYG\\}", "" + CmsPropertyHandler.getPrefferedWYSIWYG()); extraHeader = extraHeader.replaceAll("\\$\\{WYSIWYGEditorJS\\}", WYSIWYGEditorFile); extraHeader = extraHeader.replaceAll("\\$\\{publishedLabel\\}", getLocalizedString(locale, "tool.contenttool.state.published")); if (CmsPropertyHandler.getPersonalDisableEditOnSightToolbar(principal.getName())) { extraHeader = extraHeader.replaceAll("\\$\\{editOnSightFooterToolbarIsActive\\}", "false"); extraHeader = extraHeader.replaceAll("\\$\\{editOnSightFooterToolbarOverideCSS\\}", ".editOnSightFooterToolbar{display:none}"); } else { extraHeader = extraHeader.replaceAll("\\$\\{editOnSightFooterToolbarIsActive\\}", "true"); extraHeader = extraHeader.replaceAll("\\$\\{editOnSightFooterToolbarOverideCSS\\}", ""); } if (CmsPropertyHandler.getShowInlinePropertiesIcon().equalsIgnoreCase("false")) { extraHeader = extraHeader.replaceAll("\\$\\{useInlinePropertiesIcon\\}", "false"); } else { extraHeader = extraHeader.replaceAll("\\$\\{useInlinePropertiesIcon\\}", "true"); } if (getRequest().getParameter("approveEntityName") != null && !getRequest().getParameter("approveEntityName").equals("") && getRequest().getParameter("approveEntityId") != null && !getRequest().getParameter("approveEntityId").equals("")) { extraHeader = extraHeader.replaceAll("\\$\\{approveEntityName\\}", "" + getRequest().getParameter("approveEntityName")); extraHeader = extraHeader.replaceAll("\\$\\{approveEntityId\\}", "" + getRequest().getParameter("approveEntityId")); extraHeader = extraHeader.replaceAll("\\$\\{publishingEventId\\}", "" + getRequest().getParameter("publishingEventId")); } else { extraHeader = extraHeader.replaceAll("\\$\\{approveEntityName\\}", ""); extraHeader = extraHeader.replaceAll("\\$\\{approveEntityId\\}", ""); extraHeader = extraHeader.replaceAll("\\$\\{publishingEventId\\}", ""); } StringBuffer skinCSS = new StringBuffer(); String theme = CmsPropertyHandler.getTheme(principal.getName()); if (!theme.equalsIgnoreCase("Default")) { skinCSS.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + this.getRequest().getContextPath() + "/css/skins/" + theme + "/componentEditor.css\" />"); String themeFileJQueryUI = CmsPropertyHandler.getThemeFile(theme, "jquery-ui.css"); if (themeFileJQueryUI != null) skinCSS.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + this.getRequest().getContextPath() + "/css/skins/" + theme + "/jquery-ui.css\" />"); else skinCSS.append( "<link rel=\"stylesheet\" type=\"text/css\" href=\"script/jqueryplugins-latest/ui/css/jquery-ui.css\" />"); } else { skinCSS.append( "<link rel=\"stylesheet\" type=\"text/css\" href=\"script/jqueryplugins-latest/ui/css/jquery-ui.css\" />"); } extraHeader = extraHeader.replaceAll("\\$\\{skinDeliveryCSS\\}", skinCSS.toString()); String sortBaseUrl = componentEditorUrl + "ViewSiteNodePageComponents!moveComponent.action?siteNodeId=" + templateController.getSiteNodeId() + "&languageId=" + templateController.getLanguageId() + "&contentId=" + templateController.getContentId() + "&showSimple=" + this.getTemplateController().getDeliveryContext().getShowSimple() + ""; extraHeader = extraHeader.replaceAll("\\$\\{sortBaseUrl\\}", sortBaseUrl); this.getTemplateController().getDeliveryContext().setUseFullUrl(oldUseFullUrl); String changeUrl = componentEditorUrl + "ViewSiteNodePageComponents!listComponentsForChange.action?siteNodeId=" + templateController.getSiteNodeId() + "&languageId=" + templateController.getLanguageId() + "&contentId=" + templateController.getContentId() + "&componentId=" + component.getId() + "&slotId=base&showSimple=" + this.getTemplateController().getDeliveryContext().getShowSimple(); extraBody = extraBody + "<script type=\"text/javascript\">$(function() { initializeComponentEventHandler('base0_" + component.getId() + "Comp', '" + component.getId() + "', '', '" + componentEditorUrl + "ViewSiteNodePageComponents!deleteComponent.action?siteNodeId=" + templateController.getSiteNodeId() + "&languageId=" + templateController.getLanguageId() + "&contentId=" + templateController.getContentId() + "&componentId=" + component.getId() + "&slotId=base&showSimple=" + this.getTemplateController().getDeliveryContext().getShowSimple() + "','" + changeUrl + "'); }); </script>"; String submitToPublishHTML = getLocalizedString(locale, "deliver.editOnSight.submitToPublish"); String addComponentHTML = getLocalizedString(locale, "deliver.editOnSight.addComponentHTML"); String deleteComponentHTML = getLocalizedString(locale, "deliver.editOnSight.deleteComponentHTML"); String changeComponentHTML = getLocalizedString(locale, "deliver.editOnSight.changeComponentHTML"); String accessRightsHTML = getLocalizedString(locale, "deliver.editOnSight.accessRightsHTML"); String pageComponentsHTML = getLocalizedString(locale, "deliver.editOnSight.pageComponentsHTML"); String viewSourceHTML = getLocalizedString(locale, "deliver.editOnSight.viewSourceHTML"); String componentEditorInNewWindowHTML = getLocalizedString(locale, "deliver.editOnSight.componentEditorInNewWindowHTML"); String savePageTemplateHTML = getLocalizedString(locale, "deliver.editOnSight.savePageTemplateHTML"); String savePagePartTemplateHTML = getLocalizedString(locale, "deliver.editOnSight.savePagePartTemplateHTML"); String editHTML = getLocalizedString(locale, "deliver.editOnSight.editHTML"); String editInlineHTML = getLocalizedString(locale, "deliver.editOnSight.editContentInlineLabel"); String propertiesHTML = getLocalizedString(locale, "deliver.editOnSight.propertiesHTML"); String favouriteComponentsHeader = getLocalizedString(locale, "tool.common.favouriteComponentsHeader"); String noActionAvailableHTML = getLocalizedString(locale, "deliver.editOnSight.noActionAvailableHTML"); String notifyLabel = getLocalizedString(locale, "deliver.editOnSight.notifyLabel"); String subscribeToContentLabel = getLocalizedString(locale, "deliver.editOnSight.subscribeToContentLabel"); String subscribeToPageLabel = getLocalizedString(locale, "deliver.editOnSight.subscribeToPageLabel"); String translateContentLabel = getLocalizedString(locale, "deliver.editOnSight.translateContentLabel"); String confirmDeleteLabel = getLocalizedString(locale, "deliver.editOnSight.confirmDeleteLabel"); String leaveWarningOnDirtyPageText = getLocalizedString(locale, "deliver.editOnSight.leaveWarningOnDirtyPage.text"); String saveTemplateUrl = "saveComponentStructure('" + componentEditorUrl + "CreatePageTemplate!input.action?contentId=" + templateController.getSiteNode(deliveryContext.getSiteNodeId()).getMetaInfoContentId() + "');"; String savePartTemplateUrl = "savePartComponentStructure('" + componentEditorUrl + "CreatePageTemplate!input.action?contentId=" + templateController.getSiteNode(deliveryContext.getSiteNodeId()).getMetaInfoContentId() + "');"; if (!hasSaveTemplateAccess) { saveTemplateUrl = "alert('Not authorized to save template');"; savePartTemplateUrl = "alert('Not authorized to save part template');"; } String personalStartUrl = "/"; String repositoryId = CmsPropertyHandler.getPreferredRepositoryId(principal.getName()); logger.info("repositoryId: " + repositoryId); if (repositoryId == null) { List<RepositoryVO> repos = RepositoryController.getController() .getAuthorizedRepositoryVOList(principal, false); if (repos.size() > 0) repositoryId = "" + repos.get(0).getId(); } if (repositoryId != null) { SiteNodeVO siteNodeVO = SiteNodeController.getController() .getRootSiteNodeVO(new Integer(repositoryId), templateController.getDatabase()); personalStartUrl = "ViewPage!renderDecoratedPage.action?siteNodeId=" + siteNodeVO.getId(); } String returnAddress = "" + componentEditorUrl + "ViewInlineOperationMessages.action"; String notifyUrl = componentEditorUrl + "CreateEmail!inputChooseRecipientsV3.action?enableUsers=true&originalUrl=" + URLEncoder.encode(templateController.getOriginalFullURL().replaceFirst("cmsUserName=.*?", ""), "utf-8") + "&returnAddress=" + URLEncoder.encode(returnAddress, "utf-8") + "&extraTextProperty=tool.managementtool.createEmailNotificationPageExtraText.text"; String pageSubscriptionUrl = componentEditorUrl + "Subscriptions!input.action?interceptionPointCategory=SiteNodeVersion&entityName=" + SiteNode.class.getName() + "&entityId=" + templateController.getSiteNodeId() + "&returnAddress=" + URLEncoder.encode(returnAddress, "utf-8"); extraBody = extraBody.replaceAll("\\$siteNodeId", "" + templateController.getSiteNodeId()); extraBody = extraBody.replaceAll("\\$languageId", "" + templateController.getLanguageId()); extraBody = extraBody.replaceAll("\\$repositoryId", "" + templateController.getSiteNode().getRepositoryId()); extraBody = extraBody.replaceAll("\\$originalFullURL", URLEncoder.encode(templateController.getOriginalFullURL(), "UTF-8")); extraBody = extraBody.replaceAll("\\$notifyUrl", notifyUrl); extraBody = extraBody.replaceAll("\\$pageSubscriptionUrl", pageSubscriptionUrl); extraBody = extraBody.replaceAll("\\$editHTML", editHTML); extraBody = extraBody.replaceAll("\\$submitToPublishHTML", submitToPublishHTML); extraBody = extraBody.replaceAll("\\$confirmDeleteLabel", confirmDeleteLabel); extraBody = extraBody.replaceAll("\\$\\{leaveWarningOnDirtyPageText\\}", leaveWarningOnDirtyPageText); extraBody = extraBody.replaceAll("\\$notifyHTML", notifyLabel); extraBody = extraBody.replaceAll("\\$subscribeToContentHTML", subscribeToContentLabel); extraBody = extraBody.replaceAll("\\$subscribeToPageHTML", subscribeToPageLabel); extraBody = extraBody.replaceAll("\\$addComponentHTML", addComponentHTML); extraBody = extraBody.replaceAll("\\$deleteComponentHTML", deleteComponentHTML); extraBody = extraBody.replaceAll("\\$changeComponentHTML", changeComponentHTML); extraBody = extraBody.replaceAll("\\$accessRightsHTML", accessRightsHTML); extraBody = extraBody.replaceAll("\\$pageComponents", pageComponentsHTML); extraBody = extraBody.replaceAll("\\$componentEditorInNewWindowHTML", componentEditorInNewWindowHTML); extraBody = extraBody.replaceAll("\\$savePageTemplateHTML", savePageTemplateHTML); extraBody = extraBody.replaceAll("\\$savePagePartTemplateHTML", savePagePartTemplateHTML); extraBody = extraBody.replaceAll("\\$saveTemplateUrl", saveTemplateUrl); extraBody = extraBody.replaceAll("\\$savePartTemplateUrl", savePartTemplateUrl); extraBody = extraBody.replaceAll("\\$viewSource", viewSourceHTML); extraBody = extraBody.replaceAll("\\$propertiesHTML", propertiesHTML); extraBody = extraBody.replaceAll("\\$favouriteComponentsHeader", favouriteComponentsHeader); extraBody = extraBody.replaceAll("\\$noActionAvailableHTML", noActionAvailableHTML); extraBody = extraBody.replaceAll("\\$\\{deliver.editOnSight.pendingPageApproval.title\\}", getLocalizedString(locale, "deliver.editOnSight.pendingPageApproval.title")); extraBody = extraBody.replaceAll("\\$\\{deliver.editOnSight.pendingContentApproval.title\\}", getLocalizedString(locale, "deliver.editOnSight.pendingContentApproval.title")); extraBody = extraBody.replaceAll("\\$\\{deliver.editOnSight.toolbarInlineEditing.title\\}", getLocalizedString(locale, "deliver.editOnSight.toolbarInlineEditing.title")); extraBody = extraBody.replaceAll("\\$\\{deliver.editOnSight.toolbarState.title\\}", getLocalizedString(locale, "deliver.editOnSight.toolbarState.title")); extraBody = extraBody.replaceAll("\\$\\{tool.contenttool.approve.label\\}", getLocalizedString(locale, "tool.contenttool.approve.label")); extraBody = extraBody.replaceAll("\\$\\{tool.contenttool.deny.label\\}", getLocalizedString(locale, "tool.contenttool.deny.label")); extraBody = extraBody.replaceAll("\\$\\{tool.common.saveButton.label\\}", getLocalizedString(locale, "tool.common.saveButton.label")); extraBody = extraBody.replaceAll("\\$\\{tool.common.cancelButton.label\\}", getLocalizedString(locale, "tool.common.cancelButton.label")); extraBody = extraBody.replaceAll("\\$\\{tool.common.publishing.publishButtonLabel\\}", getLocalizedString(locale, "tool.common.publishing.publishButtonLabel")); extraBody = extraBody.replaceAll("\\$\\{tool.structuretool.toolbarV3.previewPageLabel\\}", getLocalizedString(locale, "tool.structuretool.toolbarV3.previewPageLabel")); extraBody = extraBody.replaceAll("\\$\\{tool.structuretool.toolbarV3.previewMediumScreenPageLabel\\}", getLocalizedString(locale, "tool.structuretool.toolbarV3.previewMediumScreenPageLabel")); extraBody = extraBody.replaceAll("\\$\\{tool.structuretool.toolbarV3.previewSmallScreenPageLabel\\}", getLocalizedString(locale, "tool.structuretool.toolbarV3.previewSmallScreenPageLabel")); extraBody = extraBody.replaceAll("\\$\\{tool.structuretool.toolbarV3.disableEditmodeNotAllowed\\}", getLocalizedString(locale, "tool.structuretool.toolbarV3.disableEditmodeNotAllowed")); extraBody = extraBody.replaceAll("\\$\\{homeURL\\}", personalStartUrl); extraBody = extraBody.replaceAll("\\$\\{currentLanguageCode\\}", "" + templateController .getLanguageCode(templateController.getLanguageId()).getLanguage().toUpperCase()); extraBody = extraBody.replaceAll("\\$\\{currentLanguageName\\}", templateController .getLanguageCode(templateController.getLanguageId()).getDisplayName().toUpperCase()); StringBuffer languagesSB = new StringBuffer(); List<LanguageVO> languages = templateController.getAvailableLanguages(); for (LanguageVO language : languages) { if (language.getId() != templateController.getLanguageId()) languagesSB.append("<li style=\"margin-bottom: 6px;\"><a style=\"color: black;\" href=\"" + templateController.getCurrentPageUrl().replaceAll( "languageId=" + templateController.getLanguageId(), "languageId=" + language.getId()) + "\">" + language.getLanguageCode().toUpperCase() + "</a></li>"); } extraBody = extraBody.replaceAll("\\$\\{languageList\\}", languagesSB.toString()); extraBody = extraBody.replaceAll("\\$addComponentJavascript", "window.hasAccessToAddComponent" + component.getId() + "_" + component.getCleanedSlotName() + " = " + hasAccessToAddComponent + ";"); extraBody = extraBody.replaceAll("\\$deleteComponentJavascript", "window.hasAccessToDeleteComponent" + component.getId() + "_" + component.getCleanedSlotName() + " = " + hasAccessToDeleteComponent + ";"); extraBody = extraBody.replaceAll("\\$changeComponentJavascript", "window.hasAccessToChangeComponent" + component.getId() + "_" + component.getCleanedSlotName() + " = " + hasAccessToChangeComponent + ";"); extraBody = extraBody.replaceAll("\\$changeAccessJavascript", "window.hasAccessToAccessRights" + " = " + hasAccessToAccessRights + ";"); extraBody = extraBody.replaceAll("\\$submitToPublishJavascript", "window.hasAccessToSubmitToPublish = " + hasSubmitToPublishAccess + ";"); extraBody = extraBody.replaceAll("\\$pageStructureJavascript", "window.hasPageStructureAccess = " + hasPageStructureAccess + ";"); extraBody = extraBody.replaceAll("\\$openInNewWindowJavascript", "window.hasOpenInNewWindowAccess = " + hasOpenInNewWindowAccess + ";"); extraBody = extraBody.replaceAll("\\$allowViewSourceJavascript", "window.hasAccessToViewSource = " + hasViewSourceAccess + ";"); extraBody = extraBody.replaceAll("\\$allowSavePageTemplateJavascript", "window.hasAccessToSavePageTemplate = " + hasSaveTemplateAccess + ";"); extraBody = extraBody.replaceAll("\\$submitToNotifyJavascript", "window.hasAccessToNotifyUserOfPage = " + showNotifyUserOfPage + ";"); extraBody = extraBody.replaceAll("\\$contentNotificationsJavascript", "window.hasAccessToContentNotifications = " + showContentNotifications + ";"); extraBody = extraBody.replaceAll("\\$pageNotificationsJavascript", "window.hasAccessToPageNotifications = " + showPageNotifications + ";"); extraBody = extraBody.replaceAll("\\$W3CValidatorJavascript", "window.hasAccessToW3CValidator = " + showW3CValidator + ";"); extraBody = extraBody.replaceAll("\\$ShowLanguageMenuJavascript", "window.hasAccessToShowLanguageMenu = " + showLanguageMenu + ";"); extraBody = extraBody.replaceAll("\\$ShowApproveButtonsJavascript", "window.useApprovalFlow = " + useApprovalFlow + ";"); extraBody = extraBody.replaceAll("\\$autoShowApprovalButtonsJavascript", "window.autoShowApprovalButtons = " + autoShowApprovalButtons + ";"); extraBody = extraBody.replaceAll("\\$useDoubleClickOnTextToInlineEdit", "" + CmsPropertyHandler.getUseDoubleClickOnTextToInlineEdit()); extraBody = extraBody.replaceAll("\\$showHomeButtonJavascript", "window.showHomeButton = " + showHomeButton + ";"); extraBody = extraBody.replaceAll("\\$showMySettingsButtonJavascript", "window.showMySettingsButton = " + showMySettingsButton + ";"); extraBody = extraBody.replaceAll("\\$\\{deliver.editOnSight.toolbarHomeButton.title\\}", getLocalizedString(new Locale(CmsPropertyHandler.getPreferredLanguageCode(principal.getName())), "deliver.editOnSight.toolbarHomeButton.title")); extraBody = extraBody.replaceAll("\\$\\{deliver.editOnSight.toolbarValidateW3CButton.title\\}", getLocalizedString(new Locale(CmsPropertyHandler.getPreferredLanguageCode(principal.getName())), "deliver.editOnSight.toolbarValidateW3CButton.title")); extraBody = extraBody.replaceAll("\\$\\{deliver.editOnSight.toolbarNewWindowButton.title\\}", getLocalizedString(new Locale(CmsPropertyHandler.getPreferredLanguageCode(principal.getName())), "deliver.editOnSight.toolbarNewWindowButton.title")); extraBody = extraBody.replaceAll("\\$\\{deliver.editOnSight.toolbarMySettingsButton.title\\}", getLocalizedString(new Locale(CmsPropertyHandler.getPreferredLanguageCode(principal.getName())), "deliver.editOnSight.toolbarMySettingsButton.title")); extraBody = extraBody.replaceAll("\\$\\{deliver.editOnSight.toolbarValidateW3CErrorsQuestion.label\\}", getLocalizedString(new Locale(CmsPropertyHandler.getPreferredLanguageCode(principal.getName())), "deliver.editOnSight.toolbarValidateW3CErrorsQuestion.label")); extraBody = extraBody.replaceAll("\\$\\{deliver.editOnSight.toolbarValidateW3CNoErrors.label\\}", getLocalizedString(new Locale(CmsPropertyHandler.getPreferredLanguageCode(principal.getName())), "deliver.editOnSight.toolbarValidateW3CNoErrors.label")); StringBuffer userDefinedButtonsSB = new StringBuffer(); List<ToolbarButton> buttons = AdminToolbarService.getService().getFooterToolbarButtons( "tool.deliver.editOnSight.toolbarRight", principal, locale, templateController.getHttpServletRequest(), true); for (ToolbarButton button : buttons) { try { if (button.getCustomMarkup() == null) { userDefinedButtonsSB .append("<div id=\"" + button.getId() + "\" class=\"right editOnSightToolbarButton " + button.getCssClass() + "\" title=\"" + button.getTitle() + "\" onclick=\"" + button.getActionURL() + "\"></div>"); } else { if (button.getCustomMarkupPlacement().equals("before")) userDefinedButtonsSB.append("" + button.getCustomMarkup()); userDefinedButtonsSB .append("<div id=\"" + button.getId() + "\" class=\"right editOnSightToolbarButton " + button.getCssClass() + "\" title=\"" + button.getTitle() + "\" onclick=\"" + button.getActionURL() + "\">" + (button.getCustomMarkupPlacement().equals("inside") ? button.getCustomMarkup() : "") + "</div>"); if (button.getCustomMarkupPlacement().equals("after")) userDefinedButtonsSB.append("" + button.getCustomMarkup()); } } catch (Exception e) { logger.warn("Problem adding custome EOS button: " + e.getMessage(), e); } } extraBody = extraBody.replaceAll("\\$\\{userDefinedButtons\\}", userDefinedButtonsSB.toString()); //List tasks = getTasks(); //component.setTasks(tasks); //String tasks = templateController.getContentAttribute(component.getContentId(), "ComponentTasks", true); /* Map context = new HashMap(); context.put("templateLogic", templateController); StringWriter cacheString = new StringWriter(); PrintWriter cachedStream = new PrintWriter(cacheString); new VelocityTemplateProcessor().renderTemplate(context, cachedStream, extraBody); extraBody = cacheString.toString(); */ //extraHeader.replaceAll() timer.printElapsedTime("Read files"); StringBuffer modifiedTemplate = new StringBuffer(template); //Adding stuff in the header int indexOfHeadEndTag = modifiedTemplate.indexOf("</head"); if (indexOfHeadEndTag == -1) indexOfHeadEndTag = modifiedTemplate.indexOf("</HEAD"); if (indexOfHeadEndTag > -1) { modifiedTemplate = modifiedTemplate.replace(indexOfHeadEndTag, modifiedTemplate.indexOf(">", indexOfHeadEndTag) + 1, extraHeader); } else { int indexOfHTMLStartTag = modifiedTemplate.indexOf("<html"); if (indexOfHTMLStartTag == -1) { indexOfHTMLStartTag = modifiedTemplate.indexOf("<HTML"); } if (indexOfHTMLStartTag > -1) { modifiedTemplate = modifiedTemplate .insert(modifiedTemplate.indexOf(">", indexOfHTMLStartTag) + 1, "<head>" + extraHeader); } else { logger.info( "The current template is not a valid document. It does not comply with the simplest standards such as having a correct header."); } } timer.printElapsedTime("Header handled"); //Adding stuff in the body int indexOfBodyStartTag = modifiedTemplate.indexOf("<body"); if (indexOfBodyStartTag == -1) indexOfBodyStartTag = modifiedTemplate.indexOf("<BODY"); if (indexOfBodyStartTag > -1) { //String pageComponentStructureDiv = ""; String pageComponentStructureDiv = getPageComponentStructureDiv(templateController, deliveryContext.getSiteNodeId(), deliveryContext.getLanguageId(), component); timer.printElapsedTime("pageComponentStructureDiv"); String componentPaletteDiv = getComponentPaletteDiv(deliveryContext.getSiteNodeId(), deliveryContext.getLanguageId(), templateController); //String componentPaletteDiv = ""; timer.printElapsedTime("componentPaletteDiv"); modifiedTemplate = modifiedTemplate.insert(modifiedTemplate.indexOf(">", indexOfBodyStartTag) + 1, extraBody + pageComponentStructureDiv + componentPaletteDiv); } else { logger.info( "The current template is not a valid document. It does not comply with the simplest standards such as having a correct body."); } timer.printElapsedTime("Body handled"); decoratedTemplate = modifiedTemplate.toString(); } catch (Exception e) { e.printStackTrace(); logger.warn( "An error occurred when deliver tried to decorate your template to enable onSiteEditing. Reason " + e.getMessage(), e); } return decoratedTemplate; }
From source file:com.flexoodb.common.FlexUtils.java
static public String getRDBMSRecordAsXML(String tablename, RecordSet rec, String idcolumn, String parentidcolumn, boolean includeidcolumns, boolean listall) throws Exception { StringBuffer res = new StringBuffer(); int size = rec.size(); if (size > 0) { // first we get the table struc Enumeration en = rec.getColumnNames(); ConcurrentHashMap<String, String> columns = new ConcurrentHashMap<String, String>(); while (en.hasMoreElements()) { String cname = (String) en.nextElement(); String type = rec.getColumnType(cname); columns.put(cname.toLowerCase(), type); }/*from w w w. j av a 2s .c om*/ boolean done = false; int i = 0; while (i < rec.size() && !done) { res.append("<" + tablename + ">"); en = columns.keys(); while (en.hasMoreElements()) { String cname = ((String) en.nextElement()).toLowerCase(); String type = columns.get(cname); boolean readrec = includeidcolumns; if (!readrec) { readrec = (!cname.equalsIgnoreCase(idcolumn) && !cname.equalsIgnoreCase(parentidcolumn)); } if (readrec) { if (type.toUpperCase().indexOf("BLOB") > -1 || type.toUpperCase().indexOf("BINARY") > -1) { Object o = rec.getContent(cname); if (o instanceof com.mysql.jdbc.Blob) { //byte[] b = BufferedInputStreamToString(((com.mysql.jdbc.Blob)o).getBinaryStream()).getBytes(); Blob blob = ((Blob) o); byte[] b = blob.getBytes(1, (int) blob.length()); res.append("<" + cname + " type=\"byte[]\"><![CDATA[" + new String(b) + "]]></" + cname + ">"); } else { res.append("<" + cname + " type=\"byte[]\"><![CDATA[" + o + "]]></" + cname + ">"); } } else if (type.indexOf("CHAR") > -1 || type.indexOf("TEXT") > -1) { res.append("<" + cname + " type=\"String\"><![CDATA[" + stripNonValidChars(rec.getString(cname)) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("DATE") || type.equalsIgnoreCase("DATETIME") || type.equalsIgnoreCase("TIMESTAMP") || (type != null && type.toUpperCase().equals("YEAR"))) { res.append("<" + cname + " type=\"XMLGregorianCalendar\"><![CDATA[" + rec.getString(cname) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("LONG") || type.equalsIgnoreCase("TINY") || type.equalsIgnoreCase("BIT") || type.equalsIgnoreCase("BIGINT") || type.equalsIgnoreCase("SMALLINT") || type.equalsIgnoreCase("TINYINT") || type.equalsIgnoreCase("MEDIUMINT") || type.equalsIgnoreCase("INT")) { res.append("<" + cname + " type=\"BigInteger\"><![CDATA[" + rec.getInt(cname) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("DOUBLE") || type.equalsIgnoreCase("NUMERIC") || type.equalsIgnoreCase("DECIMAL")) { res.append("<" + cname + " type=\"Double\"><![CDATA[" + rec.getDouble(cname) + "]]></" + cname + ">"); } else if (type.equalsIgnoreCase("FLOAT")) { res.append("<" + cname + " type=\"Float\"><![CDATA[" + rec.getFloat(cname) + "]]></" + cname + ">"); } /*else if (type.equalsIgnoreCase("LONG")) { res.append("<"+proper(cname)+" type=\"Long\"><![CDATA["+rec.getDouble(cname)+"]]></"+proper(cname)+">"); }*/ else { //res.append("<"+proper(cname)+" type=\""+cname+"\"><![CDATA["+rec.getString(cname)+"]]></"+proper(cname)+">"); throw new Exception(cname + " type " + type + " is not recognized."); } } } res.append("</" + tablename + ">\n"); if (!listall) { done = true; } else { i++; rec.next(); } } } return new String(res.substring(0).getBytes("UTF8")); }
From source file:com.flexoodb.common.FlexUtils.java
static public String getRDBMSRecordAsXML(String tablename, RecordSet rec, String idcolumn, String parentidcolumn, boolean includeidcolumns, FlexElement idelement) throws Exception { StringBuffer res = new StringBuffer(); int size = rec.size(); if (size > 0) { // first we get the table struc Enumeration en = rec.getColumnNames(); ConcurrentHashMap<String, String> columns = new ConcurrentHashMap<String, String>(); while (en.hasMoreElements()) { String cname = (String) en.nextElement(); String type = rec.getColumnType(cname); columns.put(cname.toLowerCase(), type); }// w ww .j a v a 2 s.co m res.append("<" + tablename + ">"); en = columns.keys(); String cname = ""; FlexElement aliascolumn = null; while (en.hasMoreElements()) { aliascolumn = null; cname = ""; cname = (String) en.nextElement(); String objectField = ""; aliascolumn = (FlexElement) idelement.getElementByName(cname.trim(), false); if (aliascolumn == null) { objectField = cname; } else { if (aliascolumn.getAttribute("alias") == null) { objectField = cname; } else { objectField = aliascolumn.getAttribute("alias").getValue(); } } String type = columns.get(cname); boolean readrec = includeidcolumns; if (!readrec) { readrec = (!cname.equalsIgnoreCase(idcolumn) && !cname.equalsIgnoreCase(parentidcolumn)); } if (readrec) { if (type.toUpperCase().indexOf("BLOB") > -1 || type.toUpperCase().indexOf("BINARY") > -1) { Object o = rec.getContent(cname); if (o != null) { //System.out.print(cname+")type:"+type+" "+o.getClass()); Blob blob = ((Blob) o); byte[] b = blob.getBytes(1, (int) blob.length()); res.append("<" + objectField + " type=\"byte[]\"><![CDATA[" + new String(b) + "]]></" + objectField + ">"); } else { res.append("<" + objectField + " type=\"byte[]\"><![CDATA[]]></" + objectField + ">"); } } else if (type.indexOf("CHAR") > -1 || type.indexOf("TEXT") > -1 || type.toUpperCase().equals("YEAR")) { res.append("<" + objectField + " type=\"String\"><![CDATA[" + rec.getString(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("DATETIME") || type.equalsIgnoreCase("TIMESTAMP") || type.toUpperCase().equals("DATE") || type.toUpperCase().equals("TIME")) { res.append("<" + objectField + " type=\"XMLGregorianCalendar\"><![CDATA[" + rec.getString(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("LONG") || type.equalsIgnoreCase("TINY") || type.equalsIgnoreCase("BIT") || type.equalsIgnoreCase("BIGINT") || type.equalsIgnoreCase("SMALLINT") || type.equalsIgnoreCase("TINYINT") || type.equalsIgnoreCase("MEDIUMINT") || type.equalsIgnoreCase("INT")) { res.append("<" + objectField + " type=\"BigInteger\"><![CDATA[" + rec.getInt(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("DOUBLE") || type.equalsIgnoreCase("NUMERIC") || type.equalsIgnoreCase("DECIMAL")) { res.append("<" + objectField + " type=\"Double\"><![CDATA[" + rec.getDouble(cname) + "]]></" + objectField + ">"); } else if (type.equalsIgnoreCase("FLOAT")) { res.append("<" + objectField + " type=\"Float\"><![CDATA[" + rec.getFloat(cname) + "]]></" + objectField + ">"); } /*else if (type.equalsIgnoreCase("LONG")) { res.append("<"+proper(cname)+" type=\"Long\"><![CDATA["+rec.getDouble(cname)+"]]></"+proper(cname)+">"); }*/ else { //res.append("<"+proper(objectField)+" type=\""+cname+"\"><![CDATA["+rec.getString(cname)+"]]></"+proper(objectField)+">"); throw new Exception(objectField + " type " + type + " is not recognized."); } } } res.append("</" + tablename + ">"); } //System.out.println(">>>1:"+res.toString()); return new String(res.substring(0).getBytes("UTF8")); }