fixed bug #1038067
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPSyntaxRdr.java
index ba4366c..dd1c5a4 100644 (file)
@@ -6,12 +6,17 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 
 import net.sourceforge.phpeclipse.IPreferenceConstants;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
@@ -21,12 +26,8 @@ import net.sourceforge.phpeclipse.phpeditor.php.PHPFunction;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPKeyword;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPType;
 
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.Serializer;
-import org.apache.xml.serialize.SerializerFactory;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
@@ -119,14 +120,13 @@ public class PHPSyntaxRdr {
           }
         } catch (IOException e) {
         }
-      }
+      } 
     }
   }
   public static void readFromStream(InputStream stream) throws CoreException {
     try {
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
       DocumentBuilder parser = factory.newDocumentBuilder();
-      org.apache.crimson.parser.Parser2 pp;
       Document document = parser.parse(new InputSource(stream));
       //               Read in the Standard PHPSyntax "stuff"
       NodeList elements = document.getElementsByTagName(PHPSYNTAX_TAG);
@@ -165,7 +165,7 @@ public class PHPSyntaxRdr {
           } else if (Function != null) {
             syntaxdata.add(new PHPFunction(Function, usage, description));
           } else if (Constant != null) {
-            syntaxdata.add(new PHPConstant(Constant, usage));
+            syntaxdata.add(new PHPConstant(Constant, null, description));
           }
         }
       }
@@ -263,24 +263,38 @@ public class PHPSyntaxRdr {
           //      Attr usage = document.createAttribute(USAGE_ATTR);
           Text usage = document.createTextNode(((PHPFunction) bufferobj).getDescription());
           node.appendChild(usage);
-          //          usage.setValue(((PHPFunction) bufferobj).getUsage());
-          //          attributes.setNamedItem(usage);
         }
+        if (bufferobj instanceof PHPConstant) {
+            //      Attr usage = document.createAttribute(USAGE_ATTR);
+            Text usage = document.createTextNode(((PHPConstant) bufferobj).getDescription());
+            node.appendChild(usage);
+          }
       }
-      OutputFormat format = new OutputFormat();
-      format.setPreserveSpace(true);
-      try {
-        Serializer serializer = SerializerFactory.getSerializerFactory("xml").makeSerializer(stream, format);
-        serializer.asDOMSerializer().serialize(document);
-      } catch (UnsupportedEncodingException e) {
-      } catch (IOException e) {
-      } //$NON-NLS-1$
-      //                       Serializer serializer = SerializerFactory.getSerializer().makeSerializer(stream, format); //$NON-NLS-1$
-    } catch (ParserConfigurationException e) {
-      throwWriteException(e);
-      //        } catch (IOException e) {
-      //            throwWriteException(e);
-    }
+      Transformer transformer=TransformerFactory.newInstance().newTransformer();
+               transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+               transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
+               DOMSource source = new DOMSource(document);
+               StreamResult result = new StreamResult(stream);
+
+               transformer.transform(source, result);
+
+       } catch (ParserConfigurationException e) {
+               throwWriteException(e);
+       } catch (TransformerException e) {
+               throwWriteException(e);
+       }               
+//      OutputFormat format = new OutputFormat();
+//      format.setPreserveSpace(true);
+//      try {
+//        Serializer serializer = SerializerFactory.getSerializerFactory("xml").makeSerializer(stream, format);
+//        serializer.asDOMSerializer().serialize(document);
+//      } catch (UnsupportedEncodingException e) {
+//      } catch (IOException e) {
+//      } //$NON-NLS-1$
+//      //                     Serializer serializer = SerializerFactory.getSerializer().makeSerializer(stream, format); //$NON-NLS-1$
+//    } catch (ParserConfigurationException e) {
+//      throwWriteException(e);
+//    }
   }
 
   private static void throwReadException(Throwable t) throws CoreException {