org.eclipse.equinox.p2.updatesite_1.0.300.v20110815-1419

16:44:39.421 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.p2.updatesite_1.0.300.v20110815-1419.jar
package org.eclipse.equinox.internal.p2.updatesite;

import java.io.File;
import java.net.URL;
import org.eclipse.equinox.internal.p2.core.helpers.URLUtil;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator
  implements BundleActivator
{
  public static String ID = "org.eclipse.equinox.p2.updatesite";
  private static BundleContext bundleContext;
  
  public void start(BundleContext context)
    throws Exception
  {
    setBundleContext(context);
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    setBundleContext(null);
  }
  
  public static synchronized void setBundleContext(BundleContext bundleContext)
  {
    bundleContext = bundleContext;
  }
  
  public static synchronized BundleContext getBundleContext()
  {
    return bundleContext;
  }
  
  public static String getRepositoryName(URL location)
  {
    File file = URLUtil.toFile(location);
    return file == null ? location.toExternalForm() : file.getAbsolutePath();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.updatesite.Activator
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.updatesite;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
import org.eclipse.equinox.p2.publisher.eclipse.URLEntry;
import org.eclipse.osgi.util.NLS;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

public class CategoryParser
  extends DefaultHandler
{
  private static final SAXParserFactory parserFactory = ;
  private static final String PLUGIN_ID = Activator.ID;
  private static final String ARCHIVE = "archive";
  private static final String CATEGORY = "category";
  private static final String CATEGORY_DEF = "category-def";
  private static final String DESCRIPTION = "description";
  private static final String FEATURE = "feature";
  private static final String SITE = "site";
  private static final String IU = "iu";
  private static final String QUERY = "query";
  private static final String EXPRESSION = "expression";
  private static final String PARAM = "param";
  private static final int STATE_ARCHIVE = 3;
  private static final int STATE_CATEGORY = 4;
  private static final int STATE_CATEGORY_DEF = 5;
  private static final int STATE_DESCRIPTION_CATEGORY_DEF = 7;
  private static final int STATE_DESCRIPTION_SITE = 6;
  private static final int STATE_FEATURE = 2;
  private static final int STATE_IGNORED_ELEMENT = -1;
  private static final int STATE_INITIAL = 0;
  private static final int STATE_IU = 8;
  private static final int STATE_EXPRESSION = 9;
  private static final int STATE_PARAM = 10;
  private static final int STATE_QUERY = 11;
  private static final int STATE_SITE = 1;
  private boolean DESCRIPTION_SITE_ALREADY_SEEN = false;
  Stack<Object> objectStack = new Stack();
  private SAXParser parser;
  Stack<Integer> stateStack = new Stack();
  private final List<String> messageKeys = new ArrayList(4);
  private MultiStatus status;
  
  private static void debug(String s)
  {
    Tracing.debug("CategoryParser: " + s);
  }
  
  static void log(Exception e)
  {
    LogHelper.log(new Status(4, Activator.ID, "Internal Error", e));
  }
  
  static void log(String message)
  {
    LogHelper.log(new Status(2, Activator.ID, message, null));
  }
  
  static void log(String message, Exception e)
  {
    LogHelper.log(new Status(2, Activator.ID, message, e));
  }
  
  public CategoryParser(URI siteLocation)
  {
    stateStack = new Stack();
    objectStack = new Stack();
    status = null;
    DESCRIPTION_SITE_ALREADY_SEEN = false;
    try
    {
      parserFactory.setNamespaceAware(true);
      parser = parserFactory.newSAXParser();
    }
    catch (ParserConfigurationException e)
    {
      log(e);
    }
    catch (SAXException e)
    {
      log(e);
    }
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("Created");
    }
  }
  
  public int currentState()
  {
    Integer state = (Integer)stateStack.peek();
    if (state != null) {
      return state.intValue();
    }
    return -1;
  }
  
  public void characters(char[] ch, int start, int length)
  {
    String text = new String(ch, start, length);
    
    int state = currentState();
    switch (state)
    {
    case 6: 
    case 7: 
      objectStack.push(text);
      break;
    case 9: 
    case 10: 
      text = text.trim();
      String existing = null;
      if ((objectStack.peek() instanceof String)) {
        existing = (String)objectStack.pop();
      }
      if (existing != null) {
        text = existing + text;
      }
      objectStack.push(text);
      break;
    }
  }
  
  public void endElement(String uri, String localName, String qName)
  {
    String text = null;
    URLEntry info = null;
    
    int state = currentState();
    switch (state)
    {
    case -1: 
    case 3: 
    case 4: 
    case 11: 
      stateStack.pop();
      break;
    case 0: 
      internalError(Messages.DefaultSiteParser_ParsingStackBackToInitialState);
      break;
    case 1: 
      stateStack.pop();
      if ((objectStack.peek() instanceof String))
      {
        text = (String)objectStack.pop();
        SiteModel site = (SiteModel)objectStack.peek();
        site.getDescription().setAnnotation(text);
      }
      break;
    case 2: 
      stateStack.pop();
      objectStack.pop();
      break;
    case 8: 
      stateStack.pop();
      SiteIU completeIU = (SiteIU)objectStack.pop();
      String id = completeIU.getID();
      String expression = completeIU.getQueryExpression();
      if ((id == null) && (expression == null)) {
        internalError("The IU must specify an id or an expression to match against.");
      }
      break;
    case 9: 
      stateStack.pop();
      if ((objectStack.peek() instanceof String))
      {
        text = (String)objectStack.pop();
        SiteIU iu = (SiteIU)objectStack.peek();
        iu.setQueryExpression(text);
        if (Tracing.DEBUG_GENERATOR_PARSING) {
          debug("Found Expression: " + text);
        }
      }
      break;
    case 10: 
      stateStack.pop();
      if ((objectStack.peek() instanceof String))
      {
        text = (String)objectStack.pop();
        SiteIU iu = (SiteIU)objectStack.peek();
        iu.addQueryParams(text);
        if (Tracing.DEBUG_GENERATOR_PARSING) {
          debug("Found Param: " + text);
        }
      }
      break;
    case 5: 
      stateStack.pop();
      if ((objectStack.peek() instanceof String))
      {
        text = (String)objectStack.pop();
        SiteCategory category = (SiteCategory)objectStack.peek();
        category.setDescription(text);
      }
      objectStack.pop();
      break;
    case 6: 
      stateStack.pop();
      text = "";
      while ((objectStack.peek() instanceof String))
      {
        String newText = (String)objectStack.pop();
        if ((trailingSpace(newText)) && (!leadingSpace(text))) {
          text = " " + text;
        }
        text = newText.trim() + text;
        if ((leadingSpace(newText)) && (!leadingSpace(text))) {
          text = " " + text;
        }
      }
      text = text.trim();
      
      info = (URLEntry)objectStack.pop();
      if (text != null) {
        info.setAnnotation(text);
      }
      SiteModel siteModel = (SiteModel)objectStack.peek();
      if (DESCRIPTION_SITE_ALREADY_SEEN) {
        debug(NLS.bind(Messages.DefaultSiteParser_ElementAlreadySet, new String[] { getState(state) }));
      }
      siteModel.setDescription(info);
      DESCRIPTION_SITE_ALREADY_SEEN = true;
      break;
    case 7: 
      stateStack.pop();
      text = "";
      while ((objectStack.peek() instanceof String))
      {
        String newText = (String)objectStack.pop();
        if ((trailingSpace(newText)) && (!leadingSpace(text))) {
          text = " " + text;
        }
        text = newText.trim() + text;
        if ((leadingSpace(newText)) && (!leadingSpace(text))) {
          text = " " + text;
        }
      }
      text = text.trim();
      
      info = (URLEntry)objectStack.pop();
      if (text != null) {
        info.setAnnotation(text);
      }
      SiteCategory category = (SiteCategory)objectStack.peek();
      if (category.getDescription() != null)
      {
        internalError(NLS.bind(Messages.DefaultSiteParser_ElementAlreadySet, new String[] { getState(state), category.getLabel() }));
      }
      else
      {
        checkTranslated(info.getAnnotation());
        category.setDescription(info.getAnnotation());
      }
      break;
    default: 
      internalError(NLS.bind(Messages.DefaultSiteParser_UnknownEndState, new String[] { getState(state) }));
    }
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End Element:" + uri + ":" + localName + ":" + qName);
    }
  }
  
  private void error(IStatus error)
  {
    if (status == null) {
      status = new MultiStatus(PLUGIN_ID, 0, Messages.DefaultSiteParser_ErrorParsingSite, null);
    }
    status.add(error);
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      LogHelper.log(error);
    }
  }
  
  public void error(SAXParseException ex)
  {
    logStatus(ex);
  }
  
  public void fatalError(SAXParseException ex)
    throws SAXException
  {
    logStatus(ex);
    throw ex;
  }
  
  private String getState(int state)
  {
    switch (state)
    {
    case -1: 
      return "Ignored";
    case 0: 
      return "Initial";
    case 1: 
      return "Site";
    case 2: 
      return "Feature";
    case 8: 
      return "IU";
    case 3: 
      return "Archive";
    case 4: 
      return "Category";
    case 5: 
      return "Category Def";
    case 7: 
      return "Description / Category Def";
    case 6: 
      return "Description / Site";
    }
    return Messages.DefaultSiteParser_UnknownState;
  }
  
  public MultiStatus getStatus()
  {
    return status;
  }
  
  private void handleCategoryDefState(String elementName, Attributes attributes)
  {
    if (elementName.equals("description"))
    {
      stateStack.push(new Integer(7));
      processInfo(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState()) }));
    }
  }
  
  private void handleCategoryState(String elementName, Attributes attributes)
  {
    internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState()) }));
  }
  
  private void handleFeatureState(String elementName, Attributes attributes)
  {
    if (elementName.equals("category"))
    {
      stateStack.push(new Integer(4));
      processCategory(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState()) }));
    }
  }
  
  private void handleInitialState(String elementName, Attributes attributes)
    throws SAXException
  {
    if (elementName.equals("site"))
    {
      stateStack.push(new Integer(1));
      processSite(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState()) }));
      
      throw new SAXException(Messages.DefaultSiteParser_InvalidXMLStream);
    }
  }
  
  private void handleSiteState(String elementName, Attributes attributes)
  {
    if (elementName.equals("description"))
    {
      stateStack.push(new Integer(6));
      processInfo(attributes);
    }
    else if (elementName.equals("feature"))
    {
      stateStack.push(new Integer(2));
      processFeature(attributes);
    }
    else if (elementName.equals("iu"))
    {
      stateStack.push(new Integer(8));
      processIU(attributes);
    }
    else if (elementName.equals("archive"))
    {
      stateStack.push(new Integer(3));
      processArchive(attributes);
    }
    else if (elementName.equals("category-def"))
    {
      stateStack.push(new Integer(5));
      processCategoryDef(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState()) }));
    }
  }
  
  private void handleIUState(String elementName, Attributes attributes)
  {
    if (elementName.equals("query"))
    {
      stateStack.push(new Integer(11));
      processQuery(attributes);
    }
    else if (elementName.equals("category"))
    {
      stateStack.push(new Integer(4));
      processCategory(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState()) }));
    }
  }
  
  private void handleQueryState(String elementName, Attributes attributes)
  {
    if (elementName.equals("expression"))
    {
      stateStack.push(new Integer(9));
      processExpression(attributes);
    }
    else if (elementName.equals("param"))
    {
      stateStack.push(new Integer(10));
      processParam(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState()) }));
    }
  }
  
  private void handleExpression(String elementName, Attributes attributes)
  {
    internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState()) }));
  }
  
  private void handleParamState(String elementName, Attributes attributes)
  {
    internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState()) }));
  }
  
  private void internalError(String message)
  {
    error(new Status(4, PLUGIN_ID, 0, message, null));
  }
  
  private void internalErrorUnknownTag(String msg)
  {
    stateStack.push(new Integer(-1));
    internalError(msg);
  }
  
  private boolean leadingSpace(String str)
  {
    if (str.length() <= 0) {
      return false;
    }
    return Character.isWhitespace(str.charAt(0));
  }
  
  private void logStatus(SAXParseException ex)
  {
    String name = ex.getSystemId();
    if (name == null) {
      name = "";
    } else {
      name = name.substring(1 + name.lastIndexOf("/"));
    }
    String msg;
    String msg;
    if (name.equals(""))
    {
      msg = NLS.bind(Messages.DefaultSiteParser_ErrorParsing, new String[] { ex.getMessage() });
    }
    else
    {
      String[] values = { name, Integer.toString(ex.getLineNumber()), Integer.toString(ex.getColumnNumber()), ex.getMessage() };
      msg = NLS.bind(Messages.DefaultSiteParser_ErrorlineColumnMessage, values);
    }
    error(new Status(4, PLUGIN_ID, msg, ex));
  }
  
  public SiteModel parse(InputStream in)
    throws SAXException, IOException
  {
    stateStack.push(new Integer(0));
    parser.parse(new InputSource(in), this);
    if (objectStack.isEmpty()) {
      throw new SAXException(Messages.DefaultSiteParser_NoSiteTag);
    }
    if ((objectStack.peek() instanceof SiteModel))
    {
      SiteModel site = (SiteModel)objectStack.pop();
      site.setMessageKeys(messageKeys);
      return site;
    }
    String stack = "";
    Iterator<Object> iter = objectStack.iterator();
    while (iter.hasNext()) {
      stack = stack + iter.next().toString() + "\r\n";
    }
    throw new SAXException(NLS.bind(Messages.DefaultSiteParser_WrongParsingStack, new String[] { stack }));
  }
  
  private void processArchive(Attributes attributes)
  {
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End processing Archive");
    }
  }
  
  private void processCategory(Attributes attributes)
  {
    String category = attributes.getValue("name");
    Object obj = objectStack.peek();
    if ((obj instanceof SiteFeature)) {
      ((SiteFeature)obj).addCategoryName(category);
    } else if ((obj instanceof SiteIU)) {
      ((SiteIU)obj).addCategoryName(category);
    }
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End processing Category: name:" + category);
    }
  }
  
  private void processCategoryDef(Attributes attributes)
  {
    SiteCategory category = new SiteCategory();
    String name = attributes.getValue("name");
    String label = attributes.getValue("label");
    checkTranslated(label);
    category.setName(name);
    category.setLabel(label);
    
    SiteModel site = (SiteModel)objectStack.peek();
    site.addCategory(category);
    objectStack.push(category);
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End processing CategoryDef: name:" + name + " label:" + label);
    }
  }
  
  private void processFeature(Attributes attributes)
  {
    SiteFeature feature = new SiteFeature();
    
    String id = attributes.getValue("id");
    String ver = attributes.getValue("version");
    
    boolean noId = (id == null) || (id.trim().equals(""));
    if (noId) {
      internalError(NLS.bind(Messages.DefaultSiteParser_Missing, new String[] { "url", getState(currentState()) }));
    }
    feature.setFeatureIdentifier(id);
    feature.setFeatureVersion(ver);
    
    SiteModel site = (SiteModel)objectStack.peek();
    site.addFeature(feature);
    feature.setSiteModel(site);
    
    objectStack.push(feature);
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End Processing Feature Tag: id:" + id + " version:" + ver);
    }
  }
  
  private void processIU(Attributes attributes)
  {
    SiteIU iu = new SiteIU();
    SiteModel site = (SiteModel)objectStack.peek();
    
    String id = attributes.getValue("id");
    String range = attributes.getValue("range");
    id = id == null ? null : id.trim();
    range = range == null ? null : range.trim();
    
    iu.setID(id);
    iu.setRange(range);
    
    site.addIU(iu);
    objectStack.push(iu);
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End processing iu.");
    }
  }
  
  private void processExpression(Attributes attributes)
  {
    SiteIU iu = (SiteIU)objectStack.peek();
    iu.setQueryType(attributes.getValue("type"));
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End processing Expression: " + iu.getQueryType());
    }
  }
  
  private void processQuery(Attributes attributes)
  {
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End processing Query.");
    }
  }
  
  private void processParam(Attributes attributes)
  {
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End processing Param.");
    }
  }
  
  private void processInfo(Attributes attributes)
  {
    URLEntry inf = new URLEntry();
    String infoURL = attributes.getValue("url");
    inf.setURL(infoURL);
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("Processed Info: url:" + infoURL);
    }
    objectStack.push(inf);
  }
  
  private void processSite(Attributes attributes)
  {
    SiteModel site = new SiteModel();
    objectStack.push(site);
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End process Site tag.");
    }
  }
  
  public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
  {
    if (Tracing.DEBUG_GENERATOR_PARSING)
    {
      debug("State: " + currentState());
      debug("Start Element: uri:" + uri + " local Name:" + localName + " qName:" + qName);
    }
    switch (currentState())
    {
    case -1: 
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { localName, getState(currentState()) }));
      break;
    case 0: 
      handleInitialState(localName, attributes);
      break;
    case 1: 
      handleSiteState(localName, attributes);
      break;
    case 2: 
      handleFeatureState(localName, attributes);
      break;
    case 8: 
      handleIUState(localName, attributes);
      break;
    case 9: 
      handleExpression(localName, attributes);
      break;
    case 11: 
      handleQueryState(localName, attributes);
      break;
    case 10: 
      handleParamState(localName, attributes);
      break;
    case 3: 
      handleSiteState(localName, attributes);
      break;
    case 4: 
      handleCategoryState(localName, attributes);
      break;
    case 5: 
      handleCategoryDefState(localName, attributes);
      break;
    case 6: 
      handleSiteState(localName, attributes);
      break;
    case 7: 
      handleSiteState(localName, attributes);
      break;
    default: 
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownStartState, new String[] { getState(currentState()) }));
    }
  }
  
  private boolean trailingSpace(String str)
  {
    if (str.length() <= 0) {
      return false;
    }
    return Character.isWhitespace(str.charAt(str.length() - 1));
  }
  
  private void checkTranslated(String value)
  {
    if ((value != null) && (value.length() > 1) && (value.startsWith("%"))) {
      messageKeys.add(value.substring(1));
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.updatesite.CategoryParser
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.updatesite;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.publisher.AbstractPublisherApplication;
import org.eclipse.equinox.p2.publisher.IPublisherAction;
import org.eclipse.equinox.p2.publisher.Publisher;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;

public class CategoryPublisherApplication
  extends AbstractPublisherApplication
{
  private String categoryQualifier = null;
  private URI categoryDefinition = null;
  
  protected void initializeRepositories(PublisherInfo publisherInfo)
    throws ProvisionException
  {
    try
    {
      if (metadataLocation != null)
      {
        IMetadataRepository result = Publisher.loadMetadataRepository(agent, metadataLocation, true, true);
        if (result != null)
        {
          Object property = result.getProperties().get("p2.compressed");
          if (property != null)
          {
            boolean compressProperty = Boolean.valueOf((String)property).booleanValue();
            compress = ((compressProperty) || (compress));
          }
        }
      }
    }
    catch (ProvisionException localProvisionException) {}
    super.initializeRepositories(publisherInfo);
  }
  
  protected void processParameter(String arg, String parameter, PublisherInfo pinfo)
    throws URISyntaxException
  {
    super.processParameter(arg, parameter, pinfo);
    
    append = true;
    if (arg.equalsIgnoreCase("-categoryQualifier")) {
      categoryQualifier = parameter;
    }
    if (arg.equalsIgnoreCase("-categoryDefinition")) {
      categoryDefinition = URIUtil.fromString(parameter);
    }
  }
  
  protected IPublisherAction[] createActions()
  {
    return new IPublisherAction[] { new CategoryXMLAction(categoryDefinition, categoryQualifier) };
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.updatesite.CategoryPublisherApplication
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.updatesite;

import java.net.URI;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.publisher.IPublisherInfo;
import org.eclipse.equinox.p2.publisher.IPublisherResult;

public class CategoryXMLAction
  extends SiteXMLAction
{
  public CategoryXMLAction(URI location, String categoryQualifier)
  {
    super(location, categoryQualifier);
  }
  
  public IStatus perform(IPublisherInfo publisherInfo, IPublisherResult results, IProgressMonitor monitor)
  {
    try
    {
      updateSite = UpdateSite.loadCategoryFile(location, getTransport(publisherInfo), monitor);
    }
    catch (ProvisionException e)
    {
      return new Status(4, Activator.ID, Messages.Error_generating_category, e);
    }
    if (updateSite == null) {
      return new Status(4, Activator.ID, Messages.Error_generating_category);
    }
    return super.perform(publisherInfo, results, monitor);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.p2.updatesite.CategoryXMLAction
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.p2.updatesite;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
import org.eclipse.equinox.p2.publisher.eclipse.URLEntry;
import org.eclipse.osgi.util.NLS;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

public class DefaultSiteParser
  extends DefaultHandler
{
  private static final String ARCHIVE = "archive";
  private static final String CATEGORY = "category";
  private static final String CATEGORY_DEF = "category-def";
  private static final String ASSOCIATE_SITES_URL = "associateSitesURL";
  private static final String ASSOCIATE_SITE = "associateSite";
  private static final String DEFAULT_INFO_URL = "index.html";
  private static final String DESCRIPTION = "description";
  private static final String FEATURE = "feature";
  private static final String FEATURES = "features/";
  private static final SAXParserFactory parserFactory = ;
  private static final String PLUGIN_ID = Activator.ID;
  private static final String SITE = "site";
  private static final int STATE_ARCHIVE = 3;
  private static final int STATE_CATEGORY = 4;
  private static final int STATE_CATEGORY_DEF = 5;
  private static final int STATE_DESCRIPTION_CATEGORY_DEF = 7;
  private static final int STATE_DESCRIPTION_SITE = 6;
  private static final int STATE_FEATURE = 2;
  private static final int STATE_IGNORED_ELEMENT = -1;
  private static final int STATE_INITIAL = 0;
  private static final int STATE_SITE = 1;
  private int currentState;
  private boolean DESCRIPTION_SITE_ALREADY_SEEN = false;
  Stack<Object> objectStack = new Stack();
  private SAXParser parser;
  Stack<Integer> stateStack = new Stack();
  private final List<String> messageKeys = new ArrayList(4);
  private MultiStatus status;
  private final URI siteLocation;
  
  private static void debug(String s)
  {
    Tracing.debug("DefaultSiteParser: " + s);
  }
  
  private static URLEntry[] getAssociateSites(String associateSitesURL)
  {
    try
    {
      DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = domFactory.newDocumentBuilder();
      Document document = builder.parse(associateSitesURL);
      if (document == null) {
        return null;
      }
      NodeList mirrorNodes = document.getElementsByTagName("associateSite");
      URLEntry[] mirrors = new URLEntry[mirrorNodes.getLength()];
      for (int i = 0; i < mirrorNodes.getLength(); i++)
      {
        Element mirrorNode = (Element)mirrorNodes.item(i);
        mirrors[i] = new URLEntry();
        String infoURL = mirrorNode.getAttribute("url");
        String label = mirrorNode.getAttribute("label");
        mirrors[i].setURL(infoURL);
        mirrors[i].setAnnotation(label);
        if (Tracing.DEBUG_GENERATOR_PARSING) {
          debug("Processed mirror: url:" + infoURL + " label:" + label);
        }
      }
      return mirrors;
    }
    catch (Exception e)
    {
      if ((associateSitesURL != null) && ((associateSitesURL.startsWith("http://")) || 
        (associateSitesURL.startsWith("https://")) || 
        (associateSitesURL.startsWith("file://")) || 
        (associateSitesURL.startsWith("ftp://")) || 
        (associateSitesURL.startsWith("jar://")))) {
        log(Messages.DefaultSiteParser_mirrors, e);
      }
    }
    return null;
  }
  
  static void log(Exception e)
  {
    LogHelper.log(new Status(4, Activator.ID, "Internal Error", e));
  }
  
  static void log(String message)
  {
    LogHelper.log(new Status(2, Activator.ID, message, null));
  }
  
  static void log(String message, Exception e)
  {
    LogHelper.log(new Status(2, Activator.ID, message, e));
  }
  
  public DefaultSiteParser(URI siteLocation)
  {
    this.siteLocation = siteLocation;
    stateStack = new Stack();
    objectStack = new Stack();
    status = null;
    DESCRIPTION_SITE_ALREADY_SEEN = false;
    try
    {
      parserFactory.setNamespaceAware(true);
      parser = parserFactory.newSAXParser();
    }
    catch (ParserConfigurationException e)
    {
      log(e);
    }
    catch (SAXException e)
    {
      log(e);
    }
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("Created");
    }
  }
  
  public void characters(char[] ch, int start, int length)
  {
    String text = new String(ch, start, length);
    
    int state = ((Integer)stateStack.peek()).intValue();
    if ((state == 6) || (state == 7)) {
      objectStack.push(text);
    }
  }
  
  public void endElement(String uri, String localName, String qName)
  {
    String text = null;
    URLEntry info = null;
    
    int state = ((Integer)stateStack.peek()).intValue();
    switch (state)
    {
    case -1: 
    case 3: 
    case 4: 
      stateStack.pop();
      break;
    case 0: 
      internalError(Messages.DefaultSiteParser_ParsingStackBackToInitialState);
      break;
    case 1: 
      stateStack.pop();
      if ((objectStack.peek() instanceof String))
      {
        text = (String)objectStack.pop();
        SiteModel site = (SiteModel)objectStack.peek();
        site.getDescription().setAnnotation(text);
      }
      break;
    case 2: 
      stateStack.pop();
      objectStack.pop();
      break;
    case 5: 
      stateStack.pop();
      if ((objectStack.peek() instanceof String))
      {
        text = (String)objectStack.pop();
        SiteCategory category = (SiteCategory)objectStack.peek();
        category.setDescription(text);
      }
      objectStack.pop();
      break;
    case 6: 
      stateStack.pop();
      text = "";
      while ((objectStack.peek() instanceof String))
      {
        String newText = (String)objectStack.pop();
        if ((trailingSpace(newText)) && (!leadingSpace(text))) {
          text = " " + text;
        }
        text = newText.trim() + text;
        if ((leadingSpace(newText)) && (!leadingSpace(text))) {
          text = " " + text;
        }
      }
      text = text.trim();
      
      info = (URLEntry)objectStack.pop();
      if (text != null) {
        info.setAnnotation(text);
      }
      SiteModel siteModel = (SiteModel)objectStack.peek();
      if (DESCRIPTION_SITE_ALREADY_SEEN) {
        debug(NLS.bind(Messages.DefaultSiteParser_ElementAlreadySet, new String[] { getState(state) }));
      }
      siteModel.setDescription(info);
      DESCRIPTION_SITE_ALREADY_SEEN = true;
      break;
    case 7: 
      stateStack.pop();
      text = "";
      while ((objectStack.peek() instanceof String))
      {
        String newText = (String)objectStack.pop();
        if ((trailingSpace(newText)) && (!leadingSpace(text))) {
          text = " " + text;
        }
        text = newText.trim() + text;
        if ((leadingSpace(newText)) && (!leadingSpace(text))) {
          text = " " + text;
        }
      }
      text = text.trim();
      
      info = (URLEntry)objectStack.pop();
      if (text != null) {
        info.setAnnotation(text);
      }
      SiteCategory category = (SiteCategory)objectStack.peek();
      if (category.getDescription() != null)
      {
        internalError(NLS.bind(Messages.DefaultSiteParser_ElementAlreadySet, new String[] { getState(state), category.getLabel() }));
      }
      else
      {
        checkTranslated(info.getAnnotation());
        category.setDescription(info.getAnnotation());
      }
      break;
    default: 
      internalError(NLS.bind(Messages.DefaultSiteParser_UnknownEndState, new String[] { getState(state) }));
    }
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      debug("End Element:" + uri + ":" + localName + ":" + qName);
    }
  }
  
  private void error(IStatus error)
  {
    if (status == null) {
      status = new MultiStatus(PLUGIN_ID, 0, Messages.DefaultSiteParser_ErrorParsingSite, null);
    }
    status.add(error);
    if (Tracing.DEBUG_GENERATOR_PARSING) {
      LogHelper.log(error);
    }
  }
  
  public void error(SAXParseException ex)
  {
    logStatus(ex);
  }
  
  public void fatalError(SAXParseException ex)
    throws SAXException
  {
    logStatus(ex);
    throw ex;
  }
  
  private String getState(int state)
  {
    switch (state)
    {
    case -1: 
      return "Ignored";
    case 0: 
      return "Initial";
    case 1: 
      return "Site";
    case 2: 
      return "Feature";
    case 3: 
      return "Archive";
    case 4: 
      return "Category";
    case 5: 
      return "Category Def";
    case 7: 
      return "Description / Category Def";
    case 6: 
      return "Description / Site";
    }
    return Messages.DefaultSiteParser_UnknownState;
  }
  
  public MultiStatus getStatus()
  {
    return status;
  }
  
  private void handleCategoryDefState(String elementName, Attributes attributes)
  {
    if (elementName.equals("feature"))
    {
      stateStack.push(new Integer(2));
      processFeature(attributes);
    }
    else if (elementName.equals("archive"))
    {
      stateStack.push(new Integer(3));
      processArchive(attributes);
    }
    else if (elementName.equals("category-def"))
    {
      stateStack.push(new Integer(5));
      processCategoryDef(attributes);
    }
    else if (elementName.equals("description"))
    {
      stateStack.push(new Integer(7));
      processInfo(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState) }));
    }
  }
  
  private void handleCategoryState(String elementName, Attributes attributes)
  {
    if (elementName.equals("description"))
    {
      stateStack.push(new Integer(6));
      processInfo(attributes);
    }
    else if (elementName.equals("feature"))
    {
      stateStack.push(new Integer(2));
      processFeature(attributes);
    }
    else if (elementName.equals("archive"))
    {
      stateStack.push(new Integer(3));
      processArchive(attributes);
    }
    else if (elementName.equals("category-def"))
    {
      stateStack.push(new Integer(5));
      processCategoryDef(attributes);
    }
    else if (elementName.equals("category"))
    {
      stateStack.push(new Integer(4));
      processCategory(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState) }));
    }
  }
  
  private void handleFeatureState(String elementName, Attributes attributes)
  {
    if (elementName.equals("description"))
    {
      stateStack.push(new Integer(6));
      processInfo(attributes);
    }
    else if (elementName.equals("feature"))
    {
      stateStack.push(new Integer(2));
      processFeature(attributes);
    }
    else if (elementName.equals("archive"))
    {
      stateStack.push(new Integer(3));
      processArchive(attributes);
    }
    else if (elementName.equals("category-def"))
    {
      stateStack.push(new Integer(5));
      processCategoryDef(attributes);
    }
    else if (elementName.equals("category"))
    {
      stateStack.push(new Integer(4));
      processCategory(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState) }));
    }
  }
  
  private void handleInitialState(String elementName, Attributes attributes)
    throws SAXException
  {
    if (elementName.equals("site"))
    {
      stateStack.push(new Integer(1));
      processSite(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState) }));
      
      throw new SAXException(Messages.DefaultSiteParser_InvalidXMLStream);
    }
  }
  
  private void handleSiteState(String elementName, Attributes attributes)
  {
    if (elementName.equals("description"))
    {
      stateStack.push(new Integer(6));
      processInfo(attributes);
    }
    else if (elementName.equals("feature"))
    {
      stateStack.push(new Integer(2));
      processFeature(attributes);
    }
    else if (elementName.equals("archive"))
    {
      stateStack.push(new Integer(3));
      processArchive(attributes);
    }
    else if (elementName.equals("category-def"))
    {
      stateStack.push(new Integer(5));
      processCategoryDef(attributes);
    }
    else
    {
      internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, new String[] { elementName, getState(currentState) }));
    }
  }
  
  private void internalError(String message)
  {
    error(new Status(4, PLUGIN_ID, 0, message, null));
  }
  
  private void internalErrorUnknownTag(String msg)
  {
    stateStack.push(new Integer(-1));
    internalError(msg);
  }
  
  private boolean leadingSpace(String str)
  {
    if (str.length() <= 0) {
      return false;
    }
    return Character.isWhitespace(str.charAt(0));
  }
  
  private void logStatus(SAXParseException ex)
  {
    String name = ex.getSystemId();
    if (name == null) {
      name = "";
    } else {
      name = name.substring(1 + name.lastIndexOf("/"));
    }
    if (name.equals("")) {
      name = siteLocation.toString();
    }
    String[] values = { name, Integer.toString(ex.getLineNumber()), Integer.toString(ex.getColumnNumber()), ex.getMessage() };
    String msg = NLS.bind(Messages.DefaultSiteParser_ErrorlineColumnMessage, values);
    error(new Status(4, PLUGIN_ID, msg, ex));
  }
  
  public SiteModel parse(InputStream in)
    throws SAXException, IOException
  {
    stateStack.push(new Integer(0));
    currentState = ((Integer)stateStack.peek()).intValue();
    parser.parse(new InputSource(in), this);
    if (objectStack.isEmpty()) {
      throw new SAXException(Messages.DefaultSiteParser_NoSiteTag);
    }
    if ((objectStack.peek() instanceof SiteModel))
    {
      SiteModel site = (SiteModel)objectStack.pop();
      site.setMessageKeys(messageKeys);
      return site;
    }
    String stack = "";
    Iterator<Object> iter = objectStack.iterator();
    while (iter.hasNext()) {
      stack = stack + iter.next().toString() + "\r\n";
    }
    throw new SAXException(NLS.bind(Messages.DefaultSiteParser_WrongParsingStack, 
1 2 3 4 5

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