Exemple #1
0
 /**
  * Build CSS Style Sheet content of the <code>element</code> Object by using {@link CSSEngine}
  * engine configuration. The serialization result is stored into the <code>writer</code>. If
  * <code>serializeChildNodes</code> is true, the method will serialize too the child nodes of the
  * <code>element</code>. The {@link CSSSerializerConfiguration} <code>configuration</code> is used
  * to generate selector with condition like Text[style='SWT.MULTI'].
  *
  * @param writer
  * @param engine
  * @param element
  * @param serializeChildNodes
  * @param configuration
  * @throws IOException
  */
 public void serialize(
     Writer writer,
     CSSEngine engine,
     Object element,
     boolean serializeChildNodes,
     CSSSerializerConfiguration configuration)
     throws IOException {
   Map selectors = new HashMap();
   serialize(writer, engine, element, serializeChildNodes, selectors, configuration);
   boolean firstSelector = true;
   for (Iterator iterator = selectors.entrySet().iterator(); iterator.hasNext(); ) {
     Map.Entry entry = (Map.Entry) iterator.next();
     String selectorName = (String) entry.getKey();
     CSSStyleDeclaration styleDeclaration = (CSSStyleDeclaration) entry.getValue();
     if (styleDeclaration != null) {
       int length = styleDeclaration.getLength();
       // Start selector
       startSelector(writer, selectorName, firstSelector);
       firstSelector = false;
       for (int i = 0; i < length; i++) {
         String propertyName = styleDeclaration.item(i);
         String propertyValue = styleDeclaration.getPropertyValue(propertyName);
         property(writer, propertyName, propertyValue);
       }
       // End selector
       endSelector(writer, selectorName);
     }
   }
 }
 private final String getPropertyValue(String name) {
   Object sd = this.styleDeclarations;
   if (sd instanceof CSSStyleDeclaration) {
     return ((CSSStyleDeclaration) sd).getPropertyValue(name);
   } else if (sd instanceof ArrayList) {
     ArrayList sds = (ArrayList) sd;
     synchronized (sds) {
       int size = sds.size();
       for (int i = size; --i >= 0; ) {
         CSSStyleDeclaration styleDeclaration = (CSSStyleDeclaration) sds.get(i);
         String pv = styleDeclaration.getPropertyValue(name);
         if (pv != null && !"".equals(pv)) {
           return pv;
         }
       }
     }
     return null;
   } else {
     return null;
   }
 }