📄 copytree_engine.java
字号:
/*** * get the container list holding the structural navigation menu in a given page * * @param targetPageID the ID of the page to find the menu on * @param jData * @return the ContainerList holding the menu */ private JahiaContainerList getTargetCList( int targetPageID, JahiaData jData ) throws JahiaException { return jData.containers().getAbsoluteContainerList( "jahialinks", targetPageID ); } // end getTargetClist /*** * get the container holding the direct link to a given page * * @param parentPageID the ID of the page to find the menu on * @param childPageID the ID of the child page the link points to * @return an array of int[] {linkContainerID, linkFieldID} */ private int[] getDirectLink( int parentPageID, int childPageID ) throws JahiaException { int linkFieldID = 0; int linkContainerID = 0; String childPageIDStr = new Integer(childPageID).toString(); JahiaPage parentPage = pSrv.lookupPage(parentPageID); if(parentPage == null) { return new int[] {0,0}; } // get all the container IDs in the parent page Vector pageContainerIDs = new Vector(); Vector cListsIDs = ctnSrv.getContainerListIDsInPage(parentPage); if(cListsIDs != null) { Enumeration cListsIDsEnum = cListsIDs.elements(); while(cListsIDsEnum.hasMoreElements()) { int listID = ((Integer)cListsIDsEnum.nextElement()).intValue(); Vector containerIDs = ctnSrv.getctnidsInList(listID); pageContainerIDs.addAll(containerIDs); } } Enumeration pageContainerIDsEnum = pageContainerIDs.elements(); while(pageContainerIDsEnum.hasMoreElements()) { int ctnID = ((Integer)pageContainerIDsEnum.nextElement()).intValue(); Vector fieldIDs = ctnSrv.getFieldIDsInContainer(ctnID); Enumeration fieldIDsEnum = fieldIDs.elements(); while(fieldIDsEnum.hasMoreElements()) { int fieldID = ((Integer)fieldIDsEnum.nextElement()).intValue(); JahiaField field = fldSrv.loadField(fieldID); if((field.getType() == FieldTypes.PAGE) && field.getValue().equals(childPageIDStr)) { linkContainerID = ctnID; linkFieldID = fieldID; } } } return new int[] {linkContainerID, linkFieldID}; } // end getDirectLink /*** * given a page ID, return the page title * * @param pageID the page ID, as an <code>int</code> * @return the page title, or "Undefined page" if lookup fails */ private String getPageTitle(int pageID) throws JahiaException { String pageTitle = "Undefined page"; JahiaPage page = pSrv.lookupPage(pageID); if(page != null) { pageTitle = page.getTitle(); } return pageTitle; } // end getPageTitle /*** * given a page ID, return the page title * * @param pageIDInt the page ID, as an <code>Integer</code> * @return the page title, or "Undefined page" if lookup fails */ private String getPageTitle(Integer pageIDInt) throws JahiaException { return getPageTitle(pageIDInt.intValue()); } // end getPageTitle /*** * given a page ID (as a <code>String</code>), return the page title * * @param pageIDStr the page ID, as a <code>String</code> * @return the page title, or "Undefined page" if lookup fails */ private String getPageTitle(String pageIDStr) throws JahiaException { String pageTitle = "Undefined page"; try { pageTitle = getPageTitle(Integer.parseInt(pageIDStr)); } catch(Throwable t) { // do nothing... } return pageTitle; } // end getPageTitle //------------------------------------------------------------------------- private Vector drawSubTree( HashMap engineMap, GenericTree tree, Vector out, Vector addBefore, boolean isRoot, boolean isLast ) throws JahiaException { HashMap lineMap = new HashMap(); GenericTree siteTree = (GenericTree) engineMap.get("siteTree" );// GenericTree targetBranch = (GenericTree) engineMap.get("targetBranch"); JahiaUser theUser = (JahiaUser) engineMap.get("theUser" ); Integer targetPageIDObj = (Integer) engineMap.get("targetPageID"); Integer sourcePageIDObj = (Integer) engineMap.get(SOURCEPAGE_ID); String operation = (String) engineMap.get("operation" ); if (siteTree == null) {toDebug("CopyTree_Engine :: drawSubTree :: siteTree is NULL"); return null;}// if (targetBranch == null) {toDebug("CopyTree_Engine :: drawSubTree :: targetBranch is NULL"); return null;} if (theUser == null) {toDebug("CopyTree_Engine :: drawSubTree :: theUser is NULL"); return null;} if (targetPageIDObj == null) {toDebug("CopyTree_Engine :: drawSubTree :: targetPageIDObj is NULL"); return null;} int targetPageID = targetPageIDObj.intValue(); lineMap.put("spacer", addBefore); int size = tree.getChildren().size(); JahiaTreeViewPageWrapper page = (JahiaTreeViewPageWrapper) tree.getRoot().getData(); // // check selectability... //// boolean isInTargetSubTree = siteTree.isInSubTree(targetBranch, page.getID(), "org.jahia.services.pages.JahiaTreeViewPageWrapper"); boolean isInTargetPath = isPageInPath(page.getID(), targetPageID); boolean isTargetChild = (page.getPage().getParentID() == targetPageID); boolean hasWriteAccess = page.getPage().checkWriteAccess(theUser); boolean hasReadAccess = page.getPage().checkReadAccess(theUser); boolean selectable = false; boolean isTargetPage = (page.getID() == targetPageID); boolean isPreviousSource = false; if(sourcePageIDObj != null) { isPreviousSource = (page.getID() == sourcePageIDObj.intValue()); } if(operation.equals(MOVE_OPERATION)) { if( !isInTargetPath && !isTargetChild && hasWriteAccess ) { selectable = true; } } else if (operation.equals(COPY_OPERATION)) { if( !isInTargetPath && hasReadAccess && !isTargetPage ) { selectable = true; } } else if(operation.equals(LINK_OPERATION)) { selectable = true; } else if(operation.equals(CHOOSE_OPERATION)) { selectable = true; } if (isRoot) { // do nothing... } else if (isLast) { if (page.isTerminal()) { lineMap.put("plug", "lastnode.gif"); lineMap.put("anchor", null); } else if (page.isExpanded()) { lineMap.put("plug", "lastnodeminus.gif"); lineMap.put("anchor", new Boolean(false)); } else { lineMap.put("plug", "lastnodeplus.gif"); lineMap.put("anchor", new Boolean(true)); } } else { if (page.isTerminal()) { lineMap.put("plug", "node.gif"); lineMap.put("anchor", null); } else if (page.isExpanded()) { lineMap.put("plug", "nodeminus.gif"); lineMap.put("anchor", new Boolean(false)); } else { lineMap.put("plug", "nodeplus.gif"); lineMap.put("anchor", new Boolean(true)); } } lineMap.put( "selectable", new Boolean(selectable) ); lineMap.put( "isPreviousSource", new Boolean(isPreviousSource) ); lineMap.put( "isTargetPage", new Boolean(isTargetPage) ); lineMap.put( "page", page ); out.add(lineMap); if (page.isExpanded()) { for (int i = 0; i < size; i++) { Vector add = (Vector) addBefore.clone(); GenericTree child = (GenericTree) tree.getChildren().get(i); if (!isLast) { add.add("vertline.gif"); } else if (!isRoot) { add.add("blank.gif"); } JahiaTreeViewPageWrapper childRoot = (JahiaTreeViewPageWrapper) child.getRoot().getData(); drawSubTree( engineMap, child, out, add, false, ((i+1) == size)); } } return out; } //-------------------------------------------------------------------------- /** * expand the top tree if needed to display the currently selected source page * * @author Khue Nguyen */ private void expandSourcePageBranch(int sourcePageID, GenericTree tree, ParamBean jParams) throws JahiaException { JahiaConsole.println(CLASS_NAME+".expandSourcepageBranch","sourcePageID="+sourcePageID); if ( tree == null ) return; JahiaPageService pageServ = ServicesRegistry.getInstance().getJahiaPageService(); if (pageServ == null) { throw new JahiaException (CLASS_NAME+".expandSourcePageBranch", "Page service not available.", JahiaException.SERVICE_ERROR, JahiaException.CRITICAL); } Vector parents = pageServ.getPagePath (sourcePageID, jParams); if ( parents == null ) return; int size = parents.size(); JahiaPage page = null; GenericTree subTree = null; JahiaTreeViewPageWrapper pageWrapper = null; Node node = null; for ( int i=0 ; i<size ; i++ ){ page = (JahiaPage)parents.get(i); JahiaConsole.println(CLASS_NAME+".expandSourcepageBranch"," process parent "+page.getID()); subTree = tree.getSubTree(page.getID(), "org.jahia.services.pages.JahiaTreeViewPageWrapper"); if (subTree != null) { node = subTree.getRoot(); if (node != null) { pageWrapper = (JahiaTreeViewPageWrapper) node.getData(); if ( !pageWrapper.isExpanded() ){ JahiaConsole.println(CLASS_NAME+".expandSourcepageBranch"," process parent wrapper "+pageWrapper.getID() + " is not expanded"); // let's expand this parent pageWrapper.expand(); if(subTree.getChildren().size() == 0) { JahiaConsole.println(CLASS_NAME+".expandSourcepageBranch"," process parent wrapper "+pageWrapper.getID() + " has no child"); tree = tSrv.extendTree(pageWrapper.getID(), tree, PageLoadFlags.DIRECT, 4, jParams); } } } } } } //------------------------------------------------------------------------- private synchronized void toDebug (String message) { if (true) { JahiaConsole.println (message, ""); } }} // end class CopyTree_Engine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -