List of usage examples for java.lang SecurityException printStackTrace
public void printStackTrace()
From source file:org.jbuilt.componentTree.jsf.AbstractJsfComponentTreeBuilder.java
@SuppressWarnings("unchecked") public UISelectBoolean selectBooleanCheckbox(Object... args) { UISelectBoolean selectBooleanCheckbox = new HtmlSelectBooleanCheckbox(); System.out.print("selectBooleanCheckbox"); incrementIndent();//from w ww . ja va 2s. c o m System.out.println(" "); for (Object arg : args) { if (arg instanceof ComponentAttribute) { ((UIComponent) selectBooleanCheckbox).getAttributes().put( ((ComponentAttribute<String, Object>) arg).getKey(), ((ComponentAttribute<String, Object>) arg).getValue()); } else if (arg instanceof UIComponent) { if (((UISelectBoolean) arg) .getFacet((String) ((UIComponent) arg).getAttributes().get("name")) == null) { (selectBooleanCheckbox).getChildren().add((UIComponent) arg); } else { ((selectBooleanCheckbox).getFacets()) .put((String) ((UISelectBoolean) arg).getAttributes().get("name"), (UIComponent) arg); } } else if (arg instanceof Converter) { try { if (selectBooleanCheckbox.getClass().getDeclaredMethod("setConverter", selectBooleanCheckbox.getClass()) != null) { selectBooleanCheckbox.getClass() .getDeclaredMethod("setConverter", selectBooleanCheckbox.getClass()) .invoke(selectBooleanCheckbox, (Converter) arg); } } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } else if (arg instanceof Validator) { try { if (selectBooleanCheckbox.getClass().getDeclaredMethod("addValidator", selectBooleanCheckbox.getClass()) != null) { selectBooleanCheckbox.getClass() .getDeclaredMethod("addValidator", selectBooleanCheckbox.getClass()) .invoke(selectBooleanCheckbox, (Validator) arg); } } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } decrementIndent(); System.out.print("end_selectBooleanCheckbox\n"); return selectBooleanCheckbox; }
From source file:org.jbuilt.componentTree.jsf.AbstractJsfComponentTreeBuilder.java
@SuppressWarnings("unchecked") public UISelectMany selectManyCheckbox(Object... args) { UISelectMany selectManyCheckbox = new HtmlSelectManyCheckbox(); System.out.print("selectManyCheckbox"); incrementIndent();//w ww.j av a 2s . c o m System.out.println(" "); for (Object arg : args) { if (arg instanceof ComponentAttribute) { ((UIComponent) selectManyCheckbox).getAttributes().put( ((ComponentAttribute<String, Object>) arg).getKey(), ((ComponentAttribute<String, Object>) arg).getValue()); } else if (arg instanceof UIComponent) { if (((UISelectMany) arg) .getFacet((String) ((UIComponent) arg).getAttributes().get("name")) == null) { (selectManyCheckbox).getChildren().add((UIComponent) arg); } else { ((selectManyCheckbox).getFacets()) .put((String) ((UISelectMany) arg).getAttributes().get("name"), (UIComponent) arg); } } else if (arg instanceof Converter) { try { if (selectManyCheckbox.getClass().getDeclaredMethod("setConverter", selectManyCheckbox.getClass()) != null) { selectManyCheckbox.getClass() .getDeclaredMethod("setConverter", selectManyCheckbox.getClass()) .invoke(selectManyCheckbox, (Converter) arg); } } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } else if (arg instanceof Validator) { try { if (selectManyCheckbox.getClass().getDeclaredMethod("addValidator", selectManyCheckbox.getClass()) != null) { selectManyCheckbox.getClass() .getDeclaredMethod("addValidator", selectManyCheckbox.getClass()) .invoke(selectManyCheckbox, (Validator) arg); } } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } decrementIndent(); System.out.print("end_selectManyCheckbox\n"); return selectManyCheckbox; }
From source file:edu.ku.brc.specify.config.SpecifyAppContextMgr.java
/** * Checks a for a format file created by the Wizard for reading and adding a new * wizard to the UIFieldFormatMgr.// w w w . j av a 2 s .c o m * @param fmtFileName the name of the file. * @return true if the formatter was added */ protected boolean addFormatFromFile(final String fmtFileName, final boolean isCatNum) { Collection coll = getClassObject(Collection.class); Institution inst = getClassObject(Institution.class); boolean isAccGlobal = inst != null && inst.getIsAccessionsGlobal(); String prefix = isCatNum || !isAccGlobal ? coll.getCollectionName() : null; String path = UIRegistry.getAppDataDir() + File.separator + (prefix != null ? (prefix + "_") : "") + fmtFileName; File uifFile = new File(path); boolean loadedOK = false; if (uifFile.exists()) { try { loadedOK = UIFieldFormatterMgr.getInstance().addFormatter(uifFile); if (loadedOK) { try { uifFile.delete(); } catch (SecurityException ex) { } } } catch (Exception ex) { ex.printStackTrace(); } } return loadedOK; }
From source file:com.andrew.apollo.MusicPlaybackService.java
/** * @return A card ID used to save and restore playlists, i.e., the queue. *//*from ww w .j ava 2 s. c o m*/ private int getCardId() { int mCardId = -1; try { final ContentResolver resolver = getContentResolver(); Cursor cursor = resolver.query(Uri.parse("content://media/external/fs_id"), null, null, null, null); if (cursor != null && cursor.moveToFirst()) { mCardId = cursor.getInt(0); cursor.close(); } } catch (SecurityException e) { e.printStackTrace(); // it seems that content://media/external/fs_id is not accessible // from Android 6.0 in some phones or phone states (who knows) // this is an undocumented URI } return mCardId; }
From source file:com.andrew.apollo.MusicPlaybackService.java
/** * Resumes or starts playback.// ww w . j a v a 2 s. c om */ public void play() { if (mAudioManager == null) { return; } stopSimplePlayer(); int status = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); if (D) LOG.info("Starting playback: audio focus request status = " + status); if (status != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { return; } try { mAudioManager.registerMediaButtonEventReceiver( new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName())); } catch (SecurityException e) { e.printStackTrace(); // see explanation in initService } if (mPlayer != null && mPlayer.isInitialized()) { setNextTrack(); if (mShuffleEnabled && (mHistory.empty() || mHistory.peek() != mPlayPos)) { mHistory.push(mPlayPos); } final long duration = mPlayer.duration(); if (mRepeatMode != REPEAT_CURRENT && duration > 2000 && mPlayer.position() >= duration - 2000) { gotoNext(true); } mPlayer.start(); if (mPlayerHandler != null) { mPlayerHandler.removeMessages(FADE_DOWN); mPlayerHandler.sendEmptyMessage(FADE_UP); } if (!mIsSupposedToBePlaying) { mIsSupposedToBePlaying = true; notifyChange(PLAYSTATE_CHANGED); } cancelShutdown(); updateNotification(); } }
From source file:com.andrew.apollo.MusicPlaybackService.java
private void initService() { // Initialize the favorites and recents databases mFavoritesCache = FavoritesStore.getInstance(this); mRecentsCache = RecentStore.getInstance(this); // Initialize the notification helper mNotificationHelper = new NotificationHelper(this); // Initialize the image fetcher mImageFetcher = ImageFetcher.getInstance(this); // Initialize the image cache mImageFetcher.setImageCache(ImageCache.getInstance(this)); // Start up the thread running the service. Note that we create a // separate thread because the service normally runs in the process's // main thread, which we don't want to block. We also make it // background priority so CPU-intensive work will not disrupt the UI. final HandlerThread thread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); thread.start();/* ww w .j a v a 2 s . c om*/ // Initialize the handler mPlayerHandler = new MusicPlayerHandler(this, thread.getLooper()); // Initialize the audio manager and register any headset controls for // playback mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); try { if (mAudioManager != null) { mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); } } catch (SecurityException e) { e.printStackTrace(); // ignore // some times the phone does not grant the MODIFY_PHONE_STATE permission // this permission is for OMEs and we can't do anything about it } // Use the remote control APIs to set the playback state setUpRemoteControlClient(); // Initialize the preferences mPreferences = getSharedPreferences("Service", 0); mCardId = getCardId(); registerExternalStorageListener(); // Initialize the media player mPlayer = new MultiPlayer(this); mPlayer.setHandler(mPlayerHandler); ConfigurationManager CM = ConfigurationManager.instance(); // Load Repeat Mode setRepeatMode(CM.getInt(Constants.PREF_KEY_GUI_PLAYER_REPEAT_MODE)); // Load Shuffle Mode On/Off enableShuffle(CM.getBoolean(Constants.PREF_KEY_GUI_PLAYER_SHUFFLE_ENABLED)); MusicUtils.isShuffleEnabled(); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(SERVICECMD); filter.addAction(TOGGLEPAUSE_ACTION); filter.addAction(PAUSE_ACTION); filter.addAction(STOP_ACTION); filter.addAction(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); // Initialize the wake lock final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); if (powerManager != null) { mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.setReferenceCounted(false); } // Initialize the delayed shutdown intent final Intent shutdownIntent = new Intent(this, MusicPlaybackService.class); shutdownIntent.setAction(SHUTDOWN_ACTION); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); // Listen for the idle state scheduleDelayedShutdown(); // Bring the queue back reloadQueue(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); updateNotification(); }
From source file:com.ext.portlet.epsos.EpsosHelperService.java
@SuppressWarnings("deprecation") public static void signSAMLAssertion(SignableSAMLObject as, String keyAlias, char[] keyPassword) throws Exception { //String KEY_STORE_NAME="Unknown-1"; //String KEY_STORE_PASS="spirit"; //String PRIVATE_KEY_PASS="spirit"; //String KEY_ALIAS="server1"; ConfigurationManagerService cms = ConfigurationManagerService.getInstance(); //String KEY_STORE_NAME =GetterUtil.getString(GnPropsUtil.get("portalb", "KEYSTORE_LOCATION"),"Unknown-1"); String KEYSTORE_LOCATION = cms.getProperty("javax.net.ssl.keyStore"); String KEY_STORE_PASS = cms.getProperty("javax.net.ssl.keyStorePassword"); //GetterUtil.getString(GnPropsUtil.get("portalb", "KEYSTORE_PASSWORD"),"spirit"); String KEY_ALIAS = cms.getProperty("javax.net.ssl.key.alias"); //GetterUtil.getString(GnPropsUtil.get("portalb", "PRIVATEKEY_ALIAS"),"server1"); String PRIVATE_KEY_PASS = cms.getProperty("javax.net.ssl.privateKeyPassword"); //GetterUtil.getString(GnPropsUtil.get("portalb", "PRIVATEKEY_PASSWORD"),"spirit"); _log.debug("-------" + KEYSTORE_LOCATION); _log.debug("-------" + KEY_STORE_PASS); _log.debug("-------" + KEY_ALIAS); _log.debug("-------" + PRIVATE_KEY_PASS); KeyStoreManager keyManager = new DefaultKeyStoreManager(); //KeyPair kp = null; X509Certificate cert = null;//from w w w .j a v a 2s.c om //check if we must use the default key PrivateKey privateKey = null; PublicKey publicKey = null; if (keyAlias == null) { // kp = keyManager.getDefaultPrivateKey(); cert = (X509Certificate) keyManager.getDefaultCertificate(); } else { KeyStore keyStore = KeyStore.getInstance("JKS"); ClassLoader cl = Thread.currentThread().getContextClassLoader(); File file = new File(KEYSTORE_LOCATION); keyStore.load(new FileInputStream(file), KEY_STORE_PASS.toCharArray()); privateKey = (PrivateKey) keyStore.getKey(KEY_ALIAS, PRIVATE_KEY_PASS.toCharArray()); X509Certificate cert1 = (X509Certificate) keyStore.getCertificate(KEY_ALIAS); publicKey = cert1.getPublicKey(); //kp = keyManager.getPrivateKey(keyAlias, keyPassword); cert = (X509Certificate) keyManager.getCertificate(keyAlias); } org.opensaml.xml.signature.Signature sig = (org.opensaml.xml.signature.Signature) Configuration .getBuilderFactory().getBuilder(org.opensaml.xml.signature.Signature.DEFAULT_ELEMENT_NAME) .buildObject(org.opensaml.xml.signature.Signature.DEFAULT_ELEMENT_NAME); Credential signingCredential = SecurityHelper.getSimpleCredential(cert, privateKey); //sig.setCanonicalizationAlgorithm(SignatureConstants.TRANSFORM_C14N_EXCL_OMIT_COMMENTS); sig.setSigningCredential(signingCredential); // sig.setKeyInfo(SecurityHelper.getKeyInfoGenerator(signingCredential, null, null).generate(signingCredential)); sig.setSignatureAlgorithm("http://www.w3.org/2000/09/xmldsig#rsa-sha1"); sig.setCanonicalizationAlgorithm("http://www.w3.org/2001/10/xml-exc-c14n#"); SecurityConfiguration secConfig = Configuration.getGlobalSecurityConfiguration(); try { SecurityHelper.prepareSignatureParams(sig, signingCredential, secConfig, null); } catch (SecurityException e) { throw new SMgrException(e.getMessage(), e); } as.setSignature(sig); try { Configuration.getMarshallerFactory().getMarshaller(as).marshall(as); } catch (MarshallingException e) { throw new SMgrException(e.getMessage(), e); } try { org.opensaml.xml.signature.Signer.signObject(sig); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.stadtrallye.rallyesoft.services.UploadService.java
private void upload(final PictureManager.Picture picture, boolean previewUpload) { final int biteSize = 8192 * 4; FileInputStream fileInputStream = null; picture.uploading();/* w w w. jav a 2 s. c om*/ try { Uri uri = Uri.parse(picture.getUri()); Log.d(THIS, "Source: " + picture.getUri()); initReport(picture, biteSize); long fileSize = -1; try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && picture.getUri().startsWith("content://")) { // Check for the freshest data. persistUriPermissionApi19(uri); } AssetFileDescriptor fileDescriptor = getContentResolver().openAssetFileDescriptor(uri, "r"); fileSize = fileDescriptor.getDeclaredLength();//TODO report as indeterminate progress if length unknown fileInputStream = fileDescriptor.createInputStream(); } catch (SecurityException e) { Log.e(THIS, "No access rights... WTF", e); return; } TypedOutput uploadStream; RetroAuthCommunicator comm = Server.getCurrentServer().getAuthCommunicator(); Picture responsePicture; final long picSize = fileSize; reportUploadBegins(picSize, biteSize); final FileInputStream fIn = fileInputStream; if (previewUpload) { Bitmap img = BitmapFactory.decodeStream(fileInputStream); int biggerSide = (img.getWidth() > img.getHeight()) ? img.getWidth() : img.getHeight(); double factor = PictureSize.Preview.getDimension().height * 1.0 / biggerSide; int w = (int) Math.round(img.getWidth() * factor); int h = (int) Math.round(img.getHeight() * factor); final Bitmap scaled = Bitmap.createScaledBitmap(img, w, h, true); Log.i(THIS, "scaled bitmap. it now is " + w + "x" + h); uploadStream = new TypedOutput() { @Override public String fileName() { return picture.getHash(); } @Override public String mimeType() { return "image/jpeg"; } @Override public long length() { return -1; } @Override public void writeTo(OutputStream out) throws IOException { scaled.compress(Bitmap.CompressFormat.JPEG, 80, out); } }; reportUploadIndeterminate(picture); responsePicture = comm.uploadPreviewPicture(picture.getHash(), uploadStream); picture.uploadedPreview(); } else { uploadStream = new TypedOutput() { @Override public String fileName() { return picture.getHash(); } @Override public String mimeType() { return picture.getMimeType(); } @Override public long length() { return picSize; } @Override public void writeTo(OutputStream out) throws IOException { final byte[] buf = new byte[biteSize]; int readSize = 0; int i = 0; while (readSize >= 0) { readSize = fIn.read(buf); out.write(buf); i++; reportUploadProgress(picture, i); } } }; responsePicture = comm.uploadPicture(picture.getHash(), uploadStream); picture.uploaded(); } if (responsePicture != null) { if (!responsePicture.pictureHash.equals(picture.getHash())) { //TODO picture.serverResponse(responsePicture), possibly rename file / hash, if the server would like to Log.w(THIS, "The server responded with a different hash than it was asked for... We should rename our file, but cannot since it is not yet implemented"); } } reportUploadComplete(picture); Log.i(THIS, "Picture " + picture.pictureID + " successfully uploaded (" + picSize + " bytes)"); return; } catch (RetrofitError e) { if (e.isNetworkError()) { Log.e(THIS, "Retrofit Network error", e.getCause()); } else { Log.e(THIS, "Server declined", e); } } catch (FileNotFoundException e) { Log.e(THIS, "File was not were it was supposed to be: " + picture.getUri(), e); picture.discard(); return; } catch (IOException e) { Log.e(THIS, "Upload failed", e); } finally { if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } picture.failed(); reportUploadFailure(picture); }
From source file:com.ecyrd.jspwiki.WikiEngine.java
/** * Does all the real initialization./*from w w w . j ava2s. c o m*/ */ private void initialize(Properties props) throws WikiException { m_startTime = new Date(); m_properties = props; // // Initialized log4j. However, make sure that // we don't initialize it multiple times. Also, if // all of the log4j statements have been removed from // the property file, we do not do any property setting // either.q // if (!c_configured) { if (props.getProperty("log4j.rootCategory") != null) { PropertyConfigurator.configure(props); } c_configured = true; } log.info("*******************************************"); log.info(Release.APPNAME + " " + Release.getVersionString() + " starting. Whee!"); fireEvent(WikiEngineEvent.INITIALIZING); // begin initialization log.debug("Java version: " + System.getProperty("java.runtime.version")); log.debug("Java vendor: " + System.getProperty("java.vm.vendor")); log.debug("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch")); log.debug("Default server locale: " + Locale.getDefault()); log.debug("Default server timezone: " + TimeZone.getDefault().getDisplayName(true, TimeZone.LONG)); if (m_servletContext != null) { log.info("Servlet container: " + m_servletContext.getServerInfo()); if (m_servletContext.getMajorVersion() < 2 || (m_servletContext.getMajorVersion() == 2 && m_servletContext.getMinorVersion() < 4)) { throw new InternalWikiException( "I require a container which supports at least version 2.4 of Servlet specification"); } } log.debug("Configuring WikiEngine..."); // Initializes the CommandResolver m_commandResolver = new CommandResolver(this, props); // // Create and find the default working directory. // m_workDir = TextUtil.getStringProperty(props, PROP_WORKDIR, null); if (m_workDir == null) { m_workDir = System.getProperty("java.io.tmpdir", "."); m_workDir += File.separator + Release.APPNAME + "-" + m_appid; } try { File f = new File(m_workDir); f.mkdirs(); // // A bunch of sanity checks // if (!f.exists()) throw new WikiException("Work directory does not exist: " + m_workDir); if (!f.canRead()) throw new WikiException("No permission to read work directory: " + m_workDir); if (!f.canWrite()) throw new WikiException("No permission to write to work directory: " + m_workDir); if (!f.isDirectory()) throw new WikiException("jspwiki.workDir does not point to a directory: " + m_workDir); } catch (SecurityException e) { log.fatal("Unable to find or create the working directory: " + m_workDir, e); throw new IllegalArgumentException("Unable to find or create the working dir: " + m_workDir); } log.info("JSPWiki working directory is '" + m_workDir + "'"); m_saveUserInfo = TextUtil.getBooleanProperty(props, PROP_STOREUSERNAME, m_saveUserInfo); m_useUTF8 = "UTF-8".equals(TextUtil.getStringProperty(props, PROP_ENCODING, "ISO-8859-1")); m_baseURL = TextUtil.getStringProperty(props, PROP_BASEURL, ""); if (!m_baseURL.endsWith("/")) { m_baseURL = m_baseURL + "/"; } m_beautifyTitle = TextUtil.getBooleanProperty(props, PROP_BEAUTIFYTITLE, m_beautifyTitle); m_templateDir = TextUtil.getStringProperty(props, PROP_TEMPLATEDIR, "default"); m_frontPage = TextUtil.getStringProperty(props, PROP_FRONTPAGE, "Main"); // Initialize the page name comparator now as it may be used while // initializing other modules initPageSorter(props); // // Initialize the important modules. Any exception thrown by the // managers means that we will not start up. // // FIXME: This part of the code is getting unwieldy. We must think // of a better way to do the startup-sequence. try { Class urlclass = ClassUtil.findClass("com.ecyrd.jspwiki.url", TextUtil.getStringProperty(props, PROP_URLCONSTRUCTOR, "DefaultURLConstructor")); m_urlConstructor = (URLConstructor) urlclass.newInstance(); m_urlConstructor.initialize(this, props); m_pageManager = (PageManager) ClassUtil.getMappedObject(PageManager.class.getName(), this, props); m_pluginManager = (PluginManager) ClassUtil.getMappedObject(PluginManager.class.getName(), this, props); m_differenceManager = (DifferenceManager) ClassUtil.getMappedObject(DifferenceManager.class.getName(), this, props); m_attachmentManager = (AttachmentManager) ClassUtil.getMappedObject(AttachmentManager.class.getName(), this, props); m_variableManager = (VariableManager) ClassUtil.getMappedObject(VariableManager.class.getName(), props); // m_filterManager = (FilterManager)ClassUtil.getMappedObject(FilterManager.class.getName(), this, props ); m_renderingManager = (RenderingManager) ClassUtil.getMappedObject(RenderingManager.class.getName()); m_searchManager = (SearchManager) ClassUtil.getMappedObject(SearchManager.class.getName(), this, props); m_authenticationManager = (AuthenticationManager) ClassUtil .getMappedObject(AuthenticationManager.class.getName()); m_authorizationManager = (AuthorizationManager) ClassUtil .getMappedObject(AuthorizationManager.class.getName()); m_userManager = (UserManager) ClassUtil.getMappedObject(UserManager.class.getName()); m_groupManager = (GroupManager) ClassUtil.getMappedObject(GroupManager.class.getName()); m_editorManager = (EditorManager) ClassUtil.getMappedObject(EditorManager.class.getName(), this); m_editorManager.initialize(props); m_progressManager = new ProgressManager(); // Initialize the authentication, authorization, user and acl managers m_authenticationManager.initialize(this, props); m_authorizationManager.initialize(this, props); m_userManager.initialize(this, props); m_groupManager.initialize(this, props); m_aclManager = getAclManager(); // Start the Workflow manager m_workflowMgr = (WorkflowManager) ClassUtil.getMappedObject(WorkflowManager.class.getName()); m_workflowMgr.initialize(this, props); m_internationalizationManager = (InternationalizationManager) ClassUtil .getMappedObject(InternationalizationManager.class.getName(), this); m_templateManager = (TemplateManager) ClassUtil.getMappedObject(TemplateManager.class.getName(), this, props); m_adminBeanManager = (AdminBeanManager) ClassUtil.getMappedObject(AdminBeanManager.class.getName(), this); // Since we want to use a page filters initilize() method // as a engine startup listener where we can initialize global event listeners, // it must be called lastly, so that all object references in the engine // are availabe to the initialize() method m_filterManager = (FilterManager) ClassUtil.getMappedObject(FilterManager.class.getName(), this, props); // RenderingManager depends on FilterManager events. m_renderingManager.initialize(this, props); // // ReferenceManager has the side effect of loading all // pages. Therefore after this point, all page attributes // are available. // // initReferenceManager is indirectly using m_filterManager, therefore // it has to be called after it was initialized. // initReferenceManager(); // // Hook the different manager routines into the system. // getFilterManager().addPageFilter(m_referenceManager, -1001); getFilterManager().addPageFilter(m_searchManager, -1002); } catch (RuntimeException e) { // RuntimeExceptions may occur here, even if they shouldn't. log.fatal("Failed to start managers.", e); e.printStackTrace(); throw new WikiException("Failed to start managers: " + e.getMessage(), e); } catch (ClassNotFoundException e) { log.fatal("JSPWiki could not start, URLConstructor was not found: ", e); e.printStackTrace(); throw new WikiException(e.getMessage(), e); } catch (InstantiationException e) { log.fatal("JSPWiki could not start, URLConstructor could not be instantiated: ", e); e.printStackTrace(); throw new WikiException(e.getMessage(), e); } catch (IllegalAccessException e) { log.fatal("JSPWiki could not start, URLConstructor cannot be accessed: ", e); e.printStackTrace(); throw new WikiException(e.getMessage(), e); } catch (Exception e) { // Final catch-all for everything log.fatal("JSPWiki could not start, due to an unknown exception when starting.", e); e.printStackTrace(); throw new WikiException("Failed to start; please check log files for better information.", e); } // // Initialize the good-to-have-but-not-fatal modules. // try { if (TextUtil.getBooleanProperty(props, RSSGenerator.PROP_GENERATE_RSS, false)) { m_rssGenerator = (RSSGenerator) ClassUtil.getMappedObject(RSSGenerator.class.getName(), this, props); } m_pageRenamer = (PageRenamer) ClassUtil.getMappedObject(PageRenamer.class.getName(), this, props); } catch (Exception e) { log.error( "Unable to start RSS generator - JSPWiki will still work, " + "but there will be no RSS feed.", e); } // Start the RSS generator & generator thread if (m_rssGenerator != null) { m_rssFile = TextUtil.getStringProperty(props, RSSGenerator.PROP_RSSFILE, "rss.rdf"); File rssFile = null; if (m_rssFile.startsWith(File.separator)) { // honor absolute pathnames: rssFile = new File(m_rssFile); } else { // relative path names are anchored from the webapp root path: rssFile = new File(getRootPath(), m_rssFile); } int rssInterval = TextUtil.getIntegerProperty(props, RSSGenerator.PROP_INTERVAL, 3600); RSSThread rssThread = new RSSThread(this, rssFile, rssInterval); rssThread.start(); } fireEvent(WikiEngineEvent.INITIALIZED); // initialization complete log.info("WikiEngine configured."); m_isConfigured = true; }
From source file:org.apache.wiki.WikiEngine.java
/** * Does all the real initialization./*from w w w . j a v a 2s. c o m*/ */ private void initialize(Properties props) throws WikiException { m_startTime = new Date(); m_properties = props; // // Initialized log4j. However, make sure that // we don't initialize it multiple times. Also, if // all of the log4j statements have been removed from // the property file, we do not do any property setting // either.q // if (!c_configured) { if (props.getProperty("log4j.rootCategory") != null) { PropertyConfigurator.configure(props); } c_configured = true; } log.info("*******************************************"); log.info(Release.APPNAME + " " + Release.getVersionString() + " starting. Whee!"); fireEvent(WikiEngineEvent.INITIALIZING); // begin initialization log.debug("Java version: " + System.getProperty("java.runtime.version")); log.debug("Java vendor: " + System.getProperty("java.vm.vendor")); log.debug("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch")); log.debug("Default server locale: " + Locale.getDefault()); log.debug("Default server timezone: " + TimeZone.getDefault().getDisplayName(true, TimeZone.LONG)); if (m_servletContext != null) { log.info("Servlet container: " + m_servletContext.getServerInfo()); if (m_servletContext.getMajorVersion() < 2 || (m_servletContext.getMajorVersion() == 2 && m_servletContext.getMinorVersion() < 4)) { throw new InternalWikiException( "I require a container which supports at least version 2.4 of Servlet specification"); } } log.debug("Configuring WikiEngine..."); // Initializes the CommandResolver m_commandResolver = new CommandResolver(this, props); // // Create and find the default working directory. // m_workDir = TextUtil.getStringProperty(props, PROP_WORKDIR, null); if (m_workDir == null) { m_workDir = System.getProperty("java.io.tmpdir", "."); m_workDir += File.separator + Release.APPNAME + "-" + m_appid; } try { File f = new File(m_workDir); f.mkdirs(); // // A bunch of sanity checks // if (!f.exists()) throw new WikiException("Work directory does not exist: " + m_workDir); if (!f.canRead()) throw new WikiException("No permission to read work directory: " + m_workDir); if (!f.canWrite()) throw new WikiException("No permission to write to work directory: " + m_workDir); if (!f.isDirectory()) throw new WikiException("jspwiki.workDir does not point to a directory: " + m_workDir); } catch (SecurityException e) { log.fatal("Unable to find or create the working directory: " + m_workDir, e); throw new IllegalArgumentException("Unable to find or create the working dir: " + m_workDir); } log.info("JSPWiki working directory is '" + m_workDir + "'"); m_saveUserInfo = TextUtil.getBooleanProperty(props, PROP_STOREUSERNAME, m_saveUserInfo); m_useUTF8 = "UTF-8".equals(TextUtil.getStringProperty(props, PROP_ENCODING, "ISO-8859-1")); m_baseURL = TextUtil.getStringProperty(props, PROP_BASEURL, ""); if (!m_baseURL.endsWith("/")) { m_baseURL = m_baseURL + "/"; } m_beautifyTitle = TextUtil.getBooleanProperty(props, PROP_BEAUTIFYTITLE, m_beautifyTitle); m_templateDir = TextUtil.getStringProperty(props, PROP_TEMPLATEDIR, "default"); m_frontPage = TextUtil.getStringProperty(props, PROP_FRONTPAGE, "Main"); // Initialize the page name comparator now as it may be used while // initializing other modules initPageSorter(props); // // Initialize the important modules. Any exception thrown by the // managers means that we will not start up. // // FIXME: This part of the code is getting unwieldy. We must think // of a better way to do the startup-sequence. try { Class urlclass = ClassUtil.findClass("org.apache.wiki.url", TextUtil.getStringProperty(props, PROP_URLCONSTRUCTOR, "DefaultURLConstructor")); m_urlConstructor = (URLConstructor) urlclass.newInstance(); m_urlConstructor.initialize(this, props); m_pageManager = (PageManager) ClassUtil.getMappedObject(PageManager.class.getName(), this, props); m_pluginManager = (PluginManager) ClassUtil.getMappedObject(PluginManager.class.getName(), this, props); m_differenceManager = (DifferenceManager) ClassUtil.getMappedObject(DifferenceManager.class.getName(), this, props); m_attachmentManager = (AttachmentManager) ClassUtil.getMappedObject(AttachmentManager.class.getName(), this, props); m_variableManager = (VariableManager) ClassUtil.getMappedObject(VariableManager.class.getName(), props); // m_filterManager = (FilterManager)ClassUtil.getMappedObject(FilterManager.class.getName(), this, props ); m_renderingManager = (RenderingManager) ClassUtil.getMappedObject(RenderingManager.class.getName()); m_searchManager = (SearchManager) ClassUtil.getMappedObject(SearchManager.class.getName(), this, props); m_authenticationManager = (AuthenticationManager) ClassUtil .getMappedObject(AuthenticationManager.class.getName()); m_authorizationManager = (AuthorizationManager) ClassUtil .getMappedObject(AuthorizationManager.class.getName()); m_userManager = (UserManager) ClassUtil.getMappedObject(UserManager.class.getName()); m_groupManager = (GroupManager) ClassUtil.getMappedObject(GroupManager.class.getName()); m_editorManager = (EditorManager) ClassUtil.getMappedObject(EditorManager.class.getName(), this); m_editorManager.initialize(props); m_progressManager = new ProgressManager(); // Initialize the authentication, authorization, user and acl managers m_authenticationManager.initialize(this, props); m_authorizationManager.initialize(this, props); m_userManager.initialize(this, props); m_groupManager.initialize(this, props); m_aclManager = getAclManager(); // Start the Workflow manager m_workflowMgr = (WorkflowManager) ClassUtil.getMappedObject(WorkflowManager.class.getName()); m_workflowMgr.initialize(this, props); m_internationalizationManager = (InternationalizationManager) ClassUtil .getMappedObject(InternationalizationManager.class.getName(), this); m_templateManager = (TemplateManager) ClassUtil.getMappedObject(TemplateManager.class.getName(), this, props); m_adminBeanManager = (AdminBeanManager) ClassUtil.getMappedObject(AdminBeanManager.class.getName(), this); // Since we want to use a page filters initilize() method // as a engine startup listener where we can initialize global event listeners, // it must be called lastly, so that all object references in the engine // are availabe to the initialize() method m_filterManager = (FilterManager) ClassUtil.getMappedObject(FilterManager.class.getName(), this, props); // RenderingManager depends on FilterManager events. m_renderingManager.initialize(this, props); // // ReferenceManager has the side effect of loading all // pages. Therefore after this point, all page attributes // are available. // // initReferenceManager is indirectly using m_filterManager, therefore // it has to be called after it was initialized. // initReferenceManager(); // // Hook the different manager routines into the system. // m_filterManager.addPageFilter(m_referenceManager, -1001); m_filterManager.addPageFilter(m_searchManager, -1002); } catch (RuntimeException e) { // RuntimeExceptions may occur here, even if they shouldn't. log.fatal("Failed to start managers.", e); e.printStackTrace(); throw new WikiException("Failed to start managers: " + e.getMessage(), e); } catch (ClassNotFoundException e) { log.fatal("JSPWiki could not start, URLConstructor was not found: ", e); e.printStackTrace(); throw new WikiException(e.getMessage(), e); } catch (InstantiationException e) { log.fatal("JSPWiki could not start, URLConstructor could not be instantiated: ", e); e.printStackTrace(); throw new WikiException(e.getMessage(), e); } catch (IllegalAccessException e) { log.fatal("JSPWiki could not start, URLConstructor cannot be accessed: ", e); e.printStackTrace(); throw new WikiException(e.getMessage(), e); } catch (Exception e) { // Final catch-all for everything log.fatal("JSPWiki could not start, due to an unknown exception when starting.", e); e.printStackTrace(); throw new WikiException("Failed to start; please check log files for better information.", e); } // // Initialize the good-to-have-but-not-fatal modules. // try { if (TextUtil.getBooleanProperty(props, RSSGenerator.PROP_GENERATE_RSS, false)) { m_rssGenerator = (RSSGenerator) ClassUtil.getMappedObject(RSSGenerator.class.getName(), this, props); } m_pageRenamer = (PageRenamer) ClassUtil.getMappedObject(PageRenamer.class.getName(), this, props); } catch (Exception e) { log.error( "Unable to start RSS generator - JSPWiki will still work, " + "but there will be no RSS feed.", e); } // Start the RSS generator & generator thread if (m_rssGenerator != null) { m_rssFile = TextUtil.getStringProperty(props, RSSGenerator.PROP_RSSFILE, "rss.rdf"); File rssFile = null; if (m_rssFile.startsWith(File.separator)) { // honor absolute pathnames: rssFile = new File(m_rssFile); } else { // relative path names are anchored from the webapp root path: rssFile = new File(getRootPath(), m_rssFile); } int rssInterval = TextUtil.getIntegerProperty(props, RSSGenerator.PROP_INTERVAL, 3600); RSSThread rssThread = new RSSThread(this, rssFile, rssInterval); rssThread.start(); } fireEvent(WikiEngineEvent.INITIALIZED); // initialization complete log.info("WikiEngine configured."); m_isConfigured = true; }