org.eclipse.wst.dtd.core_1.1.501.v201107252021

16:48:58.731 INFO  jd.cli.Main - Decompiling org.eclipse.wst.dtd.core_1.1.501.v201107252021.jar
package org.eclipse.wst.dtd.core.internal;

import java.util.Hashtable;
import org.eclipse.wst.dtd.core.internal.text.RegionIterator;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;

public class Attribute
  extends DTDNode
{
  public static final String CDATA = DTDCoreMessages._UI_CHARACTER_DATA_DESC;
  public static final String ENTITIES = DTDCoreMessages._UI_ENTITY_NAMES_DESC;
  public static final String ENTITY = DTDCoreMessages._UI_ENTITY_NAME_DESC;
  public static final String ENUMERATED_NAME = DTDCoreMessages._UI_ENUM_NAME_TOKENS_DESC;
  public static final String ENUMERATED_NOTATION = DTDCoreMessages._UI_ENUM_NOTATION_DESC;
  public static final String FIXED = "#FIXED";
  public static final String ID = DTDCoreMessages._UI_IDENTIFIER_DESC;
  public static final String IDREF = DTDCoreMessages._UI_ID_REFERENCE_DESC;
  public static final String IDREFS = DTDCoreMessages._UI_ID_REFERENCES_DESC;
  public static final String IMPLIED = "#IMPLIED";
  public static final String NMTOKEN = DTDCoreMessages._UI_NAME_TOKEN_DESC;
  public static final String NMTOKENS = DTDCoreMessages._UI_NAME_TOKENS_DESC;
  public static final String REQUIRED = "#REQUIRED";
  protected static Hashtable typeHash = new Hashtable();
  public static final String[] types = { CDATA, ID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENS, ENUMERATED_NAME, ENUMERATED_NOTATION };
  private AttributeEnumList enumList;
  
  public Attribute(DTDFile file, IStructuredDocumentRegion flatNode)
  {
    super(file, flatNode);typeHash.put("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.CDATA_KEYWORD", CDATA);typeHash.put("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.ID_KEYWORD", ID);typeHash.put("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.IDREF_KEYWORD", IDREF);typeHash.put("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.IDREFS_KEYWORD", IDREFS);typeHash.put("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.ENTITY_KEYWORD", ENTITY);typeHash.put("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.ENTITIES_KEYWORD", ENTITIES);typeHash.put("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.NMTOKEN_KEYWORD", NMTOKEN);typeHash.put("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.NMTOKENS_KEYWORD", NMTOKENS);typeHash.put("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.NOTATION_KEYWORD", ENUMERATED_NOTATION);typeHash.put("()", ENUMERATED_NAME);typeHash.put(CDATA, "CDATA");typeHash.put(ID, "ID");typeHash.put(IDREF, "IDREF");typeHash.put(IDREFS, "IDREFS");typeHash.put(ENTITY, "ENTITY");typeHash.put(ENTITIES, "ENTITIES");typeHash.put(NMTOKEN, "NMTOKEN");typeHash.put(NMTOKENS, "NMTOKENS");typeHash.put(ENUMERATED_NAME, "");typeHash.put(ENUMERATED_NOTATION, "NOTATION");enumList = null;
  }
  
  public String getDefaultKind()
  {
    ITextRegion defaultKindRegion = getDefaultKindRegion();
    if (defaultKindRegion != null) {
      return getStructuredDTDDocumentRegion().getText(defaultKindRegion);
    }
    return "";
  }
  
  public ITextRegion getDefaultKindRegion()
  {
    RegionIterator iter = iterator();
    while (iter.hasNext())
    {
      ITextRegion region = iter.next();
      if ((region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.IMPLIED_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.REQUIRED_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.FIXED_KEYWORD")) {
        return region;
      }
    }
    return null;
  }
  
  public String getDefaultValue()
  {
    ITextRegion defaultValue = getNextQuotedLiteral(iterator());
    if (defaultValue != null) {
      return getValueFromQuotedRegion(defaultValue);
    }
    return "";
  }
  
  public AttributeEnumList getEnumList()
  {
    return enumList;
  }
  
  public String getImagePath()
  {
    return "icons/full/obj16/attribute.gif";
  }
  
  public ITextRegion getNameRegion()
  {
    return getNextRegion(iterator(), "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.ATTRIBUTE_NAME");
  }
  
  public ITextRegion getNextQuotedLiteral(RegionIterator iter)
  {
    while (iter.hasNext())
    {
      ITextRegion region = iter.next();
      if ((region.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.SINGLEQUOTED_LITERAL")) || (region.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.DOUBLEQUOTED_LITERAL"))) {
        return region;
      }
    }
    return null;
  }
  
  protected int getOffsetAfterType()
  {
    ITextRegion typeRegion = getTypeRegion();
    
    String type = getType();
    boolean isEnumeration = (type.equals(ENUMERATED_NAME)) || (type.equals(ENUMERATED_NOTATION));
    if (isEnumeration) {
      if (getEnumList() != null) {
        return getEnumList().getEndOffset();
      }
    }
    if (typeRegion != null) {
      return getStructuredDTDDocumentRegion().getEndOffset(typeRegion);
    }
    ITextRegion nameRegion = getNameRegion();
    return getStructuredDTDDocumentRegion().getEndOffset(nameRegion);
  }
  
  public String getType()
  {
    ITextRegion region = getTypeRegion();
    if (region != null)
    {
      String type = (String)typeHash.get(region.getType());
      if (type == null) {
        return getStructuredDTDDocumentRegion().getText(region);
      }
      return type;
    }
    if (getEnumList() != null) {
      return (String)typeHash.get("()");
    }
    return "";
  }
  
  public ITextRegion getTypeRegion()
  {
    RegionIterator iter = iterator();
    while (iter.hasNext())
    {
      ITextRegion region = iter.next();
      if ((region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.CDATA_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.ID_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.IDREF_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.IDREFS_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.ENTITY_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.ENTITIES_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.NMTOKEN_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.NMTOKENS_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.NOTATION_KEYWORD") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.PARM_ENTITY_TYPE")) {
        return region;
      }
    }
    return null;
  }
  
  public String getValueFromQuotedRegion(ITextRegion region)
  {
    String type = region.getType();
    if ((type.equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.SINGLEQUOTED_LITERAL")) || (type.equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.DOUBLEQUOTED_LITERAL")))
    {
      String text = getStructuredDTDDocumentRegion().getText(region);
      return text.substring(1, text.length() - 1);
    }
    return "";
  }
  
  public void resolveRegions()
  {
    removeChildNodes();
    RegionIterator iter = iterator();
    while (iter.hasNext())
    {
      ITextRegion currentRegion = iter.next();
      if (currentRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.LEFT_PAREN")) {
        enumList = new AttributeEnumList(getDTDFile(), getStructuredDTDDocumentRegion());
      }
      if (enumList != null)
      {
        enumList.addRegion(currentRegion);
        if (currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.RIGHT_PAREN") {
          return;
        }
      }
    }
  }
  
  public void setDefaultKind(Object requestor, String kind)
  {
    ITextRegion defaultKindRegion = getDefaultKindRegion();
    String oldDefaultKind = defaultKindRegion == null ? "" : getStructuredDTDDocumentRegion().getText(defaultKindRegion);
    if (!kind.equals(oldDefaultKind))
    {
      String newText = kind;
      int startOffset = 0;
      int length = 0;
      if (defaultKindRegion != null)
      {
        startOffset = getStructuredDTDDocumentRegion().getStartOffset(defaultKindRegion);
        length = getStructuredDTDDocumentRegion().getEndOffset(defaultKindRegion) - startOffset;
      }
      else
      {
        startOffset = getOffsetAfterType();
        newText = " " + newText;
      }
      ITextRegion defaultValue = getNextQuotedLiteral(iterator());
      if ((kind.equals("#FIXED")) || (kind.equals("")))
      {
        if (defaultValue == null) {
          newText = newText + " \"\"";
        }
      }
      else if (defaultValue != null) {
        length = getStructuredDTDDocumentRegion().getEndOffset(defaultValue) - startOffset;
      }
      replaceText(requestor, startOffset, length, newText);
    }
  }
  
  public void setDefaultKind(String kind)
  {
    beginRecording(this, DTDCoreMessages._UI_LABEL_ATTR_DEFAULT_KIND);
    setDefaultKind(this, kind);
    endRecording(this);
  }
  
  public void setDefaultValue(Object requestor, String value, boolean fixed)
  {
    ITextRegion defaultValue = getNextQuotedLiteral(iterator());
    String quoteChar = value.indexOf("\"") == -1 ? "\"" : "'";
    int startOffset = 0;
    int endOffset = 0;
    String newText = "";
    
    String oldValue = getDefaultValue();
    boolean oldKindIsFixed = getDefaultKind().equals("#FIXED");
    if ((oldValue.equals(value)) && (fixed == oldKindIsFixed)) {
      return;
    }
    if (defaultValue != null)
    {
      startOffset = getStructuredDTDDocumentRegion().getStartOffset(defaultValue);
      endOffset = getStructuredDTDDocumentRegion().getEndOffset(defaultValue);
    }
    ITextRegion defaultKindRegion = getDefaultKindRegion();
    if (defaultKindRegion != null)
    {
      startOffset = getStructuredDTDDocumentRegion().getStartOffset(defaultKindRegion);
      endOffset = endOffset == 0 ? getStructuredDTDDocumentRegion().getEndOffset(defaultKindRegion) : endOffset;
    }
    else
    {
      if (startOffset == 0)
      {
        endOffset = startOffset = getOffsetAfterType();
        newText = newText + " ";
      }
      ITextRegion typeRegion = getTypeRegion();
      if (typeRegion == null) {
        getEnumList();
      }
    }
    if (fixed) {
      newText = newText + "#FIXED ";
    } else if ((getDefaultKind().equals("")) && (value.equals(""))) {
      newText = newText + "#IMPLIED";
    }
    if ((!getType().equals("")) && (!value.equals(""))) {
      newText = newText + quoteChar + value + quoteChar;
    }
    replaceText(requestor, startOffset, endOffset - startOffset, newText);
  }
  
  public void setDefaultValue(String value, boolean fixed)
  {
    beginRecording(this, DTDCoreMessages._UI_LABEL_ATTR_DEFAULT_VAL);
    setDefaultValue(this, value, fixed);
    endRecording(this);
  }
  
  public void setType(Object requestor, String type)
  {
    String oldType = getType();
    if (!type.equals(oldType))
    {
      boolean wasEnumeration = (oldType.equals(ENUMERATED_NAME)) || (oldType.equals(ENUMERATED_NOTATION));
      boolean isEnumeration = (type.equals(ENUMERATED_NAME)) || (type.equals(ENUMERATED_NOTATION));
      String newText = "";
      int startOffset = 0;
      int endOffset = 0;
      if ((wasEnumeration) && (!isEnumeration))
      {
        AttributeEnumList enumList = getEnumList();
        if (enumList != null)
        {
          startOffset = enumList.getStartOffset();
          endOffset = enumList.getEndOffset();
        }
      }
      ITextRegion region = getTypeRegion();
      if (region != null)
      {
        startOffset = getStructuredDTDDocumentRegion().getStartOffset(region);
        if (endOffset == 0) {
          endOffset = getStructuredDTDDocumentRegion().getEndOffset(region);
        }
      }
      else if (startOffset == 0)
      {
        ITextRegion nameRegion = getNameRegion();
        newText = newText + " ";
        endOffset = startOffset = getStructuredDTDDocumentRegion().getEndOffset(nameRegion);
      }
      String newTypeWord = (String)typeHash.get(type);
      if (newTypeWord == null) {
        newTypeWord = type;
      }
      newText = newText + newTypeWord;
      if ((isEnumeration) && (!wasEnumeration))
      {
        boolean isSpaceNeeded = !type.equals(ENUMERATED_NAME);
        newText = newText + (isSpaceNeeded ? " " : "");
        newText = newText + "()";
      }
      replaceText(requestor, startOffset, endOffset - startOffset, newText);
      if ((newTypeWord.equals("")) && (!type.equals(ENUMERATED_NAME))) {
        setDefaultValue(requestor, "", false);
      }
    }
  }
  
  public void setType(String type)
  {
    beginRecording(this, DTDCoreMessages._UI_LABEL_ATTR_TYPE);
    setType(this, type);
    endRecording(this);
  }
}

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

import java.util.ArrayList;
import java.util.List;
import org.eclipse.wst.dtd.core.internal.text.RegionIterator;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;

public class AttributeEnumList
  extends DTDNode
{
  private ArrayList list = new ArrayList();
  
  public AttributeEnumList(DTDFile file, IStructuredDocumentRegion flatNode)
  {
    super(file, flatNode);
  }
  
  public String getImagePath()
  {
    return null;
  }
  
  public List getItems()
  {
    list.clear();
    RegionIterator iter = iterator();
    while (iter.hasNext())
    {
      ITextRegion name = getNextRegion(iter, "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.NAME");
      if (name != null) {
        list.add(getStructuredDTDDocumentRegion().getText(name));
      }
    }
    return list;
  }
  
  public void setItems(Object requestor, String[] items)
  {
    if (items != null)
    {
      String text = "(";
      for (int i = 0; i < items.length; i++) {
        if (i > 0) {
          text = text + " | " + items[i];
        } else {
          text = text + items[i];
        }
      }
      text = text + ")";
      replaceText(requestor, getStartOffset(), getNodeLength(), text);
    }
  }
  
  public void setItems(String[] items)
  {
    beginRecording(this, DTDCoreMessages._UI_LABEL_ATTR_ENUM_ITEMS);
    setItems(this, items);
    endRecording(this);
  }
}

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

import java.util.ArrayList;
import org.eclipse.wst.dtd.core.internal.text.RegionIterator;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;

public class AttributeList
  extends NamedTopLevelNode
{
  public AttributeList(DTDFile file, IStructuredDocumentRegion flatNode)
  {
    super(file, flatNode, "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.ATTLIST_TAG");
  }
  
  public void addAttribute(String name)
  {
    beginRecording(this, DTDCoreMessages._UI_LABEL_ATTR_LIST_ADD);
    
    DTDNode lastAttribute = (DTDNode)getLastChild();
    if (lastAttribute != null)
    {
      replaceText(this, lastAttribute.getEndOffset(), 0, "\n\t" + name + " CDATA #IMPLIED");
    }
    else
    {
      ITextRegion nameRegion = getNameRegion();
      if (nameRegion != null) {
        replaceText(this, getStructuredDTDDocumentRegion().getEndOffset(nameRegion), 0, "\n\t" + name + " CDATA #IMPLIED");
      }
    }
    endRecording(this);
  }
  
  public String getImagePath()
  {
    return "icons/full/obj16/attribute_list.gif";
  }
  
  public void insertIntoModel(Object requestor, Attribute reference, Attribute node, boolean isAfter)
  {
    int offset = 0;
    String newText = "";
    String nodeText = node.getFullNodeText();
    if (!isAfter)
    {
      offset = reference.getStartOffset();
    }
    else
    {
      Attribute attr = (Attribute)reference.getNextSibling();
      if (attr != null) {
        offset = attr.getStartOffset();
      } else {
        offset = reference.getWhitespaceEndOffset();
      }
    }
    newText = newText + nodeText;
    if (!node.hasTrailingWhitespace()) {
      newText = newText + "\n\t";
    }
    replaceText(requestor, offset, 0, newText);
  }
  
  public void resolveRegions()
  {
    removeChildNodes();
    RegionIterator iter = iterator();
    if (getNameRegion() != null) {
      skipPastName(iter);
    }
    ArrayList children = new ArrayList();
    Attribute attribute = null;
    boolean trailingWhitespace = false;
    while (iter.hasNext())
    {
      ITextRegion currentRegion = iter.next();
      if (currentRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.ATTRIBUTE_NAME"))
      {
        attribute = new Attribute(getDTDFile(), getStructuredDTDDocumentRegion());
        children.add(attribute);
        appendChild(attribute);
        trailingWhitespace = false;
      }
      if ((attribute != null) && (currentRegion.getType() != "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.END_TAG"))
      {
        if (!trailingWhitespace) {
          attribute.addRegion(currentRegion);
        } else if (currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.WHITESPACE") {
          attribute.addWhitespaceRegion(currentRegion);
        }
        if ((currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.REQUIRED_KEYWORD") || (currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.IMPLIED_KEYWORD") || (currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.SINGLEQUOTED_LITERAL") || (currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.DOUBLEQUOTED_LITERAL")) {
          trailingWhitespace = true;
        }
      }
    }
    int numKids = children.size();
    for (int i = 0; i < numKids; i++) {
      ((Attribute)children.get(i)).resolveRegions();
    }
  }
}

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

import org.eclipse.wst.dtd.core.internal.text.RegionIterator;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;

public class CMBasicNode
  extends CMRepeatableNode
{
  public CMBasicNode(DTDFile file, IStructuredDocumentRegion flatNode)
  {
    super(file, flatNode);
  }
  
  public String getImagePath()
  {
    String name = getName();
    ITextRegion pcdata = getNextRegion(iterator(), "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.CONTENT_PCDATA");
    if (pcdata != null) {
      return "icons/full/obj16/txtext.gif";
    }
    if (isRootElementContent())
    {
      if (name.equals(EMPTY)) {
        return "icons/full/obj16/emptycontent.gif";
      }
      if (name.equals(ANY)) {
        return "icons/full/obj16/any.gif";
      }
    }
    return super.getImagePath();
  }
  
  public ITextRegion getNameRegion()
  {
    RegionIterator iter = iterator();
    while (iter.hasNext())
    {
      ITextRegion region = iter.next();
      if ((region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.NAME") || (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.CONTENT_PCDATA")) {
        return region;
      }
    }
    return null;
  }
  
  public ITextRegion getOccurrenceRegion()
  {
    RegionIterator iter = iterator();
    skipPastName(iter);
    if (iter.hasNext())
    {
      ITextRegion region = iter.next();
      if (region.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.OCCUR_TYPE") {
        return region;
      }
    }
    return getNameRegion();
  }
  
  public String getType()
  {
    ITextRegion pcdata = getNextRegion(iterator(), "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.CONTENT_PCDATA");
    if (pcdata != null) {
      return PCDATA;
    }
    if (isRootElementContent())
    {
      String name = getName();
      if (isRootElementContent())
      {
        if (name.equals(EMPTY)) {
          return EMPTY;
        }
        if (name.equals(ANY)) {
          return ANY;
        }
        return name;
      }
    }
    return "";
  }
  
  public boolean isEmptyAnyOrPCData()
  {
    if (isPCData()) {
      return true;
    }
    String name = getName();
    if ((isRootElementContent()) && (
      (name.equals(EMPTY)) || (name.equals(ANY)))) {
      return true;
    }
    return false;
  }
  
  public boolean isPCData()
  {
    ITextRegion pcdata = getNextRegion(iterator(), "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.CONTENT_PCDATA");
    if (pcdata != null) {
      return true;
    }
    return false;
  }
  
  public boolean isReference()
  {
    return !isEmptyAnyOrPCData();
  }
  
  public void setName(Object requestor, String name)
  {
    super.setName(requestor, name);
    if (!isReference()) {
      setOccurrence(requestor, '1');
    }
  }
}

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

import java.util.List;
import org.eclipse.wst.dtd.core.internal.text.RegionIterator;
import org.eclipse.wst.dtd.core.internal.util.DTDUniqueNameHelper;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;

public class CMGroupNode
  extends CMRepeatableNode
{
  public static final char CHOICE = '|';
  public static final char SEQUENCE = ',';
  protected char connector = ',';
  
  public CMGroupNode(DTDFile file, IStructuredDocumentRegion flatNode)
  {
    super(file, flatNode);
  }
  
  public void addChild()
  {
    beginRecording(this, DTDCoreMessages._UI_LABEL_CM_GRP_NODE_ADD_CHILD);
    DTDNode lastNode = (DTDNode)getLastChild();
    String elementName = DTDUniqueNameHelper.getUniqueName(getChildrenList(), "ChildNode");
    if (lastNode != null) {
      replaceText(this, lastNode.getEndOffset(), 0, String.valueOf(getConnector()) + elementName);
    } else {
      replaceText(this, getStartOffset() + 1, 0, elementName);
    }
    endRecording(this);
  }
  
  public void addGroup()
  {
    beginRecording(this, DTDCoreMessages._UI_LABEL_CM_GRP_NODE_ADD_GRP);
    DTDNode lastNode = (DTDNode)getLastChild();
    if (lastNode != null) {
      replaceText(this, lastNode.getEndOffset(), 0, String.valueOf(getConnector()) + " ()");
    } else {
      replaceText(this, getStartOffset() + 1, 0, "()");
    }
    endRecording(this);
  }
  
  public void delete(Object requestor, DTDNode child)
  {
    Object[] children = getChildren();
    if ((children.length == 1) && (getFirstChild() == child))
    {
      replaceText(requestor, child.getStartOffset(), child.getNodeLength(), null);
      return;
    }
    for (int i = 0; i < children.length - 1; i++)
    {
      DTDNode childA = (DTDNode)children[i];
      DTDNode childB = (DTDNode)children[(i + 1)];
      
      boolean childADeleted = childA == child;
      boolean childBDeleted = childB == child;
      if ((childADeleted) || (childBDeleted))
      {
        int startOffset = childADeleted ? childA.getStartOffset() : childA.getEndOffset();
        int endOffset = childADeleted ? childB.getStartOffset() : childB.getEndOffset();
        replaceText(requestor, startOffset, endOffset - startOffset, "");
        removeChild(child);
        break;
      }
    }
  }
  
  public char getConnector()
  {
    Object[] children = getChildren();
    for (int i = 0; i < children.length - 1; i++)
    {
      DTDNode childA = (DTDNode)children[i];
      DTDNode childB = (DTDNode)children[(i + 1)];
      
      RegionIterator iter = new RegionIterator(getStructuredDTDDocumentRegion(), childA.getEndOffset(), childB.getStartOffset());
      
      ITextRegion currentRegion = null;
      while ((iter.hasNext()) && (currentRegion != childB.getStartRegion()))
      {
        currentRegion = iter.next();
        if (currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.CONNECTOR")
        {
          connector = getStructuredDTDDocumentRegion().getText(currentRegion).charAt(0);
          return connector;
        }
      }
    }
    return connector;
  }
  
  public String getImagePath()
  {
    switch (getConnector())
    {
    case ',': 
      return "icons/full/obj16/onesequence.gif";
    case '|': 
      return "icons/full/obj16/onechoice.gif";
    }
    return null;
  }
  
  public String getName()
  {
    return "";
  }
  
  public ITextRegion getOccurrenceRegion()
  {
    int nesting = 0;
    
    RegionIterator iter = iterator();
    
    iter.next();
    ITextRegion currentRegion = null;
    while ((iter.hasNext()) && (nesting >= 0))
    {
      currentRegion = iter.next();
      if (currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.LEFT_PAREN") {
        nesting++;
      }
      if (currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.RIGHT_PAREN") {
        nesting--;
      }
    }
    if (nesting < 0) {
      while (iter.hasNext())
      {
        currentRegion = iter.next();
        if (currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.OCCUR_TYPE") {
          return currentRegion;
        }
      }
    }
    return iter.previous();
  }
  
  public String getType()
  {
    if ((isRootElementContent()) && 
      (getFirstChild() != null))
    {
      CMNode node = (CMNode)getFirstChild();
      if (node.getType().equals(PCDATA)) {
        return MIXED;
      }
      return CHILDREN;
    }
    return "";
  }
  
  public void insertChildNode(Object requestor, String nodeText, int position)
  {
    Object[] children = getChildren();
    
    int startOffset = 0;
    String newText = "";
    if (position < children.length)
    {
      DTDNode reference = (DTDNode)children[position];
      startOffset = reference.getStartOffset();
      newText = nodeText + " " + String.valueOf(getConnector()) + " ";
    }
    else if (position == children.length)
    {
      DTDNode reference = (DTDNode)children[(position - 1)];
      startOffset = reference.getEndOffset();
      newText = " " + String.valueOf(getConnector()) + " " + nodeText;
    }
    replaceText(requestor, startOffset, 0, newText);
  }
  
  public void insertChildNode(String nodeText, int position)
  {
    beginRecording(this, DTDCoreMessages._UI_LABEL_CM_GRP_NODE_INSERT_ELEMENT);
    insertChildNode(this, nodeText, position);
    endRecording(this);
  }
  
  public void insertIntoModel(Object requestor, CMNode reference, CMNode node, boolean isAfter)
  {
    String nodeText = node.getNodeText();
    List children = getChildrenList();
    
    int index = children.indexOf(reference);
    if (index == -1) {
      index = children.size();
    } else {
      index = isAfter ? index + 1 : index;
    }
    insertChildNode(requestor, nodeText, index);
  }
  
  public void resolveRegions()
  {
    int nesting = 0;
    
    removeChildNodes();
    DTDNode currentGroupNode = null;
    CMBasicNode currentReferenceNode = null;
    RegionIterator iter = iterator();
    
    iter.next();
    while ((iter.hasNext()) && (nesting >= 0))
    {
      ITextRegion currentRegion = iter.next();
      if (nesting == 0) {
        if (currentRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.CONTENT_PCDATA"))
        {
          currentGroupNode = currentReferenceNode = null;
          DTDNode pcData = new CMBasicNode(getDTDFile(), getStructuredDTDDocumentRegion());
          pcData.addRegion(currentRegion);
          appendChild(pcData);
        }
        else if (currentRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.NAME"))
        {
          currentGroupNode = null;
          currentReferenceNode = new CMBasicNode(getDTDFile(), getStructuredDTDDocumentRegion());
          currentReferenceNode.addRegion(currentRegion);
          appendChild(currentReferenceNode);
        }
        else if (currentRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.OCCUR_TYPE"))
        {
          if (currentReferenceNode != null)
          {
            currentReferenceNode.addRegion(currentRegion);
            currentReferenceNode = null;
          }
        }
        else if (!currentRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.CONNECTOR"))
        {
          if ((currentRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.LEFT_PAREN")) && 
            (currentGroupNode == null))
          {
            currentReferenceNode = null;
            currentGroupNode = new CMGroupNode(getDTDFile(), getStructuredDTDDocumentRegion());
            appendChild(currentGroupNode);
          }
        }
      }
      if (currentRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.LEFT_PAREN")) {
        nesting++;
      }
      if (currentRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.RIGHT_PAREN"))
      {
        nesting--;
        if ((nesting == 0) && (currentGroupNode != null))
        {
          currentGroupNode.addRegion(currentRegion);
          if (iter.hasNext())
          {
            ITextRegion nextRegion = iter.next();
            if (nextRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.OCCUR_TYPE")) {
              currentGroupNode.addRegion(nextRegion);
            } else {
              iter.previous();
            }
          }
          currentGroupNode = null;
        }
      }
      if (currentGroupNode != null) {
        currentGroupNode.addRegion(currentRegion);
      }
    }
    if (nesting < 0) {
      while (iter.hasNext())
      {
        ITextRegion currentRegion = iter.next();
        currentRegion.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.OCCUR_TYPE");
      }
    }
    Object[] children = getChildren();
    for (int i = 0; i < children.length; i++)
    {
      DTDNode currentNode = (DTDNode)children[i];
      currentNode.resolveRegions();
    }
  }
  
  public void setConnector(char v)
  {
    if (connector != v)
    {
      connector = v;
      
      Object[] children = getChildren();
      if (children.length <= 1)
      {
        getDTDFile().notifyNodeChanged(this);
        return;
      }
      beginRecording(this, DTDCoreMessages._UI_LABEL_CM_GRP_NODE_CONNECTOR);
      for (int i = 0; i < children.length - 1; i++)
      {
        DTDNode childA = (DTDNode)children[i];
        DTDNode childB = (DTDNode)children[(i + 1)];
        
        RegionIterator iter = new RegionIterator(getStructuredDTDDocumentRegion(), childA.getEndOffset(), childB.getStartOffset());
        
        ITextRegion currentRegion = null;
        boolean foundConnector = false;
        while ((iter.hasNext()) && (currentRegion != childB.getStartRegion()))
        {
          currentRegion = iter.next();
          if (currentRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.CONNECTOR")
          {
            foundConnector = true;
            
            replaceText(this, getStructuredDTDDocumentRegion().getStartOffset(currentRegion), 1, String.valueOf(connector));
            
            break;
          }
        }
        if (!foundConnector) {
          replaceText(this, childA.getEndOffset(), 0, String.valueOf(connector));
        }
      }
      endRecording(this);
    }
  }
}

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

import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;

public abstract class CMNode
  extends DTDNode
{
  public static final String ANY = DTDCoreMessages._UI_LABEL_CM_NODE_ANY;
  public static final String CHILDREN = DTDCoreMessages._UI_LABEL_CM_NODE_CHILD_CONTENT;
  public static final String EMPTY = DTDCoreMessages._UI_LABEL_CM_NODE_EMPTY;
  public static final String MIXED = DTDCoreMessages._UI_LABEL_CM_NODE_MIX_CONTENT;
  public static final String PCDATA = DTDCoreMessages._UI_LABEL_CM_NODE_PCDATA;
  boolean rootElementContent;
  
  public CMNode(DTDFile file, IStructuredDocumentRegion flatNode)
  {
    super(file, flatNode);
  }
  
  public abstract String getType();
  
  public boolean isRootElementContent()
  {
    return rootElementContent;
  }
  
  public void setChildrenContent(String newChild)
  {
    if (isRootElementContent())
    {
      if (!newChild.equals(""))
      {
        beginRecording(this, DTDCoreMessages._UI_LABEL_CM_NODE_SET_CHILD_CONTENT);
        replaceText(this, getStartOffset(), getNodeLength(), "(" + newChild + ")");
        endRecording(this);
        return;
      }
      if (!getType().equals(CHILDREN))
      {
        beginRecording(this, DTDCoreMessages._UI_LABEL_CM_NODE_SET_CHILD_CONTENT);
        if ((this instanceof CMBasicNode))
        {
          replaceText(this, getStartOffset(), getNodeLength(), "(newChild)");
        }
        else
        {
          CMGroupNode group = (CMGroupNode)this;
          CMNode firstChild = (CMNode)group.getFirstChild();
          if ((firstChild != null) && (PCDATA.equals(firstChild.getType()))) {
            group.delete(firstChild);
          }
        }
        endRecording(this);
      }
    }
  }
  
  public void setContent(String content)
  {
    if (isRootElementContent())
    {
      beginRecording(this, DTDCoreMessages._UI_LABEL_CM_NODE_SET + " " + content + " " + DTDCoreMessages._UI_LABEL_CM_NODE_CONTENT);
      replaceText(this, getStartOffset(), getNodeLength(), content);
      endRecording(this);
    }
  }
  
  public void setMixedContent()
  {
    if ((isRootElementContent()) && 
      (!getType().equals(MIXED)))
    {
      beginRecording(this, DTDCoreMessages._UI_LABEL_CM_NODE_SET_MIX_CONTENT);
      if ((this instanceof CMBasicNode))
      {
        replaceText(this, getStartOffset(), getNodeLength(), "(#PCDATA | newChild)*");
      }
      else
      {
        CMGroupNode group = (CMGroupNode)this;
        group.setConnector('|');
        group.setOccurrence('*');
        CMNode firstChild = (CMNode)group.getFirstChild();
        if (!firstChild.getType().equals(PCDATA)) {
          group.insertChildNode("#PCDATA", 0);
        }
      }
      endRecording(this);
    }
  }
  
  public void setRootElementContent(boolean v)
  {
    rootElementContent = v;
  }
}

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

import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;

public abstract class CMRepeatableNode
  extends CMNode
{
  public static final char ONCE = '1';
  public static final char ONE_OR_MORE = '+';
  public static final char OPTIONAL = '?';
  public static final char ZERO_OR_MORE = '*';
  
  public CMRepeatableNode(DTDFile file, IStructuredDocumentRegion flatNode)
  {
    super(file, flatNode);
  }
  
  public String getImagePath()
  {
    return "icons/full/obj16/element_ref.gif";
  }
  
  public char getOccurrence()
  {
    ITextRegion occurRegion = getOccurrenceRegion();
    if ((occurRegion != null) && (occurRegion.getType() == "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.OCCUR_TYPE")) {
      return getStructuredDTDDocumentRegion().getText(occurRegion).charAt(0);
    }
    return '1';
  }
  
  public abstract ITextRegion getOccurrenceRegion();
  
  public void setOccurrence(char occurrence)
  {
    beginRecording(this, DTDCoreMessages._UI_LABEL_CM_REP_NODE_CHG_OCCUR);
    setOccurrence(this, occurrence);
    endRecording(this);
  }
  
  public void setOccurrence(Object requestor, char occurrence)
  {
    if (getOccurrence() != occurrence)
    {
      ITextRegion region = getOccurrenceRegion();
      if (region != null) {
        if (region.getType().equals("org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.OCCUR_TYPE"))
        {
          if (occurrence == '1') {
            getDTDFile().getStructuredDocument().replaceText(requestor, getStructuredDTDDocumentRegion().getStartOffset(region), 1, "");
          } else {
            getDTDFile().getStructuredDocument().replaceText(requestor, getStructuredDTDDocumentRegion().getStartOffset(region), 1, String.valueOf(occurrence));
          }
        }
        else if (occurrence != '1') {
          replaceText(requestor, getStructuredDTDDocumentRegion().getEndOffset(region), 0, String.valueOf(occurrence));
        }
      }
    }
  }
}

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

public class Comment$StartEndPair
{
  public int startOffset;
  public int endOffset;
  final Comment this$0;
  
  public Comment$StartEndPair(Comment paramComment)
  {
    this$0 = paramComment;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.dtd.core.internal.Comment.StartEndPair
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.dtd.core.internal;

import org.eclipse.wst.dtd.core.internal.text.RegionIterator;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;

public class Comment
  extends NamedTopLevelNode
{
  public Comment(DTDFile file, IStructuredDocumentRegion flatNode)
  {
    super(file, flatNode, "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.COMMENT");
  }
  
  public String getImagePath()
  {
    return "icons/full/obj16/comment.gif";
  }
  
  public String getName()
  {
    String text = getText();
    if (text.length() <= 30) {
      return text;
    }
    return text.substring(0, 29) + "...";
  }
  
  private void getStartAndEndOffsetForText(StartEndPair pair)
  {
    RegionIterator iter = iterator();
    ITextRegion commentStartTag = getStartTag(iter);
    ITextRegion endCommentTag = getNextRegion(iter, "org.eclipse.wst.dtd.core.internal.util.parser.DTDRegionTypes.COMMENT_END");
    endOffset = getStructuredDTDDocumentRegion().getEndOffset();
    if (commentStartTag != null) {
      startOffset = getStructuredDTDDocumentRegion().getEndOffset(commentStartTag);
    }
    if (endCommentTag != null) {
      endOffset = getStructuredDTDDocumentRegion().getStartOffset(endCommentTag);
    }
  }
  
  public String getText()
  {
    String text = getStructuredDTDDocumentRegion().getText();
    int flatNodeStart = getStructuredDTDDocumentRegion().getStartOffset();
    StartEndPair pair = new StartEndPair();
    getStartAndEndOffsetForText(pair);
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

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