/** * @ibm-not-published * @deprecated */ public static String encrypt(String pwd, String ctx) { if (pwd == null) { return null; } int offset; if (StringUtil.isNotEmpty(ctx)) { int acc = Math.abs((int) (ctx.hashCode() % ENCRYPTION.length)); offset = Math.min(ENCRYPTION.length, acc); } else { offset = Math.min(ENCRYPTION.length, (int) (Math.random() * ENCRYPTION.length)); } FastStringBuffer b = new FastStringBuffer(); b.append('['); // Write the offset/count encryptChar(b, 0, (char) offset); encryptChar(b, offset++, (char) (pwd.length())); for (int i = 0; i < Math.max(MINPWDLENGTH, pwd.length()); i++) { char c; if (i < pwd.length()) { c = pwd.charAt(i); } else { if (StringUtil.isNotEmpty(ctx)) { int pwdlen = pwd.length(); c = ctx.charAt((i - pwdlen) % ctx.length()); } else { c = (char) (Math.random() * 64 + 32); } } encryptChar(b, offset++, c); } b.append(']'); return b.toString(); }
public String generateValueList(String list) { if (StringUtil.isEmpty(list)) { return ""; } StringBuilder b = new StringBuilder(); b.append("<ul>"); String[] values = StringUtil.splitString(list, '\n'); for (int i = 0; i < values.length; i++) { String s = values[i]; if (StringUtil.isNotEmpty(s)) { String name = s; String desc = null; int pos = s.indexOf('|'); if (pos >= 0) { name = s.substring(0, pos); desc = s.substring(pos + 1); } b.append("<li>"); b.append("<b>"); b.append(TextUtil.toXMLString(name)); b.append("</b>"); if (StringUtil.isNotEmpty(desc)) { b.append(": "); b.append(TextUtil.toXMLString(desc)); } b.append("</li>"); } } b.append("</ul>"); return b.toString(); }
public String getPostId() { String id = null; // First check the URL Map<String, String> param = FrameworkUtils.getParam(); if (StringUtil.isNotEmpty(param.get("id"))) { // $NON-NLS-1$ id = param.get("id"); // $NON-NLS-1$ } if (StringUtil.isEmpty(id)) { // Then check the path info String pathInfo = FacesContext.getCurrentInstance().getExternalContext().getRequestPathInfo(); if (StringUtil.isNotEmpty(pathInfo)) { id = pathInfo.substring(1); } } if (StringUtil.isNotEmpty(id)) { if (!DominoUtils.isUnid(id)) { // Then it must be the URL slug - look it up in the view AbstractModelList<Post> posts = Post.Manager.get().getNamedCollection("All", null); // $NON-NLS-1$ posts.setResortOrder("$Key", TabularDataModel.SORT_ASCENDING); // $NON-NLS-1$ return posts.getByKey(id).getId(); } else { return id; } } return "new"; //$NON-NLS-1$ }
/** * Method to set the "assigned to" parameter, to assign the entry to a person. * * @param assignedToName * @param assignedToId */ public void setAssignedTo(String assignedToName, String assignedToId) { if (StringUtil.isNotEmpty(assignedToId)) { setAsString(ActivityXPath.assignedToId, assignedToId); } if (StringUtil.isNotEmpty(assignedToName)) { setAsString(ActivityXPath.assignedToName, assignedToName); } }
/** * Method to set the "in reply to" parameter, to set the parent entry. * * @param sectionId * @param sectionUrl */ public void setInReplyTo(String sectionId, String sectionUrl) { if (StringUtil.isNotEmpty(sectionId)) { setAsString(ActivityXPath.inReplyToId, sectionId); } if (StringUtil.isNotEmpty(sectionUrl)) { setAsString(ActivityXPath.inReplyToUrl, sectionUrl); } setAsString(ActivityXPath.inReplyToActivityId, getId()); }
protected void writeErrorSummaryShade( FacesContext context, ResponseWriter w, FormLayout c, String id) throws IOException { w.startElement("div", c); // $NON-NLS-1$ String cls = (String) getProperty(PROP_ERRORDIVSHADECLASS); if (StringUtil.isNotEmpty(cls)) { w.writeAttribute("class", cls, null); // $NON-NLS-1$ } if (StringUtil.isNotEmpty(id)) { w.writeAttribute("id", id, null); // $NON-NLS-1$ } w.endElement("div"); // $NON-NLS-1$ }
@Override public String transform(Map<String, Object> fieldmap) throws TransformerException { String xml = getTemplateContent(sourcepath + inviteTmplFile); String idXml = ""; String titleXml = ""; String contentXml = ""; String statusXml = ""; for (Map.Entry<String, Object> xmlEntry : fieldmap.entrySet()) { String currentElement = xmlEntry.getKey(); String currentValue = xmlEntry.getKey(); if (currentElement.equalsIgnoreCase("id")) { idXml = getXMLRep( getStream(sourcepath + "ConnectionEntryIdTmpl.xml"), currentElement, XmlTextUtil.escapeXMLChars(currentValue)); } else if (currentElement.equalsIgnoreCase("content")) { contentXml = getXMLRep( getStream(sourcepath + "ConnectionEntryContentTmpl.xml"), currentElement, XmlTextUtil.escapeXMLChars(currentValue)); } else if (currentElement.equalsIgnoreCase("title")) { titleXml = getXMLRep( getStream(sourcepath + "ConnectionEntryTitleTmpl.xml"), currentElement, XmlTextUtil.escapeXMLChars(currentValue)); } } statusXml = getXMLRep(getStream(sourcepath + "ConnectionEntryCategoryStatus.xml"), "status", status); xml = getXMLRep(xml, "getStatus", statusXml); if (StringUtil.isNotEmpty(idXml)) { xml = getXMLRep(xml, "getId", idXml); } if (StringUtil.isNotEmpty(titleXml)) { xml = getXMLRep(xml, "getTitle", titleXml); } if (StringUtil.isNotEmpty(contentXml)) { xml = getXMLRep(xml, "getContent", contentXml); } xml = removeExtraPlaceholders(xml); return xml; }
/* * Method used to extract the forum uuid for an id string. */ public String extractForumUuid(String uid) { if (StringUtil.isNotEmpty(uid) && StringUtil.startsWithIgnoreCase(uid, FORUMID)) { return uid.substring(FORUMID.length()); } else { return uid; } };
/* * Method used to extract the blog uuid for an id string. */ private String extractBlogUuid(String uid) { if (StringUtil.isNotEmpty(uid) && uid.indexOf(BLOGID) == 0) { return uid.substring(BLOGID.length()); } else { return uid; } };
/** Create a name with the _copy_x appended, where X is the next available number. */ public static String generateCopyName(String sourceName, String[] listOfNames) { // create a new name with same name + copy_n StringBuffer buffer = new StringBuffer(sourceName); String copyString = "copy"; // $NLS-StringUtil.copy-1$ String separator = "_"; StringBuffer copySeparator = new StringBuffer(separator); copySeparator.append(copyString); copySeparator.append(separator); String copySep = copySeparator.toString(); int index = sourceName.indexOf(copySep); long num = 1; if (index != -1) { String substring = sourceName.substring(index + copySep.length()); if (StringUtil.isNotEmpty(substring)) { try { num = Long.parseLong(substring); buffer.delete(index + copySep.length(), buffer.length()); } catch (NumberFormatException nfe) { buffer.append(copySep); } } } else { buffer.append(copySep); } return getNextUniqueValue(buffer.toString(), num, listOfNames); }
/** Strip extra spaces and html tags. */ public static String parseHtml(String s) { // Quickly strip the extra spaces if (StringUtil.isNotEmpty(s)) { StringBuilder b = new StringBuilder(); boolean space = true; int len = s.length(); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (c == ' ' || c == '\t') { if (!space) { b.append(' '); space = true; } } else if (c == '<') { // Skip the HTML tags for now while (i < len && c != '>') { i++; } } else { b.append(c); if (c == '\n' || c == '\r') { space = true; } else { space = false; } } } return b.toString(); } return s; }
protected void writeCollapseAll( FacesContext context, ResponseWriter w, UIPagerExpand pager, FacesDataIterator dataIterator) throws IOException { String text = pager.getCollapseText(); if (StringUtil.isEmpty(text)) { text = "Collapse all"; // $NLS-PagerExpandRenderer.CollapseAll-1$ } if (StringUtil.isNotEmpty(text)) { w.startElement("li", null); // $NON-NLS-1$ boolean selected = pager.isCollapseAll(); if (selected) { w.writeAttribute("class", "active", null); // $NON-NLS-1$ $NON-NLS-2$ } w.startElement("a", null); String clientId = pager.getClientId(context); String sourceId = clientId + "_ca"; // $NON-NLS-1$ w.writeAttribute("id", sourceId, null); // $NON-NLS-1$ w.writeAttribute("href", "javascript:;", null); // $NON-NLS-1$ $NON-NLS-2$ // $NON-NLS-2$ setupSubmitOnClick(context, w, pager, dataIterator, clientId, sourceId); w.writeText(text, null); w.endElement("a"); w.endElement("li"); // $NON-NLS-1$ } }
// Read a file from a resource in the NSF @SuppressWarnings("unused") private static void readFromFileResource( String resourceName, List<String> entries, boolean capitalize) throws IOException { if (TRACE) { System.out.println("Reading: " + resourceName); } InputStream is = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(resourceName); if (is != null) { if (TRACE) { System.out.println("Found: " + resourceName); } try { BufferedReader r = new BufferedReader(new InputStreamReader(is, "utf-8")); String s; while ((s = r.readLine()) != null) { if (StringUtil.isNotEmpty(s)) { entries.add(capitalize ? capitalize(s) : s); } } } finally { is.close(); } } else { if (TRACE) { System.out.println("Cannot find: " + resourceName); } } }
/** * Create a JDBC connection from a URL. The connection is actually created and added to a * FacesContextListener */ public static Connection createConnectionFromUrl(FacesContext context, String connectionUrl) throws SQLException { if (StringUtil.isNotEmpty(connectionUrl)) { return DriverManager.getConnection(connectionUrl); } return null; }
@Override protected void writeFormTitle( FacesContext context, ResponseWriter w, FormLayout c, String title, String description) throws IOException { w.startElement("div", c); // $NON-NLS-1$ String style = (String) getProperty(PROP_STYLEHEADER); if (StringUtil.isNotEmpty(style)) { w.writeAttribute("style", style, null); // $NON-NLS-1$ } String cls = (String) getProperty(PROP_STYLECLASSHEADER); if (StringUtil.isNotEmpty(cls)) { w.writeAttribute("class", cls, null); // $NON-NLS-1$ } writeFormTitleContent(context, w, c, title, description); w.endElement("div"); // $NON-NLS-1$ }
// Read a file from a class resource in the classpath private static void readFromClassResource( String resourceName, List<String> entries, boolean capitalize) throws IOException { if (TRACE) { System.out.println("Reading: " + resourceName); } InputStream is = SampleDataUtil.class.getResourceAsStream(resourceName); if (is != null) { if (TRACE) { System.out.println("Found: " + resourceName); } try { BufferedReader r = new BufferedReader(new InputStreamReader(is, "utf-8")); String s; while ((s = r.readLine()) != null) { if (StringUtil.isNotEmpty(s)) { entries.add(capitalize ? capitalize(s) : s); } } } finally { is.close(); } } else { if (TRACE) { System.out.println("Cannot find: " + resourceName); } } }
@Override protected void writeErrorSummary( FacesContext context, ResponseWriter w, FormLayout c, ComputedFormData formData) throws IOException { if (!c.isDisableErrorSummary()) { // Should we apply a filter to retain only the message belonging to the controls within the // form? // Easy enough with a FilteredIterator Iterator<FacesMessage> msg = ((DominoFacesContext) context).getMessages(); if (msg.hasNext()) { String id = c.getClientId(context) + NamingContainer.SEPARATOR_CHAR + "popup"; // $NON-NLS-1$ String shadeId = c.getClientId(context) + NamingContainer.SEPARATOR_CHAR + "shade"; // $NON-NLS-1$ writeErrorSummaryShade(context, w, c, shadeId); // TODO: make the addition of js to the component a separate function // center the error dialog on the screen StringBuilder b = new StringBuilder(); b.append("XSP.addOnLoad(function(){"); // $NON-NLS-1$ b.append("XSP.centerNode("); // $NON-NLS-1$ JavaScriptUtil.addString(b, id); b.append(");"); // $NON-NLS-1$ b.append("});"); // $NON-NLS-1$ String script = b.toString(); ExtLibUtil.addScript(context, script); w.startElement("div", c); // $NON-NLS-1$ String style = (String) getProperty(PROP_STYLEERRORSUMMARY); if (StringUtil.isNotEmpty(style)) { w.writeAttribute("style", style, null); // $NON-NLS-1$ } String cls = (String) getProperty(PROP_STYLECLASSERRORSUMMARY); if (StringUtil.isNotEmpty(cls)) { w.writeAttribute("class", cls, null); // $NON-NLS-1$ } if (StringUtil.isNotEmpty(id)) { w.writeAttribute("id", id, null); // $NON-NLS-1$ } writeErrorSummaryContent(context, w, c, msg); writeErrorSummaryButton(context, w, c, id, shadeId); w.endElement("div"); // $NON-NLS-1$ } } }
// // Footer // @Override protected void writeFooterFacet( FacesContext context, ResponseWriter w, FormLayout c, UIComponent footer) throws IOException { w.startElement("div", c); // $NON-NLS-1$ String style = (String) getProperty(PROP_STYLEFOOTER); if (StringUtil.isNotEmpty(style)) { w.writeAttribute("style", style, null); // $NON-NLS-1$ } String cls = (String) getProperty(PROP_STYLECLASSFOOTER); if (StringUtil.isNotEmpty(cls)) { w.writeAttribute("class", cls, null); // $NON-NLS-1$ } writeFooterFacetContent(context, w, c, footer); w.endElement("div"); // $NON-NLS-1$ }
@Override public boolean isCompact() { String param = getHttpRequest().getParameter(PARAM_COMPACT); if (StringUtil.isNotEmpty(param)) { return param.contentEquals(PARAM_VALUE_TRUE); } return super.isCompact(); }
/** * Implements {@link ClientSideConverter#generateClientSideConverter(FacesContext, UIComponent)} */ public String generateClientSideConverter(FacesContext context, UIComponent component) { UIInput input = (UIInput) component; DateTimeConverter converter = (DateTimeConverter) input.getConverter(); String dateType = converter.getType(); int valueType = TYPE_TIMESTAMP; if (StringUtil.isNotEmpty(dateType)) { if (dateType.equals(DateTimeConverter.TYPE_DATE)) { valueType = TYPE_DATE; } else if (dateType.equals(DateTimeConverter.TYPE_TIME)) { valueType = TYPE_TIME; } } // TODO in 9.0.2, should update this to handle message changes for SPR#MKEE7TXMLG String message; if (TYPE_DATE == valueType) { message = getMessageDate(); } else if (TYPE_TIME == valueType) { message = getMessageTime(); } else { message = getMessageBoth(); } DojoModuleResource module; StringBuilder builder = new StringBuilder(); switch (valueType) { case TYPE_DATE: { module = ISO_DATE_CONVERTER_MODULE; builder.append("new extlib.date.IsoDateConverter({message:"); // $NON-NLS-1$ JavaScriptUtil.addMessage(builder, message); builder.append("})"); // $NON-NLS-1$ break; } case TYPE_TIME: { module = ISO_TIME_CONVERTER_MODULE; builder.append("new extlib.date.IsoTimeConverter({message:"); // $NON-NLS-1$ JavaScriptUtil.addMessage(builder, message); builder.append("})"); // $NON-NLS-1$ break; } default: { // TYPE_TIMESTAMP module = ISO_DATE_TIME_CONVERTER_MODULE; builder.append("new extlib.date.IsoDateTimeConverter({message:"); // $NON-NLS-1$ JavaScriptUtil.addMessage(builder, message); builder.append("})"); // $NON-NLS-1$ break; } } if (null != module) { UIViewRootEx rootEx = (UIViewRootEx) context.getViewRoot(); rootEx.addEncodeResource(context, module); } return builder.toString(); }
/** * To get Uuid of Forum Entity * * @method getUid * @return String */ public String getUid() { String id = getAsString(ForumsXPath.uid); if (StringUtil.isNotEmpty(id)) { if (StringUtil.startsWithIgnoreCase(id, FORUMID)) { id = id.substring(FORUMID.length()); } } return id; }
protected UIComponent getFor(FacesContext context, UISelect2Picker picker) { // Associated control String control = picker.getFor(); if (StringUtil.isNotEmpty(control)) { UIComponent c = FacesUtil.getComponentFor(picker, control); return c; } return null; }
/** * Get JS snippets in JSON format, including sbtx.sample.web's JS snippets. * * @param context * @param request * @return JSSnippets in JSON format. */ public static String getJsSnippetsAsJson(ServletContext context, HttpServletRequest request) { RootNode root = getJsSnippets(context, request); String json = root.getAsJson(); String jsonEx = readRemoteJson(context, request); if (StringUtil.isNotEmpty(jsonEx) && jsonEx.contains("children")) { jsonEx = jsonEx.substring("[{\"id\":\"_root\",\"name\":\"_root\",\"children\":[".length()); json = json.substring(0, json.length() - 3) + "," + jsonEx; } return json; }
@Override protected void writeMainTableTag(FacesContext context, ResponseWriter w, FormLayout c) throws IOException { String ariaLabel = c.getAriaLabel(); if (StringUtil.isNotEmpty(ariaLabel)) { w.writeAttribute("aria-label", ariaLabel, null); // $NON-NLS-1$ } String tbStyle = (String) getProperty(PROP_TABLESTYLE); if (StringUtil.isNotEmpty(tbStyle)) { w.writeAttribute("style", tbStyle, null); // $NON-NLS-1$ } String tbStyleClass = (String) getProperty(PROP_TABLESTYLECLASS); if (StringUtil.isNotEmpty(tbStyleClass)) { w.writeAttribute("class", tbStyleClass, null); // $NON-NLS-1$ } String tbRole = (String) getProperty(PROP_TABLEROLE); if (StringUtil.isNotEmpty(tbStyleClass)) { w.writeAttribute("role", tbRole, null); // $NON-NLS-1$ } }
public Object evaluate(RestViewService service, RestViewEntry entry) throws ServiceException { // TODO: How can we cache the column name so we do not reevaluate it all the time? String columnName = getColumnName(); if (StringUtil.isNotEmpty(columnName)) { return entry.getColumnValue(columnName); } String var = service.getParameters().getVar(); if (StringUtil.isNotEmpty(var)) { // TODO: Do that on a per row basis only... Object old = service.getHttpRequest().getAttribute(var); try { service.getHttpRequest().setAttribute(var, entry); return getValue(); } finally { service.getHttpRequest().setAttribute(var, old); } } else { return getValue(); } }
@Override protected void writeErrorSummaryMainText( FacesContext context, ResponseWriter w, FormLayout c, FacesMessage.Severity sev) throws IOException { w.startElement("h1", c); // $NON-NLS-1$ String style = (String) getProperty(PROP_ERRORSUMMARYSTYLE); if (StringUtil.isNotEmpty(style)) { w.writeAttribute("style", style, null); // $NON-NLS-1$ } String cls = (String) getProperty(PROP_ERRORSUMMARYCLASS); if (StringUtil.isNotEmpty(cls)) { w.writeAttribute("class", cls, null); // $NON-NLS-1$ } String mainText = c.getErrorSummaryText(); if (StringUtil.isEmpty(mainText)) { mainText = (String) getProperty(PROP_ERRORSUMMARYMAINTEXT); } writeErrorMessage(context, w, c, mainText); w.endElement("h1"); // $NON-NLS-1$ }
@Override public void decode(FacesContext context, UIComponent component) { if (isTrackClientSelection()) { String fieldId = component.getClientId(context) + _SELECTION; String selectedTab = (String) context.getExternalContext().getRequestParameterMap().get(fieldId); if (StringUtil.isNotEmpty(selectedTab)) { ((UIDojoAccordionContainer) component).setSelectedTab(selectedTab); } } }
@Override protected void writeFormLayout(FacesContext context, ResponseWriter w, FormLayout c) throws IOException { ComputedFormData formData = createFormData(context, c); String style = c.getStyle(); String styleClass = c.getStyleClass(); w.startElement("div", c); // $NON-NLS-1$ String styleProp = (String) getProperty(PROP_FORMCONTAINERSTYLE); if (StringUtil.isNotEmpty(styleProp)) { style = ExtLibUtil.concatStyles(style, styleProp); } if (!StringUtil.isEmpty(style)) { w.writeAttribute("style", style, null); // $NON-NLS-1$ } String styleClassProp = (String) getProperty(PROP_FORMCONTAINERSTYLECLASS); if (StringUtil.isNotEmpty(styleClassProp)) { styleClass = ExtLibUtil.concatStyleClasses(styleClass, styleClassProp); } if (!StringUtil.isEmpty(styleClass)) { w.writeAttribute("class", styleClass, null); // $NON-NLS-1$ } w.writeAttribute("id", c.getClientId(context), null); // $NON-NLS-1$ newLine(w); writeErrorSummary(context, w, c, formData); writeHeader( context, w, c); // TODO:this is sort of messed up in how it is placing its divs, needs to be fixed w.startElement("div", c); // $NON-NLS-1$ writeMainTableTag(context, w, c); newLine(w); writeForm(context, w, c, formData); w.endElement("div"); // $NON-NLS-1$ newLine(w); writeFooter(context, w, c); w.endElement("div"); // $NON-NLS-1$ newLine(w); }
@Override protected void writeFormTitleContent( FacesContext context, ResponseWriter w, FormLayout c, String title, String description) throws IOException { if (StringUtil.isNotEmpty(title)) { String titleTag = (String) getProperty(PROP_TAGFORMTITLE); if (StringUtil.isNotEmpty(titleTag)) { w.startElement(titleTag, c); String style = (String) getProperty(PROP_STYLEFORMTITLE); if (StringUtil.isNotEmpty(style)) { w.writeAttribute("style", style, null); // $NON-NLS-1$ } String cls = (String) getProperty(PROP_STYLECLASSFORMTITLE); if (StringUtil.isNotEmpty(cls)) { w.writeAttribute("class", cls, null); // $NON-NLS-1$ } } w.writeText(title, null); if (StringUtil.isNotEmpty(titleTag)) { w.endElement(titleTag); } } if (StringUtil.isNotEmpty(description)) { String descTag = (String) getProperty(PROP_TAGFORMDESC); if (StringUtil.isNotEmpty(descTag)) { w.startElement(descTag, c); String style = (String) getProperty(PROP_STYLEFORMDESC); if (StringUtil.isNotEmpty(style)) { w.writeAttribute("style", style, null); // $NON-NLS-1$ } String cls = (String) getProperty(PROP_STYLECLASSFORMDESC); if (StringUtil.isNotEmpty(cls)) { w.writeAttribute("class", cls, null); // $NON-NLS-1$ } } w.writeText(description, null); if (StringUtil.isNotEmpty(descTag)) { w.endElement(descTag); } } }
@Override protected void writeErrorSummaryRow( FacesContext context, ResponseWriter w, FormLayout c, FacesMessage m) throws IOException { w.startElement("h2", c); // $NON-NLS-1$ String style = (String) getProperty(PROP_ERRORSUMMARYITEMSTYLE); if (StringUtil.isNotEmpty(style)) { w.writeAttribute("style", style, null); // $NON-NLS-1$ } String cls = (String) getProperty(PROP_ERRORSUMMARYITEMCLASS); if (StringUtil.isNotEmpty(cls)) { w.writeAttribute("class", cls, null); // $NON-NLS-1$ } String title = null; if (StringUtil.isNotEmpty(title)) { w.startElement("strong", c); // $NON-NLS-1$ w.writeText(title, null); w.endElement("strong"); // $NON-NLS-1$ } String text = m.getSummary(); w.writeText(text, null); w.endElement("h2"); // $NON-NLS-1$ }