public Answer fromAnswerBean(final AnswerBean input, final String challengeText) {

      final String answerValue = input.getAnswerHash();

      if (answerValue == null || answerValue.length() < 1) {
        throw new IllegalArgumentException("missing answer value");
      }

      final String hashString;
      final VERSION version;
      if (answerValue.contains(VERSION_SEPARATOR)) {
        final String[] s = answerValue.split(VERSION_SEPARATOR);
        try {
          version = VERSION.valueOf(s[0]);
        } catch (IllegalArgumentException e) {
          throw new IllegalArgumentException("unsupported version type " + s[0]);
        }
        hashString = s[1];
      } else {
        version = VERSION.A;
        hashString = answerValue;
      }

      return new HashSaltAnswer(
          hashString,
          input.getSalt(),
          input.getHashCount(),
          input.isCaseInsensitive(),
          input.getType(),
          version);
    }
 public AnswerBean asAnswerBean() {
   final AnswerBean answerBean = new AnswerBean();
   answerBean.setType(formatType);
   answerBean.setAnswerHash(version.toString() + VERSION_SEPARATOR + answerHash);
   answerBean.setCaseInsensitive(caseInsensitive);
   answerBean.setHashCount(hashCount);
   answerBean.setSalt(salt);
   return answerBean;
 }
 static {
   Map<QName, Attribute> attributesMap = new HashMap<QName, Attribute>();
   attributesMap.put(new QName(GROUP_ID.getLocalName()), GROUP_ID);
   attributesMap.put(new QName(ARTIFACT_ID.getLocalName()), ARTIFACT_ID);
   attributesMap.put(new QName(CLASSIFIER.getLocalName()), CLASSIFIER);
   attributesMap.put(new QName(EXTENSION.getLocalName()), EXTENSION);
   attributesMap.put(new QName(VERSION.getLocalName()), VERSION);
   attributesMap.put(new QName(NAME.getLocalName()), NAME);
   attributes = attributesMap;
 }
 public Element toXml() {
   final Element answerElement = new Element(ChaiResponseSet.XML_NODE_ANSWER_VALUE);
   answerElement.setText(version.toString() + VERSION_SEPARATOR + answerHash);
   if (salt != null && salt.length() > 0) {
     answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_SALT, salt);
   }
   answerElement.setAttribute(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT, formatType.toString());
   if (hashCount > 1) {
     answerElement.setAttribute(
         ChaiResponseSet.XML_ATTRIBUTE_HASH_COUNT, String.valueOf(hashCount));
   }
   return answerElement;
 }
    public HashSaltAnswer fromXml(
        final Element element, final boolean caseInsensitive, final String challengeText) {
      final String answerValue = element.getText();

      if (answerValue == null || answerValue.length() < 1) {
        throw new IllegalArgumentException("missing answer value");
      }

      final String hashString;
      final VERSION version;
      if (answerValue.contains(VERSION_SEPARATOR)) {
        final String[] s = answerValue.split(VERSION_SEPARATOR);
        try {
          version = VERSION.valueOf(s[0]);
        } catch (IllegalArgumentException e) {
          throw new IllegalArgumentException("unsupported version type " + s[0]);
        }
        hashString = s[1];
      } else {
        version = VERSION.A;
        hashString = answerValue;
      }

      final String salt =
          element.getAttribute(ChaiResponseSet.XML_ATTRIBUTE_SALT) == null
              ? ""
              : element.getAttribute(ChaiResponseSet.XML_ATTRIBUTE_SALT).getValue();
      final String hashCount =
          element.getAttribute(ChaiResponseSet.XML_ATTRIBUTE_HASH_COUNT) == null
              ? "1"
              : element.getAttribute(ChaiResponseSet.XML_ATTRIBUTE_HASH_COUNT).getValue();
      int saltCount = 1;
      try {
        saltCount = Integer.parseInt(hashCount);
      } catch (NumberFormatException e) {
        /* noop */
      }
      final String formatStr =
          element.getAttributeValue(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT) == null
              ? ""
              : element.getAttributeValue(ChaiResponseSet.XML_ATTRIBUTE_CONTENT_FORMAT);
      final FormatType formatType;
      try {
        formatType = FormatType.valueOf(formatStr);
      } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException(
            "unknown content format specified in xml format value: '" + formatStr + "'");
      }
      return new HashSaltAnswer(hashString, salt, saltCount, caseInsensitive, formatType, version);
    }
    public int specialStateTransition(int s, IntStream _input) throws NoViableAltException {
      TokenStream input = (TokenStream) _input;
      int _s = s;
      switch (s) {
        case 0:
          int LA5_1 = input.LA(1);

          int index5_1 = input.index();
          input.rewind();
          s = -1;
          if ((LA5_1 == 8) && ((input.LT(1).getText().charAt(0) == 'D'))) {
            s = 2;
          } else if ((LA5_1 == WS)
              && ((CLASSPATH.equals(input.LT(1).getText())
                  || CLASSPATH_LONG.equals(input.LT(1).getText())))) {
            s = 3;
          } else if (((switchOptions.contains(input.LT(1).getText())))) {
            s = 4;
          } else if (((VERBOSE.equals(input.LT(1).getText())
              || input.LT(1).getText().startsWith(VERBOSE + ':')))) {
            s = 5;
          } else if (((VERSION.equals(input.LT(1).getText())
              || input.LT(1).getText().startsWith(VERSION + ':')))) {
            s = 6;
          } else if (((input.LT(1).getText().startsWith(XSHARE + ':')))) {
            s = 7;
          } else if (((input.LT(1).getText().startsWith(XCJNI + ':')))) {
            s = 8;
          } else if (((isParamOption(input.LT(1).getText())))) {
            s = 9;
          } else if (((memOptions.matcher(input.LT(1).getText()).matches()))) {
            s = 10;
          } else if ((true)) {
            s = 11;
          }

          input.seek(index5_1);
          if (s >= 0) return s;
          break;
      }
      NoViableAltException nvae = new NoViableAltException(getDescription(), 5, _s, input);
      error(nvae);
      throw nvae;
    }
  static ManagedArtifactRegion findManagedArtifactRegion(
      Node current, ITextViewer textViewer, int offset) {
    while (current != null && !(current instanceof Element)) {
      current = current.getParentNode();
    }
    if (current != null) {
      Node artNode = null;
      Node groupNode = null;
      if (ARTIFACT_ID.equals(current.getNodeName())) { // $NON-NLS-1$
        artNode = current;
      }
      if (GROUP_ID.equals(current.getNodeName())) { // $NON-NLS-1$
        groupNode = current;
      }
      // only on artifactid and groupid elements..
      if (artNode == null && groupNode == null) {
        return null;
      }
      Node root = current.getParentNode();
      boolean isDependency = false;
      boolean isPlugin = false;
      if (root != null) {
        String name = root.getNodeName();
        if (DEPENDENCY.equals(name)) { // $NON-NLS-1$
          isDependency = true;
        }
        if (PLUGIN.equals(name)) { // $NON-NLS-1$
          isPlugin = true;
        }
      } else {
        return null;
      }
      if (!isDependency && !isPlugin) {
        // some kind of other identifier
        return null;
      }
      // now see if version is missing
      NodeList childs = root.getChildNodes();
      for (int i = 0; i < childs.getLength(); i++) {
        Node child = childs.item(i);
        if (child instanceof Element) {
          Element el = (Element) child;
          if (VERSION.equals(el.getNodeName())) { // $NON-NLS-1$
            return null;
          }
          if (artNode == null && ARTIFACT_ID.equals(el.getNodeName())) { // $NON-NLS-1$
            artNode = el;
          }
          if (groupNode == null && GROUP_ID.equals(el.getNodeName())) { // $NON-NLS-1$
            groupNode = el;
          }
        }
      }
      if (groupNode != null && artNode != null) {
        assert groupNode instanceof IndexedRegion;
        assert artNode instanceof IndexedRegion;

        IndexedRegion groupReg = (IndexedRegion) groupNode;
        IndexedRegion artReg = (IndexedRegion) artNode;
        int startOffset = Math.min(groupReg.getStartOffset(), artReg.getStartOffset());
        int length = Math.max(groupReg.getEndOffset(), artReg.getEndOffset()) - startOffset;
        String groupId = XmlUtils.getTextValue(groupNode);
        String artifactId = XmlUtils.getTextValue(artNode);
        final MavenProject prj = XmlUtils.extractMavenProject(textViewer);
        if (prj != null) {
          // now we can create the region I guess,
          return new ManagedArtifactRegion(
              startOffset, length, groupId, artifactId, isDependency, isPlugin, prj);
        }
      }
    }
    return null;
  }
Exemple #8
0
/**
 * This class contains options which are used in the GUI. They are also stored in the project's home
 * directory.
 *
 * @author BaseX Team 2005-15, BSD License
 * @author Christian Gruen
 */
public final class GUIOptions extends Options {
  // DATABASE & PROGRAM PATHS =================================================

  /** Comment: written to options file. */
  public static final Comment C_PATHS = new Comment("Paths");

  /** Path to database input. */
  public static final StringOption INPUTPATH = new StringOption("INPUTPATH", HOME);
  /** Path for additional material. */
  public static final StringOption DATAPATH = new StringOption("DATAPATH", HOME);
  /** Path to working directory. */
  public static final StringOption WORKPATH = new StringOption("WORKPATH", HOME);
  /** Path to database project. */
  public static final StringOption PROJECTPATH = new StringOption("PROJECTPATH", "");
  /** Last editor files. */
  public static final StringsOption EDITOR = new StringsOption("EDITOR");
  /** Input paths. */
  public static final StringsOption INPUTS = new StringsOption("INPUTS");
  /** Open editor files. */
  public static final StringsOption OPEN = new StringsOption("OPEN");

  /** Comment: written to options file. */
  public static final Comment C_LAYOUT = new Comment("Layout");

  /** Default GUI Font. */
  public static final StringOption FONT = new StringOption("FONT", Font.SANS_SERIF);
  /** Default GUI Monospace Font. */
  public static final StringOption MONOFONT =
      new StringOption("MONOFONT", WIN ? "Consolas" : Font.MONOSPACED);
  /** Font TYPE = plain, bold, italics). */
  public static final NumberOption FONTTYPE = new NumberOption("FONTTYPE", 0);
  /** Font size. */
  public static final NumberOption FONTSIZE = new NumberOption("FONTSIZE", GUIConstants.FONTSIZE);

  /** Red GUI color factor. */
  public static final NumberOption COLORRED = new NumberOption("COLORRED", 15);
  /** Green GUI color factor. */
  public static final NumberOption COLORGREEN = new NumberOption("COLORGREEN", 11);
  /** Blue GUI color factor. */
  public static final NumberOption COLORBLUE = new NumberOption("COLORBLUE", 6);

  /** Comment: written to options file. */
  public static final Comment C_WINDOWS = new Comment("Windows");

  /** Last updated version. */
  public static final StringOption UPDATEVERSION =
      new StringOption("UPDATEVERSION", VERSION.replaceAll(" .*", ""));

  /** GUI Layout. */
  public static final StringOption VIEWS = new StringOption("VIEWS", GUIConstants.VIEWS);

  /** GUI height. */
  public static final NumbersOption GUISIZE = new NumbersOption("GUISIZE", 1004, 748);
  /** GUI position. */
  public static final NumbersOption GUILOC = new NumbersOption("GUILOC", 10, 10);
  /** Flag for maximized GUI window. */
  public static final BooleanOption MAXSTATE = new BooleanOption("MAXSTATE", false);

  /** Flag for displaying buttons in the GUI window. */
  public static final BooleanOption SHOWBUTTONS = new BooleanOption("SHOWBUTTONS", true);
  /** Flag for displaying the text field in the GUI window. */
  public static final BooleanOption SHOWINPUT = new BooleanOption("SHOWINPUT", true);
  /** Flag for displaying the status bar in the GUI window. */
  public static final BooleanOption SHOWSTATUS = new BooleanOption("SHOWSTATUS", true);

  /** Flag for activated info view. */
  public static final BooleanOption SHOWINFO = new BooleanOption("SHOWINFO", true);
  /** Flag for activated map view. */
  public static final BooleanOption SHOWMAP = new BooleanOption("SHOWMAP", true);
  /** Flag for activated table view. */
  public static final BooleanOption SHOWTABLE = new BooleanOption("SHOWTABLE", false);
  /** Flag for activated result view. */
  public static final BooleanOption SHOWTEXT = new BooleanOption("SHOWTEXT", true);
  /** Flag for activated tree view. */
  public static final BooleanOption SHOWFOLDER = new BooleanOption("SHOWFOLDER", false);
  /** Flag for activated query view. */
  public static final BooleanOption SHOWEXPLORE = new BooleanOption("SHOWEXPLORE", false);
  /** Flag for activated plot view. */
  public static final BooleanOption SHOWPLOT = new BooleanOption("SHOWPLOT", false);
  /** Flag for activated xquery view. */
  public static final BooleanOption SHOWEDITOR = new BooleanOption("SHOWEDITOR", true);
  /** Flag for activated tree view. */
  public static final BooleanOption SHOWTREE = new BooleanOption("SHOWTREE", false);
  /** Flag for activated project structure. */
  public static final BooleanOption SHOWPROJECT = new BooleanOption("SHOWPROJECT", true);

  /** Dialog location. */
  public static final NumbersOption FONTSLOC = new NumbersOption("FONTSLOC", 10, 530);
  /** Dialog location. */
  public static final NumbersOption COLORSLOC = new NumbersOption("COLORSLOC", 530, 620);
  /** Dialog location. */
  public static final NumbersOption BINDINGSLOC = new NumbersOption("BINDINGSLOC", 100, 230);

  /** Preferences tab. */
  public static final NumberOption PREFTAB = new NumberOption("PREFTAB", 0);
  /** Flag for Java look and feel. */
  public static final StringOption LOOKANDFEEL = new StringOption("LOOKANDFEEL", "");
  /** Flag for dissolving name attributes. */
  public static final BooleanOption SHOWNAME = new BooleanOption("SHOWNAME", true);
  /** Focus follows mouse. */
  public static final BooleanOption MOUSEFOCUS = new BooleanOption("MOUSEFOCUS", false);
  /** Flag for showing the simple file dialog. */
  public static final BooleanOption SIMPLEFD = new BooleanOption("SIMPLEFD", false);

  /** Sort ascending. */
  public static final BooleanOption ASCSORT = new BooleanOption("ASCSORT", true);
  /** Case sensitive sorting. */
  public static final BooleanOption CASESORT = new BooleanOption("CASESORT", true);
  /** Merge duplicate lines. */
  public static final BooleanOption MERGEDUPL = new BooleanOption("MERGEDUPL", false);

  /** Show line margin. */
  public static final BooleanOption SHOWMARGIN = new BooleanOption("SHOWMARGIN", true);
  /** Line margin. */
  public static final NumberOption MARGIN = new NumberOption("MARGIN", 80);
  /** Insert tabs as spaces. */
  public static final BooleanOption TABSPACES = new BooleanOption("TABSPACES", true);
  /** Indentation. */
  public static final NumberOption INDENT = new NumberOption("INDENT", 2);
  /** Show invisible characters. */
  public static final BooleanOption SHOWINVISIBLE = new BooleanOption("SHOWINVISIBLE", true);
  /** Show newlines. */
  public static final BooleanOption SHOWNL = new BooleanOption("SHOWNL", false);
  /** Show line numbers. */
  public static final BooleanOption SHOWLINES = new BooleanOption("SHOWLINES", true);
  /** Mark current line. */
  public static final BooleanOption MARKLINE = new BooleanOption("MARKLINE", true);
  /** Save before executing file. */
  public static final BooleanOption SAVERUN = new BooleanOption("SAVERUN", false);
  /** Automatically add characters. */
  public static final BooleanOption AUTO = new BooleanOption("AUTO", true);
  /** Default file filter. */
  public static final StringOption FILES = new StringOption("FILES", "*.xml, *.xq*");
  /** Flag for activated project structure. */
  public static final BooleanOption HIDDENFILES = new BooleanOption("HIDDENFILES", true);

  /** Current input mode in global text field (Search, XQuery, Command). */
  public static final NumberOption SEARCHMODE = new NumberOption("SEARCHMODE", 0);
  /** Flag for realtime context filtering. */
  public static final BooleanOption FILTERRT = new BooleanOption("FILTERRT", false);
  /** Flag for realtime query execution. */
  public static final BooleanOption EXECRT = new BooleanOption("EXECRT", false);

  /** Name of new database. */
  public static final StringOption DBNAME = new StringOption("DBNAME", "");
  /** Last insertion type. */
  public static final NumberOption LASTINSERT = new NumberOption("LASTINSERT", 1);

  /** Comment: written to options file. */
  public static final Comment C_VISUALIZATIONS = new Comment("Visualizations");

  /** Show attributes in treemap. */
  public static final BooleanOption MAPATTS = new BooleanOption("MAPATTS", false);
  /** Treemap Offsets. */
  public static final NumberOption MAPOFFSETS = new NumberOption("MAPOFFSETS", 3);
  /** Map algorithm. */
  public static final NumberOption MAPALGO = new NumberOption("MAPALGO", 0);
  /** number of children <-> size weight in (0;100). */
  public static final NumberOption MAPWEIGHT = new NumberOption("MAPWEIGHT", 0);

  /** Slim rectangles to text length. */
  public static final BooleanOption TREESLIMS = new BooleanOption("TREESLIM", true);
  /** Show attributes in treeview. */
  public static final BooleanOption TREEATTS = new BooleanOption("TREEATTS", false);

  /** Dot sizes in plot. */
  public static final NumberOption PLOTDOTS = new NumberOption("PLOTDOTS", 0);
  /** Logarithmic plot. */
  public static final BooleanOption PLOTXLOG = new BooleanOption("PLOTXLOG", false);
  /** Logarithmic plot. */
  public static final BooleanOption PLOTYLOG = new BooleanOption("PLOTYLOG", false);

  /** Maximum text size to be displayed. */
  public static final NumberOption MAXTEXT = new NumberOption("MAXTEXT", 1 << 21);
  /** Maximum number of hits to be displayed (-1: return all hits; default: 250K). */
  public static final NumberOption MAXRESULTS = new NumberOption("MAXHITS", 250000);

  /** Comment: written to options file. */
  public static final Comment C_SEARCH = new Comment("Search");

  /** Search text. */
  public static final StringOption SR_SEARCH = new StringOption("SR_SEARCH", "");
  /** Replace text. */
  public static final StringOption SR_REPLACE = new StringOption("SR_REPLACE", "");
  /** Regular expressions. */
  public static final BooleanOption SR_REGEX = new BooleanOption("SR_REGEX", false);
  /** Match case. */
  public static final BooleanOption SR_CASE = new BooleanOption("SR_CASE", false);
  /** Whole word. */
  public static final BooleanOption SR_WORD = new BooleanOption("SR_WORD", false);
  /** Multi-line mode. */
  public static final BooleanOption SR_MULTI = new BooleanOption("SR_MULTI", false);
  /** Last searched strings. */
  public static final StringsOption SEARCHED = new StringsOption("SEARCHED");
  /** Last replaced strings. */
  public static final StringsOption REPLACED = new StringsOption("REPLACED");

  /** Comment: written to options file. */
  public static final Comment C_HISTORY = new Comment("History");

  /** Last command inputs. */
  public static final StringsOption COMMANDS = new StringsOption("COMMANDS");
  /** Last keyword inputs. */
  public static final StringsOption SEARCH = new StringsOption("SEARCH");
  /** Last XQuery inputs. */
  public static final StringsOption XQUERY = new StringsOption("XQUERY");

  /** Constructor. */
  public GUIOptions() {
    super(new IOFile(HOME + IO.BASEXSUFFIX + "gui"));
    // reset realtime operations
    set(FILTERRT, false);
    set(EXECRT, false);
    gui = true;
  }
}