public static void main(String[] args) throws Exception { // The path to the documents directory. gDataDir = Utils.getDataDir(KeepSourceTogether.class); Document dstDoc = new Document(gDataDir + "TestFile.Destination.doc"); Document srcDoc = new Document(gDataDir + "TestFile.Source.doc"); // Set the source document to appear straight after the destination document's content. srcDoc.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS); // Iterate through all sections in the source document. for (Paragraph para : (Iterable<Paragraph>) srcDoc.getChildNodes(NodeType.PARAGRAPH, true)) { para.getParagraphFormat().setKeepWithNext(true); } dstDoc.appendDocument(srcDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING); dstDoc.save(gDataDir + "TestDcc.KeepSourceTogether Out.doc"); System.out.println("Documents appended successfully."); }
public static void main(String[] args) throws Exception { // The path to the documents directory. String dataDir = Utils.getDataDir(InsertNestedFields.class); Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert few page breaks (just for testing) for (int i = 0; i < 5; i++) builder.insertBreak(BreakType.PAGE_BREAK); // Move DocumentBuilder cursor into the primary footer. builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY); // We want to insert a field like this: // { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" } Field field = builder.insertField("IF "); builder.moveTo(field.getSeparator()); builder.insertField("PAGE"); builder.write(" <> "); builder.insertField("NUMPAGES"); builder.write(" \"See Next Page\" \"Last Page\" "); // Finally update the outer field to recalcaluate the final value. Doing this will automatically // update // the inner fields at the same time. field.update(); doc.save(dataDir + "InsertNestedFields Out.docx"); System.out.println("Nested fields inserted into the document successfully."); }
public static void createAppDefinition(String appPath, boolean hideFromWS, boolean autoLaunch) { Session sessionAsSigner = null; Database dbUnplugged = null; Document docApp = null; try { String correctedPath = appPath.replace("\\", "/"); Logger.debug("create unplugged application " + correctedPath); Configuration config = Configuration.get(); // open unplugged db sessionAsSigner = Utils.getCurrentSessionAsSigner(); dbUnplugged = sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath()); // check if an app document for this app already exists and create it if not DocumentCollection dcApp = dbUnplugged.search("Form=\"UserDatabase\" & Path=\"" + correctedPath + "\""); if (dcApp.getCount() == 0) { // create new app document Logger.debug("application not found: create new"); docApp = dbUnplugged.createDocument(); docApp.replaceItemValue("form", "UserDatabase"); docApp.replaceItemValue("Path", correctedPath); } else { throw (new Exception("application for " + correctedPath + " already exists in Unplugged")); } docApp.replaceItemValue("Active", "1"); docApp.replaceItemValue("ShowOnWS", (hideFromWS ? "no" : "")); docApp.replaceItemValue("AutoLaunchApp", (autoLaunch ? "yes" : "")); docApp.replaceItemValue("ReplAttachmentExts", ""); // send all attachments docApp.computeWithForm(true, true); docApp.save(); Logger.debug("done"); } catch (Exception e) { Logger.error(e); } finally { Utils.recycle(docApp, dbUnplugged); } }
public static void ajaxEditDocument(Long documentId, String newTitle, String newContent) { Document document = Document.findById(documentId); document.changeSubject(newTitle); Config config = Config.getInstance(); User currentUser = User.findById(config.getSingedInUserId()); Version newVersion = new Version(currentUser, document, newContent).save(); System.out.println("* A new version is successfully created."); document.addVersion(newVersion); document.save(); }
/** * RWFException constructor * * @param Database d the current database */ public RWFException(Database d) { super(); try { Document e = d.createDocument(); e.replaceItemValue("Form", EXCEPTION_FORM); e.replaceItemValue(EXCEPTION_TYPE_FIELD, "Workflow Exception"); e.save(); } catch (NotesException e) { e.printStackTrace(); System.out.println(e.text); } }
/** * RWFException constructor * * @param - msg, String the error message to be used. * @param Database d the current database * @param Document doc the context document. */ public RWFException(String msg, Database d, Document doc) { super(msg); try { Document e = d.createDocument(); e.replaceItemValue("Form", EXCEPTION_FORM); e.replaceItemValue(EXCEPTION_TYPE_FIELD, "Workflow Exception"); e.replaceItemValue(EXCEPTION_MSG_FIELD, msg); RichTextItem rt = e.createRichTextItem(EXCEPTION_DOCLINK_FIELD); rt.appendDocLink(doc); e.save(); } catch (NotesException e) { e.printStackTrace(); System.out.println(e.text); } }
public static void main(String[] args) throws Exception { // The path to the documents directory. String dataDir = Utils.getDataDir(ConvertFieldsInParagraph.class); Document doc = new Document(dataDir + "TestFile.doc"); // Pass the appropriate parameters to convert all IF fields to static text that are encountered // only in the last // paragraph of the document. FieldsHelper.convertFieldsToStaticText( doc.getFirstSection().getBody().getLastParagraph(), FieldType.FIELD_IF); // Save the document with fields transformed to disk. doc.save(dataDir + "TestFileParagraph Out.doc"); System.out.println("Converted fields in the paragraph with text successfully."); }
/** The main entry point for the application. */ public static void main(String[] args) throws Exception { String dataDir = "src/programmingwithdocuments/workingwithbookmarks/untanglerowbookmarks/data/"; // Load a document. Document doc = new Document(dataDir + "TestDefect1352.doc"); // This perform the custom task of putting the row bookmark ends into the same row with the // bookmark starts. untangleRowBookmarks(doc); // Now we can easily delete rows by a bookmark without damaging any other row's bookmarks. deleteRowByBookmark(doc, "ROW2"); // This is just to check that the other bookmark was not damaged. if (doc.getRange().getBookmarks().get("ROW1").getBookmarkEnd() == null) throw new Exception("Wrong, the end of the bookmark was deleted."); // Save the finished document. doc.save(dataDir + "TestDefect1352 Out.doc"); }
// create an Unplugged user private static void createUser(Database dbUnplugged, String userName, boolean isActive) { Document docUser = null; try { Logger.info("create user document for " + userName); docUser = dbUnplugged.createDocument(); docUser.replaceItemValue("Form", "User"); docUser.replaceItemValue("UserName", userName); docUser.replaceItemValue("Active", (isActive ? "1" : "0")); docUser.computeWithForm(true, true); docUser.save(); } catch (Exception e) { Logger.error(e); } finally { Utils.recycle(docUser); } }
// removes the specified applications for the user from Unplugged @SuppressWarnings("unchecked") public static void deleteApplication(String userName, Vector<String> appPaths) { Session sessionAsSigner = null; Database dbUnplugged = null; Document docUser = null; View vwUsers = null; Name nmUser = null; Document docApp = null; try { Configuration config = Configuration.get(); // open unplugged db sessionAsSigner = Utils.getCurrentSessionAsSigner(); dbUnplugged = sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath()); nmUser = sessionAsSigner.createName(userName); // get all application documents for this user DocumentCollection dcApp = dbUnplugged.search("Form=\"UserDatabase\" & @IsMember(\"" + userName + "\"; UserName)"); Document docTemp = null; int numRemoved = 0; // update app documents docApp = dcApp.getFirstDocument(); while (null != docApp) { String path = docApp.getItemValueString("Path"); if (appPaths.contains(path)) { // remove application Vector<String> appUsers = docApp.getItemValue("UserName"); Logger.debug(nmUser.getCanonical() + " is a user for " + path + " - removing"); appUsers.remove(nmUser.getCanonical()); docApp.replaceItemValue("UserName", appUsers); docApp.computeWithForm(true, true); docApp.save(); numRemoved++; } docTemp = dcApp.getNextDocument(docApp); docApp.recycle(); docApp = docTemp; } if (numRemoved == dcApp.getCount()) { // user removed from all apps - remove user config Logger.info( "Unplugged user " + nmUser.getCanonical() + " removed from all applications - remove user config"); // check for user account vwUsers = dbUnplugged.getView(USERS_VIEW); docUser = vwUsers.getDocumentByKey(nmUser.getAbbreviated(), true); if (docUser != null) { docUser.remove(true); Logger.info("removed Unplugged user " + nmUser.getCanonical()); } } } catch (Exception e) { Logger.error(e); } finally { Utils.recycle(docUser, nmUser, dbUnplugged, sessionAsSigner); } }
/* * Create an Unplugged application definition in the Unplugged database * and add the specified user to it. The user is created if Unplugged * if he doesn't exist yet. */ @SuppressWarnings("unchecked") public static boolean createApplication(String userName, String appPath, boolean isActive) { Session sessionAsSigner = null; Database dbUnplugged = null; Document docApp = null; Document docUser = null; View vwUsers = null; Name nmUser = null; try { String correctedPath = appPath.replace("\\", "/"); Logger.debug("create unplugged application " + correctedPath + " for " + userName); Configuration config = Configuration.get(); // open unplugged db sessionAsSigner = Utils.getCurrentSessionAsSigner(); dbUnplugged = sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath()); // create notes name object for user nmUser = sessionAsSigner.createName(userName); // check if user already exists in Unplugged vwUsers = dbUnplugged.getView(USERS_VIEW); docUser = vwUsers.getDocumentByKey(nmUser.getAbbreviated(), true); if (docUser == null) { // user doesn't exist yet: create Unplugged.createUser(dbUnplugged, nmUser.getCanonical(), isActive); } else if (docUser.getItemValueString("Active").equals("1") && !isActive) { // mark user as inactive docUser.replaceItemValue("Active", "0"); docUser.save(); } else if (!docUser.getItemValueString("Active").equals("1") && isActive) { // mark user as active docUser.replaceItemValue("Active", "1"); docUser.save(); } // check if an app document for this app already exists and create it if not DocumentCollection dcApp = dbUnplugged.search("Form=\"UserDatabase\" & Path=\"" + correctedPath + "\""); if (dcApp.getCount() == 0) { // create new app document Logger.debug("application not found: create new"); docApp = dbUnplugged.createDocument(); docApp.replaceItemValue("form", "UserDatabase"); docApp.replaceItemValue("Path", correctedPath); } else { // update existing app document docApp = dcApp.getFirstDocument(); } Vector<String> appUsers = docApp.getItemValue("UserName"); if (!appUsers.contains(nmUser.getCanonical())) { Logger.debug(nmUser.getCanonical() + " not in list of application users: adding"); appUsers.add(nmUser.getCanonical()); docApp.replaceItemValue("UserName", appUsers); docApp.replaceItemValue("Active", "1"); docApp.computeWithForm(true, true); docApp.save(); } Logger.debug("done"); } catch (NotesException e) { Logger.error(e); } finally { Utils.recycle(docUser, docApp, nmUser, dbUnplugged); } return true; }