/** * Import an XQuery library module from the given document. The namespace and preferred prefix of * the module are extracted from the module itself. The MIME type of the document is set to * "application/xquery" as a side-effect. * * @param module the non-XML document that holds the library module's source * @return this service, to chain calls * @throws DatabaseException if the module is an XML document, or the module declaration cannot be * found at the top of the document */ public QueryService importModule(Document module) { if (module instanceof XMLDocument) throw new DatabaseException("module cannot be an XML document: " + module); Matcher matcher = MODULE_DECLARATION_DQUOTE.matcher(module.contentsAsString()); if (!matcher.find()) { matcher = MODULE_DECLARATION_SQUOTE.matcher(module.contentsAsString()); if (!matcher.find()) throw new DatabaseException("couldn't find a module declaration at the top of " + module); } module.metadata().setMimeType("application/xquery"); String moduleNamespace = matcher.group(1); // TODO: should do URILiteral processing here to replace entity and character references and // normalize // whitespace, but since it seems that eXist doesn't do it either (bug?) there's no reason to // rush. Document prevModule = moduleMap.get(moduleNamespace); if (prevModule != null && !prevModule.equals(module)) throw new DatabaseException( "module " + moduleNamespace + " already bound to " + prevModule + ", can't rebind to " + module); moduleMap.put(moduleNamespace, module); return this; }
/** * Updates the AttributedCharacterIterator by invoking <code>formatToCharacterIterator</code> on * the <code>Format</code>. If this is successful, <code>updateMask(AttributedCharacterIterator) * </code> is then invoked to update the internal bitmask. */ void updateMask() { if (getFormat() != null) { Document doc = getFormattedTextField().getDocument(); validMask = false; if (doc != null) { try { string = doc.getText(0, doc.getLength()); } catch (BadLocationException ble) { string = null; } if (string != null) { try { Object value = stringToValue(string); AttributedCharacterIterator iterator = getFormat().formatToCharacterIterator(value); updateMask(iterator); } catch (ParseException pe) { } catch (IllegalArgumentException iae) { } catch (NullPointerException npe) { } } } } }
public void summaryAction(HttpServletRequest req, HttpServletResponse res) { if (AccountController.redirectIfNoCookie(req, res)) return; Map<String, Object> viewData = new HashMap<String, Object>(); DocumentManager docMan = new DocumentManager(); try { if (req.getParameter("documentId") != null) { // Get the document ID int docId = Integer.parseInt(req.getParameter("documentId")); // Get the document using document id Document document = docMan.get(docId); // Set title to name of the document viewData.put("title", document.getDocumentName()); // Create List of access records List<AccessRecord> accessRecords = new LinkedList<AccessRecord>(); // Add access records for document to the list accessRecords = docMan.getAccessRecords(docId); viewData.put("accessRecords", accessRecords); } else { // Go back to thread page. } } catch (Exception e) { Logger.getLogger("").log(Level.SEVERE, "An error occurred when getting profile user", e); } view(req, res, "/views/group/Document.jsp", viewData); }
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try { DateFormat df = DateFormat.getDateTimeInstance(); String titleStr = "C3P0 Status - " + df.format(new Date()); DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); DocumentBuilder db = fact.newDocumentBuilder(); Document doc = db.newDocument(); Element htmlElem = doc.createElement("html"); Element headElem = doc.createElement("head"); Element titleElem = doc.createElement("title"); titleElem.appendChild(doc.createTextNode(titleStr)); Element bodyElem = doc.createElement("body"); Element h1Elem = doc.createElement("h1"); h1Elem.appendChild(doc.createTextNode(titleStr)); Element h3Elem = doc.createElement("h3"); h3Elem.appendChild(doc.createTextNode("PooledDataSources")); Element pdsDlElem = doc.createElement("dl"); pdsDlElem.setAttribute("class", "PooledDataSources"); for (Iterator ii = C3P0Registry.getPooledDataSources().iterator(); ii.hasNext(); ) { PooledDataSource pds = (PooledDataSource) ii.next(); StatusReporter sr = findStatusReporter(pds, doc); pdsDlElem.appendChild(sr.reportDtElem()); pdsDlElem.appendChild(sr.reportDdElem()); } headElem.appendChild(titleElem); htmlElem.appendChild(headElem); bodyElem.appendChild(h1Elem); bodyElem.appendChild(h3Elem); bodyElem.appendChild(pdsDlElem); htmlElem.appendChild(bodyElem); res.setContentType("application/xhtml+xml"); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); Source src = new DOMSource(doc); Result result = new StreamResult(res.getOutputStream()); transformer.transform(src, result); } catch (IOException e) { throw e; } catch (Exception e) { throw new ServletException(e); } }
/** Resets the value of the JFormattedTextField to be <code>value</code>. */ void resetValue(Object value) throws BadLocationException, ParseException { Document doc = getFormattedTextField().getDocument(); String string = valueToString(value); try { ignoreDocumentMutate = true; doc.remove(0, doc.getLength()); doc.insertString(0, string, null); } finally { ignoreDocumentMutate = false; } updateValue(value); }
public Element reportDtElem() { StringBuffer sb = new StringBuffer(255); sb.append(shortTypeName); sb.append(" [ dataSourceName: "); sb.append(pds.getDataSourceName()); sb.append("; identityToken: "); sb.append(pds.getIdentityToken()); sb.append(" ]"); Element dtElem = doc.createElement("dt"); dtElem.appendChild(doc.createTextNode(sb.toString())); return dtElem; }
public void actionPerformed(ActionEvent e) { ETextArea target = (ETextArea) getFocusedComponent(); try { Document document = target.getDocument(); int position = target.getCaretPosition(); String whitespace = target.getIndentationOfLineAtOffset(position); String prefix = "{\n" + whitespace + Parameters.getParameter("indent.string"); String suffix = "\n" + whitespace + "}"; document.insertString(position, prefix + suffix, null); target.setCaretPosition(position + prefix.length()); } catch (BadLocationException ex) { ex.printStackTrace(); } }
/** * Reads an XML document from an input source and copies its values into the specified object * * @param ob The object to receive the values * @param source The location of the XML document * @throws IOException If there is an error reading the document */ public void readObject(Object ob, InputSource source) throws IOException { try { // Create a document builder to read the document DocumentBuilder builder = factory.newDocumentBuilder(); // Read the document Document doc = builder.parse(source); // Get the root element Element element = doc.getDocumentElement(); // Copy the root element into the bean readObject(ob, element); } catch (SAXException exc) { throw new IOException("Error parsing XML document: " + exc.toString()); } catch (ParserConfigurationException exc) { throw new IOException("Error parsing XML document: " + exc.toString()); } }
public Element reportDdElem() { Element ddElem = doc.createElement("dd"); return ddElem; }
/** * Displays the Create Discussion page for a HTTP Get, or creates a Discussion Thread for a HTTP * Post * * <p>- Requires a cookie for the session user - Requires a groupId request parameter for a GET - * Requires a groupId and threadName request parameter for a POST - Requires a document request * part for a POST * * @param req The HTTP Request * @param res The HTTP Response */ public void createDiscussionAction(HttpServletRequest req, HttpServletResponse res) { // Ensure there is a cookie for the session user if (AccountController.redirectIfNoCookie(req, res)) return; Map<String, Object> viewData = new HashMap<>(); if (req.getMethod() == HttpMethod.Get) { viewData.put("title", "Create Discussion"); viewData.put("groupId", req.getParameter("groupId")); view(req, res, "/views/group/CreateDiscussion.jsp", viewData); return; } else if (req.getMethod() == HttpMethod.Post) { // save discussion GroupManager groupMan = new GroupManager(); DiscussionThread thread = new DiscussionThread(); int groupId = Integer.parseInt(req.getParameter("groupId")); thread.setGroupId(groupId); thread.setGroup(groupMan.get(groupId)); thread.setThreadName(req.getParameter("threadName")); DiscussionManager dm = new DiscussionManager(); dm.createDiscussion(thread); try { Part documentPart = req.getPart("document"); // if we have a document to upload if (documentPart.getSize() > 0) { String uuid = DocumentController.saveDocument(this.getServletContext(), documentPart); Document doc = new Document(); doc.setDocumentName(getFileName(documentPart)); doc.setDocumentPath(uuid); doc.setVersionNumber(1); doc.setThreadId(thread.getId()); doc.setGroupId(thread.getGroupId()); DocumentManager docMan = new DocumentManager(); docMan.createDocument(doc); // Get uploading User HttpSession session = req.getSession(); Session userSession = (Session) session.getAttribute("userSession"); User uploader = userSession.getUser(); // Create a notification to all in the group NotificationManager notificationMan = new NotificationManager(); groupMan = new GroupManager(); List<User> groupUsers = groupMan.getGroupUsers(groupId); for (User u : groupUsers) { Notification notification = new Notification( u.getId(), u, groupId, null, "User " + uploader.getFullName() + " has uploaded a document", "/document/document?documentId=" + doc.getId()); notificationMan.createNotification(notification); } } } catch (Exception e) { logger.log(Level.SEVERE, "Document save error", e); } redirectToLocal(req, res, "/group/discussion/?threadId=" + thread.getId()); return; } httpNotFound(req, res); }