added php help to phpsyntax.xml
authorkhartlage <khartlage>
Sat, 25 Oct 2003 12:10:58 +0000 (12:10 +0000)
committerkhartlage <khartlage>
Sat, 25 Oct 2003 12:10:58 +0000 (12:10 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/template/TemplateSet.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSyntaxRdr.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpsyntax.xml

index 7e17912..ab30dd3 100644 (file)
@@ -26,6 +26,7 @@ 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.IStatus;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.NamedNodeMap;
@@ -34,274 +35,277 @@ import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 /**
  * <code>ObfuscatorIgnoreSet</code> manages a collection of templates and makes them
  * persistent.
  */
 public class TemplateSet {
-       
-       private static class TemplateComparator implements Comparator {
-               public int compare(Object arg0, Object arg1) {
-                       if (arg0 == arg1)
-                               return 0;
-                       
-                       if (arg0 == null)
-                               return -1;
-                               
-                       Template template0= (Template) arg0;
-                       Template template1= (Template) arg1;
-                       
-                       return template0.getName().compareTo(template1.getName());
-               }
-       }
-
-       private static final String TEMPLATE_TAG= "template"; //$NON-NLS-1$
-       private static final String NAME_ATTRIBUTE= "name"; //$NON-NLS-1$
-       private static final String DESCRIPTION_ATTRIBUTE= "description"; //$NON-NLS-1$
-       private static final String CONTEXT_ATTRIBUTE= "context"; //$NON-NLS-1$
-       private static final String ENABLED_ATTRIBUTE= "enabled"; //$NON-NLS-1$
-
-       private List fTemplates= new ArrayList();
-       private Comparator fTemplateComparator= new TemplateComparator();
-       private Template[] fSortedTemplates= new Template[0];
-       
-       /**
-        * Convenience method for reading templates from a file.
-        * 
-        * @see #addFromStream(InputStream)
-        */
-       public void addFromFile(File file) throws CoreException {
-               InputStream stream= null;
-
-               try {
-                       stream= new FileInputStream(file);
-                       addFromStream(stream);
-
-               } catch (IOException e) {
-                       throwReadException(e);
-
-               } finally {
-                       try {
-                               if (stream != null)
-                                       stream.close();
-                       } catch (IOException e) {}
-               }               
-       }
-
-       /**
-        * Reads templates from a XML stream and adds them to the template set.
-        */     
-       public void addFromStream(InputStream stream) throws CoreException {
-               try {
-                       DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
-                       DocumentBuilder parser= factory.newDocumentBuilder();           
-                       Document document= parser.parse(new InputSource(stream));
-                       NodeList elements= document.getElementsByTagName(TEMPLATE_TAG);
-                       
-                       int count= elements.getLength();
-                       for (int i= 0; i != count; i++) {
-                               Node node= elements.item(i);                                    
-                               NamedNodeMap attributes= node.getAttributes();
-
-                               if (attributes == null)
-                                       continue;
-
-                               String name= getAttributeValue(attributes, NAME_ATTRIBUTE);
-                               String description= getAttributeValue(attributes, DESCRIPTION_ATTRIBUTE);
-                               String context= getAttributeValue(attributes, CONTEXT_ATTRIBUTE);
-                               Node enabledNode= attributes.getNamedItem(ENABLED_ATTRIBUTE);
-
-                               if (name == null || description == null || context == null)
-                                       throw new SAXException(TemplateMessages.getString("TemplateSet.error.missing.attribute")); //$NON-NLS-1$
-
-                               boolean enabled= (enabledNode == null) || (enabledNode.getNodeValue().equals("true")); //$NON-NLS-1$
-
-                               StringBuffer buffer= new StringBuffer();
-                               NodeList children= node.getChildNodes();
-                               for (int j= 0; j != children.getLength(); j++) {
-                                       String value= children.item(j).getNodeValue();
-                                       if (value != null)
-                                               buffer.append(value);
-                               }
-                               String pattern= buffer.toString().trim();
-
-                               Template template= new Template(name, description, context, pattern);   
-                               template.setEnabled(enabled);
-                               add(template);
-                       }
-       
-                       sort();
-
-               } catch (ParserConfigurationException e) {
-                       throwReadException(e);
-               } catch (IOException e) {
-                       throwReadException(e);
-               } catch (SAXException e) {
-                       throwReadException(e);
-               }
-       }
-       
-       private String getAttributeValue(NamedNodeMap attributes, String name) {
-               Node node= attributes.getNamedItem(name);
-
-               return node == null
-                       ? null
-                       : node.getNodeValue();
-       }
-
-       /**
-        * Convenience method for saving to a file.
-        * 
-        * @see #saveToStream(OutputStream)
-        */
-       public void saveToFile(File file) throws CoreException {
-               OutputStream stream= null;
-
-               try {
-                       stream= new FileOutputStream(file);
-                       saveToStream(stream);
-
-               } catch (IOException e) {
-                       throwWriteException(e);
-
-               } finally {
-                       try {
-                               if (stream != null)
-                                       stream.close();
-                       } catch (IOException e) {}
-               }
-       }
-               
-       /**
-        * Saves the template set as XML.
-        */
-       public void saveToStream(OutputStream stream) throws CoreException {
-               try {
-                       DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
-                       DocumentBuilder builder= factory.newDocumentBuilder();          
-                       Document document= builder.newDocument();
-
-                       Node root= document.createElement("templates"); // $NON-NLS-1$ //$NON-NLS-1$
-                       document.appendChild(root);
-                       
-                       for (int i= 0; i != fTemplates.size(); i++) {
-                               Template template= (Template) fTemplates.get(i);
-                               
-                               Node node= document.createElement("template"); // $NON-NLS-1$ //$NON-NLS-1$
-                               root.appendChild(node);
-                               
-                               NamedNodeMap attributes= node.getAttributes();
-                               
-                               Attr name= document.createAttribute(NAME_ATTRIBUTE);
-                               name.setValue(template.getName());
-                               attributes.setNamedItem(name);
-       
-                               Attr description= document.createAttribute(DESCRIPTION_ATTRIBUTE);
-                               description.setValue(template.getDescription());
-                               attributes.setNamedItem(description);
-       
-                               Attr context= document.createAttribute(CONTEXT_ATTRIBUTE);
-                               context.setValue(template.getContextTypeName());
-                               attributes.setNamedItem(context);                       
-
-                               Attr enabled= document.createAttribute(ENABLED_ATTRIBUTE);
-                               enabled.setValue(template.isEnabled() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
-                               attributes.setNamedItem(enabled);
-                               
-                               Text pattern= document.createTextNode(template.getPattern());
-                               node.appendChild(pattern);                      
-                       }               
-                       
-                       OutputFormat format = new OutputFormat();
-                       format.setPreserveSpace(true);
-                       Serializer serializer = SerializerFactory.getSerializerFactory("xml").makeSerializer(stream, format); //$NON-NLS-1$
-                       serializer.asDOMSerializer().serialize(document);
-
-               } catch (ParserConfigurationException e) {
-                       throwWriteException(e);
-               } catch (IOException e) {
-                       throwWriteException(e);
-               }               
-       }
-
-       private static void throwReadException(Throwable t) throws CoreException {
+
+  private static class TemplateComparator implements Comparator {
+    public int compare(Object arg0, Object arg1) {
+      if (arg0 == arg1)
+        return 0;
+
+      if (arg0 == null)
+        return -1;
+
+      Template template0 = (Template) arg0;
+      Template template1 = (Template) arg1;
+
+      return template0.getName().compareTo(template1.getName());
+    }
+  }
+
+  private static final String TEMPLATE_TAG = "template"; //$NON-NLS-1$
+  private static final String NAME_ATTRIBUTE = "name"; //$NON-NLS-1$
+  private static final String DESCRIPTION_ATTRIBUTE = "description"; //$NON-NLS-1$
+  private static final String CONTEXT_ATTRIBUTE = "context"; //$NON-NLS-1$
+  private static final String ENABLED_ATTRIBUTE = "enabled"; //$NON-NLS-1$
+
+  private List fTemplates = new ArrayList();
+  private Comparator fTemplateComparator = new TemplateComparator();
+  private Template[] fSortedTemplates = new Template[0];
+
+  /**
+   * Convenience method for reading templates from a file.
+   * 
+   * @see #addFromStream(InputStream)
+   */
+  public void addFromFile(File file) throws CoreException {
+    InputStream stream = null;
+
+    try {
+      stream = new FileInputStream(file);
+      addFromStream(stream);
+
+    } catch (IOException e) {
+      throwReadException(e);
+
+    } finally {
+      try {
+        if (stream != null)
+          stream.close();
+      } catch (IOException e) {
+      }
+    }
+  }
+
+  /**
+   * Reads templates from a XML stream and adds them to the template set.
+   */
+  public void addFromStream(InputStream stream) throws CoreException {
+    try {
+      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+      DocumentBuilder parser = factory.newDocumentBuilder();
+      Document document = parser.parse(new InputSource(stream));
+      NodeList elements = document.getElementsByTagName(TEMPLATE_TAG);
+
+      int count = elements.getLength();
+      for (int i = 0; i != count; i++) {
+        Node node = elements.item(i);
+        NamedNodeMap attributes = node.getAttributes();
+
+        if (attributes == null)
+          continue;
+
+        String name = getAttributeValue(attributes, NAME_ATTRIBUTE);
+        String description = getAttributeValue(attributes, DESCRIPTION_ATTRIBUTE);
+        String context = getAttributeValue(attributes, CONTEXT_ATTRIBUTE);
+        Node enabledNode = attributes.getNamedItem(ENABLED_ATTRIBUTE);
+
+        if (name == null || description == null || context == null)
+          throw new SAXException(TemplateMessages.getString("TemplateSet.error.missing.attribute")); //$NON-NLS-1$
+
+        boolean enabled = (enabledNode == null) || (enabledNode.getNodeValue().equals("true")); //$NON-NLS-1$
+
+        StringBuffer buffer = new StringBuffer();
+        NodeList children = node.getChildNodes();
+        for (int j = 0; j != children.getLength(); j++) {
+          String value = children.item(j).getNodeValue();
+          if (value != null)
+            buffer.append(value);
+        }
+        String pattern = buffer.toString().trim();
+
+        Template template = new Template(name, description, context, pattern);
+        template.setEnabled(enabled);
+        add(template);
+      }
+
+      sort();
+
+    } catch (ParserConfigurationException e) {
+      throwReadException(e);
+    } catch (IOException e) {
+      throwReadException(e);
+    } catch (SAXParseException e) {
+                       System.out.println("SAXParseException in line:"+e.getLineNumber()+" column:"+e.getColumnNumber());
+      throwReadException(e);
+    } catch (SAXException e) {
+      throwReadException(e);
+    }
+  }
+
+  private String getAttributeValue(NamedNodeMap attributes, String name) {
+    Node node = attributes.getNamedItem(name);
+
+    return node == null ? null : node.getNodeValue();
+  }
+
+  /**
+   * Convenience method for saving to a file.
+   * 
+   * @see #saveToStream(OutputStream)
+   */
+  public void saveToFile(File file) throws CoreException {
+    OutputStream stream = null;
+
+    try {
+      stream = new FileOutputStream(file);
+      saveToStream(stream);
+
+    } catch (IOException e) {
+      throwWriteException(e);
+
+    } finally {
+      try {
+        if (stream != null)
+          stream.close();
+      } catch (IOException e) {
+      }
+    }
+  }
+
+  /**
+   * Saves the template set as XML.
+   */
+  public void saveToStream(OutputStream stream) throws CoreException {
+    try {
+      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+      DocumentBuilder builder = factory.newDocumentBuilder();
+      Document document = builder.newDocument();
+
+      Node root = document.createElement("templates"); // $NON-NLS-1$ //$NON-NLS-1$
+      document.appendChild(root);
+
+      for (int i = 0; i != fTemplates.size(); i++) {
+        Template template = (Template) fTemplates.get(i);
+
+        Node node = document.createElement("template"); // $NON-NLS-1$ //$NON-NLS-1$
+        root.appendChild(node);
+
+        NamedNodeMap attributes = node.getAttributes();
+
+        Attr name = document.createAttribute(NAME_ATTRIBUTE);
+        name.setValue(template.getName());
+        attributes.setNamedItem(name);
+
+        Attr description = document.createAttribute(DESCRIPTION_ATTRIBUTE);
+        description.setValue(template.getDescription());
+        attributes.setNamedItem(description);
+
+        Attr context = document.createAttribute(CONTEXT_ATTRIBUTE);
+        context.setValue(template.getContextTypeName());
+        attributes.setNamedItem(context);
+
+        Attr enabled = document.createAttribute(ENABLED_ATTRIBUTE);
+        enabled.setValue(template.isEnabled() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
+        attributes.setNamedItem(enabled);
+
+        Text pattern = document.createTextNode(template.getPattern());
+        node.appendChild(pattern);
+      }
+
+      OutputFormat format = new OutputFormat();
+      format.setPreserveSpace(true);
+      Serializer serializer = SerializerFactory.getSerializerFactory("xml").makeSerializer(stream, format); //$NON-NLS-1$
+      serializer.asDOMSerializer().serialize(document);
+
+    } catch (ParserConfigurationException e) {
+      throwWriteException(e);
+    } catch (IOException e) {
+      throwWriteException(e);
+    }
+  }
+
+  private static void throwReadException(Throwable t) throws CoreException {
     PHPeclipsePlugin.log(t);
-//             IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
-//                     ObfuscatorMessages.getString("TemplateSet.error.read"), t); //$NON-NLS-1$
-//             throw new JavaUIException(status);
-       }
-       
-       private static void throwWriteException(Throwable t) throws CoreException {
+    //         IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
+    //                 ObfuscatorMessages.getString("TemplateSet.error.read"), t); //$NON-NLS-1$
+    //         throw new JavaUIException(status);
+  }
+
+  private static void throwWriteException(Throwable t) throws CoreException {
     PHPeclipsePlugin.log(t);
-//             IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
-//                     ObfuscatorMessages.getString("TemplateSet.error.write"), t); //$NON-NLS-1$
-//             throw new JavaUIException(status);
-       }
-
-       /**
-        * Adds a template to the set.
-        */
-       public void add(Template template) {
-               if (exists(template))
-                       return; // ignore duplicate
-               
-               fTemplates.add(template);
-               sort();
-       }
-
-       private boolean exists(Template template) {
-               for (Iterator iterator = fTemplates.iterator(); iterator.hasNext();) {
-                       Template anotherTemplate = (Template) iterator.next();
-
-                       if (template.equals(anotherTemplate))
-                               return true;
-               }
-               
-               return false;
-       }
-       
-       /**
-        * Removes a template to the set.
-        */     
-       public void remove(Template template) {
-               fTemplates.remove(template);
-               sort();
-       }
-
-       /**
-        * Empties the set.
-        */             
-       public void clear() {
-               fTemplates.clear();
-               sort();
-       }
-       
-       /**
-        * Returns all templates.
-        */
-       public Template[] getTemplates() {
-               return (Template[]) fTemplates.toArray(new Template[fTemplates.size()]);
-       }
-       
-       /**
-        * Returns all templates with a given name.
-        */
-       public Template[] getTemplates(String name) {
-               ArrayList res= new ArrayList();
-               for (Iterator iterator= fTemplates.iterator(); iterator.hasNext();) {
-                       Template curr= (Template) iterator.next();
-                       if (curr.getName().equals(name)) {
-                               res.add(curr);
-                       }
-               }
-               return (Template[]) res.toArray(new Template[res.size()]);
-       }       
-       
-       private void sort() {
-               fSortedTemplates= (Template[]) fTemplates.toArray(new Template[fTemplates.size()]);
-               Arrays.sort(fSortedTemplates, fTemplateComparator);
-       }
-       
-}
+    //         IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
+    //                 ObfuscatorMessages.getString("TemplateSet.error.write"), t); //$NON-NLS-1$
+    //         throw new JavaUIException(status);
+  }
+
+  /**
+   * Adds a template to the set.
+   */
+  public void add(Template template) {
+    if (exists(template))
+      return; // ignore duplicate
+
+    fTemplates.add(template);
+    sort();
+  }
+
+  private boolean exists(Template template) {
+    for (Iterator iterator = fTemplates.iterator(); iterator.hasNext();) {
+      Template anotherTemplate = (Template) iterator.next();
+
+      if (template.equals(anotherTemplate))
+        return true;
+    }
+
+    return false;
+  }
+
+  /**
+   * Removes a template to the set.
+   */
+  public void remove(Template template) {
+    fTemplates.remove(template);
+    sort();
+  }
+
+  /**
+   * Empties the set.
+   */
+  public void clear() {
+    fTemplates.clear();
+    sort();
+  }
+
+  /**
+   * Returns all templates.
+   */
+  public Template[] getTemplates() {
+    return (Template[]) fTemplates.toArray(new Template[fTemplates.size()]);
+  }
+
+  /**
+   * Returns all templates with a given name.
+   */
+  public Template[] getTemplates(String name) {
+    ArrayList res = new ArrayList();
+    for (Iterator iterator = fTemplates.iterator(); iterator.hasNext();) {
+      Template curr = (Template) iterator.next();
+      if (curr.getName().equals(name)) {
+        res.add(curr);
+      }
+    }
+    return (Template[]) res.toArray(new Template[res.size()]);
+  }
+
+  private void sort() {
+    fSortedTemplates = (Template[]) fTemplates.toArray(new Template[fTemplates.size()]);
+    Arrays.sort(fSortedTemplates, fTemplateComparator);
+  }
 
+}
index 591542c..ba4366c 100644 (file)
@@ -26,6 +26,7 @@ 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;
@@ -35,283 +36,259 @@ import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 /**
  * <code>PHPSyntaxRdr</code> reads PHP specifics from an XML file (eg. keywords) 
  */
 
 public class PHPSyntaxRdr {
-       private static final String PHPDEFAULT_FILE = "default-phpsyntax.xml"; //$NON-NLS-1$
-       private static final String PHPSYNTAX_FILE = "phpsyntax.xml"; //$NON-NLS-1$
-       private static final String USERSYNTAX_FILE = "usersyntax.xml"; //$NON-NLS-1$
-       private static final String USERDEFAULT_FILE = "default-usersyntax.xml"; //$NON-NLS-1$
-       private static final String PHPSYNTAX_TAG = "phpsyntax"; //$NON-NLS-1$
-       private static final String KEYWORD_ATTR = "keyword"; //$NON-NLS-1$
-       private static final String TYPE_ATTR = "type"; //$NON-NLS-1$
-       private static final String CONSTANT_ATTR = "constant"; //$NON-NLS-1$
-       private static final String FN_ATTR = "function"; //$NON-NLS-1$
-       private static final String USAGE_ATTR = "usage"; //$NON-NLS-1$
-       private static final String TOKENVAL_ATTR = "tokenval"; //$NON-NLS-1$
-       private static IPreferenceStore store;
-       private static boolean hasXMLFileBeenRead = true;
+  private static final String PHPDEFAULT_FILE = "default-phpsyntax.xml"; //$NON-NLS-1$
+  private static final String PHPSYNTAX_FILE = "phpsyntax.xml"; //$NON-NLS-1$
+  private static final String USERSYNTAX_FILE = "usersyntax.xml"; //$NON-NLS-1$
+  private static final String USERDEFAULT_FILE = "default-usersyntax.xml"; //$NON-NLS-1$
+  private static final String PHPSYNTAX_TAG = "phpsyntax"; //$NON-NLS-1$
+  private static final String KEYWORD_ATTR = "keyword"; //$NON-NLS-1$
+  private static final String TYPE_ATTR = "type"; //$NON-NLS-1$
+  private static final String CONSTANT_ATTR = "constant"; //$NON-NLS-1$
+  private static final String FN_ATTR = "function"; //$NON-NLS-1$
+  private static final String USAGE_ATTR = "usage"; //$NON-NLS-1$
+  private static final String TOKENVAL_ATTR = "tokenval"; //$NON-NLS-1$
+  private static IPreferenceStore store;
+  private static boolean hasXMLFileBeenRead = true;
 
-       //The following variable is used to hold the syntax from
-       //the suers custom file - if that file should be changed,
-       //then all entries in this variable should be removed from
-       //the word list, reread from the file and then reinserted.
-       private static ArrayList userdefsyntaxdata;
+  //The following variable is used to hold the syntax from
+  //the suers custom file - if that file should be changed,
+  //then all entries in this variable should be removed from
+  //the word list, reread from the file and then reinserted.
+  private static ArrayList userdefsyntaxdata;
 
-       private static ArrayList syntaxdata;
+  private static ArrayList syntaxdata;
 
-       public PHPSyntaxRdr() {
-               // see getSyntaxData()
-               syntaxdata = null;
-               store = PHPeclipsePlugin.getDefault().getPreferenceStore();
-       }
+  public PHPSyntaxRdr() {
+    // see getSyntaxData()
+    syntaxdata = null;
+    store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+  }
 
-       public static void readInSyntax() {
-               try {
-                       hasXMLFileBeenRead = true;
-                       /*Attempt to read the syntax file from the metadata
-                        * if this does not work, create metadata from default*/
-                       File syntaxFile = getSyntaxFile();
-                       if (syntaxFile.exists()) {
-                               readFromFile(syntaxFile);
-                       } else {
-                               readFromStream(
-                                       PHPSyntaxRdr.class.getResourceAsStream(PHPSYNTAX_FILE));
-                               saveToFile(syntaxFile);
-                       }
-                       /*Read the user-defined syntax file if it exists*/
-                       //String buffer = new String(store.getString(PHPeclipsePlugin.PHP_USERDEF_XMLFILE));
-                       if (store == null)
-                               store = PHPeclipsePlugin.getDefault().getPreferenceStore();
-                       String buffer =
-                               new String(
-                                       store.getString(IPreferenceConstants.PHP_USERDEF_XMLFILE));
-                       if (!(buffer.equals("") || buffer == null)) {
-                               readFromFile(buffer);
-                       }
-               } catch (CoreException ce) {
-                       ce.printStackTrace();
-               }
-       }
+  public static void readInSyntax() {
+    try {
+      hasXMLFileBeenRead = true;
+      /*Attempt to read the syntax file from the metadata
+       * if this does not work, create metadata from default*/
+      File syntaxFile = getSyntaxFile();
+      if (syntaxFile.exists()) {
+        readFromFile(syntaxFile);
+      } else {
+        readFromStream(PHPSyntaxRdr.class.getResourceAsStream(PHPSYNTAX_FILE));
+        saveToFile(syntaxFile);
+      }
+      /*Read the user-defined syntax file if it exists*/
+      //String buffer = new String(store.getString(PHPeclipsePlugin.PHP_USERDEF_XMLFILE));
+      if (store == null)
+        store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+      String buffer = new String(store.getString(IPreferenceConstants.PHP_USERDEF_XMLFILE));
+      if (!(buffer.equals("") || buffer == null)) {
+        readFromFile(buffer);
+      }
+    } catch (CoreException ce) {
+      ce.printStackTrace();
+    }
+  }
 
-       public static void readFromFile(String filename) {
-               try {
-                       readFromFile(new File(filename));
-               } catch (CoreException e) {
-               }
-       }
+  public static void readFromFile(String filename) {
+    try {
+      readFromFile(new File(filename));
+    } catch (CoreException e) {
+    }
+  }
 
-       public static void readFromFile(File file) throws CoreException {
-               InputStream stream = null;
+  public static void readFromFile(File file) throws CoreException {
+    InputStream stream = null;
 
-               if (file.exists()) {
-                       try {
-                               stream = new FileInputStream(file);
-                               readFromStream(stream);
-                       } catch (IOException e) {
-                               throwReadException(e);
-                       } finally {
-                               try {
-                                       if (stream != null) {
-                                               stream.close();
-                                       }
-                               } catch (IOException e) {
-                               }
-                       }
-               }
-       }
-       public static void readFromStream(InputStream stream)
-               throws CoreException {
-               try {
-                       DocumentBuilderFactory factory =
-                               DocumentBuilderFactory.newInstance();
-                       DocumentBuilder parser = factory.newDocumentBuilder();
-                       Document document = parser.parse(new InputSource(stream));
-                       //Read in the Standard PHPSyntax "stuff"
-                       NodeList elements = document.getElementsByTagName(PHPSYNTAX_TAG);
+    if (file.exists()) {
+      try {
+        stream = new FileInputStream(file);
+        readFromStream(stream);
+      } catch (IOException e) {
+        throwReadException(e);
+      } finally {
+        try {
+          if (stream != null) {
+            stream.close();
+          }
+        } 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);
 
-                       int count = elements.getLength();
-                       for (int i = 0; i != count; i++) {
-                               Node node = elements.item(i);
-                               NamedNodeMap attributes = node.getAttributes();
+      int count = elements.getLength();
+      for (int i = 0; i != count; i++) {
+        Node node = elements.item(i);
+        NamedNodeMap attributes = node.getAttributes();
 
-                               if (attributes == null)
-                                       continue;
+        if (attributes == null)
+          continue;
 
-                               String Keyword = getAttributeValue(attributes, KEYWORD_ATTR);
-                               String Type = getAttributeValue(attributes, TYPE_ATTR);
-                               String Function = getAttributeValue(attributes, FN_ATTR);
-                               String Constant = getAttributeValue(attributes, CONSTANT_ATTR);
-                               String usage = getAttributeValue(attributes, USAGE_ATTR);
-                               String Tokenval = getAttributeValue(attributes, TOKENVAL_ATTR);
+        String Keyword = getAttributeValue(attributes, KEYWORD_ATTR);
+        String Type = getAttributeValue(attributes, TYPE_ATTR);
+        String Function = getAttributeValue(attributes, FN_ATTR);
+        String Constant = getAttributeValue(attributes, CONSTANT_ATTR);
+        String usage = getAttributeValue(attributes, USAGE_ATTR);
+        String Tokenval = getAttributeValue(attributes, TOKENVAL_ATTR);
+      
+        StringBuffer buffer = new StringBuffer();
+        NodeList children = node.getChildNodes();
+        for (int j = 0; j != children.getLength(); j++) {
+          String value = children.item(j).getNodeValue();
+          if (value != null)
+            buffer.append(value);
+        }
+        String description = buffer.toString().trim();
 
-                               StringBuffer buffer = new StringBuffer();
-                               NodeList children = node.getChildNodes();
-                               for (int j = 0; j != children.getLength(); j++) {
-                                       String value = children.item(j).getNodeValue();
-                                       if (value != null)
-                                               buffer.append(value);
-                               }
-                               String description = buffer.toString().trim();
+        if (Keyword == null && Type == null && Function == null && Constant == null) {
+          //ignore as it is not a valid phpsyntax tag
+        } else {
+          if (Keyword != null) {
+            syntaxdata.add(new PHPKeyword(Keyword, usage, Tokenval));
+          } else if (Type != null) {
+            syntaxdata.add(new PHPType(Type, usage));
+          } else if (Function != null) {
+            syntaxdata.add(new PHPFunction(Function, usage, description));
+          } else if (Constant != null) {
+            syntaxdata.add(new PHPConstant(Constant, usage));
+          }
+        }
+      }
+    } catch (ParserConfigurationException e) {
+      throwReadException(e);
+    } catch (IOException e) {
+      throwReadException(e);
+    } catch (SAXParseException e) {
+      System.out.println("SAXParseException in line:"+e.getLineNumber()+" column:"+e.getColumnNumber());
+      throwReadException(e);
+    } catch (SAXException e) {
+      throwReadException(e);
+    }
+  }
 
-                               if (Keyword == null
-                                       && Type == null
-                                       && Function == null
-                                       && Constant == null) {
-                                       //ignore as it is not a valid phpsyntax tag
-                               } else {
-                                       if (Keyword != null) {
-                                               syntaxdata.add(
-                                                       new PHPKeyword(Keyword, usage, Tokenval));
-                                       } else if (Type != null) {
-                                               syntaxdata.add(new PHPType(Type, usage));
-                                       } else if (Function != null) {
-                                               syntaxdata.add(
-                                                       new PHPFunction(Function, usage, description));
-                                       } else if (Constant != null) {
-                                               syntaxdata.add(new PHPConstant(Constant, usage));
-                                       }
-                               }
-                       }
-               } catch (ParserConfigurationException e) {
-                       throwReadException(e);
-               } catch (IOException e) {
-                       throwReadException(e);
-               } catch (SAXException e) {
-                       throwReadException(e);
-               }
-       }
+  public static ArrayList getSyntaxData() {
+    if (syntaxdata == null) {
+      syntaxdata = new ArrayList();
+      readInSyntax();
+    }
+    return syntaxdata;
+  }
 
-       public static ArrayList getSyntaxData() {
-               if (syntaxdata==null) {
-                       syntaxdata = new ArrayList();
-                       readInSyntax();
-               }
-               return syntaxdata;
-       }
+  public static void replaceUserDefFile() {
+    /*Replace the user-defined syntax file if it exists*/
+    String buffer = new String(store.getString(IPreferenceConstants.PHP_USERDEF_XMLFILE));
+    if (!buffer.equals("") || buffer == null) {
+      readFromFile(buffer);
+    }
+  }
 
-       public static void replaceUserDefFile() {
-               /*Replace the user-defined syntax file if it exists*/
-               String buffer =
-                       new String(
-                               store.getString(IPreferenceConstants.PHP_USERDEF_XMLFILE));
-               if (!buffer.equals("") || buffer == null) {
-                       readFromFile(buffer);
-               }
-       }
+  public static ArrayList getUserSyntaxData() {
+    return userdefsyntaxdata;
+  }
 
-       public static ArrayList getUserSyntaxData() {
-               return userdefsyntaxdata;
-       }
+  private static File getSyntaxFile() {
+    IPath path = PHPeclipsePlugin.getDefault().getStateLocation();
+    path = path.append(PHPSYNTAX_FILE);
+    return path.toFile();
+  }
 
-       private static File getSyntaxFile() {
-               IPath path = PHPeclipsePlugin.getDefault().getStateLocation();
-               path = path.append(PHPSYNTAX_FILE);
-               return path.toFile();
-       }
+  private static String getAttributeValue(NamedNodeMap attributes, String name) {
+    Node node = attributes.getNamedItem(name);
+    return node == null ? null : node.getNodeValue();
+  }
 
-       private static String getAttributeValue(
-               NamedNodeMap attributes,
-               String name) {
-               Node node = attributes.getNamedItem(name);
-               return node == null ? null : node.getNodeValue();
-       }
+  public static void saveToFile(File file) throws CoreException {
+    OutputStream stream = null;
+    try {
+      stream = new FileOutputStream(file);
+      saveToStream(stream);
+    } catch (IOException e) {
+      throwWriteException(e);
+    } finally {
+      try {
+        if (stream != null)
+          stream.close();
+      } catch (IOException e) {
+      }
+    }
+  }
 
-       public static void saveToFile(File file) throws CoreException {
-               OutputStream stream = null;
-               try {
-                       stream = new FileOutputStream(file);
-                       saveToStream(stream);
-               } catch (IOException e) {
-                       throwWriteException(e);
-               } finally {
-                       try {
-                               if (stream != null)
-                                       stream.close();
-                       } catch (IOException e) {
-                       }
-               }
-       }
+  public static void saveToStream(OutputStream stream) throws CoreException {
+    try {
+      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+      DocumentBuilder builder = factory.newDocumentBuilder();
+      Document document = builder.newDocument();
+      Node root = document.createElement("PHPStandardSyntax"); // $NON-NLS-1$ //$NON-NLS-1$
+      document.appendChild(root);
+      for (int i = 0; i != syntaxdata.size(); i++) {
+        Object bufferobj = (Object) syntaxdata.get(i);
+        Attr name = null;
+        Node node = document.createElement(PHPSYNTAX_TAG); // $NON-NLS-1$ //$NON-NLS-1$
+        root.appendChild(node);
+        NamedNodeMap attributes = node.getAttributes();
+        if (bufferobj instanceof PHPType)
+          name = document.createAttribute(TYPE_ATTR);
+        if (bufferobj instanceof PHPKeyword)
+          name = document.createAttribute(KEYWORD_ATTR);
+        if (bufferobj instanceof PHPFunction)
+          name = document.createAttribute(FN_ATTR);
+        if (bufferobj instanceof PHPConstant)
+          name = document.createAttribute(CONSTANT_ATTR);
+        name.setValue(((PHPElement) bufferobj).getName());
+        attributes.setNamedItem(name);
+        Attr description = document.createAttribute(USAGE_ATTR);
+        description.setValue(((PHPElement) bufferobj).getUsage());
+        attributes.setNamedItem(description);
+        if (bufferobj instanceof PHPKeyword) {
+          Attr tokenval = document.createAttribute(TOKENVAL_ATTR);
+          tokenval.setValue((new Integer(((PHPKeyword) bufferobj).gettokenval())).toString());
+          attributes.setNamedItem(tokenval);
+        }
+        if (bufferobj instanceof PHPFunction) {
+          //      Attr usage = document.createAttribute(USAGE_ATTR);
+          Text usage = document.createTextNode(((PHPFunction) bufferobj).getDescription());
+          node.appendChild(usage);
+          //          usage.setValue(((PHPFunction) bufferobj).getUsage());
+          //          attributes.setNamedItem(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);
+    }
+  }
 
-       public static void saveToStream(OutputStream stream) throws CoreException {
-               try {
-                       DocumentBuilderFactory factory =
-                               DocumentBuilderFactory.newInstance();
-                       DocumentBuilder builder = factory.newDocumentBuilder();
-                       Document document = builder.newDocument();
-                       Node root = document.createElement("PHPStandardSyntax"); // $NON-NLS-1$ //$NON-NLS-1$
-                       document.appendChild(root);
-                       for (int i = 0; i != syntaxdata.size(); i++) {
-                               Object bufferobj = (Object) syntaxdata.get(i);
-                               Attr name = null;
-                               Node node = document.createElement(PHPSYNTAX_TAG); // $NON-NLS-1$ //$NON-NLS-1$
-                               root.appendChild(node);
-                               NamedNodeMap attributes = node.getAttributes();
-                               if (bufferobj instanceof PHPType)
-                                       name = document.createAttribute(TYPE_ATTR);
-                               if (bufferobj instanceof PHPKeyword)
-                                       name = document.createAttribute(KEYWORD_ATTR);
-                               if (bufferobj instanceof PHPFunction)
-                                       name = document.createAttribute(FN_ATTR);
-                               if (bufferobj instanceof PHPConstant)
-                                       name = document.createAttribute(CONSTANT_ATTR);
-                               name.setValue(((PHPElement) bufferobj).getName());
-                               attributes.setNamedItem(name);
-                               Attr description = document.createAttribute(USAGE_ATTR);
-                               description.setValue(((PHPElement) bufferobj).getUsage());
-                               attributes.setNamedItem(description);
-                               if (bufferobj instanceof PHPKeyword) {
-                                       Attr tokenval = document.createAttribute(TOKENVAL_ATTR);
-                                       tokenval.setValue(
-                                               (new Integer(((PHPKeyword) bufferobj).gettokenval()))
-                                                       .toString());
-                                       attributes.setNamedItem(tokenval);
-                               }
-                               if (bufferobj instanceof PHPFunction) {
-                                       //      Attr usage = document.createAttribute(USAGE_ATTR);
-                                       Text usage =
-                                               document.createTextNode(
-                                                       ((PHPFunction) bufferobj).getDescription());
-                                       node.appendChild(usage);
-                                       //          usage.setValue(((PHPFunction) bufferobj).getUsage());
-                                       //          attributes.setNamedItem(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);
-               }
-       }
+  private static void throwReadException(Throwable t) throws CoreException {
+    PHPeclipsePlugin.log(t);
+  }
 
-       private static void throwReadException(Throwable t) throws CoreException {
-               PHPeclipsePlugin.log(t);
-               //              IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
-               //                      ObfuscatorMessages.getString("TemplateSet.error.read"), t); //$NON-NLS-1$
-               //              throw new JavaUIException(status);
-       }
-
-       private static void throwWriteException(Throwable t) throws CoreException {
-               PHPeclipsePlugin.log(t);
-               //              IStatus status= new JavaUIStatus(JavaStatusConstants.TEMPLATE_IO_EXCEPTION,
-               //                      ObfuscatorMessages.getString("TemplateSet.error.write"), t); //$NON-NLS-1$
-               //              throw new JavaUIException(status);
-       }
+  private static void throwWriteException(Throwable t) throws CoreException {
+    PHPeclipsePlugin.log(t);
+  }
 
 }
index 998d77f..20eb1ba 100644 (file)
@@ -447,7 +447,7 @@ This function is identical to ereg_replace() except that this ignores case disti
         <phpsyntax function="exp"></phpsyntax>
         <phpsyntax function="explode" usage="array explode ( string separator, string string [, int limit])">Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string separator.
 If limit is set, the returned array will contain a maximum of limit elements with the last element containing the rest of string.
-If separator is an empty string (""), explode() will return FALSE. If separator contains a value that is not contained in string, 
+If separator is an empty string (&quot;&quot;), explode() will return FALSE. If separator contains a value that is not contained in string, 
 then explode() will return an array containing string. 
 Note: The limit parameter was added in PHP 4.0.1 
         </phpsyntax>
@@ -1565,7 +1565,7 @@ zerofill - 1 if the column is zero-filled
         <phpsyntax function="mysql_list_dbs" usage="resource mysql_list_dbs ( [resource link_identifier])">List databases available on a MySQL server</phpsyntax>
         <phpsyntax function="mysql_list_fields" usage="resource mysql_list_fields ( string database_name, string table_name [, resource link_identifier])">List MySQL result fields</phpsyntax>
         <phpsyntax function="mysql_list_processes" usage="resource mysql_list_processes ( [resource link_identifier])">List MySQL processes</phpsyntax>
-        <phpsyntax function="mysql_list_tables" usage="resource mysql_list_tables ( string database [, resource link_identifier])"List tables in a MySQL database</phpsyntax>
+        <phpsyntax function="mysql_list_tables" usage="resource mysql_list_tables ( string database [, resource link_identifier])">List tables in a MySQL database</phpsyntax>
         <phpsyntax function="mysql_num_fields" usage="int mysql_num_fields ( resource result)">Get number of fields in result</phpsyntax>
         <phpsyntax function="mysql_num_rows" usage="int mysql_num_rows ( resource result)">Get number of rows in result</phpsyntax>
         <phpsyntax function="mysql_pconnect" usage="resource mysql_pconnect ( [string server [, string username [, string password [, int client_flags]]]])">Open a persistent connection to a MySQL server </phpsyntax>
@@ -2015,7 +2015,7 @@ Note: This information is also available in the predefined constant PHP_VERSION.
         <phpsyntax function="preg_replace_callback"></phpsyntax>
         <phpsyntax function="preg_split"></phpsyntax>
         <phpsyntax function="prev" usage="mixed prev ( array array)">Rewind the internal array pointer</phpsyntax>
-        <phpsyntax function="print" usage="">
+        <phpsyntax function="print">
 Output a string.
 Outputs arg. Returns TRUE on success or FALSE on failure. 
 print() is not actually a real function (it is a language construct) so you are not required to use parentheses with it. 
@@ -2181,7 +2181,7 @@ This does not indicate whether the user accepted the cookie.
 
 All the arguments except the name argument are optional. 
 If only the name argument is present, the cookie by that name will be deleted from the remote client. 
-You may also replace an argument with an empty string ("") in order to skip that argument. 
+You may also replace an argument with an empty string (&quot;&quot;) in order to skip that argument. 
 Because the expire and secure arguments are integers, they cannot be skipped with an empty string, use a zero (0) instead. 
         </phpsyntax>
         <phpsyntax function="setdepth"></phpsyntax>
@@ -2283,9 +2283,9 @@ will return the original version.
 </phpsyntax>
         <phpsyntax function="str_shuffle" usage="string str_shuffle ( string str)">Randomly shuffles a string</phpsyntax> 
         <phpsyntax function="str_word_count" usage="mixed str_word_count ( string string [, int format])">Return information about words used in a string </phpsyntax>
-        <phpsyntax function="strcasecmp" usage"int strcasecmp ( string str1, string str2)">Binary safe case-insensitive string comparison </phpsyntax>
+        <phpsyntax function="strcasecmp" usage="int strcasecmp ( string str1, string str2)">Binary safe case-insensitive string comparison </phpsyntax>
         <phpsyntax function="strchr" usage="string strchr ( string haystack, string needle)">Find the first occurrence of a character.This function is an alias for strstr(), and is identical in every way.</phpsyntax>
-        <phpsyntax function="strcmp" usage"int strcmp ( string str1, string str2)">Binary safe string comparison.
+        <phpsyntax function="strcmp" usage="int strcmp ( string str1, string str2)">Binary safe string comparison.
 Returns &lt; 0 if str1 is less than str2; &gt; 0 if str1 is greater than str2, and 0 if they are equal. 
 Note that this comparison is case sensitive. 
         </phpsyntax>