Exemplo n.º 1
0
 /**
  * Convert a <code>QName</code> to a qualified name, as used by DOM and SAX. The returned string
  * has a format of <code>prefix:localName</code> if the prefix is set, or just <code>localName
  * </code> if not.
  *
  * @param qName the <code>QName</code>
  * @return the qualified name
  */
 protected String toQualifiedName(QName qName) {
   String prefix = qName.getPrefix();
   if (!StringUtils.hasLength(prefix)) {
     return qName.getLocalPart();
   } else {
     return prefix + ":" + qName.getLocalPart();
   }
 }
Exemplo n.º 2
0
 /**
  * Starts the prefix mapping for the given prefix.
  *
  * @see org.xml.sax.ContentHandler#startPrefixMapping(String, String)
  */
 protected void startPrefixMapping(String prefix, String namespace) throws SAXException {
   if (getContentHandler() != null) {
     if (prefix == null) {
       prefix = "";
     }
     if (!StringUtils.hasLength(namespace)) {
       return;
     }
     if (!namespace.equals(namespaces.get(prefix))) {
       getContentHandler().startPrefixMapping(prefix, namespace);
       namespaces.put(prefix, namespace);
     }
   }
 }
Exemplo n.º 3
0
 /**
  * Copy field value form source to destination, not include specify field name
  *
  * <p>Final & static field are excluded
  *
  * @param <E>
  * @param source source object
  * @param dest destination object
  * @param excludedFieldName field name specify for not included
  * @return
  */
 public static <E extends Object> E copy(Object source, E dest, String... excludedFieldName) {
   if (source == null || dest == null) {
     return null;
   }
   Field[] fields = ClassUtils.getNoStaticNorFinalFieldArray(source);
   try {
     if (ClassUtils.isSameType(source, dest)) { // same type object
       for (Field field : fields) {
         field.setAccessible(true);
         if (StringUtils.isInList(field.getName(), excludedFieldName)) { // filter
           continue;
         }
         field.set(dest, field.get(source));
       }
     } else {
       for (Field field : fields) {
         field.setAccessible(true);
         if (StringUtils.isInList(field.getName(), excludedFieldName)) { // filter
           continue;
         }
         Field destField = null;
         try {
           destField = dest.getClass().getDeclaredField(field.getName());
         } catch (NoSuchFieldException e) {
         }
         if (destField != null) {
           destField.setAccessible(true);
           destField.set(dest, field.get(source));
         }
       }
     }
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   return dest;
 }
Exemplo n.º 4
0
 /**
  * Return standard JavaBean get Method Name
  *
  * <p>etc. input: 'age' output: 'getAge'
  *
  * @param field
  * @return
  */
 public static String getGetMethodName(String field) {
   return "get" + StringUtils.firstLetterUpper(field);
 }