CmpDisplayViewAnalyzing.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package com.kingdee.shr.customer.gtiit.helper;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.LinkedHashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import org.dom4j.Document;
  8. import org.dom4j.DocumentException;
  9. import org.dom4j.DocumentHelper;
  10. import org.dom4j.Element;
  11. import com.google.common.collect.Maps;
  12. import com.kingdee.bos.Context;
  13. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  14. import com.kingdee.shr.base.syssetting.web.dynamic.model.FieldInfo;
  15. import com.kingdee.shr.base.syssetting.web.dynamic.model.UIViewInfo;
  16. import com.kingdee.shr.base.syssetting.web.dynamic.util.UIViewUtil;
  17. public class CmpDisplayViewAnalyzing {
  18. public static List<FieldInfo> getAdjSalaryApplyListFields(Context ctx, String display) throws SHRWebException {
  19. UIViewInfo uiViewInfo = UIViewUtil.getUIViewInfoByUIPK(ctx, display);
  20. if (uiViewInfo == null)
  21. return null;
  22. String content = uiViewInfo.getContent();
  23. List<FieldInfo> fields = null;
  24. try {
  25. fields = parseFieldByUIViewContent(content);
  26. } catch (DocumentException e) {
  27. throw new SHRWebException(e);
  28. }
  29. return fields;
  30. }
  31. public static List<FieldInfo> parseFieldByUIViewContent(String content) throws DocumentException {
  32. List<FieldInfo> fields = new ArrayList<>();
  33. Document doc = DocumentHelper.parseText(content);
  34. Element root = doc.getRootElement();
  35. Element body = root.element("body");
  36. List<Element> elements = body.elements("field");
  37. if (elements == null || elements.size() == 0)
  38. return fields;
  39. fields = parseFields(elements);
  40. return fields;
  41. }
  42. public static List<FieldInfo> parseFields(List<Element> elements) {
  43. List<FieldInfo> fields = new ArrayList<>();
  44. for (Element element : elements) {
  45. FieldInfo field = new FieldInfo();
  46. field.setName(element.attributeValue("name"));
  47. field.setAlias(element.attributeValue("label"));
  48. field.setType(element.attributeValue("type"));
  49. Map<String, String> attributes = new HashMap<>();
  50. attributes.put("required", element.attributeValue("required"));
  51. attributes.put("frozen", element.attributeValue("frozen"));
  52. attributes.put("filter", element.attributeValue("filter"));
  53. field.setAttributes(attributes);
  54. fields.add(field);
  55. }
  56. return fields;
  57. }
  58. public static Map<String, Map<String, Boolean>> complementDefaultField(Context ctx, String display) throws SHRWebException {
  59. List<FieldInfo> listFields = getAdjSalaryApplyListFields(ctx, display);
  60. if (listFields == null)
  61. return null;
  62. Map<String, Map<String, Boolean>> attrMap = new LinkedHashMap<>();
  63. for (FieldInfo listField : listFields) {
  64. String type = listField.getType();
  65. Map<String, String> attributes = listField.getAttributes();
  66. Map<String, Boolean> valueMap = Maps.newHashMap();
  67. if (type != null && type.equals("hidden"))
  68. valueMap.put("hidden", Boolean.TRUE);
  69. if ("true".equalsIgnoreCase(attributes.get("frozen")))
  70. valueMap.put("frozen", Boolean.TRUE);
  71. if ("true".equalsIgnoreCase(attributes.get("required")))
  72. valueMap.put("required", Boolean.TRUE);
  73. attrMap.put(listField.getName(), valueMap);
  74. }
  75. return attrMap;
  76. }
  77. }