Ejemplo n.º 1
0
 // get licensing features, with appropriate defaults
 @SuppressWarnings("unchecked")
 private void loadLicensingFeatures(Element licensingElt) {
   List<LicensingFeature> licensingFeats = new ArrayList<LicensingFeature>();
   boolean containsLexFeat = false;
   if (licensingElt != null) {
     for (Iterator<Element> it = licensingElt.getChildren("feat").iterator(); it.hasNext(); ) {
       Element featElt = it.next();
       String attr = featElt.getAttributeValue("attr");
       if (attr.equals("lex")) containsLexFeat = true;
       String val = featElt.getAttributeValue("val");
       List<String> alsoLicensedBy = null;
       String alsoVals = featElt.getAttributeValue("also-licensed-by");
       if (alsoVals != null) {
         alsoLicensedBy = Arrays.asList(alsoVals.split("\\s+"));
       }
       boolean licenseEmptyCats = true;
       boolean licenseMarkedCats = false;
       boolean instantiate = true;
       byte loc = LicensingFeature.BOTH;
       String lmc = featElt.getAttributeValue("license-marked-cats");
       if (lmc != null) {
         licenseMarkedCats = Boolean.valueOf(lmc).booleanValue();
         // change defaults
         licenseEmptyCats = false;
         loc = LicensingFeature.TARGET_ONLY;
         instantiate = false;
       }
       String lec = featElt.getAttributeValue("license-empty-cats");
       if (lec != null) {
         licenseEmptyCats = Boolean.valueOf(lec).booleanValue();
       }
       String inst = featElt.getAttributeValue("instantiate");
       if (inst != null) {
         instantiate = Boolean.valueOf(inst).booleanValue();
       }
       String locStr = featElt.getAttributeValue("location");
       if (locStr != null) {
         if (locStr.equals("target-only")) loc = LicensingFeature.TARGET_ONLY;
         if (locStr.equals("args-only")) loc = LicensingFeature.ARGS_ONLY;
         if (locStr.equals("both")) loc = LicensingFeature.BOTH;
       }
       licensingFeats.add(
           new LicensingFeature(
               attr, val, alsoLicensedBy, licenseEmptyCats, licenseMarkedCats, instantiate, loc));
     }
   }
   if (!containsLexFeat) {
     licensingFeats.add(LicensingFeature.defaultLexFeature);
   }
   _licensingFeatures = new LicensingFeature[licensingFeats.size()];
   licensingFeats.toArray(_licensingFeatures);
 }
Ejemplo n.º 2
0
  /**
   * Initialize the backend systems, the log handler and the restrictor. A subclass can tune this
   * step by overriding {@link #createRestrictor(String)} and {@link
   * #createLogHandler(ServletConfig, boolean)}
   *
   * @param pServletConfig servlet configuration
   */
  @Override
  public void init(ServletConfig pServletConfig) throws ServletException {
    super.init(pServletConfig);

    Configuration config = initConfig(pServletConfig);

    // Create a log handler early in the lifecycle, but not too early
    String logHandlerClass = config.get(ConfigKey.LOGHANDLER_CLASS);
    logHandler =
        logHandlerClass != null
            ? (LogHandler) ClassUtil.newInstance(logHandlerClass)
            : createLogHandler(pServletConfig, Boolean.valueOf(config.get(ConfigKey.DEBUG)));

    // Different HTTP request handlers
    httpGetHandler = newGetHttpRequestHandler();
    httpPostHandler = newPostHttpRequestHandler();

    if (restrictor == null) {
      restrictor =
          createRestrictor(NetworkUtil.replaceExpression(config.get(ConfigKey.POLICY_LOCATION)));
    } else {
      logHandler.info("Using custom access restriction provided by " + restrictor);
    }
    configMimeType = config.get(ConfigKey.MIME_TYPE);
    backendManager = new BackendManager(config, logHandler, restrictor);
    requestHandler = new HttpRequestHandler(config, backendManager, logHandler);

    initDiscoveryMulticast(config);
  }
Ejemplo n.º 3
0
  public static void invokeSetMethod(Object obj, String prop, String value)
      throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Class cl = obj.getClass();
    // change first letter to uppercase
    String setMeth = "set" + prop.substring(0, 1).toUpperCase() + prop.substring(1);

    // try string method
    try {
      Class[] cldef = {String.class};
      Method meth = cl.getMethod(setMeth, cldef);
      Object[] params = {value};
      meth.invoke(obj, params);
      return;
    } catch (NoSuchMethodException ex) {
      try {
        // try int method
        Class[] cldef = {Integer.TYPE};
        Method meth = cl.getMethod(setMeth, cldef);
        Object[] params = {Integer.valueOf(value)};
        meth.invoke(obj, params);
        return;
      } catch (NoSuchMethodException nsmex) {
        // try boolean method
        Class[] cldef = {Boolean.TYPE};
        Method meth = cl.getMethod(setMeth, cldef);
        Object[] params = {Boolean.valueOf(value)};
        meth.invoke(obj, params);
        return;
      }
    }
  }
  // START SJSAS 6439313
  public void init() throws IOException {
    // END SJSAS 6439313
    try {

      String clientAuthStr = (String) attributes.get("clientauth");
      if (clientAuthStr != null) {
        clientAuth = Boolean.valueOf(clientAuthStr).booleanValue();
      }

      // SSL protocol variant (e.g., TLS, SSL v3, etc.)
      String protocol = (String) attributes.get("protocol");
      if (protocol == null) {
        protocol = defaultProtocol;
      }

      // Certificate encoding algorithm (e.g., SunX509)
      String algorithm = (String) attributes.get("algorithm");
      if (algorithm == null) {
        algorithm = defaultAlgorithm;
      }

      // Create and init SSLContext
      /* SJSAS 6439313
      SSLContext context = SSLContext.getInstance(protocol);
       */

      // START SJSAS 6439313
      context = SSLContext.getInstance(protocol);
      // END SJSAS 6439313

      // Configure SSL session timeout and cache size
      configureSSLSessionContext(context.getServerSessionContext());

      String trustAlgorithm = (String) attributes.get("truststoreAlgorithm");
      if (trustAlgorithm == null) {
        trustAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
      }

      context.init(
          getKeyManagers(algorithm, (String) attributes.get("keyAlias")),
          getTrustManagers(trustAlgorithm),
          new SecureRandom());

      // create proxy
      sslProxy = context.getServerSocketFactory();

      // Determine which cipher suites to enable
      String requestedCiphers = (String) attributes.get("ciphers");
      if (requestedCiphers != null) {
        enabledCiphers = getEnabledCiphers(requestedCiphers, sslProxy.getSupportedCipherSuites());
      }

    } catch (Exception e) {
      if (e instanceof IOException) throw (IOException) e;
      throw new IOException(e.getMessage());
    }
  }
Ejemplo n.º 5
0
Archivo: Macro.java Proyecto: bramk/bnd
  public String _toclasspath(String args[]) {
    verifyCommand(args, _toclasspathHelp, null, 2, 3);
    boolean cl = true;
    if (args.length > 2) cl = Boolean.valueOf(args[2]);

    Collection<String> names = Processor.split(args[1]);
    Collection<String> paths = new ArrayList<String>(names.size());
    for (String name : names) {
      String path = name.replace('.', '/') + (cl ? ".class" : "");
      paths.add(path);
    }
    return Processor.join(paths, ",");
  }
Ejemplo n.º 6
0
  @SuppressWarnings("OverridableMethodCallInConstructor")
  Notepad() {
    super(true);

    // Trying to set Nimbus look and feel
    try {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (Exception ignored) {
    }

    setBorder(BorderFactory.createEtchedBorder());
    setLayout(new BorderLayout());

    // create the embedded JTextComponent
    editor = createEditor();
    // Add this as a listener for undoable edits.
    editor.getDocument().addUndoableEditListener(undoHandler);

    // install the command table
    commands = new HashMap<Object, Action>();
    Action[] actions = getActions();
    for (Action a : actions) {
      commands.put(a.getValue(Action.NAME), a);
    }

    JScrollPane scroller = new JScrollPane();
    JViewport port = scroller.getViewport();
    port.add(editor);

    String vpFlag = getProperty("ViewportBackingStore");
    if (vpFlag != null) {
      Boolean bs = Boolean.valueOf(vpFlag);
      port.setScrollMode(bs ? JViewport.BACKINGSTORE_SCROLL_MODE : JViewport.BLIT_SCROLL_MODE);
    }

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add("North", createToolbar());
    panel.add("Center", scroller);
    add("Center", panel);
    add("South", createStatusbar());
  }
Ejemplo n.º 7
0
  public static void invokeSetMethodCaseInsensitive(Object obj, String prop, String value)
      throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    String alternateMethodName = null;
    Class cl = obj.getClass();

    String setMeth = "set" + prop;

    Method[] methodsList = cl.getMethods();
    boolean methodFound = false;
    int i = 0;
    for (i = 0; i < methodsList.length; ++i) {
      if (methodsList[i].getName().equalsIgnoreCase(setMeth) == true) {
        Class[] parameterTypes = methodsList[i].getParameterTypes();
        if (parameterTypes.length == 1) {
          if (parameterTypes[0].getName().equals("java.lang.String")) {
            methodFound = true;
            break;
          } else alternateMethodName = methodsList[i].getName();
        }
      }
    }
    if (methodFound == true) {
      Object[] params = {value};
      methodsList[i].invoke(obj, params);
      return;
    }
    if (alternateMethodName != null) {
      try {
        // try int method
        Class[] cldef = {Integer.TYPE};
        Method meth = cl.getMethod(alternateMethodName, cldef);
        Object[] params = {Integer.valueOf(value)};
        meth.invoke(obj, params);
        return;
      } catch (NoSuchMethodException nsmex) {
        // try boolean method
        Class[] cldef = {Boolean.TYPE};
        Method meth = cl.getMethod(alternateMethodName, cldef);
        Object[] params = {Boolean.valueOf(value)};
        meth.invoke(obj, params);
        return;
      }

    } else throw new NoSuchMethodException(setMeth);
  }
  @Override
  @SuppressWarnings("unchecked")
  public <T> T getOption(SocketOption<T> name) throws IOException {
    if (name == null) throw new NullPointerException();
    if (!supportedOptions().contains(name))
      throw new UnsupportedOperationException("'" + name + "' not supported");

    synchronized (stateLock) {
      ensureOpen();

      if (name == StandardSocketOptions.IP_TOS
          || name == StandardSocketOptions.IP_MULTICAST_TTL
          || name == StandardSocketOptions.IP_MULTICAST_LOOP) {
        return (T) Net.getSocketOption(fd, family, name);
      }

      if (name == StandardSocketOptions.IP_MULTICAST_IF) {
        if (family == StandardProtocolFamily.INET) {
          int address = Net.getInterface4(fd);
          if (address == 0) return null; // default interface

          InetAddress ia = Net.inet4FromInt(address);
          NetworkInterface ni = NetworkInterface.getByInetAddress(ia);
          if (ni == null) throw new IOException("Unable to map address to interface");
          return (T) ni;
        } else {
          int index = Net.getInterface6(fd);
          if (index == 0) return null; // default interface

          NetworkInterface ni = NetworkInterface.getByIndex(index);
          if (ni == null) throw new IOException("Unable to map index to interface");
          return (T) ni;
        }
      }

      if (name == StandardSocketOptions.SO_REUSEADDR && reuseAddressEmulated) {
        return (T) Boolean.valueOf(isReuseAddress);
      }

      // no special handling
      return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
    }
  }
Ejemplo n.º 9
0
  public synchronized void init(Properties configuration) {
    initParams(configuration);
    if (firstTime) {
      firstTime = false;

      // try {TNCPort = Integer.parseInt(configuration.getProperty("SoundcardTNCDevice",
      // "1").trim());}
      // catch (Exception e){System.err.println("Exception parsing KISSTNCPortNumber
      // "+e.toString());}
      // tncPort =(byte)((TNCPort-1)<<4);
      try {
        TXDelay = (Integer.parseInt(configuration.getProperty("KISSTXDelay", "200").trim()) / 10);
      } catch (Exception e) {
        System.err.println("Exception parsing KISSTXDelay " + e.toString());
      }
      try {
        Persist = Integer.parseInt(configuration.getProperty("KISSPersist", "255").trim());
      } catch (Exception e) {
        System.err.println("Exception parsing KISSPersist " + e.toString());
      }
      try {
        SlotTime = (Integer.parseInt(configuration.getProperty("KISSSlotTime", "0").trim()));
      } catch (Exception e) {
        System.err.println("Exception parsing KISSPersist " + e.toString());
      }
      boolean fulldux = false;
      try {
        fulldux =
            Boolean.valueOf(configuration.getProperty("KISSFullDuplex", "false").trim())
                .booleanValue();
      } catch (Exception e) {
        System.err.println("Exception parsing KISSFullDuplex " + e.toString());
      }
      if (fulldux) FullDuplex = 1;
      try {
        TXTail = (Integer.parseInt(configuration.getProperty("KISSTXTail", "100").trim()) / 10);
      } catch (Exception e) {
        System.err.println("Exception parsing KISSTXTail " + e.toString());
      }

      try {
        rate = Integer.parseInt(configuration.getProperty("SoundcardSampleRate", "9600").trim());
      } catch (Exception e) {
        System.err.println("Exception parsing SoundcardSampleRate " + e.toString());
      }

      try {
        latency_ms = Integer.parseInt(configuration.getProperty("SoundcardLatency", "100").trim());
      } catch (Exception e) {
        System.err.println("Exception parsing SoundcardLatency " + e.toString());
      }

      // if (!configuration.containsKey("SoundCardName"))
      //	configuration.put("SerialPortName", configuration.getProperty("KISSPortName", ""));
      String soundcard = configuration.getProperty("SoundcardName", "default").trim();
      soundin = configuration.getProperty("SoundcardInputName", "default").trim();
      soundout = configuration.getProperty("SoundcardOutputName", "default").trim();
      if (soundin.equals("default")) soundin = soundcard;
      if (soundout.equals("default")) soundout = soundcard;

      System.err.println(
          "Starting up Afsk1200 modem on ["
              + soundin
              + ", "
              + soundout
              + "] at "
              + rate
              + " samples/s");

      try {
        modulator = new sivantoledo.ax25.Afsk1200Modulator(rate);
        demodulator = new sivantoledo.ax25.Afsk1200MultiDemodulator(rate, this);
        // afsk = new sivantoledo.ax25.Afsk1200(rate, this);
        modulator.setTxDelay(TXDelay);
      } catch (Exception e) {
        System.err.println("Afsk1200 constructor exception: " + e.getMessage());
        System.exit(1);
      }

      String ptt_port = configuration.getProperty("PTTPort", "none").trim();
      String ptt_signal = configuration.getProperty("PTTSignal", "RTS").trim();
      if (!ptt_port.equals("none")) {
        try {
          ptt = new SerialTransmitController(ptt_port, ptt_signal);
          System.err.println("Opened a serial PTT port: " + ptt_port);
        } catch (Exception e) {
          System.err.println("PTT initialization error: " + e.getMessage());
          ptt = null;
        }
      } else {
        System.err.println("Warning: No PTT port (okay for receive only or for VOX)");
      }

      sc =
          new sivantoledo.ax25.Soundcard(
              rate, soundin, soundout, latency_ms, demodulator, modulator);
      new Thread(this, "SoundInterface Read").start();
    }
  }
  // [Issue#381]
  public void testSingleElementArray() throws Exception {
    final int intTest = 932832;
    final double doubleTest = 32.3234;
    final long longTest = 2374237428374293423L;
    final short shortTest = (short) intTest;
    final float floatTest = 84.3743f;
    final byte byteTest = (byte) 43;
    final char charTest = 'c';

    final ObjectMapper mapper = new ObjectMapper();
    mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);

    final int intValue = mapper.readValue(asArray(intTest), Integer.TYPE);
    assertEquals(intTest, intValue);
    final Integer integerWrapperValue =
        mapper.readValue(asArray(Integer.valueOf(intTest)), Integer.class);
    assertEquals(Integer.valueOf(intTest), integerWrapperValue);

    final double doubleValue = mapper.readValue(asArray(doubleTest), Double.class);
    assertEquals(doubleTest, doubleValue);
    final Double doubleWrapperValue =
        mapper.readValue(asArray(Double.valueOf(doubleTest)), Double.class);
    assertEquals(Double.valueOf(doubleTest), doubleWrapperValue);

    final long longValue = mapper.readValue(asArray(longTest), Long.TYPE);
    assertEquals(longTest, longValue);
    final Long longWrapperValue = mapper.readValue(asArray(Long.valueOf(longTest)), Long.class);
    assertEquals(Long.valueOf(longTest), longWrapperValue);

    final short shortValue = mapper.readValue(asArray(shortTest), Short.TYPE);
    assertEquals(shortTest, shortValue);
    final Short shortWrapperValue =
        mapper.readValue(asArray(Short.valueOf(shortTest)), Short.class);
    assertEquals(Short.valueOf(shortTest), shortWrapperValue);

    final float floatValue = mapper.readValue(asArray(floatTest), Float.TYPE);
    assertEquals(floatTest, floatValue);
    final Float floatWrapperValue =
        mapper.readValue(asArray(Float.valueOf(floatTest)), Float.class);
    assertEquals(Float.valueOf(floatTest), floatWrapperValue);

    final byte byteValue = mapper.readValue(asArray(byteTest), Byte.TYPE);
    assertEquals(byteTest, byteValue);
    final Byte byteWrapperValue = mapper.readValue(asArray(Byte.valueOf(byteTest)), Byte.class);
    assertEquals(Byte.valueOf(byteTest), byteWrapperValue);

    final char charValue =
        mapper.readValue(asArray(quote(String.valueOf(charTest))), Character.TYPE);
    assertEquals(charTest, charValue);
    final Character charWrapperValue =
        mapper.readValue(asArray(quote(String.valueOf(charTest))), Character.class);
    assertEquals(Character.valueOf(charTest), charWrapperValue);

    final boolean booleanTrueValue = mapper.readValue(asArray(true), Boolean.TYPE);
    assertTrue(booleanTrueValue);

    final boolean booleanFalseValue = mapper.readValue(asArray(false), Boolean.TYPE);
    assertFalse(booleanFalseValue);

    final Boolean booleanWrapperTrueValue =
        mapper.readValue(asArray(Boolean.valueOf(true)), Boolean.class);
    assertEquals(Boolean.TRUE, booleanWrapperTrueValue);
  }
Ejemplo n.º 11
0
  @Override
  protected void initComponentDefaults(UIDefaults table) {
    String prefValue;
    // True if file choosers orders by type
    boolean isOrderFilesByType = false;
    // True if file choosers shows all files by default
    prefValue =
        OSXPreferences.getString( //
                OSXPreferences.FINDER_PREFERENCES, "AppleShowAllFiles", "false") //
            .toLowerCase();
    boolean isFileHidingEnabled = prefValue.equals("false") || prefValue.equals("no");
    boolean isQuickLookEnabled =
        Boolean.valueOf(QuaquaManager.getProperty("Quaqua.FileChooser.quickLookEnabled", "true"));

    Font smallSystemFont = SMALL_SYSTEM_FONT;
    Color grayedFocusCellBorderColor = (Color) table.get("listHighlight");

    Object[] uiDefaults = {
      "Browser.expandedIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 0}),
      "Browser.expandingIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 1}),
      "Browser.focusedSelectedExpandedIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 2}),
      "Browser.focusedSelectedExpandingIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 3}),
      "Browser.selectedExpandedIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 4}),
      "Browser.selectedExpandingIcon",
      new UIDefaults.ProxyLazyValue(
          "ch.randelshofer.quaqua.QuaquaIconFactory",
          "createIcon",
          new Object[] {jaguarDir + "Browser.disclosureIcons.png", 6, Boolean.TRUE, 5}),
      //
      "Browser.selectionBackground",
      new ColorUIResource(56, 117, 215),
      "Browser.selectionForeground",
      new ColorUIResource(255, 255, 255),
      "Browser.inactiveSelectionBackground",
      new ColorUIResource(208, 208, 208),
      "Browser.inactiveSelectionForeground",
      new ColorUIResource(0, 0, 0),
      "Browser.sizeHandleIcon",
      makeIcon(getClass(), commonDir + "Browser.sizeHandleIcon.png"),
      "FileChooser.homeFolderIcon",
      LookAndFeel.makeIcon(getClass(), commonDir + "FileChooser.homeFolderIcon.png"),
      //
      "FileView.computerIcon",
      LookAndFeel.makeIcon(getClass(), commonDir + "FileView.computerIcon.png"),
      //
      "FileChooser.fileHidingEnabled",
      isFileHidingEnabled,
      "FileChooser.quickLookEnabled",
      isQuickLookEnabled,
      "FileChooser.orderByType",
      isOrderFilesByType,
      "FileChooser.previewLabelForeground",
      new ColorUIResource(0x000000),
      "FileChooser.previewValueForeground",
      new ColorUIResource(0x000000),
      "FileChooser.previewLabelFont",
      smallSystemFont,
      "FileChooser.previewValueFont",
      smallSystemFont,
      "FileChooser.splitPaneDividerSize",
      6,
      "FileChooser.previewLabelInsets",
      new InsetsUIResource(0, 0, 0, 4),
      "FileChooser.cellTipOrigin",
      new Point(18, 1),
      "FileChooser.autovalidate",
      Boolean.TRUE,
      "FileChooser.browserFocusCellHighlightBorder",
      new UIDefaults.ProxyLazyValue(
          "javax.swing.plaf.BorderUIResource$EmptyBorderUIResource",
          new Object[] {new Insets(1, 1, 1, 1)}),
      "FileChooser.browserFocusCellHighlightBorderGrayed",
      new UIDefaults.ProxyLazyValue(
          "javax.swing.plaf.BorderUIResource$MatteBorderUIResource",
          new Object[] {1, 1, 1, 1, grayedFocusCellBorderColor}),
      "FileChooser.browserCellBorder",
      new UIDefaults.ProxyLazyValue(
          "javax.swing.plaf.BorderUIResource$EmptyBorderUIResource",
          new Object[] {new Insets(1, 1, 1, 1)}),
      "FileChooser.browserUseUnselectedExpandIconForLabeledFile",
      Boolean.TRUE,
      "Sheet.showAsSheet",
      Boolean.TRUE,
    };
    table.putDefaults(uiDefaults);
  }