Source Code Cross Referenced for XmlValidator.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » metaobj » shared » control » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » sakai » org.sakaiproject.metaobj.shared.control 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/shared/control/XmlValidator.java $
003:         * $Id: XmlValidator.java 14230 2006-09-05 18:02:51Z chmaurer@iupui.edu $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.metaobj.shared.control;
021:
022:        import java.util.Iterator;
023:        import java.util.List;
024:
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:        import org.sakaiproject.component.cover.ComponentManager;
028:        import org.sakaiproject.metaobj.shared.mgt.StructuredArtifactValidationService;
029:        import org.sakaiproject.metaobj.shared.model.ElementBean;
030:        import org.sakaiproject.metaobj.shared.model.ValidationError;
031:        import org.sakaiproject.metaobj.utils.mvc.impl.ValidatorBase;
032:        import org.springframework.validation.Errors;
033:
034:        public class XmlValidator extends ValidatorBase {
035:            protected final Log logger = LogFactory.getLog(getClass());
036:            protected String parentPrefix = "";
037:
038:            //private FileNameValidator fileNameValidator;
039:
040:            public XmlValidator() {
041:            }
042:
043:            public XmlValidator(String parentPrefix) {
044:                this .parentPrefix = parentPrefix;
045:            }
046:
047:            public boolean supports(Class clazz) {
048:                return (ElementBean.class.isAssignableFrom(clazz));
049:            }
050:
051:            public void validate(Object obj, Errors errors) {
052:                validate(obj, errors, false);
053:            }
054:
055:            public void validate(Object obj, Errors errors,
056:                    boolean checkListNumbers) {
057:                ElementBean elementBean = (ElementBean) obj;
058:
059:                StructuredArtifactValidationService service = getStructuredArtifactValidationService();
060:                List errorList = service.validate(elementBean);
061:
062:                for (Iterator i = errorList.iterator(); i.hasNext();) {
063:                    ValidationError error = (ValidationError) i.next();
064:                    errors.rejectValue(error.getFieldName(), error
065:                            .getErrorCode(), error.getErrorInfo(), error
066:                            .getDefaultMessage());
067:                }
068:            }
069:
070:            protected StructuredArtifactValidationService getStructuredArtifactValidationService() {
071:                return (StructuredArtifactValidationService) ComponentManager
072:                        .getInstance().get(
073:                                StructuredArtifactValidationService.class);
074:            }
075:
076:            /*
077:            protected void validateDisplayName(ElementBean elementBean, Errors errors) {
078:               // don't care about display name here
079:            }
080:
081:            protected void validateElement(Element rootElement, SchemaNode childSchema,
082:                                           Object value, Errors errors) {
083:               validateChildElement(rootElement.getChild(childSchema.getName()),
084:                  childSchema, value, errors);
085:            }
086:
087:
088:            protected void validateChildElement(Element childElement, SchemaNode childSchema,
089:                                              Object value, Errors errors) {
090:               if (childElement != null) {
091:                  String stringValue = null;
092:                  if (value != null && value instanceof String) {
093:                     stringValue = (String) value;
094:                     value = childSchema.getActualNormalizedValue(stringValue);
095:                  }
096:
097:                  childElement.setText(childSchema.getSchemaNormalizedValue(value));
098:               } else if (childSchema.getMinOccurs() > 0) {
099:                  errors.rejectValue(childSchema.getName(),
100:                     "required value {0}",
101:                     new Object[]{childSchema.getName()},
102:                     MessageFormat.format("required value {0}", new Object[]{childSchema.getName()}));
103:               }
104:            }
105:
106:            protected boolean checkWrappedField(SchemaNode childSchema, ElementBean elementBean, Errors errors) {
107:
108:               Class childClass = elementBean.getType(childSchema.getName());
109:               Object value = elementBean.get(childSchema.getName());
110:
111:               if (!(value instanceof FieldValueWrapper)) {
112:                  return false;
113:               }
114:
115:               FieldValueWrapper beanValue = (FieldValueWrapper) elementBean.get(childSchema.getName());
116:
117:               if (beanValue.getValue() == null) {
118:                  if (childSchema.getMinOccurs() > 0) {
119:                     throw new NormalizationException("Required field", "required field {0}",
120:                        new Object[]{childSchema.getName()});
121:                  } else {
122:                     elementBean.getBaseElement().removeChild(childSchema.getName());
123:                     return true;
124:                  }
125:               }
126:
127:               // check date...
128:               this.pushNestedPath(childSchema.getName(), errors);
129:               beanValue.validate(errors);
130:               this.popNestedPath(errors);
131:
132:               Element dateElement = elementBean.getBaseElement().getChild(childSchema.getName());
133:
134:               if (dateElement == null) {
135:                  dateElement = new Element(childSchema.getName());
136:                  elementBean.getBaseElement().addContent(dateElement);
137:               }
138:               dateElement.setText(childSchema.getSchemaNormalizedValue(beanValue.getValue()));
139:
140:               return true;
141:            }
142:
143:            //   public FileNameValidator getFileNameValidator() {
144:            //      return fileNameValidator;
145:            //   }
146:            //
147:            //   public void setFileNameValidator(FileNameValidator fileNameValidator) {
148:            //      this.fileNameValidator = fileNameValidator;
149:            //   }
150:
151:             */
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.