Example usage for org.w3c.dom Element getFirstChild

List of usage examples for org.w3c.dom Element getFirstChild

Introduction

In this page you can find the example usage for org.w3c.dom Element getFirstChild.

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

Usage

From source file:org.alfresco.web.config.forms.FormConfigRuntime.java

/**
 * @param properties/*from  w  w  w  .j a  v  a  2 s.  co  m*/
 * @return
 */
public boolean syncGlobalConfigs(HashMap<String, Object> properties) {
    boolean status = false;

    Element formsElem = XmlUtils.findFirstElement("config[not(@evaluator) and not(@condition)]/forms",
            (Element) configDocument.getFirstChild());
    if (formsElem == null) {
        formsElem = setGlobalConfigFormsElement();
        status = true;
    }

    String configType = (String) properties.get("config-type");
    if (configType != null) {
        if (configType.equals("default-control")) {
            String typeName = (String) properties.get("type-name");
            String newTypeName = (properties.containsKey("new-type-name"))
                    ? (String) properties.get("new-type-name")
                    : null;

            Element defaultControlsElem = XmlUtils.findFirstElement("default-controls", formsElem);
            if (defaultControlsElem == null) {
                defaultControlsElem = configDocument.createElement("default-controls");
                appendChild(formsElem, defaultControlsElem);
                status = true;
            }
            if (typeName != null) {
                Element typeControlElem = XmlUtils.findFirstElement("type[@name='" + typeName + "']",
                        defaultControlsElem);
                if (newTypeName != null && !typeName.equals(newTypeName)) {
                    if (typeControlElem != null) {
                        //typeControlElem.getParentNode().removeChild(typeControlElem);
                        removeChild(typeControlElem);
                        typeControlElem = null;
                        status = true;
                    }
                    typeName = newTypeName;
                }
                Control control = (Control) properties.get("control");
                if (typeControlElem == null) {
                    typeControlElem = configDocument.createElement("type");
                    manageAttribute(typeControlElem, "name", typeName);
                    manageAttribute(typeControlElem, "template", control.getTemplate());
                    appendChild(defaultControlsElem, typeControlElem);
                    status = true;
                }

                if (control.getParams() != null) {
                    boolean parametersChanged = false;
                    ControlParam[] controlParameters = control.getParams();
                    if (typeControlElem.getChildNodes().getLength() != controlParameters.length) {
                        parametersChanged = true;
                    } else {
                        for (ControlParam controlParam : controlParameters) {
                            String parameterValue = controlParam.getValue();
                            Element parameterElem = XmlUtils.findFirstElement(
                                    "control-param[@name='" + controlParam.getName() + "']",
                                    defaultControlsElem);
                            if (parameterElem == null) {
                                parametersChanged = true;
                            } else if (!parameterElem.getTextContent().equals(parameterValue)) {
                                parametersChanged = true;
                            }
                        }
                    }
                    if (parametersChanged) {
                        while (typeControlElem.getChildNodes().getLength() > 0) {
                            removeChild(typeControlElem.getFirstChild());
                        }
                        for (ControlParam controlParam : controlParameters) {
                            String parameterValue = controlParam.getValue();
                            Element parameterElem = XmlUtils.findFirstElement(
                                    "control-param[@name='" + controlParam.getName() + "']",
                                    defaultControlsElem);
                            if (parameterElem == null) {
                                parameterElem = configDocument.createElement("control-param");
                                manageAttribute(parameterElem, "name", controlParam.getName());
                                status = true;
                            }
                            if (!parameterElem.getTextContent().equals(parameterValue)) {
                                parameterElem.setTextContent(parameterValue);
                                status = true;
                            }
                            if (parameterElem != null) {
                                appendChild(typeControlElem, parameterElem);
                            }
                        }
                    }
                }
            }
        } else if (configType.equals("constraint-handler")) {
            String typeName = (String) properties.get("constraint-type-name");
            String newTypeName = (properties.containsKey("new-constraint-type-name"))
                    ? (String) properties.get("new-constraint-type-name")
                    : null;

            Element constraintHandlersElem = XmlUtils.findFirstElement("constraint-handlers", formsElem);
            if (constraintHandlersElem == null) {
                constraintHandlersElem = configDocument.createElement("constraint-handlers");
                appendChild(formsElem, constraintHandlersElem);
                status = true;
            }
            if (typeName != null) {
                Element constraintHandlerElem = XmlUtils
                        .findFirstElement("constraint[@type='" + typeName + "']", constraintHandlersElem);
                if (newTypeName != null && !typeName.equals(newTypeName)) {
                    if (constraintHandlerElem != null) {
                        //constraintHandlerElem.getParentNode().removeChild(constraintHandlerElem);
                        removeChild(constraintHandlerElem);
                        constraintHandlerElem = null;
                        status = true;
                    }
                    typeName = newTypeName;
                }
                ConstraintHandlerDefinition constraintHandler = (ConstraintHandlerDefinition) properties
                        .get("constraint");
                if (constraintHandlerElem == null) {
                    constraintHandlerElem = configDocument.createElement("constraint");
                    manageAttribute(constraintHandlerElem, "type", typeName);
                    appendChild(constraintHandlersElem, constraintHandlerElem);
                    status = true;
                }
                if (manageAttribute(constraintHandlerElem, "validation-handler",
                        constraintHandler.getValidationHandler())) {
                    status = true;
                }
                if (manageAttribute(constraintHandlerElem, "event", constraintHandler.getEvent())) {
                    status = true;
                }
                if (manageAttribute(constraintHandlerElem, "message", constraintHandler.getMessage())) {
                    status = true;
                }
                if (manageAttribute(constraintHandlerElem, "message-id", constraintHandler.getMessageId())) {
                    status = true;
                }
            }
        } else if (configType.equals("dependencies")) {
            Element dependenciesElem = XmlUtils.findFirstElement("dependencies", formsElem);
            if (dependenciesElem == null) {
                dependenciesElem = configDocument.createElement("dependencies");
                appendChild(formsElem, dependenciesElem);
                status = true;
            }
            if (properties.containsKey("js")) {
                String dependency = (String) properties.get("js");
                Element jsElement = XmlUtils.findFirstElement("js[@src='" + dependency + "']",
                        dependenciesElem);
                if (jsElement == null) {
                    jsElement = configDocument.createElement("js");
                    appendChild(dependenciesElem, jsElement);
                    status = true;
                }
                if (properties.containsKey("new-js")) {
                    String newDependency = (String) properties.get("new-js");
                    if (!dependency.equals(newDependency)) {
                        dependency = newDependency;
                    }
                }
                if (manageAttribute(jsElement, "src", dependency)) {
                    status = true;
                }
            }
            if (properties.containsKey("css")) {
                String dependency = (String) properties.get("css");
                Element cssElement = XmlUtils.findFirstElement("css[@src='" + dependency + "']",
                        dependenciesElem);
                if (cssElement == null) {
                    cssElement = configDocument.createElement("css");
                    appendChild(dependenciesElem, cssElement);
                    status = true;
                }
                if (properties.containsKey("new-css")) {
                    String newDependency = (String) properties.get("new-css");
                    if (!dependency.equals(newDependency)) {
                        dependency = newDependency;
                    }
                }
                if (manageAttribute(cssElement, "src", dependency)) {
                    status = true;
                }
            }
        }
    }
    return status;
}

From source file:org.apache.manifoldcf.crawler.connectors.meridio.MeridioConnector.java

/** Close the connection.  Call this before discarding the repository connector.
*//*w  w  w  . ja va  2 s. com*/
@Override
public void disconnect() throws ManifoldCFException {
    Logging.connectors.debug("Meridio: Entering 'disconnect' method");

    try {
        if (meridio_ != null) {
            meridio_.logout();
        }
    } catch (org.apache.axis.AxisFault e) {
        long currentTime = System.currentTimeMillis();
        if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) {
            org.w3c.dom.Element elem = e.lookupFaultDetail(
                    new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode"));
            if (elem != null) {
                elem.normalize();
                String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
                Logging.connectors.warn(
                        "Unexpected http error code " + httpErrorCode + " logging out: " + e.getMessage());
                return;
            }
            Logging.connectors.warn("Unknown http error occurred while logging out: " + e.getMessage());
            return;
        }
        if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/",
                "Server.userException"))) {
            String exceptionName = e.getFaultString();
            if (exceptionName.equals("java.lang.InterruptedException"))
                throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED);
        }
        if (e.getFaultCode()
                .equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) {
            if (e.getFaultString().indexOf(" 23031#") != -1) {
                // This means that the session has expired, so reset it and retry
                meridio_ = null;
                return;
            }
        }

        Logging.connectors.warn("Meridio: Got an unknown remote exception logging out - axis fault = "
                + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString(), e);
        return;
    } catch (RemoteException remoteException) {
        Logging.connectors.warn(
                "Meridio: A remote exception occurred while " + "logging out: " + remoteException.getMessage(),
                remoteException);
    } finally {
        super.disconnect();
        meridio_ = null;
        urlBase = null;
        urlVersionBase = null;
        DmwsURL = null;
        RmwsURL = null;
        mySSLFactory = null;
        Logging.connectors.debug("Meridio: Exiting 'disconnect' method");
    }
}

From source file:org.apache.manifoldcf.crawler.connectors.meridio.MeridioConnector.java

/** Returns the categories set up in the Meridio system; these are used by the UI for two
* purposes//from ww w .  j  a  v a2  s  . c om
*
*              1)      To populate the "SearchCategory"
*                              Use "getPROP_title()" on the list of CATEGORIES object in
*                              the return ArrayList
*              2)  To assist with population of the metadata values to return. The
*                      available metadata depends on the chosen category
*
*@return Sorted array of strings containing the category names
*/
public String[] getMeridioCategories() throws ManifoldCFException, ServiceInterruption {
    Logging.connectors.debug("Entering 'getMeridioCategories' method");

    while (true) {
        getSession();
        ArrayList returnCategories = new ArrayList();

        try {
            CATEGORIES[] categories = meridio_.getCategories().getCATEGORIES();
            for (int i = 0; i < categories.length; i++) {
                if (categories[i].getPROP_categoryId() == 4 || // Global Document Category
                        categories[i].getPROP_categoryId() == 5 || // Mail Message
                        categories[i].getPROP_categoryId() > 100) // Custom Document Category
                {
                    if (!categories[i].getPROP_title().equals("<None>")) {
                        Logging.connectors.debug("Adding category <" + categories[i].getPROP_title() + ">");
                        returnCategories.add(categories[i].getPROP_title());
                    }
                }
            }

            String[] returnStringArray = new String[returnCategories.size()];
            Iterator it = returnCategories.iterator();
            for (int i = 0; it.hasNext(); i++) {
                returnStringArray[i] = (String) it.next();
            }

            java.util.Arrays.sort(returnStringArray);

            Logging.connectors.debug("Exiting 'getMeridioCategories' method");

            return returnStringArray;
        } catch (org.apache.axis.AxisFault e) {
            long currentTime = System.currentTimeMillis();
            if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) {
                org.w3c.dom.Element elem = e.lookupFaultDetail(
                        new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode"));
                if (elem != null) {
                    elem.normalize();
                    String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
                    throw new ManifoldCFException("Unexpected http error code " + httpErrorCode
                            + " getting categories: " + e.getMessage());
                }
                throw new ManifoldCFException(
                        "Unknown http error occurred while getting categories: " + e.getMessage(), e);
            }
            if (e.getFaultCode().equals(new javax.xml.namespace.QName(
                    "http://schemas.xmlsoap.org/soap/envelope/", "Server.userException"))) {
                String exceptionName = e.getFaultString();
                if (exceptionName.equals("java.lang.InterruptedException"))
                    throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED);
            }
            if (e.getFaultCode().equals(
                    new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) {
                if (e.getFaultString().indexOf(" 23031#") != -1) {
                    // This means that the session has expired, so reset it and retry
                    meridio_ = null;
                    continue;
                }
            }

            throw new ManifoldCFException(
                    "Meridio: Got an unknown remote exception getting categories - axis fault = "
                            + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString(),
                    e);
        } catch (RemoteException remoteException) {
            throw new ManifoldCFException("Meridio: A Remote Exception occurred while "
                    + "retrieving the Meridio categories: " + remoteException.getMessage(), remoteException);
        } catch (MeridioDataSetException meridioDataSetException) {
            throw new ManifoldCFException(
                    "Meridio: DataSet Exception occurred retrieving the Meridio categories: "
                            + meridioDataSetException.getMessage(),
                    meridioDataSetException);
        }
    }
}

From source file:org.apache.manifoldcf.crawler.connectors.meridio.MeridioConnector.java

/** Test the connection.  Returns a string describing the connection integrity.
*@return the connection's status as a displayable string.
*/// w ww . j  a  v a  2  s.c o m
@Override
public String check() throws ManifoldCFException {
    Logging.connectors.debug("Meridio: Entering 'check' method");

    try {
        // Force a relogin
        meridio_ = null;
        getSession();
    } catch (ServiceInterruption e) {
        return "Meridio temporarily unavailable: " + e.getMessage();
    } catch (ManifoldCFException e) {
        return e.getMessage();
    }

    try {

        /*=================================================================
        * Call a method in the Web Services API to get the Meridio system
        * name back - just something simple to test the connection
        * end-to-end
        *================================================================*/
        DMDataSet ds = meridio_.getStaticData();
        if (null == ds) {
            Logging.connectors.debug("Meridio: DM DataSet returned was null in 'check' method");
            return "Connection failed - null DM DataSet";
        }

        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("Meridio System Name is [" + ds.getSYSTEMINFO().getSystemName()
                    + "] and the comment is [" + ds.getSYSTEMINFO().getComment() + "]");

        /*=================================================================
        * For completeness, we also call a method in the RM Web
        * Service API
        *================================================================*/
        RMDataSet rmws = meridio_.getConfiguration();
        if (null == rmws) {
            Logging.connectors.warn("Meridio: RM DataSet returned was null in 'check' method");
            return "Connection failed - null RM DataSet returned";
        }

        return super.check();
    } catch (org.apache.axis.AxisFault e) {
        long currentTime = System.currentTimeMillis();
        if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) {
            org.w3c.dom.Element elem = e.lookupFaultDetail(
                    new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode"));
            if (elem != null) {
                elem.normalize();
                String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
                return "Unexpected http error code " + httpErrorCode + " accessing Meridio: " + e.getMessage();
            }
            return "Unknown http error occurred while checking: " + e.getMessage();
        }
        if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/",
                "Server.userException"))) {
            String exceptionName = e.getFaultString();
            if (exceptionName.equals("java.lang.InterruptedException"))
                throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED);
        }
        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("Meridio: Got an unknown remote exception checking - axis fault = "
                    + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying", e);
        return "Axis fault: " + e.getMessage();
    } catch (RemoteException remoteException) {
        /*=================================================================
        * Log the exception because we will then discard it
        *
        * Potentially attempting to re-login may resolve this error but
        * if it is being called soon after a successful login, then that
        * is unlikely.
        *
        * A RemoteException could be a transient network error
        *================================================================*/
        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("Meridio: Unknown remote exception occurred during 'check' method: "
                    + remoteException.getMessage(), remoteException);

        return "Connection failed - Remote exception: " + remoteException.getMessage();
    } catch (MeridioDataSetException meridioDataSetException) {
        /*=================================================================
        * Log the exception because we will then discard it
        *
        * If it is a DataSet exception it means that we could not marshal
        * or unmarshall the XML returned from the Web Service call. This
        * means there is either a problem with the code, or perhaps the
        * connector is pointing at an incorrect/unsupported version of
        * Meridio
        *================================================================*/
        if (Logging.connectors.isDebugEnabled())
            Logging.connectors.debug("Meridio: DataSet exception occurred during 'check' method: "
                    + meridioDataSetException.getMessage(), meridioDataSetException);

        return "Connection failed - DataSet exception: " + meridioDataSetException.getMessage();
    } finally {
        Logging.connectors.debug("Meridio: Exiting 'check' method");
    }
}

From source file:org.apache.manifoldcf.crawler.connectors.meridio.MeridioConnector.java

/** Queue "seed" documents.  Seed documents are the starting places for crawling activity.  Documents
* are seeded when this method calls appropriate methods in the passed in ISeedingActivity object.
*
* This method can choose to find repository changes that happen only during the specified time interval.
* The seeds recorded by this method will be viewed by the framework based on what the
* getConnectorModel() method returns./*  w w w .j a  va  2s.  com*/
*
* It is not a big problem if the connector chooses to create more seeds than are
* strictly necessary; it is merely a question of overall work required.
*
* The end time and seeding version string passed to this method may be interpreted for greatest efficiency.
* For continuous crawling jobs, this method will
* be called once, when the job starts, and at various periodic intervals as the job executes.
*
* When a job's specification is changed, the framework automatically resets the seeding version string to null.  The
* seeding version string may also be set to null on each job run, depending on the connector model returned by
* getConnectorModel().
*
* Note that it is always ok to send MORE documents rather than less to this method.
* The connector will be connected before this method can be called.
*@param activities is the interface this method should use to perform whatever framework actions are desired.
*@param spec is a document specification (that comes from the job).
*@param seedTime is the end of the time range of documents to consider, exclusive.
*@param lastSeedVersionString is the last seeding version string for this job, or null if the job has no previous seeding version string.
*@param jobMode is an integer describing how the job is being run, whether continuous or once-only.
*@return an updated seeding version string, to be stored with the job.
*/
@Override
public String addSeedDocuments(ISeedingActivity activities, Specification spec, String lastSeedVersion,
        long seedTime, int jobMode) throws ManifoldCFException, ServiceInterruption {
    Logging.connectors.debug("Meridio: Entering 'addSeedDocuments' method");
    long startTime;
    if (lastSeedVersion == null)
        startTime = 0L;
    else {
        // Unpack seed time from seed version string
        startTime = new Long(lastSeedVersion).longValue();
    }
    // Adjust start time so that we don't miss documents that squeeze in with earlier timestamps after we've already scanned that interval.
    // Chose an interval of 15 minutes, but I've never seen this effect take place over a time interval even 1/10 of that.
    long timeAdjust = 15L * 60000L;
    if (startTime > timeAdjust)
        startTime -= timeAdjust;
    else
        startTime = 0L;

    while (true) {
        getSession();

        try {
            DMSearchResults searchResults;
            int numResultsReturnedByStream = 0;

            while (true) {
                searchResults = documentSpecificationSearch(spec, startTime, seedTime,
                        numResultsReturnedByStream + 1, maxHitsToReturn);

                for (int i = 0; i < searchResults.returnedHitsCount; i++) {
                    long documentId = searchResults.dsDM.getSEARCHRESULTS_DOCUMENTS()[i].getDocId();

                    String strDocumentId = new Long(documentId).toString();
                    activities.addSeedDocument(strDocumentId);
                }

                numResultsReturnedByStream += searchResults.returnedHitsCount;
                if (numResultsReturnedByStream == searchResults.totalHitsCount)
                    break;
            }
            return new Long(seedTime).toString();
        } catch (org.apache.axis.AxisFault e) {
            long currentTime = System.currentTimeMillis();
            if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) {
                org.w3c.dom.Element elem = e.lookupFaultDetail(
                        new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode"));
                if (elem != null) {
                    elem.normalize();
                    String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
                    throw new ManifoldCFException("Unexpected http error code " + httpErrorCode
                            + " accessing Meridio: " + e.getMessage(), e);
                }
                throw new ManifoldCFException(
                        "Unknown http error occurred while performing search: " + e.getMessage(), e);
            }
            if (e.getFaultCode().equals(new javax.xml.namespace.QName(
                    "http://schemas.xmlsoap.org/soap/envelope/", "Server.userException"))) {
                String exceptionName = e.getFaultString();
                if (exceptionName.equals("java.lang.InterruptedException"))
                    throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED);
            }
            if (e.getFaultCode().equals(
                    new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) {
                if (e.getFaultString().indexOf(" 23031#") != -1) {
                    // This means that the session has expired, so reset it and retry
                    meridio_ = null;
                    continue;
                }
            }
            if (Logging.connectors.isDebugEnabled())
                Logging.connectors.debug(
                        "Meridio: Got an unknown remote exception while performing search - axis fault = "
                                + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString()
                                + " - retrying",
                        e);
            throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e,
                    currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false);
        } catch (RemoteException remoteException) {
            throw new ManifoldCFException("Meridio: A Remote Exception occurred while "
                    + "performing a search: " + remoteException.getMessage(), remoteException);
        } catch (MeridioDataSetException meridioDataSetException) {
            throw new ManifoldCFException("Meridio: A problem occurred manipulating the Web " + "Service XML: "
                    + meridioDataSetException.getMessage(), meridioDataSetException);
        }
    }

}

From source file:org.apache.manifoldcf.crawler.connectors.meridio.MeridioConnector.java

public MeridioClassContents[] getClassOrFolderContents(int classOrFolderId)
        throws ManifoldCFException, ServiceInterruption {
    Logging.connectors.debug("Entering 'getClassOrFolderContents' method");

    while (true) {
        getSession();/*from   www .  j av  a2s  . com*/
        ArrayList meridioContainers = new ArrayList();

        try {
            RMDataSet ds = meridio_.getClassContents(classOrFolderId, false, false, false);
            if (ds == null) {
                Logging.connectors.debug("No classes or folders in returned DataSet");
                return new MeridioClassContents[] {};
            }

            Rm2vClass[] classes = ds.getRm2vClass();
            Rm2vFolder[] folders = ds.getRm2vFolder();

            for (int i = 0; i < classes.length; i++) {
                if (classes[i].getHomePage() == null || classes[i].getHomePage().length() == 0) // Not a federated link
                {
                    MeridioClassContents classContents = new MeridioClassContents();

                    classContents.containerType = MeridioClassContents.CLASS;
                    classContents.classOrFolderId = classes[i].getId();
                    classContents.classOrFolderName = classes[i].getName();

                    meridioContainers.add(classContents);
                }
            }

            for (int i = 0; i < folders.length; i++) {
                MeridioClassContents classContents = new MeridioClassContents();

                classContents.containerType = MeridioClassContents.FOLDER;
                classContents.classOrFolderId = folders[i].getId();
                classContents.classOrFolderName = folders[i].getName();

                meridioContainers.add(classContents);
            }

            MeridioClassContents[] classArray = new MeridioClassContents[meridioContainers.size()];
            Iterator it = meridioContainers.iterator();
            for (int i = 0; it.hasNext(); i++) {
                classArray[i] = (MeridioClassContents) it.next();
            }
            Logging.connectors.debug("Exiting 'getClassOrFolderContents' method");

            return classArray;
        } catch (org.apache.axis.AxisFault e) {
            long currentTime = System.currentTimeMillis();
            if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) {
                org.w3c.dom.Element elem = e.lookupFaultDetail(
                        new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode"));
                if (elem != null) {
                    elem.normalize();
                    String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
                    throw new ManifoldCFException("Unexpected http error code " + httpErrorCode
                            + " getting class or folder contents: " + e.getMessage());
                }
                throw new ManifoldCFException(
                        "Unknown http error occurred while getting class or folder contents: " + e.getMessage(),
                        e);
            }
            if (e.getFaultCode().equals(new javax.xml.namespace.QName(
                    "http://schemas.xmlsoap.org/soap/envelope/", "Server.userException"))) {
                String exceptionName = e.getFaultString();
                if (exceptionName.equals("java.lang.InterruptedException"))
                    throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED);
            }
            if (e.getFaultCode().equals(
                    new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) {
                if (e.getFaultString().indexOf(" 23031#") != -1) {
                    // This means that the session has expired, so reset it and retry
                    meridio_ = null;
                    continue;
                }
            }

            throw new ManifoldCFException(
                    "Meridio: Got an unknown remote exception getting class or folder contents - axis fault = "
                            + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString(),
                    e);
        } catch (RemoteException remoteException) {
            throw new ManifoldCFException("Meridio: A Remote Exception occurred while "
                    + "retrieving class or folder contents: " + remoteException.getMessage(), remoteException);
        } catch (MeridioDataSetException meridioDataSetException) {
            throw new ManifoldCFException("Meridio: A problem occurred manipulating the Web " + "Service XML: "
                    + meridioDataSetException.getMessage(), meridioDataSetException);
        }
    }
}

From source file:org.apache.manifoldcf.crawler.connectors.meridio.MeridioConnector.java

public String[] getMeridioDocumentProperties() throws ManifoldCFException, ServiceInterruption {
    Logging.connectors.debug("Entering 'getMeridioDocumentProperties' method");

    while (true) {
        getSession();/*from w  w w . j a va  2s.  c o m*/
        ArrayList meridioDocumentProperties = new ArrayList();

        try {
            CATEGORIES[] categories = meridio_.getCategories().getCATEGORIES();
            PROPERTYDEFS[] propertyDefs = meridio_.getStaticData().getPROPERTYDEFS();

            for (int i = 0; i < propertyDefs.length; i++) {
                if (propertyDefs[i].getTableName() == null) {
                    continue;
                }

                if (propertyDefs[i].getTableName().compareTo("DOCUMENTS") == 0) {
                    meridioDocumentProperties.add(propertyDefs[i].getDisplayName());
                }

                if ((propertyDefs[i].getCategoryId() == 4 || // Global Document Category
                        propertyDefs[i].getCategoryId() == 5 || // Mail Message
                        propertyDefs[i].getCategoryId() > 100) && // Custom Category
                        propertyDefs[i].getTableName().compareTo("DOCUMENT_CUSTOMPROPS") == 0) {
                    for (int j = 0; j < categories.length; j++) {
                        if (categories[j].getPROP_categoryId() == propertyDefs[i].getCategoryId()) {
                            meridioDocumentProperties.add(
                                    categories[j].getPROP_title() + "." + propertyDefs[i].getDisplayName());

                            Logging.connectors.debug("Prop: <" + categories[j].getPROP_title() + "."
                                    + propertyDefs[i].getDisplayName() + "> Column <"
                                    + propertyDefs[i].getColumnName() + ">");

                            break;
                        }
                    }
                }
            }

            String[] returnStringArray = new String[meridioDocumentProperties.size()];
            Iterator it = meridioDocumentProperties.iterator();
            for (int i = 0; it.hasNext(); i++) {
                returnStringArray[i] = (String) it.next();
            }

            java.util.Arrays.sort(returnStringArray);
            Logging.connectors.debug("Exiting 'getMeridioDocumentProperties' method");

            return returnStringArray;
        } catch (org.apache.axis.AxisFault e) {
            long currentTime = System.currentTimeMillis();
            if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) {
                org.w3c.dom.Element elem = e.lookupFaultDetail(
                        new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode"));
                if (elem != null) {
                    elem.normalize();
                    String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
                    throw new ManifoldCFException("Unexpected http error code " + httpErrorCode
                            + " getting document properties: " + e.getMessage());
                }
                throw new ManifoldCFException(
                        "Unknown http error occurred while getting document properties: " + e.getMessage(), e);
            }
            if (e.getFaultCode().equals(new javax.xml.namespace.QName(
                    "http://schemas.xmlsoap.org/soap/envelope/", "Server.userException"))) {
                String exceptionName = e.getFaultString();
                if (exceptionName.equals("java.lang.InterruptedException"))
                    throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED);
            }
            if (e.getFaultCode().equals(
                    new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/", "Server"))) {
                if (e.getFaultString().indexOf(" 23031#") != -1) {
                    // This means that the session has expired, so reset it and retry
                    meridio_ = null;
                    continue;
                }
            }

            throw new ManifoldCFException(
                    "Meridio: Got an unknown remote exception getting document properties - axis fault = "
                            + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString(),
                    e);
        } catch (RemoteException remoteException) {
            throw new ManifoldCFException(
                    "Meridio: A Remote Exception occurred while "
                            + "retrieving the Meridio document properties: " + remoteException.getMessage(),
                    remoteException);
        } catch (MeridioDataSetException meridioDataSetException) {
            throw new ManifoldCFException(
                    "Meridio: DataSet Exception occurred retrieving the Meridio document properties: "
                            + meridioDataSetException.getMessage(),
                    meridioDataSetException);
        }
    }
}

From source file:org.apache.manifoldcf.crawler.connectors.meridio.MeridioConnector.java

/** Set up the session with Meridio */
protected void getSession() throws ManifoldCFException, ServiceInterruption {
    if (meridio_ == null) {
        // Do the first part (which used to be in connect() itself)
        try {/* w  w  w.  j  a va2s .c  o m*/
            /*=================================================================
            * Construct the URL strings from the parameters
            *================================================================*/
            String DMWSProtocol = params.getParameter("DMWSServerProtocol");
            String DMWSPort = params.getParameter("DMWSServerPort");
            if (DMWSPort == null || DMWSPort.length() == 0)
                DMWSPort = "";
            else
                DMWSPort = ":" + DMWSPort;

            String Url = DMWSProtocol + "://" + params.getParameter("DMWSServerName") + DMWSPort
                    + params.getParameter("DMWSLocation");

            Logging.connectors.debug("Meridio: Document Management Web Service (DMWS) URL is [" + Url + "]");
            DmwsURL = new URL(Url);

            String RMWSProtocol = params.getParameter("RMWSServerProtocol");
            String RMWSPort = params.getParameter("RMWSServerPort");
            if (RMWSPort == null || RMWSPort.length() == 0)
                RMWSPort = "";
            else
                RMWSPort = ":" + RMWSPort;

            Url = RMWSProtocol + "://" + params.getParameter("RMWSServerName") + RMWSPort
                    + params.getParameter("RMWSLocation");

            Logging.connectors.debug("Meridio: Record Management Web Service (RMWS) URL is [" + Url + "]");
            RmwsURL = new URL(Url);

            // Set up ssl if indicated
            String keystoreData = params.getParameter("MeridioKeystore");

            if (keystoreData != null)
                mySSLFactory = KeystoreManagerFactory.make("", keystoreData).getSecureSocketFactory();
            else
                mySSLFactory = null;

            // Put together the url base
            String clientProtocol = params.getParameter("MeridioWebClientProtocol");
            String clientPort = params.getParameter("MeridioWebClientServerPort");
            if (clientPort == null || clientPort.length() == 0)
                clientPort = "";
            else
                clientPort = ":" + clientPort;
            urlVersionBase = clientProtocol + "://" + params.getParameter("MeridioWebClientServerName")
                    + clientPort + params.getParameter("MeridioWebClientDocDownloadLocation");
            urlBase = urlVersionBase + "?launchMode=1&launchAs=0&documentId=";

        } catch (MalformedURLException malformedURLException) {
            throw new ManifoldCFException(
                    "Meridio: Could not construct the URL for either " + "the DM or RM Meridio Web Service",
                    malformedURLException, ManifoldCFException.REPOSITORY_CONNECTION_ERROR);
        }

        // Do the second part (where we actually try to connect to the system)
        try {
            /*=================================================================
            * Now try and login to Meridio; the wrapper's constructor can be
            * used as it calls the Meridio login method
            *================================================================*/
            meridio_ = new MeridioWrapper(Logging.connectors, DmwsURL, RmwsURL, null,
                    params.getParameter("DMWSProxyHost"), params.getParameter("DMWSProxyPort"),
                    params.getParameter("RMWSProxyHost"), params.getParameter("RMWSProxyPort"), null,

                    null, params.getParameter("UserName"), params.getObfuscatedParameter("Password"),
                    InetAddress.getLocalHost().getHostName(), mySSLFactory,
                    org.apache.manifoldcf.connectorcommon.common.CommonsHTTPSender.class, "client-config.wsdd");
        } catch (NumberFormatException e) {
            throw new ManifoldCFException("Meridio: bad number: " + e.getMessage(), e);
        } catch (UnknownHostException unknownHostException) {
            throw new ManifoldCFException("Meridio: A Unknown Host Exception occurred while "
                    + "connecting - is a network software and hardware configuration: "
                    + unknownHostException.getMessage(), unknownHostException);
        } catch (org.apache.axis.AxisFault e) {
            long currentTime = System.currentTimeMillis();
            if (e.getFaultCode().equals(new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HTTP"))) {
                org.w3c.dom.Element elem = e.lookupFaultDetail(
                        new javax.xml.namespace.QName("http://xml.apache.org/axis/", "HttpErrorCode"));
                if (elem != null) {
                    elem.normalize();
                    String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
                    throw new ManifoldCFException("Unexpected http error code " + httpErrorCode
                            + " accessing Meridio: " + e.getMessage(), e);
                }
                throw new ManifoldCFException("Unknown http error occurred while connecting: " + e.getMessage(),
                        e);
            }
            if (e.getFaultCode().equals(new javax.xml.namespace.QName(
                    "http://schemas.xmlsoap.org/soap/envelope/", "Server.userException"))) {
                String exceptionName = e.getFaultString();
                if (exceptionName.equals("java.lang.InterruptedException"))
                    throw new ManifoldCFException("Interrupted", ManifoldCFException.INTERRUPTED);
            }
            if (Logging.connectors.isDebugEnabled())
                Logging.connectors.debug("Meridio: Got an unknown remote exception connecting - axis fault = "
                        + e.getFaultCode().getLocalPart() + ", detail = " + e.getFaultString() + " - retrying",
                        e);
            throw new ServiceInterruption("Remote procedure exception: " + e.getMessage(), e,
                    currentTime + 300000L, currentTime + 3 * 60 * 60000L, -1, false);
        } catch (RemoteException remoteException) {
            throw new ManifoldCFException("Meridio: An unknown remote exception occurred while "
                    + "connecting: " + remoteException.getMessage(), remoteException);
        }

    }
}

From source file:com.enonic.vertical.engine.handlers.MenuHandler.java

private void buildDocumentTypeXML(Element menuitemElem, Element documentElem) {

    if (documentElem != null) {
        if (verticalProperties.isStoreXHTMLOn()) {
            Node n = documentElem.getFirstChild();
            if (n != null && n.getNodeType() == Node.CDATA_SECTION_NODE) {
                int menuItemKey = Integer.parseInt(menuitemElem.getAttribute("key"));
                String menuItemName = XMLTool.getElementText(XMLTool.getElement(menuitemElem, "name"));
                Document doc = menuitemElem.getOwnerDocument();
                String docString = XMLTool.getElementText(documentElem);
                documentElem.removeChild(n);
                XMLTool.createXHTMLNodes(doc, documentElem, docString, true);
                String menuKey = menuitemElem.getAttribute("menukey");
                VerticalAdminLogger.error(this.getClass(), 0,
                        "Received invalid XML from database, menukey=" + menuKey + ", menuitem key="
                                + menuItemKey + ", name=" + menuItemName + ". Running Tidy..",
                        null);//from   w  w w.  j  ava 2s. co m
            }
            documentElem.setAttribute("mode", "xhtml");
        } else {
            Node n = documentElem.getFirstChild();
            if (n == null) {
                Document doc = menuitemElem.getOwnerDocument();
                XMLTool.createCDATASection(doc, menuitemElem, "Scratch document.");
            } else if (n.getNodeType() != Node.CDATA_SECTION_NODE) {
                Document doc = menuitemElem.getOwnerDocument();
                String docString = XMLTool.serialize(documentElem);
                XMLTool.createCDATASection(doc, documentElem, docString);
                VerticalEngineLogger.debug(this.getClass(), 0, "Expected CDATA, found XML. Serialized it.",
                        null);
            }
        }
    }
}

From source file:com.enonic.vertical.engine.handlers.MenuHandler.java

private void copyMenu(CopyContext copyContext, Element menuElem) throws VerticalCopyException,
        VerticalCreateException, VerticalUpdateException, VerticalSecurityException {

    if (menuElem != null) {
        User user = copyContext.getUser();
        int oldMenuKey = Integer.parseInt(menuElem.getAttribute("key"));

        //if (copyContext.getOldSiteKey() != copyContext.getNewSiteKey())
        //  menuElem.setAttribute("sitekey", String.valueOf(copyContext.getNewSiteKey()));
        //else {/*  w w w  .j  a  va2s .co  m*/
        Element nameElem = XMLTool.getElement(menuElem, "name");
        Text text = (Text) nameElem.getFirstChild();
        Map translationMap = languageMap.getTranslationMap(user.getSelectedLanguageCode());
        text.setData(text.getData() + " (" + translationMap.get("%txtCopy%") + ")");
        //}

        Element elem = XMLTool.getElement(menuElem, "firstpage");
        String oldFirstPageKey = elem.getAttribute("key");
        elem.removeAttribute("key");

        elem = XMLTool.getElement(menuElem, "loginpage");
        String oldLoginPageKey = elem.getAttribute("key");
        elem.removeAttribute("key");

        elem = XMLTool.getElement(menuElem, "errorpage");
        String oldErrorPageKey = elem.getAttribute("key");
        elem.removeAttribute("key");

        String oldDefaultPageTemplateKey = null;
        elem = XMLTool.getElement(menuElem, "defaultpagetemplate");
        if (elem != null) {
            oldDefaultPageTemplateKey = elem.getAttribute("pagetemplatekey");
            elem.removeAttribute("pagetemplatekey");
        }

        Document newDoc = XMLTool.createDocument();
        Element newMenuElem = (Element) newDoc.importNode(menuElem, true);
        newDoc.appendChild(newMenuElem);
        Element menuitemsElem = XMLTool.getElement(newMenuElem, "menuitems");
        newMenuElem.removeChild(menuitemsElem);
        SiteKey menuKey = createMenu(user, copyContext, newDoc, false);

        // copy content objects and page templates
        ContentObjectHandler contentObjectHandler = getContentObjectHandler();
        contentObjectHandler.copyContentObjects(oldMenuKey, copyContext);
        PageTemplateHandler pageTemplateHandler = getPageTemplateHandler();
        pageTemplateHandler.copyPageTemplates(oldMenuKey, copyContext);

        Document doc = getMenu(user, menuKey.toInt(), true, true);
        Element docElem = doc.getDocumentElement();
        newMenuElem = (Element) docElem.getFirstChild();
        doc.replaceChild(newMenuElem, docElem);
        Element newMenuitemsElem = (Element) doc.importNode(menuitemsElem, true);
        menuitemsElem = XMLTool.getElement(newMenuElem, "menuitems");
        newMenuElem.replaceChild(newMenuitemsElem, menuitemsElem);

        // prepare copy of menu items
        prepareCopy(newMenuitemsElem, copyContext);
        updateMenu(user, copyContext, doc, false);

        if (oldFirstPageKey != null && oldFirstPageKey.length() > 0) {
            elem = XMLTool.createElementIfNotPresent(doc, newMenuElem, "firstpage");
            elem.setAttribute("key",
                    String.valueOf(copyContext.getMenuItemKey(Integer.parseInt(oldFirstPageKey))));
        }

        if (oldLoginPageKey != null && oldLoginPageKey.length() > 0) {
            elem = XMLTool.createElementIfNotPresent(doc, newMenuElem, "loginpage");
            elem.setAttribute("key",
                    String.valueOf(copyContext.getMenuItemKey(Integer.parseInt(oldLoginPageKey))));
        }

        if (oldErrorPageKey != null && oldErrorPageKey.length() > 0) {
            elem = XMLTool.createElementIfNotPresent(doc, newMenuElem, "errorpage");
            elem.setAttribute("key",
                    String.valueOf(copyContext.getMenuItemKey(Integer.parseInt(oldErrorPageKey))));
        }

        if (oldDefaultPageTemplateKey != null && oldDefaultPageTemplateKey.length() > 0) {
            elem = XMLTool.createElement(doc, newMenuElem, "defaultpagetemplate");
            elem.setAttribute("pagetemplatekey", String
                    .valueOf(copyContext.getPageTemplateKey(Integer.parseInt(oldDefaultPageTemplateKey))));
        }

        if (copyContext.isIncludeContents()) {
            menuitemsElem = XMLTool.getElement(newMenuElem, "menuitems");
            prepareUpdate(menuitemsElem);
        }

        // update default css
        Element menudataElem = XMLTool.getElement(newMenuElem, "menudata");
        Element defaultcssElem = XMLTool.getElement(menudataElem, "defaultcss");
        if (defaultcssElem != null) {
            String cssKey = defaultcssElem.getAttribute("key");
            if (cssKey != null && cssKey.length() > 0) {
                defaultcssElem.setAttribute("key", cssKey);
            }
        }

        updateMenu(user, copyContext, doc, true);

        // post-process content objects and page templates
        contentObjectHandler.copyContentObjectsPostOp(oldMenuKey, copyContext);
        pageTemplateHandler.copyPageTemplatesPostOp(oldMenuKey, copyContext);
    }
}