A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / obfuscator / ObfuscatorIgnoreSet.java
index eef0d1b..3c323aa 100644 (file)
@@ -35,36 +35,39 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 /**
- * <code>ObfuscatorIgnoreSet</code> manages a collection of templates and makes them
- * persistent.
+ * <code>ObfuscatorIgnoreSet</code> manages a collection of templates and
+ * makes them persistent.
  */
 public class ObfuscatorIgnoreSet {
 
-       //      private static class TemplateComparator implements Comparator {
-       //              public int compare(Object arg0, Object arg1) {
-       //                      if (arg0 == arg1)
-       //                              return 0;
+       // private static class TemplateComparator implements Comparator {
+       // public int compare(Object arg0, Object arg1) {
+       // if (arg0 == arg1)
+       // return 0;
        //                      
-       //                      if (arg0 == null)
-       //                              return -1;
+       // if (arg0 == null)
+       // return -1;
        //                              
-       //                      Template template0= (Template) arg0;
-       //                      Template template1= (Template) arg1;
+       // Template template0= (Template) arg0;
+       // Template template1= (Template) arg1;
        //                      
-       //                      return template0.getName().compareTo(template1.getName());
-       //              }
-       //      }
+       // return template0.getName().compareTo(template1.getName());
+       // }
+       // }
 
        private static final String TEMPLATE_TAG = "ignore"; //$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 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 HashMap fIdentifierMap = new HashMap();
-       //      private Comparator fTemplateComparator= new TemplateComparator();
-       //      private Template[] fSortedTemplates= new Template[0];
+
+       // private Comparator fTemplateComparator= new TemplateComparator();
+       // private Template[] fSortedTemplates= new Template[0];
 
        /**
         * Convenience method for reading templates from a file.
@@ -95,8 +98,8 @@ public class ObfuscatorIgnoreSet {
         */
        public void addFromStream(InputStream stream) throws CoreException {
                try {
-                       DocumentBuilderFactory factory =
-                               DocumentBuilderFactory.newInstance();
+                       DocumentBuilderFactory factory = DocumentBuilderFactory
+                                       .newInstance();
                        DocumentBuilder parser = factory.newDocumentBuilder();
                        Document document = parser.parse(new InputSource(stream));
                        NodeList elements = document.getElementsByTagName(TEMPLATE_TAG);
@@ -109,15 +112,20 @@ public class ObfuscatorIgnoreSet {
                                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);
+                               // 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(ObfuscatorMessages.getString("TemplateSet.error.missing.attribute")); //$NON-NLS-1$
+                               // if (name == null || description == null || context == null)
+                               // throw new
+                               // SAXException(ObfuscatorMessages.getString("TemplateSet.error.missing.attribute"));
+                               // //$NON-NLS-1$
 
-                               //                              boolean enabled= true; //(enabledNode == null) || (enabledNode.getNodeValue().equals("true")); //$NON-NLS-1$
+                               // boolean enabled= true; //(enabledNode == null) ||
+                               // (enabledNode.getNodeValue().equals("true")); //$NON-NLS-1$
 
                                StringBuffer buffer = new StringBuffer();
                                NodeList children = node.getChildNodes();
@@ -127,13 +135,15 @@ public class ObfuscatorIgnoreSet {
                                                buffer.append(value);
                                }
                                String pattern = buffer.toString().trim();
-                               fIdentifierMap.put(pattern, new PHPIdentifier(pattern, PHPIdentifier.VARIABLE) );
-                               //                              Template template= new Template(name, description, context, pattern);   
-                               //                              template.setEnabled(enabled);
-                               //                              add(template);
+                               fIdentifierMap.put(pattern, new PHPIdentifier(pattern,
+                                               PHPIdentifier.VARIABLE));
+                               // Template template= new Template(name, description, context,
+                               // pattern);
+                               // template.setEnabled(enabled);
+                               // add(template);
                        }
 
-                       //                      sort();
+                       // sort();
 
                } catch (ParserConfigurationException e) {
                        throwReadException(e);
@@ -178,43 +188,48 @@ public class ObfuscatorIgnoreSet {
         */
        public void saveToStream(OutputStream stream) throws CoreException {
                try {
-                       DocumentBuilderFactory factory =
-                               DocumentBuilderFactory.newInstance();
+                       DocumentBuilderFactory factory = DocumentBuilderFactory
+                                       .newInstance();
                        DocumentBuilder builder = factory.newDocumentBuilder();
                        Document document = builder.newDocument();
 
-                       Node root = document.createElement("obfuscator"); // $NON-NLS-1$ //$NON-NLS-1$
+                       Node root = document.createElement("obfuscator"); // $NON-NLS-1$
+                                                                                                                               // //$NON-NLS-1$
                        document.appendChild(root);
                        Iterator iter = fIdentifierMap.keySet().iterator();
                        while (iter.hasNext()) {
-                               //                      for (int i= 0; i != fTemplates.size(); i++) {
-                               //                              Template template= (Template) fTemplates.get(i);
+                               // for (int i= 0; i != fTemplates.size(); i++) {
+                               // Template template= (Template) fTemplates.get(i);
 
-                               Node node = document.createElement("ignore"); // $NON-NLS-1$ //$NON-NLS-1$
+                               Node node = document.createElement("ignore"); // $NON-NLS-1$
+                                                                                                                               // //$NON-NLS-1$
                                root.appendChild(node);
 
-                               //                              NamedNodeMap attributes= node.getAttributes();
+                               // NamedNodeMap attributes= node.getAttributes();
                                //                              
-                               //                              Attr name= document.createAttribute(NAME_ATTRIBUTE);
-                               //                              name.setValue(template.getName());
-                               //                              attributes.setNamedItem(name);
+                               // 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 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 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);
+                               // 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((String) iter.next());
                                node.appendChild(pattern);
                        }
-                       Transformer transformer=TransformerFactory.newInstance().newTransformer();
+                       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);
@@ -226,98 +241,104 @@ public class ObfuscatorIgnoreSet {
                        throwWriteException(e);
                } catch (TransformerException e) {
                        throwWriteException(e);
-               }               
-//                     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);
-//             }
+               }
+               // 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);
+               // 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);
+               // 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
+       // 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();
+       // 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;
-       //              }
+       // if (template.equals(anotherTemplate))
+       // return true;
+       // }
        //              
-       //              return false;
-       //      }
+       // return false;
+       // }
        //      
-       //      /**
-       //       * Removes a template to the set.
-       //       */     
-       //      public void remove(Template template) {
-       //              fTemplates.remove(template);
-       //              sort();
-       //      }
+       // /**
+       // * Removes a template to the set.
+       // */
+       // public void remove(Template template) {
+       // fTemplates.remove(template);
+       // sort();
+       // }
        //
-               /**
-                * Empties the set.
-                */             
-               public void clear() {
-                       fIdentifierMap.clear();
-       //              fTemplates.clear();
-       //              sort();
-               }
+       /**
+        * Empties the set.
+        */
+       public void clear() {
+               fIdentifierMap.clear();
+               // fTemplates.clear();
+               // sort();
+       }
+
        //      
-       //      /**
-       //       * Returns all templates.
-       //       */
-       //      public Template[] getTemplates() {
-       //              return (Template[]) fTemplates.toArray(new Template[fTemplates.size()]);
-       //      }
+       // /**
+       // * 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()]);
-       //      }       
+       // 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);
-       //      }
-
+       // private void sort() {
+       // fSortedTemplates= (Template[]) fTemplates.toArray(new
+       // Template[fTemplates.size()]);
+       // Arrays.sort(fSortedTemplates, fTemplateComparator);
+       // }
        /**
         * @return
         */