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$ } }
/** * @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 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$ }
@Override public void createProperties(Properties properties, String[] products, String path) throws IOException { Product p = findProduct(products); if (p == Product.UNKNOWN) { if (StringUtil.startsWithIgnoreCase(path, "Domino")) { p = Product.DOMINO; } else if (StringUtil.startsWithIgnoreCase(path, "Connections")) { p = Product.CONNECTIONS; } else if (StringUtil.startsWithIgnoreCase(path, "SmartCloud")) { p = Product.SMARTCLOUD; } } if (p != Product.UNKNOWN) { // Else, add the proper prefix switch (p) { case DOMINO: { properties.put("basedocurl", "http://www-10.lotus.com/ldd/ddwiki.nsf"); properties.put("endpoint", "domino"); } break; case CONNECTIONS: { properties.put("endpoint", "connections"); } break; case SMARTCLOUD: { properties.put("endpoint", "smartcloud"); } break; } } }
/* * 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; } };
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(); }
/** * 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()); }
/** * 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; }
/* * Method responsible for generating appropriate REST URLs * * @param ProfileEntity ( Ref Class : ProfileEntity ) * @param ProfileType ( Ref Class : ProfileType ) * @param params : ( Ref Class : ProfileParams ) * @return String */ protected String resolveProfileUrl( String profileEntity, String profileType, Map<String, String> params) { if (logger.isLoggable(Level.FINEST)) { logger.entering(sourceClass, "resolveCommunityUrl", profileEntity + profileType); } StringBuilder proBaseUrl = new StringBuilder(ProfileBaseUrl); if (StringUtil.isEmpty(profileEntity)) { profileEntity = ProfileEntity.NONADMIN.getProfileEntityType(); // Default // Entity // Type } if (StringUtil.isEmpty(profileType)) { profileType = ProfileType.GETPROFILE.getProfileType(); // Default // Profile // Type } if (AuthUtil.INSTANCE.getAuthValue(endpoint).equalsIgnoreCase("oauth")) { if (profileEntity.equalsIgnoreCase(ProfileEntity.NONADMIN.getProfileEntityType())) { proBaseUrl.append(seperator).append("oauth"); } } if (profileEntity.equalsIgnoreCase("")) { // if it is non admin API then // no need to append anythin proBaseUrl.append(seperator).append(profileType); } else { proBaseUrl.append(profileEntity).append(seperator).append(profileType); } // Add required parameters if (null != params) { if (params.size() > 0) { proBaseUrl.append("?"); boolean setSeperator = false; for (Map.Entry<String, String> param : params.entrySet()) { if (setSeperator) { proBaseUrl.append("&"); } String paramvalue = ""; try { paramvalue = URLEncoder.encode(param.getValue(), "UTF-8"); } catch (UnsupportedEncodingException e) { } proBaseUrl.append(param.getKey() + "=" + paramvalue); setSeperator = true; } } } if (logger.isLoggable(Level.FINEST)) { logger.log(Level.FINEST, Messages.ProfileInfo_7 + proBaseUrl.toString()); } return proBaseUrl.toString(); }
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$ }
/** * Returns the Uuid of the Blog,post or comment * * @method getUid * @return uuid */ public String getUid() { String id = getAsString(BlogXPath.uid); if (StringUtil.isNotEmpty(id)) { if (StringUtil.startsWithIgnoreCase(id, BLOGID)) { id = id.substring(BLOGID.length()); } else if (StringUtil.startsWithIgnoreCase(id, POSTID)) { id = id.substring(POSTID.length()); } else { id = id.substring(COMMENTID.length()); } } return id; }
@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; }
/** 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; }
// 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); } } }
// 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); } } }
/** * Method to remove the user profile from cache. * * @param userId */ protected void removeProfileDataFromCache(String userId) throws ProfileServiceException { if (logger.isLoggable(Level.FINEST)) { logger.entering(sourceClass, "removeProfileDataFromCache", userId); } if (isEmail(userId)) { String key; Set<String> keys = lruCache.getKeySet(); Iterator<String> itr = keys.iterator(); while (itr.hasNext()) { key = itr.next(); Document data = lruCache.get(key); // check if email in profile object is same as input userId String email = ""; try { email = DOMUtil.value(data, Profile.xpathMap.get("email")); } catch (XMLException e) { continue; } // cache hit if (StringUtil.equalsIgnoreCase(email, userId)) { lruCache.remove(key); } } // Cache miss } else { lruCache.remove(userId); } if (logger.isLoggable(Level.FINEST)) { logger.exiting(sourceClass, "removeProfileDataFromCache"); } }
/* * 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; } };
@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$ }
/** 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); }
public static String getDefaultRendererType(ThemeControl c, String defaultRenderer) { if (useTheme852 /*ExtLibUtil.isXPages852()*/) { // 852: we assume OneUI if (!isOneUITheme(FacesContextEx.getCurrentInstance())) { // or we could actually check to see if it's OneUI return defaultRenderer; } if (OneUIRendererTypes == null) { synchronized (ThemeUtil.class) { if (OneUIRendererTypes == null) { OneUIRendererTypes = buildOneUIMap(); } } } String rt = OneUIRendererTypes.get(c.getStyleKitFamily()); if (StringUtil.isEmpty(rt)) { return defaultRenderer; } return rt; } else { // Post 852: we assume that the renderer type is forced by a theme // So we just set the default renderer here return defaultRenderer; } }
/** * 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; }
public boolean isAuthenticatedUser() { Principal p = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal(); if (p != null) { return StringUtil.equals(getId(), p.getName()); } return false; }
/** * Given the current name, append a long until a unique is found, starting at the given starting * num. */ public static String getNextUniqueValue(String name, long startingNum, String[] listOfNames) { boolean valid = true; for (int i = 0; i < Long.MAX_VALUE; i++) { StringBuffer newBuffer = new StringBuffer(name); newBuffer.append(startingNum); String test = newBuffer.toString(); if (listOfNames != null) { for (int x = 0; x < listOfNames.length; x++) { String currName = listOfNames[x]; if (StringUtil.equals(currName, test)) { valid = false; } } } if (!valid) { valid = true; startingNum++; } else { return test; } } return name; }
/** * Wrapper method to send Invite to a user to become colleague * * @param profile profile of the user to whom the invite is to be sent * @param inviteMsg Invite message to the other user * @return value is true if invite is sent successfully else value is false * @throws ProfileServiceException */ public boolean sendInvite(Profile profile, String inviteMsg) throws ProfileServiceException { if (logger.isLoggable(Level.FINEST)) { logger.entering(sourceClass, "getColleagues", inviteMsg); } if (profile == null) { throw new IllegalArgumentException(StringUtil.format("A null profile was passed")); } Map<String, String> parameters = new HashMap<String, String>(); String url = resolveProfileUrl( ProfileEntity.NONADMIN.getProfileEntityType(), ProfileType.CONNECTIONS.getProfileType()); if (isEmail(profile.getReqId())) { parameters.put(ProfileRequestParams.EMAIL, profile.getReqId()); } else { parameters.put(ProfileRequestParams.USERID, profile.getReqId()); } parameters.put("connectionType", "colleague"); XMLProfilesPayloadBuilder builder = XMLProfilesPayloadBuilder.INSTANCE; Object content = builder.generateInviteRequestPayload(inviteMsg); // getClientService().post(url, parameters, content); boolean result = executePost(url, parameters, null, content, null); if (logger.isLoggable(Level.FINEST)) { logger.exiting(sourceClass, "getColleagues"); } return result; }
/** Read a SQL file from the resources. */ public static String readSqlFile(String fileName) { if (StringUtil.isNotEmpty(fileName)) { final Application app = Application.get(); final VFSObjectCache c = app.getVFSCache(); try { String fullPath = JDBC_ROOT + VFS.SEPARATOR + fileName; if (!fullPath.endsWith(".sql")) { // $NON-NLS-1$ fullPath = fullPath + ".sql"; // $NON-NLS-1$ } return (String) c.get( fullPath, new VFSObjectCache.ObjectLoader() { // $NON-NLS-1$ @Override public Object loadObject(VFSFile file) throws VFSException { if (file.exists()) { try { final String s = file.loadAsString(); return s; } catch (final Exception ex) { throw new VFSException( ex, StringUtil.format( "Error while reading {0} Query {1}", "SQL", file)); // $NLX-JdbcUtil.Errorwhilereading0Query1-1$ // $NON-NLS-2$ } } throw new VFSException( null, StringUtil.format( "{0) file {1} does not exist", "SQL Query", file)); // $NLX-JdbcUtil.0file1doesnotexist-1$ // $NON-NLS-2$ } }); } catch (final VFSException ex) { throw new FacesExceptionEx( ex, StringUtil.format( "Error while loading {0} query file {1}", "SQL", fileName)); // $NLX-JdbcUtil.Errorwhileloading0queryfile1-1$ // $NON-NLS-2$ } } return null; }
@Override public void setUrl(String url) { super.setUrl(url); // Make the URL the service name if not already set if (StringUtil.isEmpty(oaProvider.getServiceName())) { oaProvider.setServiceName(url); } }
@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$ } } }
@Override public boolean isCompact() { String param = getHttpRequest().getParameter(PARAM_COMPACT); if (StringUtil.isNotEmpty(param)) { return param.contentEquals(PARAM_VALUE_TRUE); } return super.isCompact(); }
// // 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$ }