📄 containerlistproperties_engine.java
字号:
/*** * get the date in millisecond * * * @param cursorField the number of the field into the container * * @param theContainer the container in which get the fieldInfo * */ private String getSortInfo4Date( int cursorField, JahiaContainer theContainer, ParamBean jParams ) throws JahiaException { String sortInfo = null; int counter = 0; Enumeration fList = theContainer.getFields(); while (fList.hasMoreElements()) { JahiaField f = (JahiaField) fList.nextElement(); //f = ServicesRegistry.getInstance(). //getJahiaFieldService().loadField( f.getID(), LoadFlags.ALL, jParams ); if (counter == cursorField) { if (f.getType() == 4) { sortInfo = (String)f.getObject(); } } counter++; } return sortInfo; } // end getSortInfo4Date /*** * sort the containers and the fieldInfoToDisplay vector * * The vector "containers" contains * all the containers of the container list. * The vector "fieldInfoToDisplay" contains * the fields values on which the sort is done. * a value in "fieldInfoToDisplay" correspond to * the container at the same index into "containers". * * @param jParams a ParamBean object * (with request and response) * @param engineMap then engine map, to be forwarded * to the JSP file * @param containerSort How to sort the containers * (alphabetically or order of insertion, * ascending or descending) */ private void shell_sort(ParamBean jParams, HashMap engineMap, String containerSort) throws JahiaException { Vector containers = (Vector)engineMap.get("containers"); Vector fieldInfoToDisplay = (Vector)engineMap.get("fieldInfoToDisplay"); Vector sortInfo4Date = (Vector)engineMap.get("sortInfo4Date"); int n = containers.size(); int incr; int j; JahiaContainer c = null; String str= ""; boolean flag = false; for (incr = n/2; incr >0; incr = incr/2) { for (int i = incr; i<n; i++) { c = (JahiaContainer)containers.get(i); str = (String)fieldInfoToDisplay.get(i); String str2 = ""; String str4Test = str; String str4Test2 = ""; if (sortInfo4Date != null && !sortInfo4Date.isEmpty()) { str2 = (String)sortInfo4Date.get(i); str4Test = str2; //System.out.println("sort date "+str+" : "+str2); } for (j = i; j>=incr; j= j- incr) { if (containerSort.equals("insertAsc")) { if ( c.getID() < ( (JahiaContainer)containers.get(j-incr) ).getID() ) { flag = true; } else { flag = false; } } else if (containerSort.equals("insertDesc")) { if ( c.getID() >= ( (JahiaContainer)containers.get(j-incr) ).getID() ) { flag = true; } else { flag = false; } } else if (containerSort.equals("alphAsc")) { str4Test2 = (String)fieldInfoToDisplay.get(j-incr); if (sortInfo4Date != null && !sortInfo4Date.isEmpty()) { str4Test2 = (String)sortInfo4Date.get(j-incr); } try { Double d1 = new Double(str4Test); Double d2 = new Double(str4Test2); int comp2 = d1.compareTo(d2); if ( comp2 < 0 ) { flag = true; } else { flag = false; } } catch (NumberFormatException e) { String value = (String)fieldInfoToDisplay.get(j-incr); try { str = (new RE("<(.*?)>")).subst(str,""); value = (new RE("<(.*?)>")).subst(value,""); } catch (RESyntaxException re) { JahiaConsole.println("ContainerListProperties_Engine.shell_sort",re.toString()); } catch (Throwable t) { JahiaConsole.println("ContainerListProperties_Engine.shell_sort",t.toString()); } int comp = str.compareToIgnoreCase( value ); if ( comp < 0 ) { flag = true; } else { flag = false; } } } else if (containerSort.equals("alphDesc")) { str4Test2 = (String)fieldInfoToDisplay.get(j-incr); if (sortInfo4Date != null && !sortInfo4Date.isEmpty()) { str4Test2 = (String)sortInfo4Date.get(j-incr); } try { Double d1 = new Double(str4Test); Double d2 = new Double(str4Test2); int comp2 = d1.compareTo(d2); if ( comp2 >= 0 ) { flag = true; } else { flag = false; } } catch (NumberFormatException e) { int comp = str.compareToIgnoreCase( (String)fieldInfoToDisplay.get(j-incr) ); if ( comp >= 0 ) { flag = true; } else { flag = false; } } } if ( flag ) { containers.set(j,containers.get(j-incr)); fieldInfoToDisplay.set(j,fieldInfoToDisplay.get(j-incr)); if (sortInfo4Date != null && !sortInfo4Date.isEmpty()) { sortInfo4Date.set(j,sortInfo4Date.get(j-incr)); } } else { break; } } containers.set(j,c); fieldInfoToDisplay.set(j,str); if (sortInfo4Date != null && !sortInfo4Date.isEmpty()) { sortInfo4Date.set(j,str2); } } } engineMap.put("fieldInfoToDisplay", fieldInfoToDisplay); engineMap.put("sortInfo4Date", sortInfo4Date); engineMap.put("containers", containers); }// end shell_sort //-------------------------------------------------------------------------- /*** * composes the hashmap that contains the pair (String fieldDefName, Integer aclID) * * @param JahiaContainerList cList, the container list * @param ParamBean jParam, the parambean that contains reference to the page * @param HashMap EngineMap, needed to store the first field def name as "fieldAclDefaultField" attribute * @return HashMap * @author NK */ private HashMap buildFieldDefAcls( JahiaContainerList cList, ParamBean jParams , HashMap engineMap ) throws JahiaException { HashMap hash = new HashMap(); if ( cList == null || jParams.getPage()==null ) return hash; JahiaContainer theContainer = null; Enumeration enum = cList.getContainers(); if ( enum.hasMoreElements() ) theContainer = (JahiaContainer)enum.nextElement(); // get the first available ctn. if ( theContainer == null ) return hash; String prop = null; boolean done = false; JahiaField aField = null; JahiaFieldDefinition theDef = null; Enumeration fList = theContainer.getFields(); while (fList.hasMoreElements()) { aField = (JahiaField) fList.nextElement(); theDef = aField.getDefinition(); if ( theDef != null ){ prop = cList.getProperty("view_field_acl_"+theDef.getName()); if ( prop != null ){ try { int aclID = Integer.parseInt(prop); hash.put(theDef.getName(),new Integer(aclID)); if ( !done ){ engineMap.put("fieldAclDefaultField",theDef.getName()); done = true; } } catch ( Throwable t ){ JahiaConsole.println(CLASS_NAME+".buildFieldDefAcls()", " requested acl ( view_field_acl_" + theDef.getName() + "), fail "); } } else { // create the acl, because field declaration can change in template JahiaBaseACL newAcl = null; newAcl = new JahiaBaseACL (); newAcl.create(cList.getAclID()); cList.setProperty("view_field_acl_"+theDef.getName(), String.valueOf(newAcl.getID()) ); ServicesRegistry.getInstance(). getJahiaContainersService().saveContainerListInfo(cList, jParams.getPage().getAclID() ); hash.put(theDef.getName(), new Integer(newAcl.getID())); if ( !done ){ engineMap.put("fieldAclDefaultField",theDef.getName()); done = true; } } } } JahiaConsole.println(CLASS_NAME+".buildFieldDefAcls","Returned hashMap"); theContainer = null; return hash; }} // end ContainerListProperties_Engine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -