📄 copytree_engine.java
字号:
int parentPageID = pSrv.lookupPage(pageID).getParentID(); if(pageID == sourcePage.getID()) { parentPageID = targetPage.getID(); } record[0] = pageID; record[1] = parentPageID; record[2] = 0; treeList.add(record); } makeTree( treeList, homePageIDObj.intValue(), null, new Vector(), engineMap, MOVE_OPERATION, jParams.getUser() ); Vector tmpTreeData = (Vector) engineMap.get("tmpTreeData"); Vector previewMoveTreeData = tmpTreeData; engineMap.put("previewMoveTreeData", previewMoveTreeData); toDebug("CopyTree_Engine :: prepareMovePreview - return "); return true; } // end prepareMovePreview /*** * prepare a preview for a copy tree operation * * @param jParams a ParamBean object * @param engineMap the engine context * @param sourcePage the <code>JahiaPage</code> object to be copied * @param targetPage the <code>JahiaPage</code> to be made parent of the top copied page * */ private boolean prepareCopyPreview( ParamBean jParams, HashMap engineMap, JahiaPage sourcePage, JahiaPage targetPage ) throws JahiaException { toDebug(">> CopyTree_Engine :: prepareCopyPreview"); String errorMsg = (String) engineMap.get("errorMsg"); JahiaData jData = (JahiaData) engineMap.get("jData");// save this for when we make the engine available from outside the target page.../* if(targetPageID == null) { errorMsg = "No target page selected"; engineMap.put("errorMsg", errorMsg); return false; } else { engineMap.put("errorMsg", null); }*/ Integer homePageIDObj = (Integer) engineMap.get("homePageID"); Integer maxLevels = (Integer) engineMap.get("maxLevels"); if(maxLevels == null) { errorMsg = "Levels to copy must be a number"; engineMap.put("errorMsg", errorMsg); return false; } else { engineMap.put("errorMsg", null); } // build the treeList ( a Vector of {int pageID, int parentPageID} ) Vector treeList = new Vector(); Vector tmpNewBranch = new Vector(); Vector newBranch = new Vector(); Vector treeData = (Vector) engineMap.get("tmpTreeData"); HashMap tslMap = new HashMap(); HashMap revTslMap = new HashMap(); Enumeration treeDataEnum = treeData.elements(); // treeList : array of record[] = { int pageID, int parentPageID, int origPageID } while(treeDataEnum.hasMoreElements()) { int[] record = new int[3]; HashMap lineMap = (HashMap) treeDataEnum.nextElement(); Integer pageIDObj = (Integer)lineMap.get("pageID"); int pageID = pageIDObj.intValue(); int parentPageID = pSrv.lookupPage(pageID).getParentID(); record[0] = pageID; record[1] = parentPageID; record[2] = 0; treeList.add(record); // build the newBranch // process grafted PAGE -- direct addition to treeList // treeList : array of record[] = { int pageID, int parentPageID, int origPageID } if(pageID == sourcePage.getID()) { tslMap.put(new Integer(pageID + 1000), new Integer(pageID)); revTslMap.put(new Integer(pageID), new Integer(pageID + 1000)); int[] newsourcerecord = new int[3]; newsourcerecord[0] = pageID + 1000; // new pageID newsourcerecord[1] = targetPage.getID(); // new parentPageID newsourcerecord[2] = pageID; // orig pageID treeList.add(newsourcerecord); // process grafted SUBTREE -- indirect addition to treeList : temporaryBranch before parentID translation // tslMap : key = copied pageID, value = original pageID // tmprecord : array of tmprecord[] = { int newPageID, int origPageID, int origParentPageID } } else if(isPageInPath(sourcePage.getID(), pageID)) { if( (getLevelsBetween(sourcePage.getID(), pageID)) <= maxLevels.intValue() ) { tslMap.put(new Integer(pageID + 1000), new Integer(pageID)); revTslMap.put(new Integer(pageID), new Integer(pageID + 1000)); int[] tmprecord = new int[3]; tmprecord[0] = pageID + 1000; // new pageID tmprecord[1] = pageID; // orig pageID tmprecord[2] = parentPageID; // orig parentPageID tmpNewBranch.add(tmprecord); } } } // insert tslMap into engineMap engineMap.put("tslMap", tslMap); engineMap.put("revTslMap", revTslMap); // insert new records with translated parentPageID Enumeration tmpNewBranchEnum = tmpNewBranch.elements(); while(tmpNewBranchEnum.hasMoreElements()) { int[] tmprecord = (int[]) tmpNewBranchEnum.nextElement(); Integer newPageIDObj = new Integer(tmprecord[0]); Integer origPageIDObj = new Integer(tmprecord[1]); Integer origParentPageIDObj = new Integer(tmprecord[2]); if(revTslMap.containsKey(origParentPageIDObj)) { int[] record = new int[3]; record[0] = tmprecord[0]; // carry over new pageID record[1] = ((Integer)revTslMap.get(origParentPageIDObj)).intValue(); // translate parentPageID record[2] = tmprecord[1]; // note original pageID treeList.add(record); } } makeTree( treeList, homePageIDObj.intValue(), null, new Vector(), engineMap, COPY_OPERATION, jParams.getUser() ); Vector tmpTreeData = (Vector) engineMap.get("tmpTreeData"); Vector previewCopyTreeData = tmpTreeData; engineMap.put("previewCopyTreeData", previewCopyTreeData); toDebug(">> CopyTree_Engine :: prepareCopyPreview - return "); return true; } // end prepareCopyPreview /*** * call the appropriate method to execute the copy or move * * @param jParams a ParamBean object * @param engineMap a HashMap populated with the engine context * @return true on success, false otherwise */ public boolean execute( ParamBean jParams, HashMap engineMap ) throws JahiaException { return execute( jParams, engineMap, false ); } /*** * call the appropriate method to execute the copy or move * * @param jParams a ParamBean object * @param engineMap a HashMap populated with the engine context * @param isPreview <code>true</code> to generate a preview, <code>false</code> to save the tree modification * @return true on success, false otherwise */ public boolean execute( ParamBean jParams, HashMap engineMap, boolean isPreview ) throws JahiaException { String errorMsg = ""; Integer sourcePageIDObj = (Integer) engineMap.get(SOURCEPAGE_ID); Integer targetPageIDObj = (Integer) engineMap.get("targetPageID"); int sourcePageID = -1; int targetPageID = -1; JahiaPage sourcePage = null; JahiaPage targetPage = null; boolean result = false; // check validity if(targetPageIDObj == null) { errorMsg = "No target page selected"; } else { try { targetPage = pSrv.lookupPage(targetPageIDObj.intValue()); } catch (NumberFormatException nfe) { errorMsg = "Invalid target page reference"; } catch (JahiaException je) { errorMsg = "Invalid target page"; } } if(sourcePageIDObj == null) { errorMsg = "No source page selected"; } else { try { sourcePage = pSrv.lookupPage(sourcePageIDObj.intValue()); } catch (NumberFormatException nfe) { errorMsg = "Invalid source page reference"; } catch (JahiaException je) { errorMsg = "Invalid source page"; } } if ((sourcePage != null) && (targetPage != null)) { String operationStr = (String) engineMap.get("operation"); if(operationStr.equals(COPY_OPERATION)) { if(isPreview) { if(prepareCopyPreview(jParams, engineMap, sourcePage, targetPage)) { result = true; } } else { if(executeCopy(jParams, engineMap, sourcePage, targetPage)) { result = true; } } } else { if(isPreview) { if(prepareMovePreview(jParams, engineMap, sourcePage, targetPage)) { result = true; } } else { if(executeMove(jParams, engineMap, sourcePage, targetPage)) { result = true; } } } } engineMap.put("errorMsg", errorMsg); return result; } // end execute /*** * execute the page/tree move * * @param jParams a ParamBean object * @param engineMap the engine context * @param sourcePage the <code>JahiaPage</code> object to be moved * @param targetPage the <code>JahiaPage</code> to be made parent of the moved page * @return true on success, false otherwise */ private boolean executeMove( ParamBean jParams, HashMap engineMap, JahiaPage sourcePage, JahiaPage targetPage ) throws JahiaException { JahiaData jData = (JahiaData) engineMap.get("jData"); JahiaBaseACL sourceACL = sourcePage.getACL(); int newParentAclID = targetPage.getACL().getID(); if(sourcePage == null) { return false; } // get a reference to the navigation menu in the OLD parent page int[] directLink = getDirectLink( sourcePage.getParentID(), sourcePage.getID() ); int linkContainerID = directLink[0]; int linkFieldID = directLink[1]; if( (linkContainerID == 0) || (linkFieldID == 0) ) { return false; } JahiaField linkField = (JahiaField) fldSrv.loadField(linkFieldID, jParams); JahiaPage linkPage = (JahiaPage) linkField.getObject(); if(linkField == null) { return false; } // unlink the field serving as navigation link on old parent page // from the moved page linkField.setObject( null ); sReg.getJahiaFieldService().saveField(linkField, 0, jParams); // delete container serving as navigation link on old parent page sReg.getJahiaContainersService().deleteContainer(linkContainerID, jParams); // actually move the page... JahiaPage movedPage = pSrv.lookupPage(linkPage.getID()); if(movedPage == null) { return false; } movedPage = pSrv.setParentPageID(targetPage.getID(), sourcePage); /** * @todo This is probably very wrong... We should have the parent ACL * point to the parent field, NOT the parent page. */ sourceACL.setParentID(newParentAclID); movedPage.commitChanges(true); engineMap.put("movedPageID", new Integer(sourcePage.getID())); return true; } // end executeMove /*** * execute the page/tree copy * * @param jParams a ParamBean object * @param engineMap the engine context * @param sourcePage the <code>JahiaPage</code> object to be copied * @param targetPage the <code>JahiaPage</code> to be made parent of the top copied page * @return true on success, false otherwise */ private boolean executeCopy( ParamBean jParams, HashMap engineMap, JahiaPage sourcePage, JahiaPage targetPage ) throws JahiaException { toDebug(">> CopyTree_Engine :: executeCopy"); String errorMsg = "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -