org.eclipse.pde.core_3.7.1.v20120103_r372

Offset();
  }
  
  public int getXMLType()
  {
    return 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.DocumentAttributeNode
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.text;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.core.IModel;
import org.eclipse.pde.internal.core.util.PDETextHelper;

public abstract class DocumentElementNode
  extends DocumentXMLNode
  implements IDocumentElementNode
{
  private static final long serialVersionUID = 1L;
  public static final String ATTRIBUTE_VALUE_ENCODING = "UTF-8";
  public static final String ATTRIBUTE_VALUE_TRUE = "true";
  public static final String ATTRIBUTE_VALUE_FALSE = "false";
  public static final String EMPTY_VALUE = "";
  private transient IDocumentElementNode fParent;
  private transient boolean fIsErrorNode;
  private transient int fLength;
  private transient int fOffset;
  private transient IDocumentElementNode fPreviousSibling;
  private transient int fIndent;
  private ArrayList fChildren;
  private TreeMap fAttributes;
  private String fTag;
  private IDocumentTextNode fTextNode;
  private String fNamespace = "";
  private String fNamespacePrefix = "";
  
  public DocumentElementNode()
  {
    fParent = null;
    fIsErrorNode = false;
    fLength = -1;
    fOffset = -1;
    fPreviousSibling = null;
    fIndent = 0;
    
    fChildren = new ArrayList();
    fAttributes = new TreeMap();
    fTag = null;
    fTextNode = null;
  }
  
  public ArrayList getChildNodesList()
  {
    return fChildren;
  }
  
  public TreeMap getNodeAttributesMap()
  {
    return fAttributes;
  }
  
  public String writeShallow(boolean terminate)
  {
    StringBuffer buffer = new StringBuffer();
    
    buffer.append("<");
    
    String prefix = getNamespacePrefix();
    if ((prefix != null) && (prefix.length() > 0))
    {
      buffer.append(getNamespacePrefix());
      buffer.append(":");
    }
    buffer.append(getXMLTagName());
    if (isRoot())
    {
      String namespace = getNamespace();
      if ((namespace != null) && (namespace.length() > 0))
      {
        buffer.append(" ");
        buffer.append("xmlns");
        if ((prefix != null) && (prefix.length() > 0))
        {
          buffer.append(":");
          buffer.append(getNamespacePrefix());
        }
        buffer.append("=");
        buffer.append("\"");
        buffer.append(namespace);
        buffer.append("\"");
      }
    }
    buffer.append(writeAttributes());
    if (terminate) {
      buffer.append("/");
    }
    buffer.append(">");
    
    return buffer.toString();
  }
  
  public boolean isLeafNode()
  {
    return false;
  }
  
  public boolean canTerminateStartTag()
  {
    if ((!hasXMLChildren()) && (!hasXMLContent()) && (isLeafNode())) {
      return true;
    }
    return false;
  }
  
  public String write(boolean indent)
  {
    StringBuffer buffer = new StringBuffer();
    boolean hasChildren = hasXMLChildren();
    boolean hasContent = hasXMLContent();
    boolean terminate = canTerminateStartTag();
    if (isRoot()) {
      buffer.append(writeXMLDecl());
    }
    if (indent) {
      buffer.append(getIndent());
    }
    buffer.append(writeShallow(terminate));
    if (hasChildren)
    {
      IDocumentElementNode[] children = getChildNodes();
      for (int i = 0; i < children.length; i++)
      {
        children[i].setLineIndent(getLineIndent() + 3);
        buffer.append(getLineDelimiter() + children[i].write(true));
      }
    }
    if (hasContent) {
      buffer.append(writeXMLContent());
    }
    if (!terminate)
    {
      buffer.append(getTerminateIndent());
      buffer.append("</");
      String prefix = getNamespacePrefix();
      if ((prefix != null) && (prefix.length() > 0))
      {
        buffer.append(getNamespacePrefix());
        buffer.append(":");
      }
      buffer.append(getXMLTagName());
      buffer.append(">");
    }
    return buffer.toString();
  }
  
  protected String writeXMLContent()
  {
    StringBuffer buffer = new StringBuffer();
    if (isDefined(fTextNode))
    {
      buffer.append(getContentIndent());
      buffer.append(fTextNode.write());
    }
    return buffer.toString();
  }
  
  protected String writeAttributes()
  {
    StringBuffer buffer = new StringBuffer();
    IDocumentAttributeNode[] attributes = getNodeAttributes();
    for (int i = 0; i < attributes.length; i++)
    {
      IDocumentAttributeNode attribute = attributes[i];
      if ((isDefined(attribute)) && (!attribute.getAttributeName().startsWith("xmlns:"))) {
        buffer.append(getAttributeIndent() + attribute.write());
      }
    }
    return buffer.toString();
  }
  
  public IDocumentElementNode[] getChildNodes()
  {
    return (IDocumentElementNode[])fChildren.toArray(new IDocumentElementNode[fChildren.size()]);
  }
  
  public int indexOf(IDocumentElementNode child)
  {
    return fChildren.indexOf(child);
  }
  
  public IDocumentElementNode getChildAt(int index)
  {
    if (index < fChildren.size()) {
      return (IDocumentElementNode)fChildren.get(index);
    }
    return null;
  }
  
  public IDocumentElementNode getParentNode()
  {
    return fParent;
  }
  
  public void setParentNode(IDocumentElementNode node)
  {
    fParent = node;
  }
  
  public void addChildNode(IDocumentElementNode child)
  {
    addChildNode(child, fChildren.size());
  }
  
  public void addChildNode(IDocumentElementNode child, int position)
  {
    fChildren.add(position, child);
    child.setParentNode(this);
    linkNodeWithSiblings(child);
  }
  
  public IDocumentElementNode removeChildNode(IDocumentElementNode child)
  {
    int index = fChildren.indexOf(child);
    if (index != -1)
    {
      fChildren.remove(child);
      if (index < fChildren.size())
      {
        IDocumentElementNode prevSibling = index == 0 ? null : (IDocumentElementNode)fChildren.get(index - 1);
        ((IDocumentElementNode)fChildren.get(index)).setPreviousSibling(prevSibling);
      }
      return child;
    }
    return null;
  }
  
  public IDocumentElementNode removeChildNode(int index)
  {
    if ((index < 0) || (index >= fChildren.size())) {
      return null;
    }
    IDocumentElementNode child = (IDocumentElementNode)fChildren.get(index);
    
    fChildren.remove(child);
    if (index < fChildren.size())
    {
      IDocumentElementNode previousSibling = null;
      if (index != 0) {
        previousSibling = (IDocumentElementNode)fChildren.get(index - 1);
      }
      IDocumentElementNode newNode = (IDocumentElementNode)fChildren.get(index);
      newNode.setPreviousSibling(previousSibling);
    }
    return child;
  }
  
  public boolean isErrorNode()
  {
    return fIsErrorNode;
  }
  
  public void setIsErrorNode(boolean isErrorNode)
  {
    fIsErrorNode = isErrorNode;
  }
  
  public void setOffset(int offset)
  {
    fOffset = offset;
  }
  
  public void setLength(int length)
  {
    fLength = length;
  }
  
  public int getOffset()
  {
    return fOffset;
  }
  
  public int getLength()
  {
    return fLength;
  }
  
  public void setXMLAttribute(IDocumentAttributeNode attribute)
  {
    fAttributes.put(attribute.getAttributeName(), attribute);
  }
  
  public String getXMLAttributeValue(String name)
  {
    IDocumentAttributeNode attribute = (IDocumentAttributeNode)fAttributes.get(name);
    if (attribute == null) {
      return null;
    }
    return attribute.getAttributeValue();
  }
  
  public void setXMLTagName(String tag)
  {
    fTag = tag;
  }
  
  public String getXMLTagName()
  {
    return fTag;
  }
  
  public IDocumentAttributeNode getDocumentAttribute(String name)
  {
    return (IDocumentAttributeNode)fAttributes.get(name);
  }
  
  public int getLineIndent()
  {
    return fIndent;
  }
  
  public void setLineIndent(int indent)
  {
    fIndent = indent;
  }
  
  public IDocumentAttributeNode[] getNodeAttributes()
  {
    ArrayList list = new ArrayList();
    Iterator iter = fAttributes.values().iterator();
    while (iter.hasNext()) {
      list.add(iter.next());
    }
    return (IDocumentAttributeNode[])list.toArray(new IDocumentAttributeNode[list.size()]);
  }
  
  public IDocumentElementNode getPreviousSibling()
  {
    return fPreviousSibling;
  }
  
  public void setPreviousSibling(IDocumentElementNode sibling)
  {
    fPreviousSibling = sibling;
  }
  
  public String getIndent()
  {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < fIndent; i++) {
      buffer.append(" ");
    }
    return buffer.toString();
  }
  
  public void swap(IDocumentElementNode child1, IDocumentElementNode child2)
  {
    int index1 = fChildren.indexOf(child1);
    int index2 = fChildren.indexOf(child2);
    
    fChildren.set(index1, child2);
    fChildren.set(index2, child1);
    
    child1.setPreviousSibling(index2 == 0 ? null : (IDocumentElementNode)fChildren.get(index2 - 1));
    child2.setPreviousSibling(index1 == 0 ? null : (IDocumentElementNode)fChildren.get(index1 - 1));
    if (index1 < fChildren.size() - 1) {
      ((IDocumentElementNode)fChildren.get(index1 + 1)).setPreviousSibling(child2);
    }
    if (index2 < fChildren.size() - 1) {
      ((IDocumentElementNode)fChildren.get(index2 + 1)).setPreviousSibling(child1);
    }
  }
  
  public void addTextNode(IDocumentTextNode textNode)
  {
    fTextNode = textNode;
  }
  
  public IDocumentTextNode getTextNode()
  {
    return fTextNode;
  }
  
  public void removeTextNode()
  {
    fTextNode = null;
  }
  
  public void removeDocumentAttribute(IDocumentAttributeNode attr)
  {
    fAttributes.remove(attr.getAttributeName());
  }
  
  public void reconnect(IDocumentElementNode parent, IModel model)
  {
    reconnectDocument();
    
    reconnectParent(parent);
    
    reconnectPreviousSibling();
    
    reconnectText();
    
    reconnectAttributes();
    
    reconnectChildren(model);
  }
  
  private void reconnectAttributes()
  {
    Iterator keys = fAttributes.keySet().iterator();
    while (keys.hasNext())
    {
      String key = (String)keys.next();
      IDocumentAttributeNode attribute = (IDocumentAttributeNode)fAttributes.get(key);
      attribute.reconnect(this);
    }
  }
  
  private void reconnectChildren(IModel model)
  {
    for (int i = 0; i < fChildren.size(); i++)
    {
      IDocumentElementNode child = (IDocumentElementNode)fChildren.get(i);
      
      child.reconnect(this, model);
    }
  }
  
  private void reconnectDocument()
  {
    fIndent = 0;
    
    fIsErrorNode = false;
    
    fLength = -1;
    
    fOffset = -1;
  }
  
  private void reconnectParent(IDocumentElementNode parent)
  {
    fParent = parent;
  }
  
  private void reconnectPreviousSibling()
  {
    linkNodeWithSiblings(this);
  }
  
  private void linkNodeWithSiblings(IDocumentElementNode targetNode)
  {
    IDocumentElementNode parentNode = targetNode.getParentNode();
    if (parentNode == null) {
      return;
    }
    int targetNodePosition = parentNode.indexOf(targetNode);
    
    int parentNodeChildCount = parentNode.getChildCount();
    if (targetNodePosition <= 0)
    {
      targetNode.setPreviousSibling(null);
    }
    else if ((targetNodePosition >= 1) && (parentNodeChildCount >= 2))
    {
      IDocumentElementNode previousNode = parentNode.getChildAt(targetNodePosition - 1);
      targetNode.setPreviousSibling(previousNode);
    }
    int secondLastNodeIndex = parentNodeChildCount - 2;
    if ((targetNodePosition >= 0) && (targetNodePosition <= secondLastNodeIndex) && (parentNodeChildCount >= 2))
    {
      IDocumentElementNode nextNode = parentNode.getChildAt(targetNodePosition + 1);
      nextNode.setPreviousSibling(targetNode);
    }
  }
  
  private void reconnectText()
  {
    if (fTextNode != null) {
      fTextNode.reconnect(this);
    }
  }
  
  public int getChildCount()
  {
    return fChildren.size();
  }
  
  public boolean isRoot()
  {
    return false;
  }
  
  protected String getFileEncoding()
  {
    return "UTF-8";
  }
  
  protected String writeXMLDecl()
  {
    StringBuffer buffer = new StringBuffer("<?xml version=\"1.0\" encoding=\"");
    buffer.append(getFileEncoding());
    buffer.append("\"");
    buffer.append("?>");
    buffer.append(getLineDelimiter());
    return buffer.toString();
  }
  
  protected String getAttributeIndent()
  {
    return getLineDelimiter() + getIndent() + "      ";
  }
  
  protected String getContentIndent()
  {
    return getLineDelimiter() + getIndent() + "   ";
  }
  
  protected String getTerminateIndent()
  {
    return getLineDelimiter() + getIndent();
  }
  
  protected String getLineDelimiter()
  {
    return System.getProperty("line.separator");
  }
  
  protected boolean isDefined(IDocumentAttributeNode attribute)
  {
    if (attribute == null) {
      return false;
    }
    if (attribute.getAttributeValue().trim().length() <= 0) {
      return false;
    }
    return true;
  }
  
  protected boolean isDefined(IDocumentTextNode node)
  {
    if (node == null) {
      return false;
    }
    return PDETextHelper.isDefinedAfterTrim(node.getText());
  }
  
  public boolean hasXMLChildren()
  {
    if (getChildCount() == 0) {
      return false;
    }
    return true;
  }
  
  public boolean hasXMLContent()
  {
    if (isDefined(fTextNode)) {
      return true;
    }
    return false;
  }
  
  public int getNodeAttributesCount()
  {
    int count = 0;
    IDocumentAttributeNode[] attributes = getNodeAttributes();
    for (int i = 0; i < attributes.length; i++)
    {
      IDocumentAttributeNode attribute = attributes[i];
      if (isDefined(attribute)) {
        count++;
      }
    }
    return count;
  }
  
  public boolean hasXMLAttributes()
  {
    if (getNodeAttributesCount() == 0) {
      return false;
    }
    return true;
  }
  
  public boolean setXMLAttribute(String name, String value)
  {
    if ((name == null) || (name.length() == 0)) {
      return false;
    }
    if (value == null) {
      value = "";
    }
    String oldValue = getXMLAttributeValue(name);
    if ((oldValue != null) && (oldValue.equals(value))) {
      return false;
    }
    IDocumentAttributeNode attribute = (IDocumentAttributeNode)getNodeAttributesMap().get(name);
    try
    {
      if (attribute == null)
      {
        attribute = createDocumentAttributeNode();
        attribute.setAttributeName(name);
        attribute.setEnclosingElement(this);
        setXMLAttribute(attribute);
      }
      attribute.setAttributeValue(value);
    }
    catch (CoreException localCoreException)
    {
      return false;
    }
    return true;
  }
  
  public boolean setXMLContent(String text)
  {
    if (text == null) {
      text = "";
    }
    IDocumentTextNode node = getTextNode();
    if (node == null)
    {
      node = createDocumentTextNode();
      node.setEnclosingElement(this);
      addTextNode(node);
    }
    node.setText(text);
    
    return true;
  }
  
  public String getXMLContent()
  {
    IDocumentTextNode node = getTextNode();
    if (node == null) {
      return null;
    }
    return node.getText();
  }
  
  public String write()
  {
    return write(false);
  }
  
  public int getXMLType()
  {
    return 0;
  }
  
  public boolean isContentCollapsed()
  {
    return false;
  }
  
  protected IDocumentAttributeNode createDocumentAttributeNode()
  {
    return new DocumentAttributeNode();
  }
  
  protected IDocumentTextNode createDocumentTextNode()
  {
    return new DocumentTextNode();
  }
  
  public String getNamespace()
  {
    return fNamespace;
  }
  
  public String getNamespacePrefix()
  {
    return fNamespacePrefix;
  }
  
  public void setNamespace(String namespace)
  {
    fNamespace = namespace;
  }
  
  public void setNamespacePrefix(String prefix)
  {
    fNamespacePrefix = prefix;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.DocumentElementNode
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.text;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.Stack;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.Region;
import org.eclipse.pde.internal.core.util.PDEXMLHelper;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

public abstract class DocumentHandler
  extends DefaultHandler
{
  protected Stack fDocumentNodeStack = new Stack();
  protected int fHighestOffset = 0;
  private Locator fLocator;
  private IDocumentElementNode fLastError;
  private boolean fReconciling;
  
  public DocumentHandler(boolean reconciling)
  {
    fReconciling = reconciling;
  }
  
  public void startDocument()
    throws SAXException
  {
    fDocumentNodeStack.clear();
    fHighestOffset = 0;
    fLastError = null;
  }
  
  protected IDocumentElementNode getLastParsedDocumentNode()
  {
    if (fDocumentNodeStack.isEmpty()) {
      return null;
    }
    return (IDocumentElementNode)fDocumentNodeStack.peek();
  }
  
  public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
  {
    IDocumentElementNode parent = getLastParsedDocumentNode();
    IDocumentElementNode node = getDocumentNode(qName, parent);
    try
    {
      int nodeOffset = getStartOffset(qName);
      node.setOffset(nodeOffset);
      IDocument doc = getDocument();
      int line = doc.getLineOfOffset(nodeOffset);
      node.setLineIndent(node.getOffset() - doc.getLineOffset(line));
      for (int i = 0; i < attributes.getLength(); i++)
      {
        String attName = attributes.getQName(i);
        String attValue = attributes.getValue(i);
        IDocumentAttributeNode attribute = getDocumentAttribute(attName, attValue, node);
        if (attribute != null)
        {
          IRegion region = getAttributeRegion(attName, attValue, nodeOffset);
          if (region == null)
          {
            attValue = PDEXMLHelper.getWritableString(attValue);
            region = getAttributeRegion(attName, attValue, nodeOffset);
          }
          if (region != null)
          {
            attribute.setNameOffset(region.getOffset());
            attribute.setNameLength(attName.length());
            attribute.setValueOffset(region.getOffset() + region.getLength() - 1 - attValue.length());
            attribute.setValueLength(attValue.length());
          }
          node.setXMLAttribute(attribute);
        }
      }
      removeOrphanAttributes(node);
    }
    catch (BadLocationException localBadLocationException) {}
    if ((parent != null) && (node != null) && (node.getParentNode() == null)) {
      if (fReconciling)
      {
        int position = 0;
        IDocumentElementNode[] children = parent.getChildNodes();
        for (; position < children.length; position++) {
          if (children[position].getOffset() == -1) {
            break;
          }
        }
        parent.addChildNode(node, position);
      }
      else
      {
        parent.addChildNode(node);
      }
    }
    fDocumentNodeStack.push(node);
  }
  
  protected abstract IDocumentElementNode getDocumentNode(String paramString, IDocumentElementNode paramIDocumentElementNode);
  
  protected abstract IDocumentAttributeNode getDocumentAttribute(String paramString1, String paramString2, IDocumentElementNode paramIDocumentElementNode);
  
  protected abstract IDocumentTextNode getDocumentTextNode(String paramString, IDocumentElementNode paramIDocumentElementNode);
  
  private int getStartOffset(String elementName)
    throws BadLocationException
  {
    int line = fLocator.getLineNumber();
    int col = fLocator.getColumnNumber();
    IDocument doc = getDocument();
    if (col < 0) {
      col = doc.getLineLength(line);
    }
    int endOffset;
    int endOffset;
    if (line < doc.getNumberOfLines())
    {
      endOffset = doc.getLineOffset(line);
    }
    else
    {
      line = doc.getNumberOfLines() - 1;
      IRegion lineInfo = doc.getLineInformation(line);
      endOffset = lineInfo.getOffset() + lineInfo.getLength();
    }
    String text = doc.get(fHighestOffset + 1, endOffset - fHighestOffset - 1);
    
    ArrayList commentPositions = new ArrayList();
    for (int idx = 0; idx < text.length();)
    {
      idx = text.indexOf("<!--", idx);
      if (idx == -1) {
        break;
      }
      int end = text.indexOf("-->", idx);
      if (end == -1) {
        break;
      }
      commentPositions.add(new Position(idx, end - idx));
      idx = end + 1;
    }
    for (int idx = 0; idx < text.length(); idx++)
    {
      idx = text.indexOf("<" + elementName, idx);
      if (idx == -1) {
        break;
      }
      boolean valid = true;
      for (int i = 0; i < commentPositions.size(); i++)
      {
        Position pos = (Position)commentPositions.get(i);
        if (pos.includes(idx))
        {
          valid = false;
          break;
        }
      }
      if (valid) {
        break;
      }
    }
    if (idx > -1) {
      fHighestOffset += idx + 1;
    }
    return fHighestOffset;
  }
  
  private int getElementLength(IDocumentElementNode node, int line, int column)
    throws BadLocationException
  {
    int endIndex = node.getOffset();
    IDocument doc = getDocument();
    int start = Math.max(doc.getLineOffset(line), node.getOffset());
    column = doc.getLineLength(line);
    String lineText = doc.get(start, column - start + doc.getLineOffset(line));
    
    int index = lineText.indexOf("</" + node.getXMLTagName() + ">");
    if (index == -1)
    {
      index = lineText.indexOf(">");
      if (index == -1) {
        endIndex = column;
      } else {
        endIndex = index + 1;
      }
    }
    else
    {
      endIndex = index + node.getXMLTagName().length() + 3;
    }
    return start + endIndex - node.getOffset();
  }
  
  private IRegion getAttributeRegion(String name, String value, int offset)
    throws BadLocationException
  {
    FindReplaceDocumentAdapter fFindReplaceAdapter = new FindReplaceDocumentAdapter(getDocument());
    IRegion nameRegion = fFindReplaceAdapter.find(offset, "\\s" + name + "\\s*=\\s*[\"']", true, true, false, true);
    if (nameRegion != null)
    {
      nameRegion = new Region(nameRegion.getOffset() + 1, nameRegion.getLength() - 1);
      if (getDocument().get(nameRegion.getOffset() + nameRegion.getLength(), value.length()).equals(value)) {
        return new Region(nameRegion.getOffset(), nameRegion.getLength() + value.length() + 1);
      }
    }
    return null;
  }
  
  public void endElement(String uri, String localName, String qName)
    throws SAXException
  {
    if (fDocumentNodeStack.isEmpty()) {
      return;
    }
    IDocumentElementNode node = (IDocumentElementNode)fDocumentNodeStack.pop();
    try
    {
      node.setLength(getElementLength(node, fLocator.getLineNumber() - 1, fLocator.getColumnNumber()));
      setTextNodeOffset(node);
    }
    catch (BadLocationException localBadLocationException) {}
    removeOrphanElements(node);
  }
  
  protected void setTextNodeOffset(IDocumentElementNode node)
    throws BadLocationException
  {
    IDocumentTextNode textNode = node.getTextNode();
    if ((textNode != null) && (textNode.getText() != null))
    {
      if (textNode.getText().trim().length() == 0)
      {
        node.removeTextNode();
        return;
      }
      IDocument doc = getDocument();
      String text = doc.get(node.getOffset(), node.getLength());
      
      int relativeStartOffset = text.indexOf('>') + 1;
      
      int relativeEndOffset = text.lastIndexOf('<') - 1;
      if ((relativeStartOffset < 0) || (relativeStartOffset >= text.length())) {
        return;
      }
      if ((relativeEndOffset < 0) || (relativeEndOffset >= text.length())) {
        return;
      }
      while (Character.isWhitespace(text.charAt(relativeStartOffset))) {
        relativeStartOffset++;
      }
      while (Character.isWhitespace(text.charAt(relativeEndOffset))) {
        relativeEndOffset--;
      }
      textNode.setOffset(node.getOffset() + relativeStartOffset);
      textNode.setLength(relativeEndOffset - relativeStartOffset + 1);
      textNode.setText(textNode.getText().trim());
    }
  }
  
  public void fatalError(SAXParseException e)
    throws SAXException
  {
    generateErrorElementHierarchy();
  }
  
  private void generateErrorElementHierarchy()
  {
    while (!fDocumentNodeStack.isEmpty())
    {
      IDocumentElementNode node = (IDocumentElementNode)fDocumentNodeStack.pop();
      node.setIsErrorNode(true);
      removeOrphanAttributes(node);
      removeOrphanElements(node);
      if (fLastError == null) {
        fLastError = node;
      }
    }
  }
  
  public void error(SAXParseException e)
    throws SAXException
  {
    generateErrorElementHierarchy();
  }
  
  public void setDocumentLocator(Locator locator)
  {
    fLocator = locator;
  }
  
  protected abstract IDocument getDocument();
  
  public InputSource resolveEntity(String publicId, String systemId)
    throws SAXException
  {
    return new InputSource(new StringReader(""));
  }
  
  public IDocumentElementNode getLastErrorNode()
  {
    return fLastError;
  }
  
  public void characters(char[] ch, int start, int length)
    throws SAXException
  {
    if ((!fReconciling) || (fDocumentNodeStack.isEmpty())) {
      return;
    }
    IDocumentElementNode parent = (IDocumentElementNode)fDocumentNodeStack.peek();
    StringBuffer buffer = new StringBuffer();
    buffer.append(ch, start, length);
    getDocumentTextNode(buffer.toString(), parent);
  }
  
  private void removeOrphanAttributes(IDocumentElementNode node)
  {
    if (fReconciling)
    {
      IDocumentAttributeNode[] attrs = node.getNodeAttributes();
      for (int i = 0; i < attrs.length; i++) {
        if (attrs[i].getNameOffset() == -1) {
          node.removeDocumentAttribute(attrs[i]);
        }
      }
    }
  }
  
  private void removeOrphanElements(IDocumentElementNode node)
  {
    if (fReconciling)
    {
      IDocumentElementNode[] children = node.getChildNodes();
      for (int i = 0; i < children.length; i++) {
        if (children[i].getOffset() == -1) {
          node.removeChildNode(children[i]);
        }
      }
    }
  }
  
  protected boolean isReconciling()
  {
    return fReconciling;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.DocumentHandler
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.text;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.internal.core.text.plugin.DocumentGenericNode;

public abstract class DocumentNodeFactory
  implements IDocumentNodeFactory
{
  public IDocumentAttributeNode createAttribute(String name, String value, IDocumentElementNode enclosingElement)
  {
    IDocumentAttributeNode attribute = new DocumentAttributeNode();
    try
    {
      attribute.setAttributeName(name);
      attribute.setAttributeValue(value);
    }
    catch (CoreException localCoreException) {}
    attribute.setEnclosingElement(enclosingElement);
    return attribute;
  }
  
  public IDocumentTextNode createDocumentTextNode(String content, IDocumentElementNode parent)
  {
    IDocumentTextNode textNode = new DocumentTextNode();
    textNode.setEnclosingElement(parent);
    parent.addTextNode(textNode);
    textNode.setText(content);
    return textNode;
  }
  
  public IDocumentElementNode createDocumentNode(String name, IDocumentElementNode parent)
  {
    return createGeneric(name);
  }
  
  protected IDocumentElementNode createGeneric(String name)
  {
    return new DocumentGenericNode(name);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.text.DocumentNodeFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.text;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.pde.core.IModel;
import org.eclipse.pde.core.IModelChangeProvider;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.core.ModelChangedEvent;

public abstract class DocumentObject
  extends DocumentElementNode
  implements IDocumentObject
{
  private static final long serialVersionUID = 1L;
  private transient IModel fModel;
  private transient boolean fInTheModel;
  
  public DocumentObject(IModel model, String tagName)
  {
    fModel = model;
    fInTheModel = false;
    setXMLTagName(tagName);
  }
  
  public void setSharedModel(IModel model)
  {
    fModel = model;
  }
  
  public IModel getSharedModel()
  {
    return fModel;
  }
  
  public void reset()
  {
    fModel = null;
    fInTheModel = false;
  }
  
  public boolean isInTheModel()
  {
    return fInTheModel;
  }
  
  public void setInTheModel(boolean inModel)
  {
    fInTheModel = inModel;
  }
  
  public boolean isEditable()
  {
    return fModel.isEditable();
  }
  
  protected boolean shouldFireEvent()
  {
    if ((isInTheModel()) && (isEditable())) {
      return true;
    }
    return false;
  }
  
  protected String getLineDelimiter()
  {
    if ((fModel instanceof IEditingModel))
    {
      IDocument document = ((IEditingModel)fModel).getDocument();
      return TextUtilities.getDefaultLineDelimiter(document);
    }
    return super.getLineDelimiter();
  }
  
  public void reconnect(IDocumentElementNode parent, IModel model)
  {
    super.reconnect(parent, model);
    
    fInTheModel = true;
    
    fModel = model;
  }
  
  protected void firePropertyChanged(String property, Object oldValue, Object newValue)
  {
    firePropertyChanged(this, property, oldValue, newValue);
  }
  
  private void firePropertyChanged(Object object, String property, Object oldValue, Object newValue)
  {
    if ((fModel.isEditable()) && ((fModel instanceof IModelChangeProvider)))
    {
      IModelChangeProvider provider = (IModelChangeProvider)fModel;
      provider.fireModelObjectChanged(object, property, oldValue, newValue);
    }
  }
  
  protected void fireStructureChanged(Object child, int changeType)
  {
    fireStructureChanged(new Object[] { child }, changeType);
  }
  
  protected void fireStructureChanged(Object[] children, int changeType)
  {
    if ((fModel.isEditable()) && ((fModel instanceof IModelChangeProvider)))
    {
      IModelChangeProvider provider = (IModelChangeProvider)fModel;
      IModelChangedEvent event = new ModelChangedEvent(provider, changeType, children, null);
      provider.fireModelChanged(event);
    }
  }
  
  public void addChildNode(IDocumentElementNode child)
  {
    if ((child instanceof IDocumentObject)) {
      ((IDocumentObject)child).setInTheModel(true);
    }
    super.addChildNode(child);
  }
  
  public void addChildNode(IDocumentElementNode child, int position)
  {
    if ((position < 0) || (position > getChildCount())) {
      return;
    }
    if ((child instanceof IDocumentObject)) {
      ((IDocumentObject)child).setInTheModel(true);
    }
    super.addChildNode(child, position);
  }
  
  public void addChildNode(IDocumentElementNode child, int position, boolean fireEvent)
  {
    addChildNode(child, position);
    if ((fireEvent) && (shouldFireEvent())) {
      fireStructureChanged(child, 1);
    }
  }
  
  public void addChildNode(IDocumentElementNode child, boolean fireEvent)
  {
    addChildNode(child);
    if ((fireEvent) && (shouldFireEvent())) {
      fireStructureChanged(child, 1);
    }
  }
  
  public IDocumentElementNode removeChildNode(IDocumentElementNode child)
  {
    IDocumentElementNode node = super.removeChildNode(child);
    if ((node != null) && ((node instanceof IDocumentObject))) {
      ((IDocumentObject)node).setInTheModel(false);
    }
    return node;
  }
  
  public IDocumentElementNode removeChildNode(int index)
  {
    IDocumentElementNode node = super.removeChildNode(index);
    if ((node != null) && ((node instanceof IDocumentObject))) {
      ((IDocumentObject)node).setInTheModel(false);
    }
    return node;
  }
  
  public IDocumentElementNode removeChildNode(IDocumentElementNode child, boolean fireEvent)
  {
    IDocumentElementNode node = removeChildNode(child);
    if ((fireEvent) && (shouldFireEvent())) {
      fireStructureChanged(child, 2);
    }
    return node;
  }
  
  public IDocumentElementNode removeChildNode(int index, Class clazz, boolean fireEvent)
  {
    IDocumentElementNode node = removeChildNode(index, clazz);
    if ((fireEvent) && (shouldFireEvent())) {
      fireStructureChanged(node, 2);
    }
    return node;
  }
  
  public IDocumentElementNode removeChildNode(int index, Class clazz)
  {
    if ((index < 0) || (index >= getChildCount()) || (!clazz.isInstance(getChildAt(index)))) {
      return null;
    }
    IDocumentElementNode node = removeChildNode(index);
    return node;
  }
  
  public void write(String indent, PrintWriter writer)
  {
    writer.write(write(true));
  }
  
  public void setChildNode(IDocumentElementNode newNode, Class clazz)
  {
    boolean fireEvent = shouldFireEvent();
    
    IDocumentElementNode oldNode = getChildNode(clazz);
    if ((newNode == null) && (oldNode == null)) {
      return;
    }
    if (newNode == null) {
      removeChildNode(oldNode, fireEvent);
    } else if (oldNode == null) {
      addChildNode(newNode, fireEvent);
    } else {
      replaceChildNode(newNode, oldNode, fireEvent);
    }
  }
  
  protected void replaceChildNode(IDocumentElementNode newNode, IDocumentElementNode oldNode, boolean fireEvent)
  {
    int position = indexOf(oldNode);
    if (position < 0) {
      return;
    }
    addChildNode(newNode, position, fireEvent);
    
    removeChildNode(oldNode, fireEvent);
  }
  
  public IDocumentElementNode getChildNode(Class clazz)
  {
    ArrayList children = getChildNodesList();
    Iterator iterator = children.iterator();
    while (iterator.hasNext())
    {
      IDocumentElementNode node = (IDocumentElementNode)iterator.next();
      if (clazz.isInstance(node)) {
        return node;
      }
    }
    return null;
  }
  
  public int getChildNodeCount(Class clazz)
  {
    int count = 0;
    ArrayList children = getChildNodesList();
    Iterator iterator = children.iterator();
    while (iterator.hasNext())
    {
      IDocumentElementNode node = (IDocumentElementNode)iterator.next();
      if (clazz.isInstance(node)) {
        count++;
      }
    }
    return count;
  }
  
  public ArrayList getChildNodesList(Class clazz, boolean match)
  {
    return getChildNodesList(new Class[] { clazz }, match);
  }
  
  public ArrayList getChildNodesList(Class[] classes, boolean match)
  {
    ArrayList filteredChildren = new ArrayList();
    ArrayList children = getChildNodesList();
    Iterator iterator = children.iterator();
    while (iterator.hasNext())
    {
      IDocumentElementNode node = (IDocumentElementNode)iterator.next();
      for (int i = 0; i < classes.length; i++)
      {
        Class clazz = classes[i];
        if (clazz.isInstance(node) == match)
        {
          filteredChildren.add(node);
          break;
        }
      }
    }
    return filteredChildren;
  }
  
  public IDocumentElementNode getNextSibling(IDocumentElementNode node, Class clazz)
  {
    int position = indexOf(node);
    int lastIndex = getChildCount() - 1;
    if ((position < 0) || (position >= lastIndex)) {
      return null;
    }
    for (int i = position + 1; i <= lastIndex; i++)
    {
      IDocumentElementNode currentNode = getChildAt(i);
      if (clazz.isInstance(currentNode)) {
        return currentNode;
      }
    }
    return null;
  }
  
  public IDocumentElementNode getPreviousSibling(IDocumentElementNode node, Class clazz)
  {
    int position = indexOf(node);
    if ((position <= 0) || (position >= getChildCount())) {
      return null;
    }
    for (int i = position - 1; i >= 0; i--)
    {
      IDocumentElementNode currentNode = getChildAt(i);
      if (clazz.isInstance(currentNode)) {
        return currentNode;
      }
    }
    return null;
  }
  
  public boolean hasChildNodes(Class clazz)
  {
    ArrayList children = getChildNodesList();
    Iterator iterator = children.iterator();
    while (iterator.hasNext())
    {
      IDocumentElementNode node = (IDocumentElementNode)iterator.next();
      if (clazz.isInstance(node)) {
        return true;
      }
    }
    return false;
  }
  
  public boolean isFirstChildNode(IDocumentElementNode node, Class clazz)
  {
    int position = indexOf(node);
    if ((position < 0) || (position >= getChildCount())) {
      return false;
    }
    if (position == 0) {
      return true;
    }
    for (int i = 0; i < position; i++) {
      if (clazz.isInstance(getChildAt(i))) {
        return false;
      }
    }
    return true;
  }
  
  public boolean isLastChildNode(IDocumentElementNode node, Class clazz)
  {
    int position = indexOf(node);
    int lastIndex = getChildCount() - 1;
    if ((position < 0) || (position > lastIndex)) {
      return false;
    }
    if (position == lastIndex) {
      return true;
    }
    for (int i = position + 1; i <= lastIndex; i++) {
      if (clazz.isInstance(getChildAt(i))) {
        return false;
      }
    }
    return true;
  }
  
  public void swap(IDocumentElementNode child1, IDocumentElementNode child2, boolean fireEvent)
  {
    super.swap(child1, child2);
    if ((fireEvent) && (shouldFireEvent())) {
      firePropertyChanged(this, "type_swap", child1, child2);
    }
  }
  
  public void moveChildNode(IDocumentElementNode node, int newRelativeIndex, boolean fireEvent)
  {
    if (newRelativeIndex == 0) {
      return;
    }
    int currentIndex = indexOf(node);
    if (currentIndex == -1) {
      return;
    }
    int newIndex = newRelativeIndex + currentIndex;
    if ((newIndex < 0) || (newIndex >= getChildCount())) {
      return;
    }
    if ((newRelativeIndex == -1) || (newRelativeIndex == 1))
    {
      IDocumentElementNode sibling = getChildAt(newIndex);
      if (sibling == null) {
        return;
      }
      swap(node, sibling, fireEvent);
    }
    else
    {
      removeChildNode(node, fireEvent);
      
      IDocumentElementNode clone = clone(node);
      
      addChildNode(clone, newIndex, fireEvent);
    }
  }
  
  public IDocumentElementNode clone(IDocumentElementNode node)
  {
    IDocumentElementNode clone = null;
    try
    {
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(bout);
      out.writeObject(node);
      out.flush();
      out.close();
      byte[] bytes = bout.toByteArray();
      
      ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
      ObjectInputStream in = new ObjectInputStream(bin);
      clone = (IDocumentElementNode)in.readObject();
      in.close();
      
      clone.reconnect(this, fModel);
    }
    catch (IOException localIOException)
    {
      clone = null;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      clone = null;
    }
    return clone;
  }
  
  public boolean getBooleanAttributeValue(String name, boolean defaultValue)
  {
    String value = getXMLAttributeValue(name);
    if (value == null) {
      return defaultValue;
    }
    if (value.equalsIgnoreCase("true")) {
      return true;
    }
    if (value.equalsIgnoreCase("false"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd