132 |
132 |
* following the PUBLIC keyword in DOCTYPE declaration or
|
133 |
133 |
* the docname if no Public ID provided or
|
134 |
134 |
* null if no DOCTYPE declaration provided
|
|
135 |
* @param docid the docid to use for the INSERT OR UPDATE
|
|
136 |
* @param action the action to be performed (INSERT OR UPDATE)
|
|
137 |
* @param user the user that owns the document
|
|
138 |
* @param pub flag for public "read" access on document
|
|
139 |
* @param serverCode the serverid from xml_replication on which this document
|
|
140 |
* resides.
|
135 |
141 |
*
|
136 |
142 |
*/
|
137 |
143 |
public DocumentImpl(Connection conn, long rootnodeid, String docname,
|
138 |
144 |
String doctype, String docid, String action, String user,
|
139 |
|
int serverCode)
|
|
145 |
String pub, int serverCode)
|
140 |
146 |
throws SQLException, Exception
|
141 |
147 |
{
|
142 |
148 |
this.conn = conn;
|
... | ... | |
144 |
150 |
this.docname = docname;
|
145 |
151 |
this.doctype = doctype;
|
146 |
152 |
this.docid = docid;
|
147 |
|
writeDocumentToDB(action, user, serverCode);
|
|
153 |
writeDocumentToDB(action, user, pub, serverCode);
|
148 |
154 |
}
|
149 |
155 |
|
150 |
|
public DocumentImpl(Connection conn, long rootnodeid, String docname,
|
151 |
|
String doctype, String docid, String action, String user)
|
152 |
|
throws SQLException, Exception
|
153 |
|
{
|
154 |
|
this.conn = conn;
|
155 |
|
this.rootnodeid = rootnodeid;
|
156 |
|
this.docname = docname;
|
157 |
|
this.doctype = doctype;
|
158 |
|
this.docid = docid;
|
159 |
|
writeDocumentToDB(action, user);
|
160 |
|
}
|
|
156 |
// NOT USED ANY MORE
|
|
157 |
// public DocumentImpl(Connection conn, long rootnodeid, String docname,
|
|
158 |
// String doctype, String docid, String action, String user)
|
|
159 |
// throws SQLException, Exception
|
|
160 |
// {
|
|
161 |
// this.conn = conn;
|
|
162 |
// this.rootnodeid = rootnodeid;
|
|
163 |
// this.docname = docname;
|
|
164 |
// this.doctype = doctype;
|
|
165 |
// this.docid = docid;
|
|
166 |
// writeDocumentToDB(action, user);
|
|
167 |
// }
|
161 |
168 |
|
162 |
169 |
/**
|
163 |
170 |
* get the document name
|
... | ... | |
614 |
621 |
private void writeDocumentToDB(String action, String user)
|
615 |
622 |
throws SQLException, Exception
|
616 |
623 |
{
|
617 |
|
writeDocumentToDB(action, user, 1);
|
|
624 |
writeDocumentToDB(action, user, null, 1);
|
618 |
625 |
}
|
619 |
626 |
|
620 |
627 |
/** creates SQL code and inserts new document into DB connection */
|
621 |
|
private void writeDocumentToDB(String action, String user, int serverCode)
|
|
628 |
private void writeDocumentToDB(String action, String user, String pub,
|
|
629 |
int serverCode)
|
622 |
630 |
throws SQLException, Exception {
|
623 |
631 |
try {
|
624 |
632 |
PreparedStatement pstmt = null;
|
... | ... | |
628 |
636 |
//this.docid = ac.generate(docid, "INSERT");
|
629 |
637 |
pstmt = conn.prepareStatement(
|
630 |
638 |
"INSERT INTO xml_documents " +
|
631 |
|
"(docid, rootnodeid, docname, doctype, user_owner, " +
|
632 |
|
"user_updated, date_created, date_updated, server_location) " +
|
633 |
|
"VALUES (?, ?, ?, ?, ?, ?, sysdate, sysdate, ?)");
|
|
639 |
"(docid, rootnodeid, docname, doctype, user_owner, user_updated, " +
|
|
640 |
"date_created, date_updated, public_access, server_location) " +
|
|
641 |
"VALUES (?, ?, ?, ?, ?, ?, sysdate, sysdate, ?, ?)");
|
634 |
642 |
//note that the server_location is set to 1.
|
635 |
643 |
//this means that "localhost" in the xml_replication table must
|
636 |
644 |
//always be the first entry!!!!!
|
... | ... | |
642 |
650 |
pstmt.setString(4, doctype);
|
643 |
651 |
pstmt.setString(5, user);
|
644 |
652 |
pstmt.setString(6, user);
|
645 |
|
pstmt.setInt(7, serverCode);
|
|
653 |
if ( pub == null ) {
|
|
654 |
pstmt.setString(7, null);
|
|
655 |
} else if ( pub.toUpperCase().equals("YES") ) {
|
|
656 |
pstmt.setInt(7, 1);
|
|
657 |
} else if ( pub.toUpperCase().equals("NO") ) {
|
|
658 |
pstmt.setInt(7, 0);
|
|
659 |
}
|
|
660 |
pstmt.setInt(8, serverCode);
|
646 |
661 |
} else if (action.equals("UPDATE")) {
|
647 |
662 |
|
648 |
663 |
// Save the old document entry in a backup table
|
... | ... | |
662 |
677 |
"UPDATE xml_documents " +
|
663 |
678 |
"SET rootnodeid = ?, docname = ?, doctype = ?, " +
|
664 |
679 |
"user_updated = ?, date_updated = sysdate, " +
|
665 |
|
"server_location = ?, rev = ? WHERE docid LIKE ?");
|
|
680 |
"server_location = ?, rev = ?, public_access = ? " +
|
|
681 |
"WHERE docid LIKE ?");
|
666 |
682 |
// Bind the values to the query
|
667 |
683 |
pstmt.setLong(1, rootnodeid);
|
668 |
684 |
pstmt.setString(2, docname);
|
... | ... | |
670 |
686 |
pstmt.setString(4, user);
|
671 |
687 |
pstmt.setInt(5, serverCode);
|
672 |
688 |
pstmt.setInt(6, thisrev);
|
673 |
|
pstmt.setString(7, this.docid);
|
|
689 |
if ( pub == null ) {
|
|
690 |
pstmt.setString(7, null);
|
|
691 |
} else if ( pub.toUpperCase().equals("YES") ) {
|
|
692 |
pstmt .setInt(7, 1);
|
|
693 |
} else if ( pub.toUpperCase().equals("NO") ) {
|
|
694 |
pstmt.setInt(7, 0);
|
|
695 |
}
|
|
696 |
pstmt.setString(8, this.docid);
|
674 |
697 |
|
675 |
698 |
} else {
|
676 |
699 |
System.err.println("Action not supported: " + action);
|
... | ... | |
726 |
749 |
*
|
727 |
750 |
* @param conn the JDBC connection to the database
|
728 |
751 |
* @param filename the filename to be loaded into the database
|
|
752 |
* @param pub flag for public "read" access on document
|
|
753 |
* @param dtdfilename the dtd to be uploaded on server's file system
|
729 |
754 |
* @param action the action to be performed (INSERT OR UPDATE)
|
730 |
755 |
* @param docid the docid to use for the INSERT OR UPDATE
|
|
756 |
* @param user the user that owns the document
|
|
757 |
* @param group the group to which user belongs
|
731 |
758 |
*/
|
732 |
759 |
public static String write(Connection conn,String filename,
|
733 |
|
String aclfilename,String dtdfilename,
|
|
760 |
String pub, String dtdfilename,
|
734 |
761 |
String action, String docid, String user,
|
735 |
762 |
String group )
|
736 |
763 |
throws Exception {
|
737 |
764 |
|
738 |
|
Reader acl = null;
|
739 |
|
if ( aclfilename != null ) {
|
740 |
|
acl = new FileReader(new File(aclfilename).toString());
|
741 |
|
}
|
742 |
765 |
Reader dtd = null;
|
743 |
766 |
if ( dtdfilename != null ) {
|
744 |
767 |
dtd = new FileReader(new File(dtdfilename).toString());
|
745 |
768 |
}
|
746 |
769 |
return write ( conn, new FileReader(new File(filename).toString()),
|
747 |
|
acl, dtd, action, docid, user, group);
|
|
770 |
pub, dtd, action, docid, user, group);
|
748 |
771 |
}
|
749 |
772 |
|
750 |
|
public static String write(Connection conn,Reader xml,Reader acl,Reader dtd,
|
|
773 |
public static String write(Connection conn,Reader xml,String pub,Reader dtd,
|
751 |
774 |
String action, String docid, String user,
|
752 |
775 |
String group )
|
753 |
776 |
throws Exception {
|
754 |
|
return write ( conn, xml, acl, dtd, action, docid, user, group, 1, false);
|
|
777 |
return write ( conn, xml, pub, dtd, action, docid, user, group, 1, false);
|
755 |
778 |
}
|
756 |
779 |
|
757 |
|
public static String write(Connection conn,Reader xml,Reader acl,
|
|
780 |
public static String write(Connection conn, Reader xml, String pub,
|
758 |
781 |
String action, String docid, String user,
|
759 |
782 |
String group )
|
760 |
783 |
throws Exception {
|
... | ... | |
763 |
786 |
//originally inserted document.
|
764 |
787 |
DocumentImpl doc = new DocumentImpl(conn, docid);
|
765 |
788 |
int servercode = doc.getServerlocation();
|
766 |
|
return write(conn,xml,acl,action,docid,user,group,servercode);
|
|
789 |
return write(conn, xml, pub, action, docid, user, group, servercode);
|
767 |
790 |
}
|
768 |
791 |
else
|
769 |
792 |
{//if the file is being inserted then the servercode is always 1
|
770 |
|
return write(conn, xml, acl, action, docid, user, group, 1);
|
|
793 |
return write(conn, xml, pub, action, docid, user, group, 1);
|
771 |
794 |
}
|
772 |
795 |
}
|
773 |
796 |
|
... | ... | |
779 |
802 |
return write(conn,xml,null,action,docid,user,group,serverCode);
|
780 |
803 |
}
|
781 |
804 |
|
782 |
|
public static String write( Connection conn,Reader xml,Reader acl,
|
|
805 |
public static String write( Connection conn, Reader xml, String pub,
|
783 |
806 |
String action, String docid, String user,
|
784 |
807 |
String group, int serverCode)
|
785 |
808 |
throws Exception
|
786 |
809 |
{
|
787 |
|
return write(conn,xml,acl,null,action,docid,user,group,serverCode,false);
|
|
810 |
return write(conn,xml,pub,null,action,docid,user,group,serverCode,false);
|
788 |
811 |
}
|
789 |
812 |
|
790 |
|
public static String write( Connection conn,Reader xml,Reader acl,
|
|
813 |
public static String write( Connection conn, Reader xml, String pub,
|
791 |
814 |
String action, String docid, String user,
|
792 |
815 |
String group, int serverCode, boolean override)
|
793 |
816 |
throws Exception
|
794 |
817 |
{
|
795 |
|
return write(conn,xml,acl,null,action,docid,user,group,serverCode,override);
|
|
818 |
return write(conn,xml,pub,null,action,docid,user,group,serverCode,override);
|
796 |
819 |
}
|
797 |
820 |
|
798 |
821 |
/**
|
... | ... | |
800 |
823 |
*
|
801 |
824 |
* @param conn the JDBC connection to the database
|
802 |
825 |
* @param xml the xml stream to be loaded into the database
|
|
826 |
* @param pub flag for public "read" access on xml document
|
|
827 |
* @param dtd the dtd to be uploaded on server's file system
|
803 |
828 |
* @param action the action to be performed (INSERT OR UPDATE)
|
804 |
829 |
* @param docid the docid to use for the INSERT OR UPDATE
|
805 |
830 |
* @param user the user that owns the document
|
... | ... | |
813 |
838 |
* update will be locked and version checked.
|
814 |
839 |
*/
|
815 |
840 |
|
816 |
|
public static String write( Connection conn,Reader xml,Reader acl,Reader dtd,
|
|
841 |
public static String write( Connection conn,Reader xml,String pub,Reader dtd,
|
817 |
842 |
String action, String docid, String user,
|
818 |
843 |
String group, int serverCode, boolean override)
|
819 |
844 |
throws Exception
|
... | ... | |
858 |
883 |
MetacatReplication.replLog("lock granted for " + docid + " from " +
|
859 |
884 |
server);
|
860 |
885 |
XMLReader parser = initializeParser(conn, action, newdocid,
|
861 |
|
user, group, serverCode, dtd);
|
|
886 |
user, group, pub, serverCode, dtd);
|
862 |
887 |
conn.setAutoCommit(false);
|
863 |
888 |
parser.parse(new InputSource(xml));
|
864 |
889 |
conn.commit();
|
... | ... | |
920 |
945 |
try
|
921 |
946 |
{
|
922 |
947 |
XMLReader parser = initializeParser(conn, action, newdocid,
|
923 |
|
user, group, serverCode, dtd);
|
|
948 |
user, group, pub, serverCode, dtd);
|
924 |
949 |
conn.setAutoCommit(false);
|
925 |
950 |
parser.parse(new InputSource(xml));
|
926 |
951 |
conn.commit();
|
... | ... | |
1024 |
1049 |
*/
|
1025 |
1050 |
private static XMLReader initializeParser(Connection conn, String action,
|
1026 |
1051 |
String docid, String user, String group,
|
1027 |
|
int serverCode, Reader dtd)
|
|
1052 |
String pub, int serverCode, Reader dtd)
|
1028 |
1053 |
throws Exception
|
1029 |
1054 |
{
|
1030 |
1055 |
XMLReader parser = null;
|
... | ... | |
1033 |
1058 |
//
|
1034 |
1059 |
try {
|
1035 |
1060 |
ContentHandler chandler = new DBSAXHandler(conn, action, docid,
|
1036 |
|
user, group, serverCode);
|
|
1061 |
user, group, pub, serverCode);
|
1037 |
1062 |
EntityResolver eresolver= new DBEntityResolver(conn,
|
1038 |
1063 |
(DBSAXHandler)chandler, dtd);
|
1039 |
1064 |
DTDHandler dtdhandler = new DBDTDHandler(conn);
|
... | ... | |
1105 |
1130 |
|
1106 |
1131 |
try {
|
1107 |
1132 |
String filename = null;
|
1108 |
|
String aclfilename = null;
|
1109 |
1133 |
String dtdfilename = null;
|
1110 |
1134 |
String action = null;
|
1111 |
1135 |
String docid = null;
|
... | ... | |
1116 |
1140 |
for ( int i=0 ; i < args.length; ++i ) {
|
1117 |
1141 |
if ( args[i].equals( "-f" ) ) {
|
1118 |
1142 |
filename = args[++i];
|
1119 |
|
} else if ( args[i].equals( "-c" ) ) {
|
1120 |
|
aclfilename = args[++i];
|
1121 |
1143 |
} else if ( args[i].equals( "-r" ) ) {
|
1122 |
1144 |
dtdfilename = args[++i];
|
1123 |
1145 |
} else if ( args[i].equals( "-a" ) ) {
|
... | ... | |
1161 |
1183 |
System.err.println("Wrong number of arguments!!!");
|
1162 |
1184 |
System.err.println(
|
1163 |
1185 |
"USAGE: java DocumentImpl [-t] <-a INSERT> [-d docid] <-f filename> "+
|
1164 |
|
"[-c aclfilename] [-r dtdfilename]");
|
|
1186 |
"[-r dtdfilename]");
|
1165 |
1187 |
System.err.println(
|
1166 |
1188 |
" OR: java DocumentImpl [-t] <-a UPDATE -d docid -f filename> " +
|
1167 |
|
"[-c aclfilename] [-r dtdfilename]");
|
|
1189 |
"[-r dtdfilename]");
|
1168 |
1190 |
System.err.println(
|
1169 |
1191 |
" OR: java DocumentImpl [-t] <-a DELETE -d docid>");
|
1170 |
1192 |
System.err.println(
|
... | ... | |
1192 |
1214 |
DocumentImpl.delete(dbconn, docid, null, null);
|
1193 |
1215 |
System.out.println("Document deleted: " + docid);
|
1194 |
1216 |
} else {
|
1195 |
|
String newdocid = DocumentImpl.write(dbconn, filename, aclfilename,
|
|
1217 |
String newdocid = DocumentImpl.write(dbconn, filename, null,
|
1196 |
1218 |
dtdfilename, action, docid,
|
1197 |
1219 |
null, null);
|
1198 |
1220 |
if ((docid != null) && (!docid.equals(newdocid))) {
|
included new servlet parameter "public" specifing public read access for the submitted document
the expected values are "yes" or "no"
public parameter is optional and if it is not specified, means "no"