List of usage examples for java.lang ClassLoader getResourceAsStream
public InputStream getResourceAsStream(String name)
From source file:org.apache.ojb.broker.util.logging.LoggingConfiguration.java
protected void load() { Logger bootLogger = LoggerFactory.getBootLogger(); // first we check whether the system property // org.apache.ojb.broker.util.logging.Logger // is set (or its alias LoggerClass which is deprecated) ClassLoader contextLoader = ClassHelper.getClassLoader(); String loggerClassName;/*from ww w.j a va2s. c o m*/ _loggerClass = null; properties = new Properties(); loggerClassName = getLoggerClass(System.getProperties()); _loggerConfigFile = getLoggerConfigFile(System.getProperties()); InputStream ojbLogPropFile; if (loggerClassName == null) { // now we're trying to load the OJB-logging.properties file String ojbLogPropFilePath = System.getProperty(OJB_LOGGING_PROPERTIES_FILE, OJB_LOGGING_PROPERTIES_FILE); try { URL ojbLoggingURL = ClassHelper.getResource(ojbLogPropFilePath); if (ojbLoggingURL == null) { ojbLoggingURL = (new File(ojbLogPropFilePath)).toURL(); } ojbLogPropFile = ojbLoggingURL.openStream(); try { bootLogger.info("Found logging properties file: " + ojbLogPropFilePath); properties.load(ojbLogPropFile); _loggerConfigFile = getLoggerConfigFile(properties); loggerClassName = getLoggerClass(properties); } finally { ojbLogPropFile.close(); } } catch (Exception ex) { if (loggerClassName == null) { bootLogger.warn("Can't read logging properties file using path '" + ojbLogPropFilePath + "', message is: " + SystemUtils.LINE_SEPARATOR + ex.getMessage() + SystemUtils.LINE_SEPARATOR + "Will try to load logging properties from OJB.properties file"); } else { bootLogger.info("Problems while closing resources for path '" + ojbLogPropFilePath + "', message is: " + SystemUtils.LINE_SEPARATOR + ex.getMessage(), ex); } } } if (loggerClassName == null) { // deprecated: load the OJB.properties file // this is not good because we have all OJB properties in this config String ojbPropFile = System.getProperty("OJB.properties", "OJB.properties"); try { ojbLogPropFile = contextLoader.getResourceAsStream(ojbPropFile); if (ojbLogPropFile != null) { try { properties.load(ojbLogPropFile); loggerClassName = getLoggerClass(properties); _loggerConfigFile = getLoggerConfigFile(properties); if (loggerClassName != null) { // deprecation warning for after 1.0 bootLogger.warn("Please use a separate '" + OJB_LOGGING_PROPERTIES_FILE + "' file to specify your logging settings"); } } finally { ojbLogPropFile.close(); } } } catch (Exception ex) { } } if (loggerClassName != null) { try { _loggerClass = ClassHelper.getClass(loggerClassName); bootLogger.info("Logging: Found logger class '" + loggerClassName); } catch (ClassNotFoundException ex) { _loggerClass = PoorMansLoggerImpl.class; bootLogger.warn("Could not load logger class " + loggerClassName + ", defaulting to " + _loggerClass.getName(), ex); } } else { // still no logger configured - lets check whether commons-logging is configured if ((System.getProperty(PROPERTY_COMMONS_LOGGING_LOG) != null) || (System.getProperty(PROPERTY_COMMONS_LOGGING_LOGFACTORY) != null)) { // yep, so use commons-logging _loggerClass = CommonsLoggerImpl.class; bootLogger.info("Logging: Found commons logging properties, use " + _loggerClass); } else { // but perhaps there is a log4j.properties file ? try { ojbLogPropFile = contextLoader.getResourceAsStream("log4j.properties"); if (ojbLogPropFile != null) { // yep, so use log4j _loggerClass = Log4jLoggerImpl.class; _loggerConfigFile = "log4j.properties"; bootLogger.info("Logging: Found 'log4j.properties' file, use " + _loggerClass); ojbLogPropFile.close(); } } catch (Exception ex) { } if (_loggerClass == null) { // or a commons-logging.properties file ? try { ojbLogPropFile = contextLoader.getResourceAsStream("commons-logging.properties"); if (ojbLogPropFile != null) { // yep, so use commons-logging _loggerClass = CommonsLoggerImpl.class; _loggerConfigFile = "commons-logging.properties"; bootLogger .info("Logging: Found 'commons-logging.properties' file, use " + _loggerClass); ojbLogPropFile.close(); } } catch (Exception ex) { } if (_loggerClass == null) { // no, so default to poor man's logging bootLogger.info("** Can't find logging configuration file, use default logger **"); _loggerClass = PoorMansLoggerImpl.class; } } } } }
From source file:dpfmanager.shell.modules.report.core.ReportGenerator.java
/** * Copies the HTML folder to the reports folder. * * @param name the name//from w w w . j ava2 s . com */ private void copyHtmlFolder(String name) { // Get the target folder File nameFile = new File(name); String absolutePath = nameFile.getAbsolutePath(); String targetPath = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator)); File target = new File(targetPath + File.separator + "html"); if (!target.exists()) { target.mkdirs(); } // Copy the html folder to target String pathStr = "./src/main/resources/html"; Path path = Paths.get(pathStr); if (Files.exists(path)) { // Look in current dir File folder = new File(pathStr); if (folder.exists() && folder.isDirectory()) { try { copyDirectory(folder, target); } catch (IOException e) { e.printStackTrace(); } } } else { // Look in JAR CodeSource src = ReportGenerator.class.getProtectionDomain().getCodeSource(); if (src != null) { String jarFolder; try { Class cls = ReportGenerator.class; ClassLoader cLoader = cls.getClassLoader(); List<String> arrayFiles = new ArrayList<>(); List<File> arrayFolders = new ArrayList<>(); //files in js folder arrayFiles.add("html/js/bootstrap.min.js"); arrayFiles.add("html/js/jquery-1.9.1.min.js"); arrayFiles.add("html/js/jquery.flot.pie.min.js"); arrayFiles.add("html/js/jquery.flot.min.js"); //files in img folder arrayFiles.add("html/img/noise.jpg"); arrayFiles.add("html/img/logo.png"); arrayFiles.add("html/img/logo - copia.png"); arrayFiles.add("html/img/check_radio_sheet.png"); //files in fonts folder arrayFiles.add("html/fonts/fontawesome-webfont.woff2"); arrayFiles.add("html/fonts/fontawesome-webfont.woff"); arrayFiles.add("html/fonts/fontawesome-webfont.ttf"); arrayFiles.add("html/fonts/fontawesome-webfont.svg"); arrayFiles.add("html/fonts/fontawesome-webfont.eot"); arrayFiles.add("html/fonts/fontello.woff2"); arrayFiles.add("html/fonts/fontello.woff"); arrayFiles.add("html/fonts/fontello.ttf"); arrayFiles.add("html/fonts/fontello.svg"); arrayFiles.add("html/fonts/fontello.eot"); arrayFiles.add("html/fonts/FontAwesome.otf"); arrayFiles.add("html/fonts/Roboto-Bold.ttf"); //files in css folder arrayFiles.add("html/css/font-awesome.css"); arrayFiles.add("html/css/default.css"); arrayFiles.add("html/css/bootstrap.css"); arrayFiles.add("html/css/fontello.css"); arrayFolders.add(new File(targetPath + File.separator + "html/js/")); arrayFolders.add(new File(targetPath + File.separator + "html/img/")); arrayFolders.add(new File(targetPath + File.separator + "html/fonts/")); arrayFolders.add(new File(targetPath + File.separator + "html/css/")); //if originals folders not exists for (File item : arrayFolders) { if (!item.exists()) { item.mkdirs(); } } //copy files for (String filePath : arrayFiles) { InputStream in = cLoader.getResourceAsStream(filePath); int readBytes; byte[] buffer = new byte[4096]; jarFolder = targetPath + File.separator; File prova = new File(jarFolder + filePath); if (!prova.exists()) { prova.createNewFile(); } OutputStream resStreamOut = new FileOutputStream(prova, false); while ((readBytes = in.read(buffer)) > 0) { resStreamOut.write(buffer, 0, readBytes); } } } catch (IOException e) { context.send(BasicConfig.MODULE_MESSAGE, new ExceptionMessage("IOException", e)); } } } }
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
private void appendImageToPresentation(DefaultFormBuilder formBuilder, final String imageFilename) { if (imageFilename == null || imageFilename.isEmpty()) return;//from ww w . j a va2 s . co m ImageIcon icon = null; try { final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); final InputStream imageStream = classLoader.getResourceAsStream(imageFilename); final Image image = ImageIO.read(imageStream); icon = new ImageIcon(image); } catch (final IOException e) { icon = new ImageIcon(imageFilename); } final JLabel component = new JLabel("<html><div style=\"margin: 8pt\"></div></html>"); component.setIcon(icon); formBuilder.append(component, 3); }
From source file:javazoom.jlgui.player.amp.Player.java
/** * Constructor./*from w w w . j av a 2s.c o m*/ */ public Player(String Skin, Frame top) { super(top); topFrame = top; // Config feature. config = Config.getInstance(); config.load(initConfig); OrigineX = config.getXLocation(); OrigineY = config.getYLocation(); // Get screen size try { Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension dimension = toolkit.getScreenSize(); screenWidth = dimension.width; screenHeight = dimension.height; } catch (Exception e) { } // Minimize/Maximize/Icon features. topFrame.addWindowListener(this); topFrame.setLocation(OrigineX, OrigineY); topFrame.setSize(0, 0); // Polis : Comment out to fix a bug under XWindow //topFrame.setResizable(false); ClassLoader cl = this.getClass().getClassLoader(); URL iconURL = cl.getResource("javazoom/jlgui/player/amp/jlguiicon.gif"); if (iconURL != null) { ImageIcon jlguiIcon = new ImageIcon(iconURL); topFrame.setIconImage(jlguiIcon.getImage()); } topFrame.show(); // DnD feature. DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, this, true); // Playlist feature. boolean playlistfound = false; if ((initSong != null) && (!initSong.equals(""))) playlistfound = loadPlaylist(initSong); else playlistfound = loadPlaylist(config.getPlaylistFilename()); // Load skin specified in args if (Skin != null) { thePath = Skin; log.info("Load default skin from " + thePath); loadSkin(thePath); config.setDefaultSkin(thePath); } // Load skin specified in jlgui.ini else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) { log.info("Load default skin from " + config.getDefaultSkin()); loadSkin(config.getDefaultSkin()); } // Default included skin else { //ClassLoader cl = this.getClass().getClassLoader(); InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz"); log.info("Load default skin for JAR"); loadSkin(sis); } // Go to playlist begining if needed. if ((playlist != null) && (playlistfound == true)) { if (playlist.getPlaylistSize() > 0) acNext.fireEvent(); } // Display the whole hide(); show(); repaint(); }
From source file:javazoom.jlgui.player.amp.PlayerApplet.java
/** * Init player applet./*from w w w. j a va2 s . c o m*/ */ public void initPlayer(String Skin) { // Config feature. config = Config.getInstance(); config.load(initConfig); OrigineX = config.getXLocation(); OrigineY = config.getYLocation(); // Get screen size try { Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension dimension = toolkit.getScreenSize(); screenWidth = dimension.width; screenHeight = dimension.height; } catch (Exception e) { } // Minimize/Maximize/Icon features. //topFrame.addWindowListener(this); topFrame.setLocation(OrigineX, OrigineY); topFrame.setSize(0, 0); // Polis : Comment out to fix a bug under XWindow //topFrame.setResizable(false); ClassLoader cl = this.getClass().getClassLoader(); URL iconURL = cl.getResource("javazoom/jlgui/player/amp/jlguiicon.gif"); if (iconURL != null) { ImageIcon jlguiIcon = new ImageIcon(iconURL); //topFrame.setIconImage(jlguiIcon.getImage()); } topFrame.show(); // DnD feature. DropTarget dt = new DropTarget(this, DnDConstants.ACTION_COPY, this, true); // Playlist feature. boolean playlistfound = false; if ((initSong != null) && (!initSong.equals(""))) playlistfound = loadPlaylist(initSong); else playlistfound = loadPlaylist(config.getPlaylistFilename()); // Load skin specified in args if (Skin != null) { thePath = Skin; log.info("Load default skin from " + thePath); loadSkin(thePath); config.setDefaultSkin(thePath); } // Load skin specified in jlgui.ini else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) { log.info("Load default skin from " + config.getDefaultSkin()); loadSkin(config.getDefaultSkin()); } // Default included skin else { //ClassLoader cl = this.getClass().getClassLoader(); InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz"); log.info("Load default skin for JAR"); loadSkin(sis); } // Go to playlist begining if needed. if ((playlist != null) && (playlistfound == true)) { if (playlist.getPlaylistSize() > 0) acNext.fireEvent(); } // Display the whole hide(); show(); repaint(); }
From source file:org.apache.cocoon.components.language.programming.java.EclipseJavaCompiler.java
public boolean compile() throws IOException { final String targetClassName = makeClassName(sourceFile); final ClassLoader classLoader = ClassUtils.getClassLoader(); String[] fileNames = new String[] { sourceFile }; String[] classNames = new String[] { targetClassName }; class CompilationUnit implements ICompilationUnit { String className;/* w w w .ja v a 2 s.c o m*/ String sourceFile; CompilationUnit(String sourceFile, String className) { this.className = className; this.sourceFile = sourceFile; } public char[] getFileName() { return className.toCharArray(); } public char[] getContents() { char[] result = null; FileReader fr = null; try { fr = new FileReader(sourceFile); Reader reader = new BufferedReader(fr); if (reader != null) { char[] chars = new char[8192]; StringBuffer buf = new StringBuffer(); int count; while ((count = reader.read(chars, 0, chars.length)) > 0) { buf.append(chars, 0, count); } result = new char[buf.length()]; buf.getChars(0, result.length, result, 0); } } catch (IOException e) { handleError(className, -1, -1, e.getMessage()); } return result; } public char[] getMainTypeName() { int dot = className.lastIndexOf('.'); if (dot > 0) { return className.substring(dot + 1).toCharArray(); } return className.toCharArray(); } public char[][] getPackageName() { StringTokenizer izer = new StringTokenizer(className, "."); char[][] result = new char[izer.countTokens() - 1][]; for (int i = 0; i < result.length; i++) { String tok = izer.nextToken(); result[i] = tok.toCharArray(); } return result; } } final INameEnvironment env = new INameEnvironment() { public NameEnvironmentAnswer findType(char[][] compoundTypeName) { StringBuffer result = new StringBuffer(); for (int i = 0; i < compoundTypeName.length; i++) { if (i > 0) { result.append("."); } result.append(compoundTypeName[i]); } return findType(result.toString()); } public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) { StringBuffer result = new StringBuffer(); for (int i = 0; i < packageName.length; i++) { if (i > 0) { result.append("."); } result.append(packageName[i]); } result.append("."); result.append(typeName); return findType(result.toString()); } private NameEnvironmentAnswer findType(String className) { try { if (className.equals(targetClassName)) { ICompilationUnit compilationUnit = new CompilationUnit(sourceFile, className); return new NameEnvironmentAnswer(compilationUnit); } String resourceName = className.replace('.', '/') + ".class"; InputStream is = classLoader.getResourceAsStream(resourceName); if (is != null) { byte[] classBytes; byte[] buf = new byte[8192]; ByteArrayOutputStream baos = new ByteArrayOutputStream(buf.length); int count; while ((count = is.read(buf, 0, buf.length)) > 0) { baos.write(buf, 0, count); } baos.flush(); classBytes = baos.toByteArray(); char[] fileName = className.toCharArray(); ClassFileReader classFileReader = new ClassFileReader(classBytes, fileName, true); return new NameEnvironmentAnswer(classFileReader); } } catch (IOException exc) { handleError(className, -1, -1, exc.getMessage()); } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException exc) { handleError(className, -1, -1, exc.getMessage()); } return null; } private boolean isPackage(String result) { if (result.equals(targetClassName)) { return false; } String resourceName = result.replace('.', '/') + ".class"; InputStream is = classLoader.getResourceAsStream(resourceName); return is == null; } public boolean isPackage(char[][] parentPackageName, char[] packageName) { StringBuffer result = new StringBuffer(); if (parentPackageName != null) { for (int i = 0; i < parentPackageName.length; i++) { if (i > 0) { result.append("."); } result.append(parentPackageName[i]); } } String str = new String(packageName); if (Character.isUpperCase(str.charAt(0)) && !isPackage(result.toString())) { return false; } result.append("."); result.append(str); return isPackage(result.toString()); } public void cleanup() { // EMPTY } }; final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems(); final Map settings = new HashMap(9); settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE); settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE); settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); settings.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE); if (sourceEncoding != null) { settings.put(CompilerOptions.OPTION_Encoding, sourceEncoding); } if (debug) { settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); } // Set the sourceCodeVersion switch (this.compilerComplianceLevel) { case 150: settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); settings.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); break; case 140: settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); break; default: settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3); } // Set the target platform switch (SystemUtils.JAVA_VERSION_INT) { case 150: settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); break; case 140: settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); break; default: settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_3); } final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); final ICompilerRequestor requestor = new ICompilerRequestor() { public void acceptResult(CompilationResult result) { try { if (result.hasErrors()) { IProblem[] errors = result.getErrors(); for (int i = 0; i < errors.length; i++) { IProblem error = errors[i]; String name = new String(errors[i].getOriginatingFileName()); handleError(name, error.getSourceLineNumber(), -1, error.getMessage()); } } else { ClassFile[] classFiles = result.getClassFiles(); for (int i = 0; i < classFiles.length; i++) { ClassFile classFile = classFiles[i]; char[][] compoundName = classFile.getCompoundName(); StringBuffer className = new StringBuffer(); for (int j = 0; j < compoundName.length; j++) { if (j > 0) { className.append("."); } className.append(compoundName[j]); } byte[] bytes = classFile.getBytes(); String outFile = destDir + "/" + className.toString().replace('.', '/') + ".class"; FileOutputStream fout = new FileOutputStream(outFile); BufferedOutputStream bos = new BufferedOutputStream(fout); bos.write(bytes); bos.close(); } } } catch (IOException exc) { exc.printStackTrace(); } } }; ICompilationUnit[] compilationUnits = new ICompilationUnit[classNames.length]; for (int i = 0; i < compilationUnits.length; i++) { String className = classNames[i]; compilationUnits[i] = new CompilationUnit(fileNames[i], className); } Compiler compiler = new Compiler(env, policy, settings, requestor, problemFactory); compiler.compile(compilationUnits); return errors.size() == 0; }
From source file:UnicodeUtil.java
private static void loadCompositions(ClassLoader loader) { DataInputStream in = null;/*from ww w. j a v a 2 s. co m*/ try { InputStream source = loader.getResourceAsStream("nu/xom/compositions.dat"); in = new DataInputStream(source); // ???? would it make sense to store a serialized HashMap instead???? compositions = new HashMap(); try { while (true) { String composed = in.readUTF(); String decomposed = in.readUTF(); compositions.put(decomposed, composed); } } catch (java.io.EOFException ex) { // finished } } catch (IOException ex) { return; } finally { try { if (in != null) in.close(); } catch (IOException ex) { // no big deal } } }
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
private Set<String> _readLines(String fileName) throws Exception { ClassLoader classLoader = getClass().getClassLoader(); Set<String> lines = new HashSet<>(); StringUtil.readLines(classLoader.getResourceAsStream(fileName), lines); return lines; }
From source file:org.alfresco.repo.search.impl.lucene.ADMLuceneTest.java
public void setUp() throws Exception { dialect = (Dialect) ctx.getBean("dialect"); nodeService = (NodeService) ctx.getBean("dbNodeService"); dictionaryService = (DictionaryService) ctx.getBean("dictionaryService"); dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO"); luceneFTS = (FullTextSearchIndexer) ctx.getBean("LuceneFullTextSearchIndexer"); contentService = (ContentService) ctx.getBean("contentService"); queryRegisterComponent = (QueryRegisterComponent) ctx.getBean("queryRegisterComponent"); namespacePrefixResolver = (DictionaryNamespaceComponent) ctx.getBean("namespaceService"); transformerDebug = (TransformerDebug) ctx.getBean("transformerDebug"); indexerAndSearcher = (IndexerAndSearcher) ctx.getBean("admLuceneIndexerAndSearcherFactory"); luceneConfig = (LuceneConfig) ctx.getBean("admLuceneIndexerAndSearcherFactory"); ((LuceneConfig) indexerAndSearcher).setMaxAtomicTransformationTime(1000000); transactionService = (TransactionService) ctx.getBean("transactionComponent"); retryingTransactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper"); tenantService = (TenantService) ctx.getBean("tenantService"); queryEngine = (QueryEngine) ctx.getBean("adm.luceneQueryEngineImpl"); nodeBulkLoader = (NodeBulkLoader) ctx.getBean("nodeDAO"); serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); namespaceDao = (NamespaceDAO) ctx.getBean("namespaceDAO"); I18NUtil.setLocale(Locale.UK); this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent"); queryRegisterComponent.loadQueryCollection("testQueryRegister.xml"); assertEquals(true, ctx.isSingleton("LuceneFullTextSearchIndexer")); testTX = transactionService.getUserTransaction(); testTX.begin();//from w ww. j a va2s .c o m this.authenticationComponent.setSystemUserAsCurrentUser(); // load in the test model ClassLoader cl = BaseNodeServiceTest.class.getClassLoader(); InputStream modelStream = cl .getResourceAsStream("org/alfresco/repo/search/impl/lucene/LuceneTest_model.xml"); assertNotNull(modelStream); model = M2Model.createModel(modelStream); dictionaryDAO.registerListener(this); dictionaryDAO.reset(); assertNotNull(dictionaryDAO.getClass(testSuperType)); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); rootNodeRef = nodeService.getRootNode(storeRef); n1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}one"), testSuperType, getOrderProperties()).getChildRef(); nodeService.setProperty(n1, QName.createQName("{namespace}property-1"), "ValueOne"); n2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}two"), testSuperType, getOrderProperties()).getChildRef(); nodeService.setProperty(n2, QName.createQName("{namespace}property-1"), "valueone"); nodeService.setProperty(n2, QName.createQName("{namespace}property-2"), "valuetwo"); n3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}three"), testSuperType, getOrderProperties()).getChildRef(); ObjectOutputStream oos; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(n3); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); Object o = ois.readObject(); ois.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Map<QName, Serializable> testProperties = new HashMap<QName, Serializable>(); testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-atomic"), "TEXT THAT IS INDEXED STORED AND TOKENISED ATOMICALLY KEYONE"); testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-unstored-tokenised-atomic"), "TEXT THAT IS INDEXED STORED AND TOKENISED ATOMICALLY KEYUNSTORED"); testProperties.put(QName.createQName(TEST_NAMESPACE, "text-indexed-stored-tokenised-nonatomic"), "TEXT THAT IS INDEXED STORED AND TOKENISED BUT NOT ATOMICALLY KEYTWO"); testProperties.put(QName.createQName(TEST_NAMESPACE, "int-ista"), Integer.valueOf(1)); testProperties.put(QName.createQName(TEST_NAMESPACE, "long-ista"), Long.valueOf(2)); testProperties.put(QName.createQName(TEST_NAMESPACE, "float-ista"), Float.valueOf(3.4f)); testProperties.put(QName.createQName(TEST_NAMESPACE, "double-ista"), Double.valueOf(5.6)); //testDate = new Date(((new Date().getTime() - 10000))); Calendar c = new GregorianCalendar(); c.setTime(new Date(((new Date().getTime() - 10000)))); //c.add(Calendar.MINUTE, -1); //c.set(Calendar.MINUTE, 0); //c.set(Calendar.MILLISECOND, 999); //c.set(Calendar.SECOND, 1); //c.set(Calendar.MILLISECOND, 0); //c.set(Calendar.SECOND, 0); //c.set(Calendar.MINUTE, 0); //c.set(Calendar.HOUR_OF_DAY, 0); // c.set(Calendar.YEAR, 2000); // c.set(Calendar.MONTH, 12); // c.set(Calendar.DAY_OF_MONTH, 31); // c.set(Calendar.HOUR_OF_DAY, 23); // c.set(Calendar.MINUTE, 59); // c.set(Calendar.SECOND, 59); // c.set(Calendar.MILLISECOND, 999); testDate = c.getTime(); testProperties.put(QName.createQName(TEST_NAMESPACE, "date-ista"), testDate); testProperties.put(QName.createQName(TEST_NAMESPACE, "datetime-ista"), testDate); testProperties.put(QName.createQName(TEST_NAMESPACE, "boolean-ista"), Boolean.valueOf(true)); testProperties.put(QName.createQName(TEST_NAMESPACE, "qname-ista"), QName.createQName("{wibble}wobble")); testProperties.put(QName.createQName(TEST_NAMESPACE, "category-ista"), new NodeRef(storeRef, "CategoryId")); testProperties.put(QName.createQName(TEST_NAMESPACE, "noderef-ista"), n1); testProperties.put(QName.createQName(TEST_NAMESPACE, "path-ista"), nodeService.getPath(n3)); testProperties.put(QName.createQName(TEST_NAMESPACE, "locale-ista"), Locale.UK); testProperties.put(QName.createQName(TEST_NAMESPACE, "period-ista"), new Period("period|12")); testProperties.put(QName.createQName(TEST_NAMESPACE, "null"), null); testProperties.put(QName.createQName(TEST_NAMESPACE, "list"), new ArrayList<Object>()); MLText mlText = new MLText(); mlText.addValue(Locale.ENGLISH, "banana"); mlText.addValue(Locale.FRENCH, "banane"); mlText.addValue(Locale.CHINESE, ""); mlText.addValue(new Locale("nl"), "banaan"); mlText.addValue(Locale.GERMAN, "banane"); mlText.addValue(new Locale("el"), ""); mlText.addValue(Locale.ITALIAN, "banana"); mlText.addValue(new Locale("ja"), "?"); mlText.addValue(new Locale("ko"), ""); mlText.addValue(new Locale("pt"), "banana"); mlText.addValue(new Locale("ru"), ""); mlText.addValue(new Locale("es"), "pltano"); testProperties.put(QName.createQName(TEST_NAMESPACE, "ml"), mlText); // Any multivalued ArrayList<Serializable> anyValues = new ArrayList<Serializable>(); anyValues.add(Integer.valueOf(100)); anyValues.add("anyValueAsString"); anyValues.add(new UnknownDataType()); testProperties.put(QName.createQName(TEST_NAMESPACE, "any-many-ista"), anyValues); // Content multivalued // - note only one the first value is used from the collection // - andit has to go in type d:any as d:content is not allowed to be multivalued ArrayList<Serializable> contentValues = new ArrayList<Serializable>(); contentValues.add(new ContentData(null, "text/plain", 0L, "UTF-16", Locale.UK)); testProperties.put(QName.createQName(TEST_NAMESPACE, "content-many-ista"), contentValues); // MLText multivalued MLText mlText1 = new MLText(); mlText1.addValue(Locale.ENGLISH, "cabbage"); mlText1.addValue(Locale.FRENCH, "chou"); MLText mlText2 = new MLText(); mlText2.addValue(Locale.ENGLISH, "lemur"); mlText2.addValue(new Locale("ru"), ""); ArrayList<Serializable> mlValues = new ArrayList<Serializable>(); mlValues.add(mlText1); mlValues.add(mlText2); testProperties.put(QName.createQName(TEST_NAMESPACE, "mltext-many-ista"), mlValues); // null in multi valued ArrayList<Object> testList = new ArrayList<Object>(); testList.add(null); testProperties.put(QName.createQName(TEST_NAMESPACE, "nullist"), testList); ArrayList<Object> testList2 = new ArrayList<Object>(); testList2.add("woof"); testList2.add(null); n4 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}four"), testType, testProperties).getChildRef(); ContentWriter multiWriter = contentService.getWriter(n4, QName.createQName(TEST_NAMESPACE, "content-many-ista"), true); multiWriter.setEncoding("UTF-16"); multiWriter.setMimetype("text/plain"); multiWriter.putContent("multicontent"); nodeService.getProperties(n1); nodeService.getProperties(n2); nodeService.getProperties(n3); nodeService.getProperties(n4); n5 = nodeService.createNode(n1, ASSOC_TYPE_QNAME, QName.createQName("{namespace}five"), testSuperType, getOrderProperties()).getChildRef(); n6 = nodeService.createNode(n1, ASSOC_TYPE_QNAME, QName.createQName("{namespace}six"), testSuperType, getOrderProperties()).getChildRef(); n7 = nodeService.createNode(n2, ASSOC_TYPE_QNAME, QName.createQName("{namespace}seven"), testSuperType, getOrderProperties()).getChildRef(); n8 = nodeService.createNode(n2, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eight-2"), testSuperType, getOrderProperties()).getChildRef(); n9 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}nine"), testSuperType, getOrderProperties()).getChildRef(); n10 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}ten"), testSuperType, getOrderProperties()).getChildRef(); n11 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eleven"), testSuperType, getOrderProperties()).getChildRef(); n12 = nodeService.createNode(n5, ASSOC_TYPE_QNAME, QName.createQName("{namespace}twelve"), testSuperType, getOrderProperties()).getChildRef(); n13 = nodeService.createNode(n12, ASSOC_TYPE_QNAME, QName.createQName("{namespace}thirteen"), testSuperType, getOrderProperties()).getChildRef(); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(); MLText desc1 = new MLText(); desc1.addValue(Locale.ENGLISH, "Alfresco tutorial"); desc1.addValue(Locale.US, "Alfresco tutorial"); Date explicitCreatedDate = new Date(); Thread.sleep(2000); properties.put(ContentModel.PROP_CONTENT, new ContentData(null, "text/plain", 0L, "UTF-8", Locale.UK)); properties.put(ContentModel.PROP_DESCRIPTION, desc1); properties.put(ContentModel.PROP_CREATED, explicitCreatedDate); //Calendar c = new GregorianCalendar(); //c.setTime(new Date()); //c.set(Calendar.MILLISECOND, 0); //c.set(Calendar.SECOND, 0); //c.set(Calendar.MINUTE, 0); //c.set(Calendar.HOUR_OF_DAY, 0); //testDate = c.getTime(); //properties.put(QName.createQName(TEST_NAMESPACE, "date-ista"), testDate); //properties.put(QName.createQName(TEST_NAMESPACE, "datetime-ista"), testDate); // note: cm:content - hence auditable aspect will be applied with any missing mandatory properties (cm:modified, cm:creator, cm:modifier) n14 = nodeService.createNode(n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}fourteen"), ContentModel.TYPE_CONTENT, properties).getChildRef(); // nodeService.addAspect(n14, DictionaryBootstrap.ASPECT_QNAME_CONTENT, // properties); assertEquals(explicitCreatedDate, nodeService.getProperty(n14, ContentModel.PROP_CREATED)); // note: cm:thumbnail - hence auditable aspect will be applied with mandatory properties (cm:created, cm:modified, cm:creator, cm:modifier) n15 = nodeService.createNode(n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}fifteen"), ContentModel.TYPE_THUMBNAIL, getOrderProperties()).getChildRef(); nodeService.setProperty(n15, ContentModel.PROP_CONTENT, new ContentData(null, "text/richtext", 0L, "UTF-8", Locale.FRENCH)); ContentWriter writer = contentService.getWriter(n14, ContentModel.PROP_CONTENT, true); writer.setEncoding("UTF-8"); // InputStream is = // this.getClass().getClassLoader().getResourceAsStream("test.doc"); // writer.putContent(is); writer.putContent( "The quick brown fox jumped over the lazy dog and ate the Alfresco Tutorial, in pdf format, along with the following stop words; a an and are" + " as at be but by for if in into is it no not of on or such that the their then there these they this to was will with: " + " and random charcters \u00E0\u00EA\u00EE\u00F0\u00F1\u00F6\u00FB\u00FF"); // System.out.println("Size is " + writer.getSize()); writer = contentService.getWriter(n15, ContentModel.PROP_CONTENT, true); writer.setEncoding("UTF-8"); // InputStream is = // this.getClass().getClassLoader().getResourceAsStream("test.doc"); // writer.putContent(is); writer.putContent(" "); nodeService.addChild(rootNodeRef, n8, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}eight-0")); nodeService.addChild(n1, n8, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eight-1")); nodeService.addChild(n2, n13, ASSOC_TYPE_QNAME, QName.createQName("{namespace}link")); nodeService.addChild(n1, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); nodeService.addChild(n2, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); nodeService.addChild(n5, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); nodeService.addChild(n6, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); nodeService.addChild(n12, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); nodeService.addChild(n13, n14, ASSOC_TYPE_QNAME, QName.createQName("{namespace}common")); documentOrder = new NodeRef[] { rootNodeRef, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n3, n1, n2 }; }
From source file:org.kairosdb.core.Main.java
private void loadPlugins(Properties props, final File propertiesFile) throws IOException { File propDir = propertiesFile.getParentFile(); if (propDir == null) propDir = new File("."); String[] pluginProps = propDir.list(new FilenameFilter() { @Override/*from w w w . java 2 s .com*/ public boolean accept(File dir, String name) { return (name.endsWith(".properties") && !name.equals(propertiesFile.getName())); } }); ClassLoader cl = getClass().getClassLoader(); for (String prop : pluginProps) { logger.info("Loading plugin properties: {}", prop); //Load the properties file from a jar if there is one first. //This way defaults can be set InputStream propStream = cl.getResourceAsStream(prop); if (propStream != null) { props.load(propStream); propStream.close(); } //Load the file in FileInputStream fis = new FileInputStream(new File(propDir, prop)); props.load(fis); fis.close(); } }