コード例 #1
0
ファイル: khtmlreader.cpp プロジェクト: KDE/koffice
void KHTMLReader::completed()
{
    kDebug(30503) << "KHTMLReader::completed";
    qApp->exit_loop();
    DOM::Document doc = _html->document(); // FIXME parse <HEAD> too
    DOM::NodeList list = doc.getElementsByTagName("body");
    DOM::Node docbody = list.item(0);

    if (docbody.isNull()) {
        kWarning(30503) << "no <BODY>, giving up";
        _it_worked = false;
        return;
    }


    parseNode(docbody);

    list = doc.getElementsByTagName("head");
    DOM::Node dochead = list.item(0);
    if (!dochead.isNull())
        parse_head(dochead);
    else
        kWarning(30503) << "WARNING: no html <HEAD> section";

    _writer->cleanUpParagraph(state()->paragraph);
    _it_worked = _writer->writeDoc();
}
コード例 #2
0
ファイル: khtmlreader.cpp プロジェクト: KDE/koffice
void KHTMLReader::parseStyle(DOM::Element e)
{
    // styles are broken broken broken broken broken broken.
    // FIXME: use getComputedStyle - note: it only returns 0, but works nevertheless
    kDebug(30503) << "entering parseStyle";
    DOM::CSSStyleDeclaration s1 = e.style();
    DOM::Document doc = _html->document();
    DOM::CSSStyleDeclaration s2 = doc.defaultView().getComputedStyle(e, "");

    kDebug(30503) << "font-weight=" << s1.getPropertyValue("font-weight").string();
    if (s1.getPropertyValue("font-weight").string() == "bolder") {
        _writer->formatAttribute(state()->paragraph, "WEIGHT", "value", "75");
    }
    if (s1.getPropertyValue("font-weight").string() == "bold") {
        _writer->formatAttribute(state()->paragraph, "WEIGHT", "value", "75");
    }

    // process e.g. <style="color: #ffffff">
    if (! s1.getPropertyValue("color").string().isEmpty()) {
        QColor c = parsecolor(s1.getPropertyValue("color").string());
        _writer->formatAttribute(state()->paragraph, "COLOR", "red", QString::number(c.red()));
        _writer->formatAttribute(state()->paragraph, "COLOR", "green", QString::number(c.green()));
        _writer->formatAttribute(state()->paragraph, "COLOR", "blue", QString::number(c.blue()));
    } // done
    // process e.g. <style="font-size: 42">
    if (! s1.getPropertyValue("font-size").string().isEmpty()) {
        QString size = s1.getPropertyValue("font-size").string();
        if (size.endsWith("pt")) {
            size = size.left(size.length() - 2);
        }
        _writer->formatAttribute(state()->paragraph, "SIZE", "value", size);
    }
    // done
    // process e.g. <style="text-align: center">this is in the center</style>
    if (! s1.getPropertyValue("text-align").string().isEmpty()) {
        state()->layout = _writer->setLayout(state()->paragraph, state()->layout);
        _writer->layoutAttribute(state()->paragraph, "FLOW", "align", s1.getPropertyValue("text-align").string());
    }
    // done

    /*if (DOM::PROPV("font-weight") == "bolder")
    _writer->formatAttribute(state()->paragraph,"WEIGHT","value","75");
    */
    /*
         // debugging code.
         kDebug(30503) <<"e.style()";
         for (unsigned int i=0;i<s1.length();i++) {
            kDebug(30503) << QString("%1: %2").arg(s1.item(i).string()).arg(s1.getPropertyValue(s1.item(i)).string());
         }
         kDebug(30503) <<"override style";
         for (unsigned int i=0;i<s2.length();i++) {
            kDebug(30503) << QString("%1: %2").arg(s2.item(i).string()).arg(s2.getPropertyValue(s2.item(i)).string());
         }
    */
}
コード例 #3
0
ファイル: parse_helpers.cpp プロジェクト: artcom/watchdog
bool
readConfigFile(dom::Document & theConfigDoc,  std::string theFileName) {
    AC_DEBUG << "Loading configuration data..." ;

    std::string myFileName = asl::expandEnvironment(theFileName);
    AC_DEBUG <<"fileName: " << myFileName;
    if (myFileName.empty()) {
        AC_DEBUG << "Watchdog::readConfigFile: Can't open configuration file "
             << myFileName << "." << std::endl;
        return false;
    }

    std::string myFileStr = asl::readFile(myFileName);
    if (myFileStr.empty()) {
        AC_DEBUG << "Watchdog::readConfigFile: Can't open configuration file "
             << myFileName << "." << std::endl;
        return false;
    }
    theConfigDoc.parseAll(myFileStr.c_str());
    if (!theConfigDoc) {
        AC_DEBUG << "Watchdog:::readConfigFile: Error reading configuration file "
             << myFileName << "." << std::endl;
        return false;
    }
    return true;
}
コード例 #4
0
ファイル: domtreeview.cpp プロジェクト: blue-shell/folderview
void DOMTreeView::initializeStyleSheetsFromDocument(const DOM::Document &doc)
{
  styleSheetsTree->clear();
  styleSheetsTree->setEnabled(true);

  DOM::StyleSheetList sheets = doc.styleSheets();
  unsigned long l = sheets.length();
  for (unsigned long i = 0; i < l; ++i) {
    DOM::StyleSheet sheet = sheets.item(i);
    // some info about the sheet itself
    QString str = "type=\"" + sheet.type().string() + "\"";
    if (!sheet.href().isEmpty())
      str += " href=\"" + sheet.href().string() + "\"";
    if (!sheet.title().isEmpty())
      str += " title=\"" + sheet.title().string() + "\"";
    if (sheet.disabled())
      str += " disabled";
    QStringList strList = QStringList(str);
    QTreeWidgetItem *topLevel = new QTreeWidgetItem(strList);
    styleSheetsTree->addTopLevelItem(topLevel);

    // list the content
    DOM::CSSStyleSheet cssSheet(sheet);
    if (!cssSheet.isNull()) {
      DOM::CSSRuleList cssRules = cssSheet.cssRules();
      unsigned long numRules = cssRules.length();
      for (unsigned long r = 0; r < numRules; ++r) {
        DOM::CSSRule rule = cssRules.item(r);
        QString cssText = rule.cssText().string();
        (void)new QTreeWidgetItem(topLevel, QStringList(cssText));
      }
    }
  }
}
コード例 #5
0
ファイル: domtreeview.cpp プロジェクト: blue-shell/folderview
void DOMTreeView::initializeCSSInfoFromElement(const DOM::Element &element)
{
  DOM::Document doc = element.ownerDocument();
  DOM::AbstractView view = doc.defaultView();
  DOM::CSSStyleDeclaration styleDecl = view.getComputedStyle(element,
                                                             DOM::DOMString());

  unsigned long l = styleDecl.length();
  cssProperties->clear();
  cssProperties->setEnabled(true);
  QList<QTreeWidgetItem *> items;
  for (unsigned long i = 0; i < l; ++i) {
    DOM::DOMString name = styleDecl.item(i);
    DOM::DOMString value = styleDecl.getPropertyValue(name);

    QStringList values;
    values.append(name.string());
    values.append(value.string());
    items.append(new QTreeWidgetItem(static_cast<QTreeWidget*>(0), values));
  }

  cssProperties->insertTopLevelItems(0, items);
  cssProperties->resizeColumnToContents(0);
}
コード例 #6
0
bool
WatchDog::init(dom::Document & theConfigDoc, bool theRestartAppFlag) {
    _myRestartAppFlag = theRestartAppFlag;
    try {
        if (theConfigDoc("WatchdogConfig")) {
            const dom::NodePtr & myConfigNode = theConfigDoc.childNode("WatchdogConfig");

            // Setup logfile
            {
                _myLogFilename = asl::expandEnvironment(myConfigNode->getAttribute("logfile")->nodeValue());
                std::string::size_type myDotPos = _myLogFilename.rfind(".", _myLogFilename.size());
                if (myDotPos == std::string::npos) {
                    myDotPos = _myLogFilename.size();
                }
                asl::Time now;
                now.toLocalTime();
                static const char * myFormatString("%Y-%M-%D-%h-%m");
                std::ostringstream myTimeString;
                myTimeString << asl::formatTime(myFormatString) << now;
                _myLogFilename = _myLogFilename.substr(0, myDotPos) + "_" + myTimeString.str() + _myLogFilename.substr(myDotPos, _myLogFilename.size());
                _myLogger.openLogFile(_myLogFilename);
            }

            // Setup watch frequency
            {
                _myWatchFrequency = asl::as<int>(myConfigNode->getAttribute("watchFrequency")->nodeValue());
                AC_DEBUG << "_myWatchFrequency: " << _myWatchFrequency ;
                if (_myWatchFrequency < 1){
                    cerr <<"### ERROR: WatchFrequency must have a value greater then 0 sec." << endl;
                    return false;
                }
            }
            
            // check for additional startup command
            if (myConfigNode->childNode("PreStartupCommand")) {
                _myStartupCommand = asl::expandEnvironment((*myConfigNode->childNode("PreStartupCommand")).firstChild()->nodeValue());
                AC_DEBUG << "_myStartupCommand: " << _myStartupCommand;
            }

            // check for application pre launch command
            if (myConfigNode->childNode("PreAppLaunchCommand")) {
                _myPreApplicationLaunchCommand = asl::expandEnvironment((*myConfigNode->childNode("PreAppLaunchCommand")).firstChild()->nodeValue());
                AC_DEBUG << "_myPreApplicationLaunchCommand: " << _myPreApplicationLaunchCommand;
            }

            // check for application post launch command
            if (myConfigNode->childNode("PostAppLaunchCommand")) {
                _myPostApplicationLaunchCommand = asl::expandEnvironment((*myConfigNode->childNode("PostAppLaunchCommand")).firstChild()->nodeValue());
                AC_DEBUG << "_myPostApplicationLaunchCommand: " << _myPostApplicationLaunchCommand;
            }
            
            // check for additional shutdown command
            if (myConfigNode->childNode("PreShutdownCommand")) {
                _myShutdownCommand = asl::expandEnvironment((*myConfigNode->childNode("PreShutdownCommand")).firstChild()->nodeValue());
                AC_DEBUG << "_myShutdownCommand: " << _myShutdownCommand;
            }

            // check for application terminate command
            if (myConfigNode->childNode("AppTerminateCommand")) {
                if (myConfigNode->childNode("AppTerminateCommand")->getAttribute("ignoreOnUdpRestart")) {
                    _myIgnoreTerminateCmdOnUdpCmd = asl::as<bool>(myConfigNode->childNode("AppTerminateCommand")->getAttribute("ignoreOnUdpRestart")->nodeValue());
                }
                _myApplicationTerminatedCommand = asl::expandEnvironment((*myConfigNode->childNode("AppTerminateCommand")).firstChild()->nodeValue());
                AC_DEBUG << "_myApplicationTerminatedCommand: " << _myApplicationTerminatedCommand;
            }

            
            // check for application pre terminate command
            if (myConfigNode->childNode("AppPreTerminateCommand")) {
                _myApplicationPreTerminateCommand = asl::expandEnvironment((*myConfigNode->childNode("AppPreTerminateCommand")).firstChild()->nodeValue());
                AC_DEBUG << "_myApplicationPreTerminateCommand: " << _myApplicationPreTerminateCommand;
            }


            // Setup UDP control
            if (myConfigNode->childNode("UdpControl")) {
                const dom::NodePtr & myUdpControlNode = myConfigNode->childNode("UdpControl");
                _myUDPCommandListenerThread = new UDPCommandListenerThread(_myAppToWatch,
                                                        myUdpControlNode, _myLogger, _myShutdownCommand);

                if (myUdpControlNode->childNode("ContinuousStatusChangeReport")) {
                    const dom::NodePtr & myContinuousStatusChangeNode = myUdpControlNode->childNode("ContinuousStatusChangeReport");
                    const dom::NodePtr & myIPAttribute = myContinuousStatusChangeNode->getAttribute("ip");
                    if (myIPAttribute) {
                        _myContinuousStateChangeIP = myIPAttribute->nodeValue();
                    }
                    const dom::NodePtr & myPortAttribute = myContinuousStatusChangeNode->getAttribute("port");
                    if (myPortAttribute) {
                        _myContinuousStateChangePort = asl::as<int>(myPortAttribute->nodeValue());
                    }
                    if (_myContinuousStateChangeIP != "" && _myContinuousStateChangePort != -1) {
                        AC_INFO << "Continuous state change will will be send to IP: '" << _myContinuousStateChangeIP << "' port :" << _myContinuousStateChangePort;
                    }
                }

            }

            // check for system reboot time command configuration
            if (myConfigNode->childNode("RebootTime")) {
                std::string myRebootTime = (*myConfigNode->childNode("RebootTime"))("#text").nodeValue();
                std::string myHours = myRebootTime.substr(0, myRebootTime.find_first_of(':'));
                std::string myMinutes = myRebootTime.substr(myRebootTime.find_first_of(':')+1, myRebootTime.length());
                _myRebootTimeInSecondsToday = asl::as<int>(myHours) * 3600;
                _myRebootTimeInSecondsToday += asl::as<int>(myMinutes) * 60;
                AC_DEBUG <<"_myRebootTimeInSecondsToday : " << _myRebootTimeInSecondsToday;
            }

            // check for system halt time command configuration
            if (myConfigNode->childNode("HaltTime")) {
                std::string myHaltTime = (*myConfigNode->childNode("HaltTime"))("#text").nodeValue();
                std::string myHours = myHaltTime.substr(0, myHaltTime.find_first_of(':'));
                std::string myMinutes = myHaltTime.substr(myHaltTime.find_first_of(':')+1, myHaltTime.length());
                _myHaltTimeInSecondsToday = asl::as<int>(myHours) * 3600;
                _myHaltTimeInSecondsToday += asl::as<int>(myMinutes) * 60;
                AC_DEBUG <<"_myHaltTimeInSecondsToday : " << _myHaltTimeInSecondsToday;
            }
            
            // Setup application
            if (myConfigNode->childNode("Application")) {
                const dom::NodePtr & myApplicationNode = myConfigNode->childNode("Application");

                if (!_myAppToWatch.setup(myApplicationNode)) {
                    return false;
                }
            } else if (myConfigNode->childNode("SwitchableApplications")) {
                const dom::NodePtr & mySwitchableApplicationsNode = myConfigNode->childNode("SwitchableApplications");

                std::string myDirectory = mySwitchableApplicationsNode->getAttribute("directory")->nodeValue();
                std::string myInitialApplication = mySwitchableApplicationsNode->getAttribute("initial")->nodeValue();

                dom::Document myApplicationConfigDoc;
                bool ok = readConfigFile(myApplicationConfigDoc, myDirectory + "/" + myInitialApplication + ".xml");
                if (!ok) {
                    AC_WARNING << "configuration file for id '" << myInitialApplication << "' could not be opened.";
                    return false;
                }

                if (!myApplicationConfigDoc("Application")) {
                    AC_WARNING << "application xml has no Application-node";
                    return false;
                }
                const dom::NodePtr & myApplicationNode = myApplicationConfigDoc.childNode("Application");

                if (!_myAppToWatch.setup(myApplicationNode, myDirectory)) {
                    return false;
                }
            } else {
                AC_WARNING << "xml document should have either Application or SwitchableApplications node";
            }
        }

    } catch (const asl::Exception & ex) {
        cerr << "### Exception: " << ex;
    } catch (...) {
        cerr << "Error, while parsing xml config file" << endl;
        exit(-1);
    }
    return true;
}
コード例 #7
0
 explicit DocumentEvent(const DOM::Document<stringT, string_adaptorT>& rhs) : proxy_t(rhs.dImpl())
 {
   if(dynamic_cast<DocumentEvent_implT*>(rhs.dImpl()) == 0)
     throw DOM::DOMException(DOM::DOMException::NOT_SUPPORTED_ERR); 
 } // DocumentEvent