incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devin...@apache.org
Subject svn commit: r1185065 - in /incubator/odf/trunk/simple/src/sample: ./ org/ org/apache/ org/apache/odftoolkit/ org/apache/odftoolkit/simple/ org/apache/odftoolkit/simple/sample/ org/apache/odftoolkit/simple/sample/ApacheLicenceMetaInfo.java
Date Mon, 17 Oct 2011 09:46:11 GMT
Author: devinhan
Date: Mon Oct 17 09:46:10 2011
New Revision: 1185065

URL: http://svn.apache.org/viewvc?rev=1185065&view=rev
Log:
#ODFTOOLKIT-293# Submit Apache Licence info automatically added code to SVN.[Developer:Devin]

Added:
    incubator/odf/trunk/simple/src/sample/   (with props)
    incubator/odf/trunk/simple/src/sample/org/   (with props)
    incubator/odf/trunk/simple/src/sample/org/apache/   (with props)
    incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/   (with props)
    incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/simple/   (with props)
    incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/simple/sample/   (with props)
    incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/simple/sample/ApacheLicenceMetaInfo.java

Propchange: incubator/odf/trunk/simple/src/sample/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: incubator/odf/trunk/simple/src/sample/org/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: incubator/odf/trunk/simple/src/sample/org/apache/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/simple/
------------------------------------------------------------------------------
    bugtraq:number = true

Propchange: incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/simple/sample/
------------------------------------------------------------------------------
    bugtraq:number = true

Added: incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/simple/sample/ApacheLicenceMetaInfo.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/simple/sample/ApacheLicenceMetaInfo.java?rev=1185065&view=auto
==============================================================================
--- incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/simple/sample/ApacheLicenceMetaInfo.java
(added)
+++ incubator/odf/trunk/simple/src/sample/org/apache/odftoolkit/simple/sample/ApacheLicenceMetaInfo.java
Mon Oct 17 09:46:10 2011
@@ -0,0 +1,93 @@
+/**********************************************************************
+ * 
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ **********************************************************************/
+package org.apache.odftoolkit.simple.sample;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+import org.odftoolkit.odfdom.pkg.OdfFileDom;
+import org.odftoolkit.simple.Document;
+import org.odftoolkit.simple.meta.Meta;
+import org.odftoolkit.odfdom.dom.attribute.meta.MetaValueTypeAttribute.Value;
+
+/**
+ * This is a sample which demos how to add Apache Licence info as user defined
+ * mata to ODF documents automatically. This will be a useful function to have
+ * in the future. As we add new unit tests and new test files, we will need to
+ * add license info to those files. This could be done via code like this.
+ * 
+ * Maybe even a 2nd class that will test an ODF file to see if it has the
+ * license in it, or one that will return the license. In the future, after we
+ * release, we could share some code with the Apache RAT project, so they could
+ * automate the testing of ODF files in projects, rather than treat them like
+ * binaries, as they do today. This would help other projects that use ODF
+ * documents, like the OpenOffice project.
+ */
+public class ApacheLicenceMetaInfo {
+	public static void main(String[] args) {
+		String patch = "C:\\resources";
+		File directry = new File(patch);
+		File[] files = directry.listFiles(new FilenameFilter() {
+			@Override
+			public boolean accept(File path, String name) {
+				if (name.contains(".od") || name.contains(".ot")) {
+					return true;
+				} else {
+					return false;
+				}
+			}
+		});
+		String license = "Licensed to the Apache Software Foundation (ASF) under one \n"
+				+ "or more contributor license agreements.  See the NOTICE file \n"
+				+ "distributed with this work for additional information \n"
+				+ "regarding copyright ownership.  The ASF licenses this file \n"
+				+ "to you under the Apache License, Version 2.0 (the \n"
+				+ "\"License\"); you may not use this file except in compliance \n"
+				+ "with the License.  You may obtain a copy of the License at \n"
+				+ "\n"
+				+ " http://www.apache.org/licenses/LICENSE-2.0 \n"
+				+ "\n"
+				+ "Unless required by applicable law or agreed to in writing, \n"
+				+ "software distributed under the License is distributed on an \n"
+				+ "\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY \n"
+				+ "KIND, either express or implied.  See the License for the \n"
+				+ "specific language governing permissions and limitations \n"
+				+ "under the License.";
+		for (File file : files) {
+			try {
+				Document doc = Document.loadDocument(file);
+				OdfFileDom metadom = doc.getMetaDom();
+				Meta metadata = new Meta(metadom);
+				String key = "License";
+				metadata.removeUserDefinedDataByName(key);
+				// org.odftoolkit.odfdom.dom.attribute.meta.MetaValueTypeAttribute.Value
+				metadata.setUserDefinedData(key, Value.STRING.toString(),
+						license);
+				doc.save(file);
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+}



Mime
View raw message