Examples of DocumentFragment


Examples of org.w3c.dom.DocumentFragment

                    parameters = new SourceParameters();
                }
                parameters = this.createParameters(parameters,
                                                   null,
                                                   true);
                DocumentFragment fragment;
                fragment = SourceUtil.readDOM(loadResource,
                                              null,
                                              parameters,
                                              resolver);
                this.setXML("/", fragment);
View Full Code Here

Examples of org.w3c.dom.DocumentFragment

        if (path == null) {
            throw new ProcessingException("getXML: Path is required");
        }
        if (path.startsWith("/") == false) path = '/' + path;

        DocumentFragment frag = null;

        if (path.equals("/") == true) {
            // get all: first authentication then application
            frag = this.authContext.getXML("/" + this.handlerName + "/authentication");

            if (frag != null) {
                // now add root node authentication
                Node root = frag.getOwnerDocument().createElementNS(null, "authentication");
                Node child;
                while (frag.hasChildNodes() == true) {
                    child = frag.getFirstChild();
                    frag.removeChild(child);
                    root.appendChild(child);
                }
                frag.appendChild(root);
            }

            if (this.applicationName != null) {
                // join
                DocumentFragment appFrag = this.authContext.getXML("/" + this.handlerName + "/applications/" + this.applicationName);
                if (appFrag != null) {
                    // now add root node application
                    Node root = appFrag.getOwnerDocument().createElementNS(null, "application");
                    Node child;
                    while (appFrag.hasChildNodes() == true) {
                        child = appFrag.getFirstChild();
                        appFrag.removeChild(child);
                        root.appendChild(child);
                    }
                    appFrag.appendChild(root);

                    if (frag == null) {
                        frag = appFrag;
                    } else {
                        while (appFrag.hasChildNodes() == true) {
                            child = appFrag.getFirstChild();
                            appFrag.removeChild(child);
                            child = frag.getOwnerDocument().importNode(child, true);
                            frag.appendChild(child);
                        }
                    }
                }
View Full Code Here

Examples of org.w3c.dom.DocumentFragment

     */
    public void addParametersFromAuthenticationXML(String handlerName,
                                                   String path,
                                                   SourceParameters parameters)
    throws ProcessingException {
        final DocumentFragment fragment = this.authContext.getXML("/" + handlerName + "/authentication" + path);
        if (fragment != null) {
            NodeList   childs = fragment.getChildNodes();
            if (childs != null) {
                Node current;
                for(int i = 0; i < childs.getLength(); i++) {
                    current = childs.item(i);

View Full Code Here

Examples of org.w3c.dom.DocumentFragment

        if (this.authSaveResource == null) {
            throw new ProcessingException("The context " + this.name + " does not support saving.");
        }

        synchronized(this.authContext) {
            DocumentFragment fragment = this.getXML(path);
            if (fragment == null) {
                // create empty fake fragment
                fragment = DOMUtil.createDocument().createDocumentFragment();
            }
            if (parameters != null) {
View Full Code Here

Examples of org.w3c.dom.DocumentFragment

            }
            parameters = this.createParameters(parameters,
                                               this.handlerName,
                                               path,
                                               null);
            DocumentFragment frag;
           
            frag = SourceUtil.readDOM(this.authLoadResource,
                                      null,
                                      parameters,
                                      resolver);
View Full Code Here

Examples of org.w3c.dom.DocumentFragment

            }
            parameters = this.createParameters(parameters,
                                               this.handlerName,
                                               path,
                                               this.applicationName);
            DocumentFragment fragment = this.getXML("/application" + path);
            if (fragment == null) {
                // create empty fake fragment
                fragment = DOMUtil.createDocument().createDocumentFragment();
            }
View Full Code Here

Examples of org.w3c.dom.DocumentFragment

        // Element: inputxml
        } else if (name.equals(INPUTXML_ELEMENT) == true) {
            String path = (String)this.stack.pop();
            String fieldname = (String)this.stack.pop();
            String contextname = (String)this.stack.pop();
            DocumentFragment defaultFragment = this.endRecording();

            if (this.formName == null) {
                throw new ProcessingException("The inputxml must be contained inside a form.");
            }
            DocumentFragment value = this.getSessionManager().registerInputField(contextname, path, fieldname, formName);
            if (value == null) value = defaultFragment;
            this.sendEvents(value);
            super.endTransformingElement("", name, name);

        // Element form
        } else if (name.equals(FORM_ELEMENT) == true
                   && this.state == STATE_FORM) {
            this.state = ((Integer)this.stack.pop()).intValue();
            this.sendEndElementEvent("form");
            this.formName = null;

        // Element form action
        } else if (name.equals(FORM_ACTION_ELEMENT) == true
                   && this.state == STATE_FORM) {
            String action = this.endTextRecording();
            AttributesImpl a = (AttributesImpl)this.stack.pop();
            this.formName = a.getValue("name");
            boolean hasPars = (action.indexOf("?") != -1);
            action = this.response.encodeURL(action + (hasPars ? '&' : '?') + SessionConstants.SESSION_FORM_PARAMETER+'='+this.formName);
            a.addAttribute("", "action", "action", "CDATA", action);
            if (a.getValue("method") == null) {
                a.addAttribute("", "method", "method", "CDATA", "POST");
            }
            this.sendStartElementEvent("form", a);

        // Element form content
        } else if (name.equals(FORM_CONTENT_ELEMENT) == true
                   && this.state == STATE_FORM) {
            // ignore this

        // Element form validation rules
        } else if (name.equals(FORM_VALIDATION_ELEMENT) == true
                   && this.state == STATE_FORM) {
            if (this.formName == null) {
                throw new ProcessingException("The validate element must be contained inside a form.");
            }
            DocumentFragment validationDoc = this.endRecording();
            String source = (String)stack.pop();
            if (!source.equals("EMPTY")) {
                // get configuration from external file
                // referenced by "src" attribute of "validate" element

                Configuration conf = null;
                Session session = null;
                try {
                    Source resource = this.resolver.resolveURI(source);
                    SAXConfigurationHandler saxBuilder = new SAXConfigurationHandler();
                    resolver.toSAX(resource, saxBuilder);

                    conf = saxBuilder.getConfiguration();
                    session = this.getSessionManager().getSession(true);
                    session.setAttribute(this.formName, conf);
                   
                    if (validationDoc != null) {
                        //validationDoc contains "validate-set" element
                        validationDoc.normalize();
                        Node validationNode = validationDoc.getFirstChild();
                        while (validationNode.getNodeType() != Node.ELEMENT_NODE) {
                            validationNode = validationNode.getNextSibling();
                            if (validationNode == null) break;
                        }
                        if (validationNode != null &&
                            validationNode.getNodeType() == Node.ELEMENT_NODE &&
                            validationNode.getNodeName().equals(FORM_VALIDATESET_ELEMENT)) {
                            String validationXML = XMLUtils.serializeNodeToXML(validationNode);
                            DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
                            conf = builder.build(new StringBufferInputStream(validationXML));
                            session.setAttribute(this.formName+"validate-set", conf);
                        }
                    }
                   
                } catch (SourceException se) {
                    throw new ProcessingException("Cannot resolve"+source, se);
                } catch (ConfigurationException ce) {
                    throw new ProcessingException("Error building Configuration out of validate-set element", ce);
                }

            } else if (validationDoc != null) {
                //validationDoc contains the validation rules inline
                try {
                    validationDoc.normalize();
                    Node validationNode = validationDoc.getFirstChild();
                    while (validationNode.getNodeType() != Node.ELEMENT_NODE) {
                        validationNode = validationNode.getNextSibling();
                        if (validationNode == null) break;
                    }
                    if (validationNode != null &&
View Full Code Here

Examples of org.w3c.dom.DocumentFragment

        if (this.getLogger().isDebugEnabled() == true) {
            this.getLogger().debug("BEGIN authenticate handler=" + loginHandlerName +
                                   ", parameters="+parameters);
        }

        DocumentFragment authenticationFragment = null;
        boolean         isValid                = false;

        Handler myHandler = this.getHandler(loginHandlerName);
        if (this.getLogger().isInfoEnabled() == true) {
            this.getLogger().info("AuthenticationManager: Trying to authenticate using handler '" + loginHandlerName +"'");
        }
        if (myHandler != null) {
            String           exceptionMsg     = null;

            if (this.getLogger().isDebugEnabled() == true) {
                this.getLogger().debug("start authentication");
            }

            final String   authenticationResourceName = myHandler.getAuthenticationResource();
            final SourceParameters authenticationParameters = myHandler.getAuthenticationResourceParameters();
            if (parameters != null) {
                parameters.add(authenticationParameters);
            } else {
                parameters = authenticationParameters;
            }

            try {
                if (this.getLogger().isDebugEnabled()) {
                    this.getLogger().debug("start invoking auth resource");
                }
                Source source = null;
                try {
                    source = org.apache.cocoon.components.source.SourceUtil.getSource(authenticationResourceName,
                                                                                      null,
                                                                                      parameters,
                                                                                      this.resolver);
                   
                    Document doc = org.apache.cocoon.components.source.SourceUtil.toDOM(source);
                    authenticationFragment = doc.createDocumentFragment();
                    authenticationFragment.appendChild(doc.getDocumentElement());
                } catch (SAXException se) {
                    throw new ProcessingException(se);
                } catch (SourceException se) {
                    throw org.apache.cocoon.components.source.SourceUtil.handle(se);
                } finally {
                    this.resolver.release(source);
                }

                if (this.getLogger().isDebugEnabled()) {
                    this.getLogger().debug("end invoking auth resource");
                }
            } catch (ProcessingException local) {
                this.getLogger().error("authenticate", local);
                exceptionMsg = local.getMessage();
            }

            // test if authentication was successful
            if (authenticationFragment != null) {
                isValid = this.isValidAuthenticationFragment(authenticationFragment);

                if (isValid == true) {
                    if (this.getLogger().isInfoEnabled() == true) {
                        this.getLogger().info("AuthenticationManager: User authenticated using handler '" + myHandler.getName()+"'");
                    }
                    // create session object if necessary, context etc and get it
                    if (this.getLogger().isDebugEnabled() == true) {
                        this.getLogger().debug("creating session");
                    }
                    SessionContext context = this.getAuthenticationSessionContext(true);
                    if (this.getLogger().isDebugEnabled() == true) {
                        this.getLogger().debug("session created");
                    }

                    myHandler = this.handlerManager.storeUserHandler(myHandler,
                                                                     this.request);

                    synchronized(context) {
                        // add special nodes to the authentication block:
                        // useragent, type and media
                        Element specialElement;
                        Text    specialValue;
                        Element authNode;

                        authNode = (Element)authenticationFragment.getFirstChild();
                        specialElement = authenticationFragment.getOwnerDocument().createElementNS(null, "useragent");
                        specialValue = authenticationFragment.getOwnerDocument().createTextNode(request.getHeader("User-Agent"));
                        specialElement.appendChild(specialValue);
                        authNode.appendChild(specialElement);

                        specialElement = authenticationFragment.getOwnerDocument().createElementNS(null, "type");
                        specialValue = authenticationFragment.getOwnerDocument().createTextNode("cocoon.authentication");
                        specialElement.appendChild(specialValue);
                        authNode.appendChild(specialElement);

                        specialElement = authenticationFragment.getOwnerDocument().createElementNS(null, "media");
                        specialValue = authenticationFragment.getOwnerDocument().createTextNode(this.mediaType);
                        specialElement.appendChild(specialValue);
                        authNode.appendChild(specialElement);

                        // store the authentication data in the context
                        context.setXML("/" + myHandler.getName(), authenticationFragment);

                        // Now create the return value for this method:
                        // <code>null</code>
                        authenticationFragment = null;

                        // And now load applications
                        boolean loaded = true;
                        Iterator applications = myHandler.getApplications().values().iterator();
                        ApplicationHandler appHandler;

                        while (applications.hasNext() == true) {
                            appHandler = (ApplicationHandler)applications.next();
                            if (appHandler.getLoadOnDemand() == false) {
                                this.loadApplicationXML((SessionContextImpl)this.getSessionManager().getContext(AuthenticationConstants.SESSION_CONTEXT_NAME),
                                                        appHandler, "/");
                            } else {
                                loaded = appHandler.getIsLoaded();
                            }
                        }
                        myHandler.setApplicationsLoaded(loaded);

                    } // end sync
                }
            }
            if (isValid == false) {
                if (this.getLogger().isInfoEnabled() == true) {
                    this.getLogger().info("AuthenticationManager: Failed authentication using handler '" +  myHandler.getName()+"'");
                }
                // get the /authentication/data Node if available
                Node data = null;

                if (authenticationFragment != null) {
                    data = DOMUtil.getFirstNodeFromPath(authenticationFragment, new String[] {"authentication","data"}, false);
                }

                // now create the following xml:
                // <failed/>
                // if data is available data is included, otherwise:
                // <data>No information</data>
                // If exception message contains info, it is included into failed
                Document       doc = DOMUtil.createDocument();
                authenticationFragment = doc.createDocumentFragment();

                Element      element = doc.createElementNS(null, "failed");
                authenticationFragment.appendChild(element);

                if (exceptionMsg != null) {
                    Text text = doc.createTextNode(exceptionMsg);
                    element.appendChild(text);
                }

                if (data == null) {
                    element = doc.createElementNS(null, "data");
                    authenticationFragment.appendChild(element);
                    Text text = doc.createTextNode("No information");
                    element.appendChild(text);
                } else {
                    authenticationFragment.appendChild(doc.importNode(data, true));
                }

            }
            if (this.getLogger().isDebugEnabled() == true) {
                this.getLogger().debug("end authentication");
View Full Code Here

Examples of org.w3c.dom.DocumentFragment

                if (parameters != null) parameters = (SourceParameters)parameters.clone();
                parameters = this.createParameters(parameters,
                                                   appHandler.getHandler().getName(),
                                                   path,
                                                   appHandler.getName());
                DocumentFragment fragment;

                Source source = null;
                try {
                    source = org.apache.cocoon.components.source.SourceUtil.getSource(loadResourceName,
                                                                                      null,
                                                                                      parameters,
                                                                                      this.resolver);
                    Document doc = org.apache.cocoon.components.source.SourceUtil.toDOM(source);
                    fragment = doc.createDocumentFragment();
                    fragment.appendChild(doc.getDocumentElement());
                } catch (SourceException se) {
                    throw org.apache.cocoon.components.source.SourceUtil.handle(se);
                } catch (IOException se) {
                    throw new ProcessingException(se);
                } catch (SAXException se) {
View Full Code Here

Examples of org.w3c.dom.DocumentFragment

            // System.out.println("Text: " + text);
            SAXSVGDocumentFactory df = new SAXSVGDocumentFactory
                (XMLResourceDescriptor.getXMLParserClassName());
            String uri = ((SVGOMDocument)bridgeContext.getDocument()).
                getURLObject().toString();
            DocumentFragment result = null;
            try {
                Document d = df.createDocument(uri, new StringReader(text));
                result = doc.createDocumentFragment();
                result.appendChild(doc.importNode(d.getDocumentElement(),
                                                  true));
            } catch (Exception ex) {
                StringBuffer sb = new StringBuffer(text.length() +
                                                   FRAGMENT_PREFIX.length() +
                                                   "</svg>".length());
                sb.append(FRAGMENT_PREFIX);
                sb.append(text);
                sb.append("</svg>");
                String newText = sb.toString();
                try {
                    Document d = df.createDocument
                        (uri, new StringReader(newText));
                    for (Node n = d.getDocumentElement().getFirstChild();
                         n != null;
                         n = n.getNextSibling()) {
                        if (n.getNodeType() == n.ELEMENT_NODE) {
                            n = doc.importNode(n, true);
                            result = doc.createDocumentFragment();
                            result.appendChild(n);
                            break;
                        }
                    }
                } catch (Exception exc) {
                    SAXDocumentFactory sdf = new SAXDocumentFactory
                        (doc.getImplementation(),
                         XMLResourceDescriptor.getXMLParserClassName());
                    try {
                        Document d = sdf.createDocument
                            (uri, new StringReader(text));
                        result = doc.createDocumentFragment();
                        result.appendChild(doc.importNode(d.getDocumentElement(), true));
                    } catch (Exception ext) {
                        if (userAgent != null)
                            userAgent.displayError(ext);
                    }
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.