private boolean swap(String noteID, boolean previous) throws Exception { // Is there a faster way? View view = ExtLibUtil.getCurrentDatabase().getView("AllDocumentation"); // view.setAutoUpdate(false); ViewNavigator vn = view.createViewNav(); try { for (ViewEntry ve = vn.getFirst(); ve != null; ve = vn.getNext(ve)) { if (ve.getNoteID().equals(noteID)) { int docIndent = ve.getIndentLevel(); Document doc = ve.getDocument(); ve = previous ? vn.getPrev(ve) : vn.getNext(ve); if (ve != null) { Document other = ve.getDocument(); if (ve.getIndentLevel() == docIndent) { Object ts = other.getItemValue("OrderTS"); other.replaceItemValue("OrderTS", doc.getItemValue("OrderTS")); doc.replaceItemValue("OrderTS", ts); doc.save(); other.save(); view.refresh(); return true; } } return false; } } } finally { vn.recycle(); } return false; }
protected void calculateFormLabelWidth(FacesContext context, UIComponent component) { StringBuilder script = new StringBuilder(); script.append("XSP.addOnLoad(function(){XSP.resizeForm("); // $NON-NLS-1$ JavaScriptUtil.addString(script, component.getClientId(context)); script.append(")});"); // $NON-NLS-1$ ExtLibUtil.addScript(context, script.toString()); }
private boolean isUsingInputPlainText(FacesContext context, UIInput component) { // most browsers use <input type=datetime, but for iOS defaulting to type=text boolean isUseInputPlainTextOnIOS = true; String option = ((FacesContextEx) context) .getProperty("xsp.theme.mobile.iOS.native.dateTime"); // $NON-NLS-1$ if (null != option) { // explicitly configured whether to use type=datetime on iOS boolean isNativeOnIOS = "true".equals(option); // $NON-NLS-1$ isUseInputPlainTextOnIOS = !isNativeOnIOS; } if (isUseInputPlainTextOnIOS) { Object deviceBeanObj = ExtLibUtil.resolveVariable(context, "deviceBean"); // $NON-NLS-1$ if (deviceBeanObj instanceof DeviceBean) { DeviceBean deviceBean = (DeviceBean) deviceBeanObj; boolean isIOS = deviceBean.isIphone() || deviceBean.isIpad() || deviceBean.isIpod(); if (isIOS) { // is iOS, so by use type=text return true; } // else other devices use type=datetime, not type=text } } // else always use type=datetime, don't need to whether check browser OS is iOS. return false; }
public InputStream getFileSteam(FileHelper fh) { try { Database ndbCurrent = ExtLibUtil.getCurrentSession().getDatabase(fh.getServer(), fh.getPath()); if (ndbCurrent == null) return null; Document docCurrent = ndbCurrent.getDocumentByUNID(fh.getDocID()); if (docCurrent == null) { ndbCurrent.recycle(); return null; } EmbeddedObject entity = docCurrent.getAttachment(fh.getName()); if (entity == null) { ndbCurrent.recycle(); docCurrent.recycle(); return null; } InputStream is = entity.getInputStream(); entity.recycle(); docCurrent.recycle(); ndbCurrent.recycle(); return is; // entity.getInputStream(); } catch (Exception e) { e.printStackTrace(); } return null; }
public String getFirstContactID() throws NotesException { if (!firstContactIDRead) { Database db = ExtLibUtil.getCurrentDatabase(); View view = db.getView("AllContacts"); Document doc = view.getFirstDocument(); if (doc != null) { firstContactID = doc.getNoteID(); } } return firstContactID; }
@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); }
public void setCallTreeRoleBased() { this.callTreeType = CALLTREE_TYPE_ROLE; try { Document docSettings = ExtLibUtil.getCurrentDatabase().getDocumentByUNID(settingsUnid); docSettings.replaceItemValue("callTreeType", callTreeType); docSettings.save(); docSettings.recycle(); } catch (NotesException e) { Logger.error(e); } }
private RootNode readSnippetsNodes() throws NotesException { Database db = ExtLibUtil.getCurrentDatabase(); View v = db.getView("AllSnippetsFlat"); try { RootNode root = new RootNode(); String snippetSearch = (String) ExtLibUtil.getViewScope().get("snippetSearch"); if (StringUtil.isNotEmpty(snippetSearch)) { v.FTSearch(snippetSearch); ViewEntryCollection col = v.getAllEntries(); for (ViewEntry e = col.getFirstEntry(); e != null; e = col.getNextEntry()) { Vector<?> values = e.getColumnValues(); String unid = e.getUniversalID(); String cat = (String) values.get(0); String name = (String) values.get(1); String jspUrl = (String) values.get(2); CategoryNode c = findCategory(root, cat); SnippetNode snippet = new SnippetNode(c, name, cat, unid, jspUrl); c.getChildren().add(snippet); } } else { v.setAutoUpdate(false); ViewNavigator nav = v.createViewNav(); nav.setBufferMaxEntries(500); for (ViewEntry e = nav.getFirst(); e != null; e = nav.getNext()) { Vector<?> values = e.getColumnValues(); String unid = e.getUniversalID(); String cat = (String) values.get(0); String name = (String) values.get(1); String jspUrl = (String) values.get(2); CategoryNode c = findCategory(root, cat); SnippetNode snippet = new SnippetNode(c, name, cat, unid, findUniqueUrl(c, unid, jspUrl)); c.getChildren().add(snippet); } } return root; } finally { v.recycle(); } }
@SuppressWarnings("unchecked") @Override public void beforePageLoad() throws Exception { // super.afterPageLoad(); FacesContext facesContext = FacesContext.getCurrentInstance(); Map<String, String> param = (Map<String, String>) ExtLibUtil.resolveVariable(facesContext, "param"); ViewState state = (ViewState) ExtLibUtil.resolveVariable(facesContext, "state"); byte[] bytes = (byte[]) state.document().getItemValue("State" + param.get("index"), byte[].class); ByteArrayInputStream bis = new ByteArrayInputStream(bytes); // ObjectInputStream ois = new ObjectInputStream(bis); Class<? extends ObjectInputStream> inputClass = (Class<? extends ObjectInputStream>) Class.forName( "com.ibm.xsp.application.AbstractSerializingStateManager$FastObjectInputStream"); Constructor<?> inputConstructor = inputClass.getConstructor(FacesContext.class, InputStream.class); ObjectInputStream ois = (ObjectInputStream) inputConstructor.newInstance(facesContext, bis); // Read the components in Object treeStructure = ois.readObject(); // Object componentStructure = ois.readObject(); Method readObjectEx = inputClass.getMethod("readObjectEx"); Object componentStructure = readObjectEx.invoke(ois); // IComponentNode localIComponentNode = (IComponentNode)treeStructure; // UIViewRootEx view = (UIViewRootEx)localIComponentNode.restore(facesContext); // Object viewState = componentStructure; // view.processRestoreState(facesContext, viewState); // System.out.println("view is " + view); Map<String, Object> viewScope = ExtLibUtil.getViewScope(); viewScope.put("contextTreeStructure", treeStructure); viewScope.put("contextComponentStructure", componentStructure); }
public FileHelper addFile(FileHelper fh, UploadedFile file, String strNewId) { try { Database ndbCurrent = ExtLibUtil.getCurrentSession().getDatabase(fh.getServer(), fh.getPath()); if (ndbCurrent == null) return null; Document docCurrent = ndbCurrent.getDocumentByUNID(fh.getDocID()); if (docCurrent == null) { ndbCurrent.recycle(); return null; } IUploadedFile FTemp = file.getUploadedFile(); File SrFile = FTemp.getServerFile(); File FNew = new File( SrFile.getParentFile().getAbsolutePath() + File.separator + FTemp.getClientFileName()); SrFile.renameTo(FNew); RichTextItem rt = null; rt = (RichTextItem) docCurrent.getFirstItem(fh.getFieldName()); if (rt == null) { rt = docCurrent.createRichTextItem(fh.getFieldName()); } EmbeddedObject em = rt.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "", FNew.getAbsolutePath(), null); docCurrent.save(true, false, true); FileHelper fhNew = new FileHelper(); fhNew.setFieldName(fh.getFieldName()); fhNew.setServer(fh.getServer()); fhNew.setPath(fh.getPath()); fhNew.setFileSize(em.getFileSize()); fhNew.setName(em.getName()); fhNew.setDisplayName(FTemp.getClientFileName()); fhNew.setId(strNewId); fhNew.setDocID(fh.getDocID()); fhNew.setFileType(ComponentSessionFacade.get().getMimeTypes().getContentType(FNew)); fhNew.setNewFile(false); rt.recycle(); docCurrent.recycle(); ndbCurrent.recycle(); return fhNew; } catch (Exception e) { e.printStackTrace(); } return null; }
/** Read the snippet categories */ public String[] getAllCategories() throws NotesException { Database db = ExtLibUtil.getCurrentDatabase(); View v = db.getView("AllSnippets"); ViewNavigator nav = v.createViewNav(); try { nav.setMaxLevel(0); // nav.setCacheSize(128); List<String> categories = new ArrayList<String>(); for (ViewEntry ve = nav.getFirst(); ve != null; ve = nav.getNext(ve)) { categories.add((String) ve.getColumnValues().get(0)); } return categories.toArray(new String[categories.size()]); } finally { nav.recycle(); } }
@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$ } } }
@SuppressWarnings("unchecked") public void removeFile(FileHelper fh) { try { Database ndbCurrent = ExtLibUtil.getCurrentSession().getDatabase(fh.getServer(), fh.getPath()); if (ndbCurrent == null) return; Document docCurrent = ndbCurrent.getDocumentByUNID(fh.getDocID()); if (docCurrent == null) { ndbCurrent.recycle(); return; } // RESULTS IN NOTE ITEM NOT FOUND ERROR AFTERWARDS // EmbeddedObject entity = docCurrent.getAttachment(fh.getName()); // if (entity == null) // return; // entity.remove(); RichTextItem rti = (RichTextItem) docCurrent.getFirstItem(fh.getFieldName()); Vector<EmbeddedObject> entitys = rti.getEmbeddedObjects(); for (EmbeddedObject entity : entitys) { if (entity.getType() == EmbeddedObject.EMBED_ATTACHMENT) { if (entity.getName().equals(fh.getName())) { entity.remove(); break; } } } docCurrent.save(true, false, true); rti.recycle(); docCurrent.recycle(); ndbCurrent.recycle(); } catch (Exception e) { e.printStackTrace(); } }
// This function is being overridden to provide style/class to tds...probably // should be bubbled up to the actual general FormTableRenderer @Override protected void writeFormRowData( FacesContext context, ResponseWriter w, FormLayout c, ComputedFormData formData, UIFormLayoutRow row, UIInput edit, ComputedRowData rowData) throws IOException { w.startElement("div", c); // $NON-NLS-1$ String fieldStyle = row.getStyle(); if (StringUtil.isEmpty(fieldStyle)) { fieldStyle = (String) getProperty(PROP_FIELDROWSTYLE); } if (StringUtil.isNotEmpty(fieldStyle)) { w.writeAttribute("style", fieldStyle, null); // $NON-NLS-1$ } String fieldClass = row.getStyleClass(); if (StringUtil.isEmpty(fieldClass)) { fieldClass = (String) getProperty(PROP_FIELDROWCLASS); } if (StringUtil.isNotEmpty(fieldClass)) { w.writeAttribute("class", fieldClass, null); // $NON-NLS-1$ } // TODO: I think this section is dead code. Look into that. boolean rowError = false; if (edit != null) { // Write the error messages, if any if (!formData.isDisableRowError()) { Iterator<FacesMessage> msg = ((DominoFacesContext) context).getMessages(edit.getClientId(context)); if (msg.hasNext()) { rowError = true; } } } boolean hasLabel = rowData.hasLabel(); boolean labelAbove = rowData.isLabelAbove(); // Write the label w.startElement("div", c); // $NON-NLS-1$ String tdStyle = (String) getProperty(PROP_FIELDCOLUMNSTYLE); if (StringUtil.isNotEmpty(tdStyle)) { w.writeAttribute("style", tdStyle, null); // $NON-NLS-1$ } // if we have an error, assign the appropriate classes String tdClass = hasLabel ? (String) getProperty(PROP_FIELDCOLUMNSTYLECLASS) : (String) getProperty(PROP_FIELDEDITNOLABELCLASS); tdClass = (rowError) ? ExtLibUtil.concatStyleClasses( (String) getProperty(PROP_ERRORROWTITLESTYLECLASS), tdClass) : tdClass; if ((TypedUtil.getChildren(row).get(0) instanceof XspInputTextarea || TypedUtil.getChildren(row).get(0) instanceof UIDojoTextarea) && getProperty(PROP_TEXTAREALABELCLASS) != null) { // if our row contains a textarea component, we need a special label class tdClass = ExtLibUtil.concatStyleClasses(tdClass, (String) getProperty(PROP_TEXTAREALABELCLASS)); } if (StringUtil.isNotEmpty(tdClass)) { w.writeAttribute("class", tdClass, null); // $NON-NLS-1$ } if (hasLabel) { String lblStyle = (String) getProperty(PROP_FIELDLABELSTYLE); String lblClass = (String) getProperty(PROP_FIELDLABELCLASS); if (labelAbove) { w.startElement("div", c); // $NON-NLS-1$ } else { String width = row.getLabelWidth(); if (StringUtil.isEmpty(width)) { width = formData.getLabelWidth(); } if (StringUtil.isEmpty(width)) { width = (String) getProperty(PROP_FIELDLABELWIDTH); } if (StringUtil.isNotEmpty(width)) { lblStyle = ExtLibUtil.concatStyles( "width:" + width, (String) getProperty(PROP_FIELDLABELSTYLE)); // $NON-NLS-1$ } } if (StringUtil.isNotEmpty(lblStyle)) { w.writeAttribute("style", lblStyle, null); // $NON-NLS-1$ } if (StringUtil.isNotEmpty(lblClass)) { w.writeAttribute("class", lblClass, null); // $NON-NLS-1$ } String label = row.getLabel(); writeFormRowLabel(context, w, c, formData, row, edit, label); if (labelAbove) { if (c.isFieldHelp()) { writeFormRowHelp(context, w, c, row, edit); } w.endElement("div"); // $NON-NLS-1$ w.startElement("div", c); // $NON-NLS-1$ } else { w.endElement("div"); // $NON-NLS-1$ w.startElement("div", c); // $NON-NLS-1$ } } String editStyle = (hasLabel && !labelAbove) ? ExtLibUtil.concatStyles( (String) getProperty(PROP_FORMROWEDITSTYLE), (String) getProperty(PROP_FIELDEDITSTYLE)) : (String) getProperty(PROP_FIELDEDITSTYLE); if (StringUtil.isNotEmpty(editStyle)) { w.writeAttribute("style", editStyle, null); // $NON-NLS-1$ } String editClass = (String) getProperty(PROP_FIELDEDITCLASS); if (TypedUtil.getChildren(row).get(0) instanceof XspInputTextarea || TypedUtil.getChildren(row).get(0) instanceof UIDojoTextarea) { editClass = ExtLibUtil.concatStyleClasses(editClass, (String) getProperty(PROP_TEXTAREASTYLECLASS)); } if (StringUtil.isNotEmpty(editClass)) { w.writeAttribute("class", editClass, null); // $NON-NLS-1$ } writeFormRowDataField(context, w, c, row, edit); if (hasLabel) { if (labelAbove) { w.endElement("div"); // $NON-NLS-1$ } // Write the help if (hasLabel) { if (!labelAbove) { if (c.isFieldHelp()) { w.startElement("div", c); // $NON-NLS-1$ writeFormRowHelp(context, w, c, row, edit); w.endElement("div"); // $NON-NLS-1$ } } } } w.endElement("div"); // $NON-NLS-1$ w.endElement("div"); // $NON-NLS-1$ }
@Override protected String getContainerStyle(TreeContextImpl node) { String style = super.getContainerStyle(node); return ExtLibUtil.concatStyles(style, "margin-left:2em; margin-right:2em"); }